Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
fix(samples): adds retry to TranslateCreateDatasetTest (#513)
Browse files Browse the repository at this point in the history
* fix(samples): adds retry to TranslateCreateDatasetTest
  • Loading branch information
telpirion committed Mar 25, 2021
1 parent dbd9cf0 commit 762dd2f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
7 changes: 7 additions & 0 deletions samples/install-without-bom/pom.xml
Expand Up @@ -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 -->
Expand Down
7 changes: 7 additions & 0 deletions samples/snapshot/pom.xml
Expand Up @@ -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 -->
Expand Down
7 changes: 7 additions & 0 deletions samples/snippets/pom.xml
Expand Up @@ -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] -->
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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(
Expand All @@ -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)
Expand All @@ -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.