Skip to content

Commit 0a2851e

Browse files
configure method parallelism for slow tests
1 parent 9faac07 commit 0a2851e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

samples/snippets/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@
159159
<configuration>
160160
<forkCount>10</forkCount>
161161
<reuseForks>false</reuseForks>
162+
<parallel>classesAndMethods</parallel>
163+
<threadCount>5</threadCount>
164+
<threadCountClasses>2</threadCountClasses>
165+
<threadCountMethods>3</threadCountMethods>
162166
<systemPropertyVariables>
163167
<spanner.test.instance>java-sample-integration-tests</spanner.test.instance>
164168
<spanner.test.instance.mr>java-client-mr-integration-tests</spanner.test.instance.mr>

samples/snippets/src/test/java/com/example/spanner/SpannerSampleIT.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.io.ByteArrayOutputStream;
4444
import java.io.IOException;
4545
import java.io.PrintStream;
46+
import java.time.Duration;
4647
import java.util.UUID;
4748
import java.util.concurrent.TimeUnit;
4849
import java.util.function.Predicate;
@@ -590,6 +591,7 @@ public void testEncryptedDatabaseAndBackupSamples() throws Exception {
590591
} finally {
591592
// Delete the backups from the test instance first, as the instance can only be deleted once
592593
// all backups have been deleted.
594+
Uninterruptibles.sleepUninterruptibly(Duration.ofMinutes(1));
593595
System.out.println("Deleting backups ...");
594596
deleteAllBackups(instanceId);
595597
instanceAdminClient.deleteInstance(instanceId);
@@ -752,15 +754,21 @@ static String formatForTest(String name) {
752754

753755
static class ShouldRetryBackupOperation implements Predicate<SpannerException> {
754756

755-
private static final int MAX_ATTEMPTS = 20;
757+
private int maxAttempts = 20;
756758
private int attempts = 0;
757759

760+
ShouldRetryBackupOperation() {}
761+
762+
ShouldRetryBackupOperation(int maxAttempts) {
763+
this.maxAttempts = maxAttempts;
764+
}
765+
758766
@Override
759767
public boolean test(SpannerException e) {
760768
if (e.getErrorCode() == ErrorCode.FAILED_PRECONDITION
761769
&& e.getMessage().contains("Please retry the operation once the pending")) {
762770
attempts++;
763-
if (attempts == MAX_ATTEMPTS) {
771+
if (attempts == maxAttempts) {
764772
// Throw custom exception so it is easier to locate in the log why it went wrong.
765773
throw SpannerExceptionFactory.newSpannerException(
766774
ErrorCode.DEADLINE_EXCEEDED,
@@ -770,6 +778,7 @@ public boolean test(SpannerException e) {
770778
attempts),
771779
e);
772780
}
781+
System.out.println("Attempt " + attempts);
773782
// Wait one minute before retrying.
774783
Uninterruptibles.sleepUninterruptibly(60L, TimeUnit.SECONDS);
775784
return true;

0 commit comments

Comments
 (0)