From 7346223783f96c5cecd1f38a250b2e8563839f87 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Fri, 3 Jan 2020 10:20:17 -0700 Subject: [PATCH 1/4] automl: use fake model ids for deployment testing so that tests do not take a long time to run --- ...ManagementIT.java => DeployModelTest.java} | 30 +++--- ...nagementIT.java => UndeployModelTest.java} | 30 +++--- ...assificationDeployModelNodeCountTest.java} | 31 ++++--- ...VisionClassificationModelManagementIT.java | 91 ------------------- ...ectDetectionDeployModelNodeCountTest.java} | 44 ++++----- 5 files changed, 62 insertions(+), 164 deletions(-) rename automl/cloud-client/src/test/java/com/example/automl/{LanguageEntityExtractionModelManagementIT.java => DeployModelTest.java} (68%) rename automl/cloud-client/src/test/java/com/example/automl/{LanguageTextClassificationModelManagementIT.java => UndeployModelTest.java} (68%) rename automl/cloud-client/src/test/java/com/example/automl/{LanguageSentimentAnalysisModelManagementIT.java => VisionClassificationDeployModelNodeCountTest.java} (65%) delete mode 100644 automl/cloud-client/src/test/java/com/example/automl/VisionClassificationModelManagementIT.java rename automl/cloud-client/src/test/java/com/example/automl/{VisionObjectDetectionModelManagementIT.java => VisionObjectDetectionDeployModelNodeCountTest.java} (58%) diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionModelManagementIT.java b/automl/cloud-client/src/test/java/com/example/automl/DeployModelTest.java similarity index 68% rename from automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionModelManagementIT.java rename to automl/cloud-client/src/test/java/com/example/automl/DeployModelTest.java index 3c460343346..38909f8bb9a 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionModelManagementIT.java +++ b/automl/cloud-client/src/test/java/com/example/automl/DeployModelTest.java @@ -31,19 +31,17 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -// Tests for Automl natural language entity extraction models. @RunWith(JUnit4.class) -public class LanguageEntityExtractionModelManagementIT { +public class DeployModelTest { private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String MODEL_ID = "TEN1974951581904273408"; + private static final String MODEL_ID = "TEN0000000000000000000"; private ByteArrayOutputStream bout; private PrintStream out; private static void requireEnvVar(String varName) { assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName) - ); + System.getenv(varName), + "Environment variable '%s' is required to perform these tests.".format(varName)); } @BeforeClass @@ -65,14 +63,16 @@ public void tearDown() { } @Test - public void testDeployUndeployModel() - throws IOException, ExecutionException, InterruptedException { - UndeployModel.undeployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("Model undeployment finished"); - - DeployModel.deployModel(PROJECT_ID, MODEL_ID); - got = bout.toString(); - assertThat(got).contains("Model deployment finished"); + public void testDeployModel() { + // As model deployment can take a long time, instead try to deploy a + // nonexistent model and confirm that the model was not found, but other + // elements of the request were valid. + try { + DeployModel.deployModel(PROJECT_ID, MODEL_ID); + String got = bout.toString(); + assertThat(got).contains("The model does not exist"); + } catch (IOException | ExecutionException | InterruptedException e) { + assertThat(e.getMessage()).contains("The model does not exist"); + } } } diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationModelManagementIT.java b/automl/cloud-client/src/test/java/com/example/automl/UndeployModelTest.java similarity index 68% rename from automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationModelManagementIT.java rename to automl/cloud-client/src/test/java/com/example/automl/UndeployModelTest.java index 2d630da6b6a..2649016991e 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationModelManagementIT.java +++ b/automl/cloud-client/src/test/java/com/example/automl/UndeployModelTest.java @@ -31,19 +31,17 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -// Tests for Automl natural language text classification models. @RunWith(JUnit4.class) -public class LanguageTextClassificationModelManagementIT { +public class UndeployModelTest { private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String MODEL_ID = "TCN6871084728972835631"; + private static final String MODEL_ID = "TEN0000000000000000000"; private ByteArrayOutputStream bout; private PrintStream out; private static void requireEnvVar(String varName) { assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName) - ); + System.getenv(varName), + "Environment variable '%s' is required to perform these tests.".format(varName)); } @BeforeClass @@ -65,14 +63,16 @@ public void tearDown() { } @Test - public void testDeployUndeployModel() - throws IOException, ExecutionException, InterruptedException { - UndeployModel.undeployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("Model undeployment finished"); - - DeployModel.deployModel(PROJECT_ID, MODEL_ID); - got = bout.toString(); - assertThat(got).contains("Model deployment finished"); + public void testUndeployModel() { + // As model deployment can take a long time, instead try to deploy a + // nonexistent model and confirm that the model was not found, but other + // elements of the request were valid. + try { + UndeployModel.undeployModel(PROJECT_ID, MODEL_ID); + String got = bout.toString(); + assertThat(got).contains("The model does not exist"); + } catch (IOException | ExecutionException | InterruptedException e) { + assertThat(e.getMessage()).contains("The model does not exist"); + } } } diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisModelManagementIT.java b/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationDeployModelNodeCountTest.java similarity index 65% rename from automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisModelManagementIT.java rename to automl/cloud-client/src/test/java/com/example/automl/VisionClassificationDeployModelNodeCountTest.java index 0bc7f68f6c7..7180a18552a 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisModelManagementIT.java +++ b/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationDeployModelNodeCountTest.java @@ -31,19 +31,17 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -// Tests for Automl natural language sentiment analysis models. @RunWith(JUnit4.class) -public class LanguageSentimentAnalysisModelManagementIT { +public class VisionClassificationDeployModelNodeCountTest { private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String MODEL_ID = "TST864310464894223026"; + private static final String MODEL_ID = "ICN0000000000000000000"; private ByteArrayOutputStream bout; private PrintStream out; private static void requireEnvVar(String varName) { assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName) - ); + System.getenv(varName), + "Environment variable '%s' is required to perform these tests.".format(varName)); } @BeforeClass @@ -65,14 +63,17 @@ public void tearDown() { } @Test - public void testDeployUndeployModel() - throws IOException, ExecutionException, InterruptedException { - UndeployModel.undeployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("Model undeployment finished"); - - DeployModel.deployModel(PROJECT_ID, MODEL_ID); - got = bout.toString(); - assertThat(got).contains("Model deployment finished"); + public void testDeployModelWithNodeCount() { + // As model deployment can take a long time, instead try to deploy a + // nonexistent model and confirm that the model was not found, but other + // elements of the request were valid. + try { + VisionClassificationDeployModelNodeCount.visionClassificationDeployModelNodeCount( + PROJECT_ID, MODEL_ID); + String got = bout.toString(); + assertThat(got).contains("The model does not exist"); + } catch (IOException | ExecutionException | InterruptedException e) { + assertThat(e.getMessage()).contains("The model does not exist"); + } } } diff --git a/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationModelManagementIT.java b/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationModelManagementIT.java deleted file mode 100644 index b7f053f6e18..00000000000 --- a/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationModelManagementIT.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.automl; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.concurrent.ExecutionException; - -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -// Tests for Automl vision image classification models. -@RunWith(JUnit4.class) -public class VisionClassificationModelManagementIT { - private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String MODEL_ID = "ICN6418888056864606028"; - private ByteArrayOutputStream bout; - private PrintStream out; - - private static void requireEnvVar(String varName) { - assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName) - ); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("GOOGLE_CLOUD_PROJECT"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - System.setOut(out); - } - - @After - public void tearDown() { - System.setOut(null); - } - - @Test - public void testDeployUndeployModel() - throws IOException, ExecutionException, InterruptedException { - UndeployModel.undeployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("Model undeployment finished"); - - DeployModel.deployModel(PROJECT_ID, MODEL_ID); - got = bout.toString(); - assertThat(got).contains("Model deployment finished"); - } - - @Test - public void testDeployUndeployModelWithNodeCount() - throws IOException, ExecutionException, InterruptedException { - UndeployModel.undeployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("Model undeployment finished"); - - VisionClassificationDeployModelNodeCount.visionClassificationDeployModelNodeCount( - PROJECT_ID, MODEL_ID); - got = bout.toString(); - assertThat(got).contains("Model deployment finished"); - } -} diff --git a/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionModelManagementIT.java b/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java similarity index 58% rename from automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionModelManagementIT.java rename to automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java index e77efa8d319..68a86ee86c1 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionModelManagementIT.java +++ b/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java @@ -31,19 +31,17 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -// Tests for Automl vision object detection models. @RunWith(JUnit4.class) -public class VisionObjectDetectionModelManagementIT { +public class VisionObjectDetectionDeployModelNodeCountTest { private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT"); - private static final String MODEL_ID = "IOD1854128448151224320"; + private static final String MODEL_ID = "0000000000000000000000"; private ByteArrayOutputStream bout; private PrintStream out; private static void requireEnvVar(String varName) { assertNotNull( - System.getenv(varName), - "Environment variable '%s' is required to perform these tests.".format(varName) - ); + System.getenv(varName), + "Environment variable '%s' is required to perform these tests.".format(varName)); } @BeforeClass @@ -65,27 +63,17 @@ public void tearDown() { } @Test - public void testDeployUndeployModel() - throws IOException, ExecutionException, InterruptedException { - UndeployModel.undeployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("Model undeployment finished"); - - DeployModel.deployModel(PROJECT_ID, MODEL_ID); - got = bout.toString(); - assertThat(got).contains("Model deployment finished"); - } - - @Test - public void testDeployUndeployModelWithNodeCount() - throws IOException, ExecutionException, InterruptedException { - UndeployModel.undeployModel(PROJECT_ID, MODEL_ID); - String got = bout.toString(); - assertThat(got).contains("Model undeployment finished"); - - VisionObjectDetectionDeployModelNodeCount.visionObjectDetectionDeployModelNodeCount( - PROJECT_ID, MODEL_ID); - got = bout.toString(); - assertThat(got).contains("Model deployment finished"); + public void testDeployModelWithNodeCount() { + // As model deployment can take a long time, instead try to deploy a + // nonexistent model and confirm that the model was not found, but other + // elements of the request were valid. + try { + VisionObjectDetectionDeployModelNodeCount.visionObjectDetectionDeployModelNodeCount( + PROJECT_ID, MODEL_ID); + String got = bout.toString(); + assertThat(got).contains("The model does not exist"); + } catch (IOException | ExecutionException | InterruptedException e) { + assertThat(e.getMessage()).contains("The model does not exist"); + } } } From 38dcd49b9abcdc94c69f8a3df5f5052c25829ff2 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Fri, 3 Jan 2020 10:31:10 -0700 Subject: [PATCH 2/4] remove bom from automl until bom is released with v1 of client library --- automl/cloud-client/pom.xml | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/automl/cloud-client/pom.xml b/automl/cloud-client/pom.xml index cd7ec71a4f3..27d243ff225 100644 --- a/automl/cloud-client/pom.xml +++ b/automl/cloud-client/pom.xml @@ -27,30 +27,17 @@ - 1.11 - 1.11 + 11 + 11 UTF-8 - - - - - - com.google.cloud - libraries-bom - 3.0.0 - pom - import - - - - + com.google.cloud google-cloud-automl + 0.115.1-beta @@ -77,7 +64,5 @@ 1.0 test - - \ No newline at end of file From 9b23e6aa8f44a850d558238532fece92acd48c20 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Fri, 3 Jan 2020 13:19:18 -0700 Subject: [PATCH 3/4] Fix typo --- .../com/example/automl/LanguageEntityExtractionPredictIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionPredictIT.java b/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionPredictIT.java index 7c9af56b6a6..2b84c67e90b 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionPredictIT.java +++ b/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionPredictIT.java @@ -78,7 +78,7 @@ public void testPredict() throws IOException { // Assert String got = bout.toString(); - assertThat(got).contains("Text Extract Entity Types:"); + assertThat(got).contains("Text Extract Entity Type:"); } @Test From b2e1a6a96b0384fb85995ad07680ea0424a32dc8 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Fri, 3 Jan 2020 13:20:55 -0700 Subject: [PATCH 4/4] Remove score threshold --- .../src/main/java/com/example/automl/BatchPredict.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/automl/cloud-client/src/main/java/com/example/automl/BatchPredict.java b/automl/cloud-client/src/main/java/com/example/automl/BatchPredict.java index 3eb4d9beaa8..3144f863544 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/BatchPredict.java +++ b/automl/cloud-client/src/main/java/com/example/automl/BatchPredict.java @@ -62,8 +62,6 @@ static void batchPredict(String projectId, String modelId, String inputUri, Stri .setName(name.toString()) .setInputConfig(inputConfig) .setOutputConfig(outputConfig) - // [0.0-1.0] Only produce results higher than this value - .putParams("score_threshold", "0.8") .build(); OperationFuture future =