Skip to content

Commit e3f0654

Browse files
authored
automl: use fake model ids for deployment testing so that tests do no… (#1929)
* automl: use fake model ids for deployment testing so that tests do not take a long time to run * remove bom from automl until bom is released with v1 of client library * Fix typo * Remove score threshold
1 parent 0676aae commit e3f0654

File tree

4 files changed

+62
-85
lines changed

4 files changed

+62
-85
lines changed
Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,27 @@
2727
import org.junit.After;
2828
import org.junit.Before;
2929
import org.junit.BeforeClass;
30-
import org.junit.Ignore;
3130
import org.junit.Test;
3231
import org.junit.runner.RunWith;
3332
import org.junit.runners.JUnit4;
3433

35-
// Tests for Automl natural language entity extraction models.
3634
@RunWith(JUnit4.class)
37-
@Ignore
38-
public class LanguageEntityExtractionModelManagementIT {
35+
public class DeployModelTest {
3936
private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID");
40-
private static final String MODEL_ID = System.getenv("ENTITY_EXTRACTION_MODEL_ID");
37+
private static final String MODEL_ID = "TEN0000000000000000000";
4138
private ByteArrayOutputStream bout;
4239
private PrintStream out;
4340

4441
private static void requireEnvVar(String varName) {
4542
assertNotNull(
46-
System.getenv(varName),
47-
"Environment variable '%s' is required to perform these tests.".format(varName)
48-
);
43+
System.getenv(varName),
44+
"Environment variable '%s' is required to perform these tests.".format(varName));
4945
}
5046

5147
@BeforeClass
5248
public static void checkRequirements() {
5349
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
5450
requireEnvVar("AUTOML_PROJECT_ID");
55-
requireEnvVar("ENTITY_EXTRACTION_MODEL_ID");
5651
}
5752

5853
@Before
@@ -68,14 +63,16 @@ public void tearDown() {
6863
}
6964

7065
@Test
71-
public void testDeployUndeployModel()
72-
throws IOException, ExecutionException, InterruptedException {
73-
UndeployModel.undeployModel(PROJECT_ID, MODEL_ID);
74-
String got = bout.toString();
75-
assertThat(got).contains("Model undeployment finished");
76-
77-
DeployModel.deployModel(PROJECT_ID, MODEL_ID);
78-
got = bout.toString();
79-
assertThat(got).contains("Model deployment finished");
66+
public void testDeployModel() {
67+
// As model deployment can take a long time, instead try to deploy a
68+
// nonexistent model and confirm that the model was not found, but other
69+
// elements of the request were valid.
70+
try {
71+
DeployModel.deployModel(PROJECT_ID, MODEL_ID);
72+
String got = bout.toString();
73+
assertThat(got).contains("The model does not exist");
74+
} catch (IOException | ExecutionException | InterruptedException e) {
75+
assertThat(e.getMessage()).contains("The model does not exist");
76+
}
8077
}
8178
}
Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,27 @@
2727
import org.junit.After;
2828
import org.junit.Before;
2929
import org.junit.BeforeClass;
30-
import org.junit.Ignore;
3130
import org.junit.Test;
3231
import org.junit.runner.RunWith;
3332
import org.junit.runners.JUnit4;
3433

35-
// Tests for Automl natural language sentiment analysis models.
3634
@RunWith(JUnit4.class)
37-
@Ignore
38-
public class LanguageSentimentAnalysisModelManagementIT {
35+
public class UndeployModelTest {
3936
private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID");
40-
private static final String MODEL_ID = System.getenv("SENTIMENT_ANALYSIS_MODEL_ID");
37+
private static final String MODEL_ID = "TEN0000000000000000000";
4138
private ByteArrayOutputStream bout;
4239
private PrintStream out;
4340

4441
private static void requireEnvVar(String varName) {
4542
assertNotNull(
46-
System.getenv(varName),
47-
"Environment variable '%s' is required to perform these tests.".format(varName)
48-
);
43+
System.getenv(varName),
44+
"Environment variable '%s' is required to perform these tests.".format(varName));
4945
}
5046

5147
@BeforeClass
5248
public static void checkRequirements() {
5349
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
5450
requireEnvVar("AUTOML_PROJECT_ID");
55-
requireEnvVar("SENTIMENT_ANALYSIS_MODEL_ID");
5651
}
5752

5853
@Before
@@ -68,14 +63,16 @@ public void tearDown() {
6863
}
6964

7065
@Test
71-
public void testDeployUndeployModel()
72-
throws IOException, ExecutionException, InterruptedException {
73-
UndeployModel.undeployModel(PROJECT_ID, MODEL_ID);
74-
String got = bout.toString();
75-
assertThat(got).contains("Model undeployment finished");
76-
77-
DeployModel.deployModel(PROJECT_ID, MODEL_ID);
78-
got = bout.toString();
79-
assertThat(got).contains("Model deployment finished");
66+
public void testUndeployModel() {
67+
// As model deployment can take a long time, instead try to deploy a
68+
// nonexistent model and confirm that the model was not found, but other
69+
// elements of the request were valid.
70+
try {
71+
UndeployModel.undeployModel(PROJECT_ID, MODEL_ID);
72+
String got = bout.toString();
73+
assertThat(got).contains("The model does not exist");
74+
} catch (IOException | ExecutionException | InterruptedException e) {
75+
assertThat(e.getMessage()).contains("The model does not exist");
76+
}
8077
}
8178
}
Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,27 @@
2727
import org.junit.After;
2828
import org.junit.Before;
2929
import org.junit.BeforeClass;
30-
import org.junit.Ignore;
3130
import org.junit.Test;
3231
import org.junit.runner.RunWith;
3332
import org.junit.runners.JUnit4;
3433

35-
// Tests for Automl natural language text classification models.
3634
@RunWith(JUnit4.class)
37-
@Ignore
38-
public class LanguageTextClassificationModelManagementIT {
35+
public class VisionClassificationDeployModelNodeCountTest {
3936
private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID");
40-
private static final String MODEL_ID = System.getenv("TEXT_CLASSIFICATION_MODEL_ID");
37+
private static final String MODEL_ID = "ICN0000000000000000000";
4138
private ByteArrayOutputStream bout;
4239
private PrintStream out;
4340

4441
private static void requireEnvVar(String varName) {
4542
assertNotNull(
46-
System.getenv(varName),
47-
"Environment variable '%s' is required to perform these tests.".format(varName)
48-
);
43+
System.getenv(varName),
44+
"Environment variable '%s' is required to perform these tests.".format(varName));
4945
}
5046

5147
@BeforeClass
5248
public static void checkRequirements() {
5349
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
5450
requireEnvVar("AUTOML_PROJECT_ID");
55-
requireEnvVar("TEXT_CLASSIFICATION_MODEL_ID");
5651
}
5752

5853
@Before
@@ -68,14 +63,17 @@ public void tearDown() {
6863
}
6964

7065
@Test
71-
public void testDeployUndeployModel()
72-
throws IOException, ExecutionException, InterruptedException {
73-
UndeployModel.undeployModel(PROJECT_ID, MODEL_ID);
74-
String got = bout.toString();
75-
assertThat(got).contains("Model undeployment finished");
76-
77-
DeployModel.deployModel(PROJECT_ID, MODEL_ID);
78-
got = bout.toString();
79-
assertThat(got).contains("Model deployment finished");
66+
public void testDeployModelWithNodeCount() {
67+
// As model deployment can take a long time, instead try to deploy a
68+
// nonexistent model and confirm that the model was not found, but other
69+
// elements of the request were valid.
70+
try {
71+
VisionClassificationDeployModelNodeCount.visionClassificationDeployModelNodeCount(
72+
PROJECT_ID, MODEL_ID);
73+
String got = bout.toString();
74+
assertThat(got).contains("The model does not exist");
75+
} catch (IOException | ExecutionException | InterruptedException e) {
76+
assertThat(e.getMessage()).contains("The model does not exist");
77+
}
8078
}
8179
}

automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionModelManagementIT.java renamed to automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,27 @@
2727
import org.junit.After;
2828
import org.junit.Before;
2929
import org.junit.BeforeClass;
30-
import org.junit.Ignore;
3130
import org.junit.Test;
3231
import org.junit.runner.RunWith;
3332
import org.junit.runners.JUnit4;
3433

35-
// Tests for Automl vision object detection models.
3634
@RunWith(JUnit4.class)
37-
@Ignore
38-
public class VisionObjectDetectionModelManagementIT {
35+
public class VisionObjectDetectionDeployModelNodeCountTest {
3936
private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID");
40-
private static final String MODEL_ID = System.getenv("OBJECT_DETECTION_MODEL_ID");
37+
private static final String MODEL_ID = "0000000000000000000000";
4138
private ByteArrayOutputStream bout;
4239
private PrintStream out;
4340

4441
private static void requireEnvVar(String varName) {
4542
assertNotNull(
46-
System.getenv(varName),
47-
"Environment variable '%s' is required to perform these tests.".format(varName)
48-
);
43+
System.getenv(varName),
44+
"Environment variable '%s' is required to perform these tests.".format(varName));
4945
}
5046

5147
@BeforeClass
5248
public static void checkRequirements() {
5349
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
5450
requireEnvVar("AUTOML_PROJECT_ID");
55-
requireEnvVar("OBJECT_DETECTION_MODEL_ID");
5651
}
5752

5853
@Before
@@ -68,27 +63,17 @@ public void tearDown() {
6863
}
6964

7065
@Test
71-
public void testDeployUndeployModel()
72-
throws IOException, ExecutionException, InterruptedException {
73-
UndeployModel.undeployModel(PROJECT_ID, MODEL_ID);
74-
String got = bout.toString();
75-
assertThat(got).contains("Model undeployment finished");
76-
77-
DeployModel.deployModel(PROJECT_ID, MODEL_ID);
78-
got = bout.toString();
79-
assertThat(got).contains("Model deployment finished");
80-
}
81-
82-
@Test
83-
public void testDeployUndeployModelWithNodeCount()
84-
throws IOException, ExecutionException, InterruptedException {
85-
UndeployModel.undeployModel(PROJECT_ID, MODEL_ID);
86-
String got = bout.toString();
87-
assertThat(got).contains("Model undeployment finished");
88-
89-
VisionObjectDetectionDeployModelNodeCount.visionObjectDetectionDeployModelNodeCount(
90-
PROJECT_ID, MODEL_ID);
91-
got = bout.toString();
92-
assertThat(got).contains("Model deployment finished");
66+
public void testDeployModelWithNodeCount() {
67+
// As model deployment can take a long time, instead try to deploy a
68+
// nonexistent model and confirm that the model was not found, but other
69+
// elements of the request were valid.
70+
try {
71+
VisionObjectDetectionDeployModelNodeCount.visionObjectDetectionDeployModelNodeCount(
72+
PROJECT_ID, MODEL_ID);
73+
String got = bout.toString();
74+
assertThat(got).contains("The model does not exist");
75+
} catch (IOException | ExecutionException | InterruptedException e) {
76+
assertThat(e.getMessage()).contains("The model does not exist");
77+
}
9378
}
9479
}

0 commit comments

Comments
 (0)