Skip to content
Permalink
Browse files
fix(samples): adds retry to TranslateCreateDatasetTest (#513)
* fix(samples): adds retry to TranslateCreateDatasetTest
  • Loading branch information
telpirion committed Mar 25, 2021
1 parent dbd9cf0 commit 762dd2f4dae77f93d59bd82dbfa4f4a896d71dfa
@@ -60,6 +60,13 @@
<version>1.1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-core</artifactId>
<version>1.94.0</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
</dependencies>

<!-- compile and run all snippet tests -->
@@ -59,6 +59,13 @@
<version>1.1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-core</artifactId>
<version>1.94.0</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
</dependencies>

<!-- compile and run all snippet tests -->
@@ -68,6 +68,13 @@
<version>1.1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-core</artifactId>
<version>1.94.0</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
<!-- [END_EXCLUDE] -->
</dependencies>
<!-- [END automl_install_with_bom] -->
@@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.TestCase.assertNotNull;

import com.google.cloud.testing.junit4.MultipleAttemptsRule;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
@@ -27,6 +28,7 @@
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -39,7 +41,7 @@ public class TranslateCreateDatasetTest {
private ByteArrayOutputStream bout;
private PrintStream out;
private PrintStream originalPrintStream;
private String datasetId;
private String got;

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

@After
public void tearDown() throws InterruptedException, ExecutionException, IOException {
String datasetId = got.split("Dataset id: ")[1].split("\n")[0];

// Delete the created dataset
DeleteDataset.deleteDataset(PROJECT_ID, datasetId);
System.setOut(originalPrintStream);
}

@Rule public MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3);

@Test
public void testCreateDataset() throws IOException, ExecutionException, InterruptedException {
// 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
String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26));
TranslateCreateDataset.createDataset(PROJECT_ID, datasetName);

String got = bout.toString();
got = bout.toString();
assertThat(got).contains("Dataset id:");
datasetId = got.split("Dataset id: ")[1].split("\n")[0];
}
}

0 comments on commit 762dd2f

Please sign in to comment.