Skip to content

Commit e72328b

Browse files
samples(testing): add retry rule (#565)
* samples(testing): add retry rule * use google-cloud-core's MultipleAttemptsRule
1 parent 0aa4521 commit e72328b

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

samples/install-without-bom/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
<artifactId>protobuf-java-util</artifactId>
7878
<version>3.15.3</version>
7979
</dependency>
80+
<dependency>
81+
<groupId>com.google.cloud</groupId>
82+
<artifactId>google-cloud-core</artifactId>
83+
<version>1.94.1</version>
84+
<classifier>tests</classifier>
85+
</dependency>
8086
</dependencies>
8187

8288
<!-- compile and run all snippet tests -->

samples/snapshot/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@
7676
<version>1.1.2</version>
7777
<scope>test</scope>
7878
</dependency>
79+
<dependency>
80+
<groupId>com.google.cloud</groupId>
81+
<artifactId>google-cloud-core</artifactId>
82+
<version>1.94.1</version>
83+
<classifier>tests</classifier>
84+
</dependency>
7985
</dependencies>
8086

8187
<!-- compile and run all snippet tests -->

samples/snippets/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@
8787
<version>1.1.2</version>
8888
<scope>test</scope>
8989
</dependency>
90+
<dependency>
91+
<groupId>com.google.cloud</groupId>
92+
<artifactId>google-cloud-core</artifactId>
93+
<version>1.94.1</version>
94+
<classifier>tests</classifier>
95+
</dependency>
9096
<!-- [END_EXCLUDE] -->
9197
</dependencies>
9298
<!-- [END pubsub_install_with_bom] -->

samples/snippets/src/main/java/utilities/State.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323
/**
2424
* This file is created using Avro tools.
2525
*
26-
* To download, visit https://avro.apache.org/releases.html#Download
26+
* <p>To download, visit https://avro.apache.org/releases.html#Download
2727
*
28-
* Run the following command from the `samples/snippets` directory to
29-
* generate this class:
28+
* <p>Run the following command from the `samples/snippets` directory to generate this class:
3029
*
31-
*`java -jar /location/to/your/avro-tools-1.10.1.jar compile schema src/main/resources/us-states.avsc src/main/java/`
30+
* <p>`java -jar /location/to/your/avro-tools-1.10.1.jar compile schema
31+
* src/main/resources/us-states.avsc src/main/java/`
3232
*/
33-
3433
package utilities;
3534

3635
import org.apache.avro.message.BinaryMessageDecoder;

samples/snippets/src/main/java/utilities/StateProto.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
/**
2121
* This file is created using protoc.
2222
*
23-
* To download, visit https://developers.google.com/protocol-buffers/docs/downloads
23+
* <p>To download, visit https://developers.google.com/protocol-buffers/docs/downloads
2424
*
25-
* Run the following command from the `samples/snippets` directory to
26-
* generate this class:
25+
* <p>Run the following command from the `samples/snippets` directory to generate this class:
2726
*
28-
*`protoc --proto_path=src/main/resources/ --java_out=src/main/java/ src/main/resources/us-states.proto`
27+
* <p>`protoc --proto_path=src/main/resources/ --java_out=src/main/java/
28+
* src/main/resources/us-states.proto`
2929
*/
30-
3130
package utilities;
3231

3332
public final class StateProto {

samples/snippets/src/test/java/pubsub/SchemaIT.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.cloud.pubsub.v1.SchemaServiceClient;
2424
import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
2525
import com.google.cloud.pubsub.v1.TopicAdminClient;
26+
import com.google.cloud.testing.junit4.MultipleAttemptsRule;
2627
import com.google.pubsub.v1.Encoding;
2728
import com.google.pubsub.v1.ProjectSubscriptionName;
2829
import com.google.pubsub.v1.SchemaName;
@@ -33,7 +34,6 @@
3334
import java.util.UUID;
3435
import org.junit.After;
3536
import org.junit.Before;
36-
import org.junit.BeforeClass;
3737
import org.junit.Rule;
3838
import org.junit.Test;
3939
import org.junit.rules.Timeout;
@@ -73,12 +73,8 @@ private static void requireEnvVar(String varName) {
7373
System.getenv(varName));
7474
}
7575

76-
@Rule public Timeout globalTimeout = Timeout.seconds(300); // 5 minute timeout
77-
78-
@BeforeClass
79-
public static void checkRequirements() {
80-
requireEnvVar("GOOGLE_CLOUD_PROJECT");
81-
}
76+
@Rule public Timeout globalTimeout = Timeout.seconds(600); // 10 minute timeout
77+
@Rule public MultipleAttemptsRule retryRule = new MultipleAttemptsRule(/*maxAttemptCount=*/ 3);
8278

8379
@Before
8480
public void setUp() {

0 commit comments

Comments
 (0)