-
Notifications
You must be signed in to change notification settings - Fork 693
pubsub emulator rule moved to a separate project #2352
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>spring-cloud-gcp</artifactId> | ||
<groupId>org.springframework.cloud</groupId> | ||
<version>1.2.3.BUILD-SNAPSHOT</version> | ||
</parent> | ||
|
||
|
||
<artifactId>spring-cloud-gcp-test</artifactId> | ||
<name>Spring Cloud GCP Test Support</name> | ||
<description>Provides tools for testing Spring Cloud GCP projects</description> | ||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-jcl</artifactId> | ||
<scope>compile</scope> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compile scope is the default, you don't have to specify it. |
||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,7 +14,7 @@ | |||||
* limitations under the License. | ||||||
*/ | ||||||
|
||||||
package org.springframework.cloud.gcp.stream.binder.pubsub; | ||||||
package org.springframework.cloud.gcp.test; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
import java.io.BufferedReader; | ||||||
import java.io.IOException; | ||||||
|
@@ -33,11 +33,10 @@ | |||||
|
||||||
import org.apache.commons.logging.Log; | ||||||
import org.apache.commons.logging.LogFactory; | ||||||
import org.junit.Assert; | ||||||
import org.junit.Assume; | ||||||
import org.junit.rules.ExternalResource; | ||||||
|
||||||
import static org.junit.Assert.fail; | ||||||
import static org.junit.Assume.assumeTrue; | ||||||
|
||||||
/** | ||||||
* Rule for instantiating and tearing down a Pub/Sub emulator instance. | ||||||
* | ||||||
|
@@ -87,7 +86,7 @@ public PubSubEmulator() { | |||||
@Override | ||||||
protected void before() throws IOException, InterruptedException { | ||||||
|
||||||
assumeTrue("PubSubEmulator rule disabled. Please enable with -Dit.pubsub-emulator.", this.enableTests); | ||||||
Assume.assumeTrue("PubSubEmulator rule disabled. Please enable with -Dit.pubsub-emulator.", this.enableTests); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that enabling it with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's an interesting question then to test whether the rule initialization or a test's If there is possibility of the rule running first, perhaps we can just document this flag well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can also try not to implement JUnit test rule. |
||||||
|
||||||
startEmulator(); | ||||||
determineHostPort(); | ||||||
|
@@ -178,7 +177,7 @@ private void startEmulator() throws IOException, InterruptedException { | |||||
.start(); | ||||||
} | ||||||
catch (IOException ex) { | ||||||
fail("Gcloud not found; leaving host/port uninitialized."); | ||||||
Assert.fail("Gcloud not found; leaving host/port uninitialized."); | ||||||
} | ||||||
|
||||||
if (configPresent) { | ||||||
|
@@ -188,7 +187,6 @@ private void startEmulator() throws IOException, InterruptedException { | |||||
else { | ||||||
createConfig(); | ||||||
} | ||||||
|
||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -214,12 +212,12 @@ private void determineHostPort() throws IOException, InterruptedException { | |||||
* to fail the test. | ||||||
*/ | ||||||
private void createConfig() throws InterruptedException { | ||||||
int attempts = 10; | ||||||
int attempts = 100; | ||||||
while (!Files.exists(EMULATOR_CONFIG_PATH) && --attempts >= 0) { | ||||||
Thread.sleep(1000); | ||||||
} | ||||||
if (attempts < 0) { | ||||||
fail( | ||||||
Assert.fail( | ||||||
"Emulator could not be configured due to missing env.yaml. Are PubSub and beta tools installed?"); | ||||||
} | ||||||
} | ||||||
|
@@ -234,7 +232,7 @@ private void createConfig() throws InterruptedException { | |||||
private void updateConfig(WatchService watchService) throws InterruptedException { | ||||||
int attempts = 10; | ||||||
while (--attempts >= 0) { | ||||||
WatchKey key = watchService.poll(100, TimeUnit.MILLISECONDS); | ||||||
WatchKey key = watchService.poll(1, TimeUnit.SECONDS); | ||||||
|
||||||
if (key != null) { | ||||||
Optional<Path> configFilePath = key.pollEvents().stream() | ||||||
|
@@ -247,7 +245,7 @@ private void updateConfig(WatchService watchService) throws InterruptedException | |||||
} | ||||||
} | ||||||
|
||||||
fail("Configuration file update could not be detected"); | ||||||
Assert.fail("Configuration file update could not be detected"); | ||||||
} | ||||||
|
||||||
/** | ||||||
|
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.
test
scope?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 in this case -- the test project itself is meant to be imported as test scope, but the rule extends a JUnit class, so it needs to be compile, not test scope.
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 wonder if we should consider making these utilities independent of JUnit. People use different test frameworks.
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.
make it generic so people can reuse it sounds good. Can you take into account that may some people will be able to contribute creating rules for junit4 or extension for junit5 specifically? Those can be issues with
ideal for contribution
orhelp wanted
. WDYT?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.
That a good idea! We should do that.