Skip to content

Commit 4924757

Browse files
telpirionShabirmean
authored andcommitted
fix(samples): adds retry to TranslateCreateDatasetTest (#513)
* fix(samples): adds retry to TranslateCreateDatasetTest
1 parent ccc966b commit 4924757

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

automl/snippets/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@
6868
<version>1.1.2</version>
6969
<scope>test</scope>
7070
</dependency>
71+
<dependency>
72+
<groupId>com.google.cloud</groupId>
73+
<artifactId>google-cloud-core</artifactId>
74+
<version>1.94.0</version>
75+
<scope>test</scope>
76+
<classifier>tests</classifier>
77+
</dependency>
7178
<!-- [END_EXCLUDE] -->
7279
</dependencies>
7380
<!-- [END automl_install_with_bom] -->

automl/snippets/src/test/java/com/example/automl/TranslateCreateDatasetTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.common.truth.Truth.assertThat;
2020
import static junit.framework.TestCase.assertNotNull;
2121

22+
import com.google.cloud.testing.junit4.MultipleAttemptsRule;
2223
import java.io.ByteArrayOutputStream;
2324
import java.io.IOException;
2425
import java.io.PrintStream;
@@ -27,6 +28,7 @@
2728
import org.junit.After;
2829
import org.junit.Before;
2930
import org.junit.BeforeClass;
31+
import org.junit.Rule;
3032
import org.junit.Test;
3133
import org.junit.runner.RunWith;
3234
import org.junit.runners.JUnit4;
@@ -39,7 +41,7 @@ public class TranslateCreateDatasetTest {
3941
private ByteArrayOutputStream bout;
4042
private PrintStream out;
4143
private PrintStream originalPrintStream;
42-
private String datasetId;
44+
private String got;
4345

4446
private static void requireEnvVar(String varName) {
4547
assertNotNull(
@@ -63,11 +65,15 @@ public void setUp() {
6365

6466
@After
6567
public void tearDown() throws InterruptedException, ExecutionException, IOException {
68+
String datasetId = got.split("Dataset id: ")[1].split("\n")[0];
69+
6670
// Delete the created dataset
6771
DeleteDataset.deleteDataset(PROJECT_ID, datasetId);
6872
System.setOut(originalPrintStream);
6973
}
7074

75+
@Rule public MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3);
76+
7177
@Test
7278
public void testCreateDataset() throws IOException, ExecutionException, InterruptedException {
7379
// Create a random dataset name with a length of 32 characters (max allowed by AutoML)
@@ -77,8 +83,7 @@ public void testCreateDataset() throws IOException, ExecutionException, Interrup
7783
String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26));
7884
TranslateCreateDataset.createDataset(PROJECT_ID, datasetName);
7985

80-
String got = bout.toString();
86+
got = bout.toString();
8187
assertThat(got).contains("Dataset id:");
82-
datasetId = got.split("Dataset id: ")[1].split("\n")[0];
8388
}
8489
}

0 commit comments

Comments
 (0)