Conversation
Codecov Report
@@ Coverage Diff @@
## master #2357 +/- ##
============================================
- Coverage 81.10% 73.35% -7.76%
+ Complexity 2315 2124 -191
============================================
Files 259 267 +8
Lines 7563 7750 +187
Branches 785 797 +12
============================================
- Hits 6134 5685 -449
- Misses 1103 1693 +590
- Partials 326 372 +46
Continue to review full report at Codecov.
|
meltsufin
left a comment
There was a problem hiding this comment.
Please try to address the Sonar findings where it makes sense.
| import org.apache.commons.logging.Log; | ||
| import org.apache.commons.logging.LogFactory; | ||
|
|
||
| public class PubSubEmulatorHelper extends AbstractEmulatorHelper { |
There was a problem hiding this comment.
Can we please refactor this not to use inheritance?
You can try turning all of the abstract methods of AbstractEmulatorHelper into an interface that each emulator would implement and then a final EmulatorHelper can be customized by.
Alternatively, you can make EmulatorHelper a generic helper that any implementation of an emulator can re-use.
There was a problem hiding this comment.
Why though? Sincerely curious; this seems like a reasonable case for inheritance.
There was a problem hiding this comment.
I'm sure if you search for "inheritance is evil", lots of reasons will pop up.
From Effective Java 3rd edition:
See:
Item 18: Favor composition over inheritance
Item 19: Design and document for inheritance or else prohibit it
Item 20: Prefer interfaces to abstract classes
There was a problem hiding this comment.
I don't do religious wars.
There was a problem hiding this comment.
Do you think it's the same as tabs vs spaces? 😄
There was a problem hiding this comment.
Yep. Each side can be justified with rational arguments, and yet, the disagreement lives on. We'll have to do a PR converting Spring tabs into Google spaces soon...
| @@ -0,0 +1,48 @@ | |||
| /* | |||
| * Copyright 2017-2018 the original author or authors. | |||
There was a problem hiding this comment.
update copyright's year
| public class PubSubEmulatorHelper extends AbstractEmulatorHelper { | ||
| private static final Log LOGGER = LogFactory.getLog(PubSubEmulatorHelper.class); | ||
|
|
||
| String getGatingPropertyName() { |
There was a problem hiding this comment.
not sure if this should be provided
|
|
||
| @BeforeClass | ||
| public static void enableTests() { | ||
| Assumptions.assumeThat(System.getProperty("it.emulator")) |
There was a problem hiding this comment.
It should be -Dit.pubsub-emulator.
There was a problem hiding this comment.
Let's keep it like this until we update Travis CI configuration. Otherwise CI would fail.
| import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
| import org.springframework.cloud.gcp.autoconfigure.core.GcpContextAutoConfiguration; | ||
| import org.springframework.cloud.gcp.autoconfigure.pubsub.GcpPubSubAutoConfiguration; | ||
| import org.springframework.cloud.gcp.autoconfigure.pubsub.GcpPubSubEmulatorAutoConfiguration; |
There was a problem hiding this comment.
Should we deprecate GcpPubSubEmulatorAutoConfiguration and move it to the test module?
There was a problem hiding this comment.
We should still support the manual path where someone starts an emulator themselves, and then runs an application relying on our pubsub starter, providing an emulator property.
| } | ||
|
|
||
| @Test | ||
| public void testCreatePublishPullNextAndDelete() { |
There was a problem hiding this comment.
How are you verifying that it's actually the emulator that you are using vs. the real service?
Maybe check the host or something?
There was a problem hiding this comment.
It's done inside the context below -- assertThat(transportChannelProvider.getTransportChannel().toString()).contains("target=dns:///localhost:8085");
|
|
||
| @BeforeClass | ||
| public static void checkToRun() { | ||
| Assumptions.assumeThat(System.getProperty("it.emulator")) |
There was a problem hiding this comment.
It should be -Dit.spanner-emulator.
Also, can we update Travis CI config to actually run this test? What would it take?
There was a problem hiding this comment.
We already install gcloud, so installing emulators would be more of the same. Can be a follow up PR to update Travis config -- Dmitry wanted to add it right away, but I remember how annoying testing travis config is (multiple tries, the only way to test is by committing), so I asked for a separate minimal Travis config PR.
| @Configuration | ||
| @EnableTransactionManagement | ||
| @EnableSpannerRepositories | ||
| public class SpannerTestConfiguration { |
There was a problem hiding this comment.
Can we make it an auto-configuration like we have for Pub/Sub?
I imagine some folks will want to use the emulator to test the whole application, rather than just run the tests.
There was a problem hiding this comment.
Eddú did that in #2356, but we've created this PR before that. Perhaps a follow-up PR to switch over to official configuration?
Co-authored-by: Mike Eltsufin <meltsufin@google.com>
elefeint
left a comment
There was a problem hiding this comment.
This turned out really well!
I wonder if we should create a package for "emulators", since we may want to add non-emulator test support in the future. But this can be done in the new repo.
| } | ||
| ---- | ||
|
|
||
| NOTE: The class rule doesn't work for `SpannerEmulator`. |
There was a problem hiding this comment.
Should we mention the workaround of setting up a custom Spanner bean and setting its destroy method to ""?
There was a problem hiding this comment.
It looks like implementation details to me. @meltsufin what do you think?
| } | ||
|
|
||
| @Bean | ||
| @ConditionalOnMissingBean |
There was a problem hiding this comment.
Wait, remove the bean definitions entirely? There are several integration tests that go against real spanner.
spring-cloud-gcp-test/pom.xml
Outdated
|
|
||
| <dependency> | ||
| <groupId>org.springframework</groupId> | ||
| <artifactId>spring-jcl</artifactId> |
There was a problem hiding this comment.
Should this be optional, too? And move under the Spring Dependencies comment?
|
|
||
| /** | ||
| * The list of command fragments that match the emulator processes to be killed. | ||
| * @param hostPort THe emulator host-port. |
spring-cloud-gcp-test/src/main/java/org/springframework/cloud/gcp/test/Emulator.java
Show resolved
Hide resolved
...main/java/org/springframework/cloud/gcp/test/spanner/SpannerEmulatorSpringConfiguration.java
Show resolved
Hide resolved
| import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
| import org.springframework.cloud.gcp.autoconfigure.core.GcpContextAutoConfiguration; | ||
| import org.springframework.cloud.gcp.autoconfigure.pubsub.GcpPubSubAutoConfiguration; | ||
| import org.springframework.cloud.gcp.autoconfigure.pubsub.GcpPubSubEmulatorAutoConfiguration; |
There was a problem hiding this comment.
We should still support the manual path where someone starts an emulator themselves, and then runs an application relying on our pubsub starter, providing an emulator property.
| } | ||
|
|
||
| @Test | ||
| public void testCreatePublishPullNextAndDelete() { |
There was a problem hiding this comment.
It's done inside the context below -- assertThat(transportChannelProvider.getTransportChannel().toString()).contains("target=dns:///localhost:8085");
|
|
||
| @BeforeClass | ||
| public static void checkToRun() { | ||
| Assumptions.assumeThat(System.getProperty("it.emulator")) |
There was a problem hiding this comment.
We already install gcloud, so installing emulators would be more of the same. Can be a follow up PR to update Travis config -- Dmitry wanted to add it right away, but I remember how annoying testing travis config is (multiple tries, the only way to test is by committing), so I asked for a separate minimal Travis config PR.
| @Configuration | ||
| @EnableTransactionManagement | ||
| @EnableSpannerRepositories | ||
| public class SpannerTestConfiguration { |
There was a problem hiding this comment.
Eddú did that in #2356, but we've created this PR before that. Perhaps a follow-up PR to switch over to official configuration?
Co-authored-by: Elena Felder <41136058+elefeint@users.noreply.github.com>
…ud-gcp into spanner-emulator
|
SonarCloud Quality Gate failed.
|
|
awaiting for redesign |
|
Converted PR to draft while we wait. |
Add test module and introduce spanner emulator helper tools.
fixes #2318 fixes #2351
cc/ @elefeint