-
Notifications
You must be signed in to change notification settings - Fork 693
Test support module #2357
base: main
Are you sure you want to change the base?
Test support module #2357
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.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why though? Sincerely curious; this seems like a reasonable case for inheritance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't do religious wars.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's the same as tabs vs spaces? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be -Dit.pubsub-emulator
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we deprecate GcpPubSubEmulatorAutoConfiguration
and move it to the test module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like implementation details to me. @meltsufin what do you think?
@@ -104,6 +105,7 @@ public TradeRepositoryTransactionalService tradeRepositoryTransactionalService() | |||
} | |||
|
|||
@Bean | |||
@ConditionalOnMissingBean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/THe/the
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
…ud-gcp into spanner-emulator
SonarCloud Quality Gate failed. 0 Bugs |
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