From 04454a215836602d16c0f50b6335c86e26c672ec Mon Sep 17 00:00:00 2001 From: nnegrey Date: Tue, 7 Jan 2020 15:17:06 -0700 Subject: [PATCH 01/10] automl: add create model tests --- ...nguageEntityExtractionCreateModelTest.java | 86 ++++++++++++++++++ ...guageSentimentAnalysisCreateModelTest.java | 90 +++++++++++++++++++ ...uageTextClassificationCreateModelTest.java | 90 +++++++++++++++++++ .../VisionClassificationCreateModelTest.java | 90 +++++++++++++++++++ .../VisionObjectDetectionCreateModelTest.java | 90 +++++++++++++++++++ 5 files changed, 446 insertions(+) create mode 100644 automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java create mode 100644 automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java create mode 100644 automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java create mode 100644 automl/cloud-client/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java create mode 100644 automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java new file mode 100644 index 00000000000..22d68a3ecae --- /dev/null +++ b/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java @@ -0,0 +1,86 @@ +/* + * Copyright 2020 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.UUID; +import java.util.concurrent.ExecutionException; + +import com.google.cloud.automl.v1.AutoMlClient; +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; + +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class LanguageEntityExtractionCreateModelTest { + + private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); + private static final String DATASET_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)); + } + + @BeforeClass + public static void checkRequirements() { + requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); + requireEnvVar("AUTOML_PROJECT_ID"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() { + System.setOut(null); + } + + @Test + public void testCreateDataset() { + // As entity extraction does not let you cancel model creation, instead try to create a model + // from a nonexistent dataset, but other elements of the request were valid. + try { + // Create a random dataset name with a length of 32 characters (max allowed by AutoML) + // To prevent name collisions when running tests in multiple java versions at once. + // AutoML doesn't allow "-", but accepts "_" + String modelName = + String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); + LanguageEntityExtractionCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); + String got = bout.toString(); + assertThat(got).contains("Dataset does not exist"); + } catch (IOException | ExecutionException | InterruptedException e) { + assertThat(e.getMessage()).contains("Dataset does not exist\""); + } + } +} diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java new file mode 100644 index 00000000000..363dff61896 --- /dev/null +++ b/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java @@ -0,0 +1,90 @@ +/* + * Copyright 2020 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.UUID; +import java.util.concurrent.ExecutionException; + +import com.google.cloud.automl.v1.AutoMlClient; +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; + +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class LanguageSentimentAnalysisCreateModelTest { + + private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); + private static final String DATASET_ID = System.getenv("SENTIMENT_ANALYSIS_DATASET_ID"); + private ByteArrayOutputStream bout; + private PrintStream out; + private String operationId; + + 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("AUTOML_PROJECT_ID"); + requireEnvVar("SENTIMENT_ANALYSIS_DATASET_ID"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() throws IOException { + // Cancel the operation + try (AutoMlClient client = AutoMlClient.create()) { + client.getOperationsClient().cancelOperation(operationId); + } + + System.setOut(null); + } + + @Test + public void testCreateDataset() throws IOException, ExecutionException, InterruptedException { + // Create a random dataset name with a length of 32 characters (max allowed by AutoML) + // To prevent name collisions when running tests in multiple java versions at once. + // AutoML doesn't allow "-", but accepts "_" + String modelName = + String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); + LanguageSentimentAnalysisCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); + + String got = bout.toString(); + assertThat(got).contains("Training started"); + + operationId = got.split("Training operation name: ")[1].split("\n")[0]; + } +} diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java new file mode 100644 index 00000000000..21696802763 --- /dev/null +++ b/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java @@ -0,0 +1,90 @@ +/* + * Copyright 2020 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.UUID; +import java.util.concurrent.ExecutionException; + +import com.google.cloud.automl.v1.AutoMlClient; +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; + +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class LanguageTextClassificationCreateModelTest { + + private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); + private static final String DATASET_ID = System.getenv("TEXT_CLASSIFICATION_DATASET_ID"); + private ByteArrayOutputStream bout; + private PrintStream out; + private String operationId; + + 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("AUTOML_PROJECT_ID"); + requireEnvVar("TEXT_CLASSIFICATION_DATASET_ID"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() throws IOException { + // Cancel the operation + try (AutoMlClient client = AutoMlClient.create()) { + client.getOperationsClient().cancelOperation(operationId); + } + + System.setOut(null); + } + + @Test + public void testCreateDataset() throws IOException, ExecutionException, InterruptedException { + // Create a random dataset name with a length of 32 characters (max allowed by AutoML) + // To prevent name collisions when running tests in multiple java versions at once. + // AutoML doesn't allow "-", but accepts "_" + String modelName = + String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); + LanguageTextClassificationCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); + + String got = bout.toString(); + assertThat(got).contains("Training started"); + + operationId = got.split("Training operation name: ")[1].split("\n")[0]; + } +} diff --git a/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java new file mode 100644 index 00000000000..93f1a36d85f --- /dev/null +++ b/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java @@ -0,0 +1,90 @@ +/* + * Copyright 2020 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.UUID; +import java.util.concurrent.ExecutionException; + +import com.google.cloud.automl.v1.AutoMlClient; +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; + +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class VisionClassificationCreateModelTest { + + private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); + private static final String DATASET_ID = System.getenv("VISION_CLASSIFICATION_DATASET_ID"); + private ByteArrayOutputStream bout; + private PrintStream out; + private String operationId; + + 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("AUTOML_PROJECT_ID"); + requireEnvVar("VISION_CLASSIFICATION_DATASET_ID"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() throws IOException { + // Cancel the operation + try (AutoMlClient client = AutoMlClient.create()) { + client.getOperationsClient().cancelOperation(operationId); + } + + System.setOut(null); + } + + @Test + public void testCreateDataset() throws IOException, ExecutionException, InterruptedException { + // Create a random dataset name with a length of 32 characters (max allowed by AutoML) + // To prevent name collisions when running tests in multiple java versions at once. + // AutoML doesn't allow "-", but accepts "_" + String modelName = + String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); + VisionClassificationCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); + + String got = bout.toString(); + assertThat(got).contains("Training started"); + + operationId = got.split("Training operation name: ")[1].split("\n")[0]; + } +} diff --git a/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java new file mode 100644 index 00000000000..8d621d36ca5 --- /dev/null +++ b/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java @@ -0,0 +1,90 @@ +/* + * Copyright 2020 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.UUID; +import java.util.concurrent.ExecutionException; + +import com.google.cloud.automl.v1.AutoMlClient; +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; + +@RunWith(JUnit4.class) +@SuppressWarnings("checkstyle:abbreviationaswordinname") +public class VisionObjectDetectionCreateModelTest { + + private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); + private static final String DATASET_ID = System.getenv("OBJECT_DETECTION_DATASET_ID"); + private ByteArrayOutputStream bout; + private PrintStream out; + private String operationId; + + 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("AUTOML_PROJECT_ID"); + requireEnvVar("OBJECT_DETECTION_DATASET_ID"); + } + + @Before + public void setUp() { + bout = new ByteArrayOutputStream(); + out = new PrintStream(bout); + System.setOut(out); + } + + @After + public void tearDown() throws IOException { + // Cancel the operation + try (AutoMlClient client = AutoMlClient.create()) { + client.getOperationsClient().cancelOperation(operationId); + } + + System.setOut(null); + } + + @Test + public void testCreateDataset() throws IOException, ExecutionException, InterruptedException { + // Create a random dataset name with a length of 32 characters (max allowed by AutoML) + // To prevent name collisions when running tests in multiple java versions at once. + // AutoML doesn't allow "-", but accepts "_" + String modelName = + String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); + VisionObjectDetectionCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); + + String got = bout.toString(); + assertThat(got).contains("Training started"); + + operationId = got.split("Training operation name: ")[1].split("\n")[0]; + } +} From 57111082a52bf9f7ede53b6d0f6a6e881a8f4419 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Tue, 7 Jan 2020 15:17:27 -0700 Subject: [PATCH 02/10] Use a fake model to speed up batch predict test --- .../com/example/automl/BatchPredictTest.java | 64 ++++++------------- 1 file changed, 18 insertions(+), 46 deletions(-) diff --git a/automl/cloud-client/src/test/java/com/example/automl/BatchPredictTest.java b/automl/cloud-client/src/test/java/com/example/automl/BatchPredictTest.java index 4bc36436056..6a702e2a708 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/BatchPredictTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/BatchPredictTest.java @@ -44,14 +44,14 @@ public class BatchPredictTest { private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); private static final String BUCKET_ID = PROJECT_ID + "-lcm"; - private static final String MODEL_ID = System.getenv("ENTITY_EXTRACTION_MODEL_ID"); + 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 @@ -62,19 +62,7 @@ public static void checkRequirements() { } @Before - public void setUp() throws IOException, ExecutionException, InterruptedException { - // Verify that the model is deployed for prediction - try (AutoMlClient client = AutoMlClient.create()) { - ModelName modelFullId = ModelName.of(PROJECT_ID, "us-central1", MODEL_ID); - Model model = client.getModel(modelFullId); - if (model.getDeploymentState() == Model.DeploymentState.UNDEPLOYED) { - // Deploy the model if not deployed - DeployModelRequest request = - DeployModelRequest.newBuilder().setName(modelFullId.toString()).build(); - client.deployModelAsync(request).get(); - } - } - + public void setUp() { bout = new ByteArrayOutputStream(); out = new PrintStream(bout); System.setOut(out); @@ -82,39 +70,23 @@ public void setUp() throws IOException, ExecutionException, InterruptedException @After public void tearDown() { - // Delete the created files from GCS - Storage storage = StorageOptions.getDefaultInstance().getService(); - Page blobs = - storage.list( - BUCKET_ID, - Storage.BlobListOption.currentDirectory(), - Storage.BlobListOption.prefix("TEST_BATCH_PREDICT/")); - - for (Blob blob : blobs.iterateAll()) { - Page fileBlobs = - storage.list( - BUCKET_ID, - Storage.BlobListOption.currentDirectory(), - Storage.BlobListOption.prefix(blob.getName())); - for (Blob fileBlob : fileBlobs.iterateAll()) { - if (!fileBlob.isDirectory()) { - fileBlob.delete(); - } - } - } - System.setOut(null); } @Test - public void testBatchPredict() throws IOException, ExecutionException, InterruptedException { - String inputUri = String.format("gs://%s/entity-extraction/input.jsonl", BUCKET_ID); - String outputUri = String.format("gs://%s/TEST_BATCH_PREDICT/", BUCKET_ID); - // Act - BatchPredict.batchPredict(PROJECT_ID, MODEL_ID, inputUri, outputUri); - - // Assert - String got = bout.toString(); - assertThat(got).contains("Batch Prediction results saved to specified Cloud Storage bucket"); + public void testBatchPredict() { + // As batch prediction can take a long time. Try to batch predict on a model and confirm that + // the model was not found, but other elements of the request were valid. + try { + String inputUri = String.format("gs://%s/entity_extraction/input.jsonl", BUCKET_ID); + String outputUri = String.format("gs://%s/TEST_BATCH_PREDICT/", BUCKET_ID); + BatchPredict.batchPredict(PROJECT_ID, MODEL_ID, inputUri, outputUri); + String got = bout.toString(); + assertThat(got) + .contains("The model is either not found or not supported for prediction yet."); + } catch (IOException | ExecutionException | InterruptedException e) { + assertThat(e.getMessage()) + .contains("The model is either not found or not supported for prediction yet."); + } } } From 1cb760cd0c1550ca733810dcf0caec0bc5fdef35 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Tue, 7 Jan 2020 15:22:37 -0700 Subject: [PATCH 03/10] Update method names and clean up Translate model test --- ...nguageEntityExtractionCreateModelTest.java | 2 +- ...guageSentimentAnalysisCreateModelTest.java | 2 +- ...uageTextClassificationCreateModelTest.java | 2 +- ...tIT.java => TranslateCreateModelTest.java} | 79 ++++--------------- .../VisionClassificationCreateModelTest.java | 2 +- ...jectDetectionDeployModelNodeCountTest.java | 2 +- 6 files changed, 21 insertions(+), 68 deletions(-) rename automl/cloud-client/src/test/java/com/example/automl/{TranslateModelManagementIT.java => TranslateCreateModelTest.java} (52%) diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java index 22d68a3ecae..1381a337bb8 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java @@ -67,7 +67,7 @@ public void tearDown() { } @Test - public void testCreateDataset() { + public void testLanguageEntityExtractionCreateModel() { // As entity extraction does not let you cancel model creation, instead try to create a model // from a nonexistent dataset, but other elements of the request were valid. try { diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java index 363dff61896..7086b6b30d7 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java @@ -74,7 +74,7 @@ public void tearDown() throws IOException { } @Test - public void testCreateDataset() throws IOException, ExecutionException, InterruptedException { + public void testLanguageSentimentAnalysisCreateModel() throws IOException, ExecutionException, InterruptedException { // Create a random dataset name with a length of 32 characters (max allowed by AutoML) // To prevent name collisions when running tests in multiple java versions at once. // AutoML doesn't allow "-", but accepts "_" diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java index 21696802763..35888f45647 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java @@ -74,7 +74,7 @@ public void tearDown() throws IOException { } @Test - public void testCreateDataset() throws IOException, ExecutionException, InterruptedException { + public void testLanguageTextClassificationCreateModel() throws IOException, ExecutionException, InterruptedException { // Create a random dataset name with a length of 32 characters (max allowed by AutoML) // To prevent name collisions when running tests in multiple java versions at once. // AutoML doesn't allow "-", but accepts "_" diff --git a/automl/cloud-client/src/test/java/com/example/automl/TranslateModelManagementIT.java b/automl/cloud-client/src/test/java/com/example/automl/TranslateCreateModelTest.java similarity index 52% rename from automl/cloud-client/src/test/java/com/example/automl/TranslateModelManagementIT.java rename to automl/cloud-client/src/test/java/com/example/automl/TranslateCreateModelTest.java index 27ab477ae27..759afd4e022 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/TranslateModelManagementIT.java +++ b/automl/cloud-client/src/test/java/com/example/automl/TranslateCreateModelTest.java @@ -24,6 +24,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.util.UUID; import java.util.concurrent.ExecutionException; import org.junit.After; @@ -38,11 +39,9 @@ public class TranslateModelManagementIT { private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); private static final String DATASET_ID = System.getenv("TRANSLATION_DATASET_ID"); - private static final String MODEL_NAME = "translation_test_create_model"; private ByteArrayOutputStream bout; private PrintStream out; - private String modelId; - private String modelEvaluationId; + private String operationId; private static void requireEnvVar(String varName) { assertNotNull( @@ -66,74 +65,28 @@ public void setUp() { } @After - public void tearDown() { - System.setOut(null); - } - - @Test - public void testModelApi() throws IOException { - // LIST MODELS - ListModels.listModels(PROJECT_ID); - String got = bout.toString(); - modelId = got.split("Model id: ")[1].split("\n")[0]; - assertThat(got).contains("Model id:"); - - // GET MODEL - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - System.setOut(out); - GetModel.getModel(PROJECT_ID, modelId); - got = bout.toString(); - assertThat(got).contains("Model id: " + modelId); - - // LIST MODEL EVALUATIONS - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - System.setOut(out); - ListModelEvaluations.listModelEvaluations(PROJECT_ID, modelId); - got = bout.toString(); - modelEvaluationId = got.split(modelId + "/modelEvaluations/")[1].split("\n")[0]; - assertThat(got).contains("Model Evaluation Name:"); + public void tearDown() throws IOException { + // Cancel the operation + try (AutoMlClient client = AutoMlClient.create()) { + client.getOperationsClient().cancelOperation(operationId); + } - // Act - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - System.setOut(out); - GetModelEvaluation.getModelEvaluation(PROJECT_ID, modelId, modelEvaluationId); - got = bout.toString(); - assertThat(got).contains("Model Evaluation Name:"); + System.setOut(null); } - @Test - public void testOperationStatus() throws IOException { - // Act - ListOperationStatus.listOperationStatus(PROJECT_ID); - - // Assert - String got = bout.toString(); - String operationId = got.split("\n")[1].split(":")[1].trim(); - assertThat(got).contains("Operation details:"); - - // Act - bout.reset(); - GetOperationStatus.getOperationStatus(operationId); - - // Assert - got = bout.toString(); - assertThat(got).contains("Operation details:"); - } @Test - public void testCreateModel() throws IOException, ExecutionException, InterruptedException { - TranslateCreateModel.createModel(PROJECT_ID, DATASET_ID, MODEL_NAME); + public void testTranslateCreateModel() throws IOException, ExecutionException, InterruptedException { + // Create a random dataset name with a length of 32 characters (max allowed by AutoML) + // To prevent name collisions when running tests in multiple java versions at once. + // AutoML doesn't allow "-", but accepts "_" + String modelName = + String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); + TranslateCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); String got = bout.toString(); assertThat(got).contains("Training started"); - String operationId = got.split("Training operation name: ")[1].split("\n")[0]; - - try (AutoMlClient client = AutoMlClient.create()) { - client.getOperationsClient().cancelOperation(operationId); - } + operationId = got.split("Training operation name: ")[1].split("\n")[0]; } } diff --git a/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java index 93f1a36d85f..8049736c746 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java @@ -74,7 +74,7 @@ public void tearDown() throws IOException { } @Test - public void testCreateDataset() throws IOException, ExecutionException, InterruptedException { + public void testVisionClassificationCreateModel() throws IOException, ExecutionException, InterruptedException { // Create a random dataset name with a length of 32 characters (max allowed by AutoML) // To prevent name collisions when running tests in multiple java versions at once. // AutoML doesn't allow "-", but accepts "_" diff --git a/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java b/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java index bff3f83503f..86f017d33d6 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java @@ -63,7 +63,7 @@ public void tearDown() { } @Test - public void testDeployModelWithNodeCount() { + public void testVisionObjectDetectionCreateModel() { // 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. From 259685d3b911e29e5088327d12e131d03ddf6e22 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Tue, 7 Jan 2020 15:23:08 -0700 Subject: [PATCH 04/10] Rename translate model --- .../test/java/com/example/automl/TranslateCreateModelTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automl/cloud-client/src/test/java/com/example/automl/TranslateCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/TranslateCreateModelTest.java index 759afd4e022..6f65a336618 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/TranslateCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/TranslateCreateModelTest.java @@ -36,7 +36,7 @@ // Tests for Automl translation models. @RunWith(JUnit4.class) -public class TranslateModelManagementIT { +public class TranslateCreateModelTest { private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID"); private static final String DATASET_ID = System.getenv("TRANSLATION_DATASET_ID"); private ByteArrayOutputStream bout; From b381058f37380289313f8851f02bb24c545052ff Mon Sep 17 00:00:00 2001 From: nnegrey Date: Tue, 7 Jan 2020 15:25:57 -0700 Subject: [PATCH 05/10] Run code formatter --- .../LanguageEntityExtractionCreateModelTest.java | 4 ++-- .../LanguageSentimentAnalysisCreateModelTest.java | 9 +++++---- .../LanguageTextClassificationCreateModelTest.java | 9 +++++---- .../com/example/automl/TranslateCreateModelTest.java | 11 +++++------ .../automl/VisionClassificationCreateModelTest.java | 9 +++++---- .../automl/VisionObjectDetectionCreateModelTest.java | 6 +++--- 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java index 1381a337bb8..62ea1a24b9b 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java @@ -44,8 +44,8 @@ public class LanguageEntityExtractionCreateModelTest { 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 diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java index 7086b6b30d7..8d6ffa27506 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java @@ -45,8 +45,8 @@ public class LanguageSentimentAnalysisCreateModelTest { 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 @@ -74,12 +74,13 @@ public void tearDown() throws IOException { } @Test - public void testLanguageSentimentAnalysisCreateModel() throws IOException, ExecutionException, InterruptedException { + public void testLanguageSentimentAnalysisCreateModel() + throws IOException, ExecutionException, InterruptedException { // Create a random dataset name with a length of 32 characters (max allowed by AutoML) // To prevent name collisions when running tests in multiple java versions at once. // AutoML doesn't allow "-", but accepts "_" String modelName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); + String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); LanguageSentimentAnalysisCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); String got = bout.toString(); diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java index 35888f45647..65ffe0adacd 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java @@ -45,8 +45,8 @@ public class LanguageTextClassificationCreateModelTest { 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 @@ -74,12 +74,13 @@ public void tearDown() throws IOException { } @Test - public void testLanguageTextClassificationCreateModel() throws IOException, ExecutionException, InterruptedException { + public void testLanguageTextClassificationCreateModel() + throws IOException, ExecutionException, InterruptedException { // Create a random dataset name with a length of 32 characters (max allowed by AutoML) // To prevent name collisions when running tests in multiple java versions at once. // AutoML doesn't allow "-", but accepts "_" String modelName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); + String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); LanguageTextClassificationCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); String got = bout.toString(); diff --git a/automl/cloud-client/src/test/java/com/example/automl/TranslateCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/TranslateCreateModelTest.java index 6f65a336618..dadf2c60ce6 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/TranslateCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/TranslateCreateModelTest.java @@ -45,9 +45,8 @@ public class TranslateCreateModelTest { 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 @@ -74,14 +73,14 @@ public void tearDown() throws IOException { System.setOut(null); } - @Test - public void testTranslateCreateModel() throws IOException, ExecutionException, InterruptedException { + public void testTranslateCreateModel() + throws IOException, ExecutionException, InterruptedException { // Create a random dataset name with a length of 32 characters (max allowed by AutoML) // To prevent name collisions when running tests in multiple java versions at once. // AutoML doesn't allow "-", but accepts "_" String modelName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); + String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); TranslateCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); String got = bout.toString(); diff --git a/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java index 8049736c746..ecf0df92c63 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java @@ -45,8 +45,8 @@ public class VisionClassificationCreateModelTest { 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 @@ -74,12 +74,13 @@ public void tearDown() throws IOException { } @Test - public void testVisionClassificationCreateModel() throws IOException, ExecutionException, InterruptedException { + public void testVisionClassificationCreateModel() + throws IOException, ExecutionException, InterruptedException { // Create a random dataset name with a length of 32 characters (max allowed by AutoML) // To prevent name collisions when running tests in multiple java versions at once. // AutoML doesn't allow "-", but accepts "_" String modelName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); + String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); VisionClassificationCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); String got = bout.toString(); diff --git a/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java index 8d621d36ca5..e20c925c49f 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java @@ -45,8 +45,8 @@ public class VisionObjectDetectionCreateModelTest { 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 @@ -79,7 +79,7 @@ public void testCreateDataset() throws IOException, ExecutionException, Interrup // To prevent name collisions when running tests in multiple java versions at once. // AutoML doesn't allow "-", but accepts "_" String modelName = - String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); + String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26)); VisionObjectDetectionCreateModel.createModel(PROJECT_ID, DATASET_ID, modelName); String got = bout.toString(); From fdf273158bfd711c3129d0d3cc5bbb7ff8d77d58 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Tue, 7 Jan 2020 15:27:52 -0700 Subject: [PATCH 06/10] Import order --- .../test/java/com/example/automl/BatchPredictTest.java | 8 ++++---- .../automl/LanguageEntityExtractionCreateModelTest.java | 1 - .../automl/LanguageSentimentAnalysisCreateModelTest.java | 3 ++- .../automl/LanguageTextClassificationCreateModelTest.java | 3 ++- .../automl/VisionClassificationCreateModelTest.java | 3 ++- .../automl/VisionObjectDetectionCreateModelTest.java | 3 ++- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/automl/cloud-client/src/test/java/com/example/automl/BatchPredictTest.java b/automl/cloud-client/src/test/java/com/example/automl/BatchPredictTest.java index 6a702e2a708..3d651a11e30 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/BatchPredictTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/BatchPredictTest.java @@ -50,8 +50,8 @@ public class BatchPredictTest { 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 @@ -83,10 +83,10 @@ public void testBatchPredict() { BatchPredict.batchPredict(PROJECT_ID, MODEL_ID, inputUri, outputUri); String got = bout.toString(); assertThat(got) - .contains("The model is either not found or not supported for prediction yet."); + .contains("The model is either not found or not supported for prediction yet."); } catch (IOException | ExecutionException | InterruptedException e) { assertThat(e.getMessage()) - .contains("The model is either not found or not supported for prediction yet."); + .contains("The model is either not found or not supported for prediction yet."); } } } diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java index 62ea1a24b9b..8f032861299 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java @@ -25,7 +25,6 @@ import java.util.UUID; import java.util.concurrent.ExecutionException; -import com.google.cloud.automl.v1.AutoMlClient; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java index 8d6ffa27506..13d83d04da1 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/LanguageSentimentAnalysisCreateModelTest.java @@ -19,13 +19,14 @@ import static com.google.common.truth.Truth.assertThat; import static junit.framework.TestCase.assertNotNull; +import com.google.cloud.automl.v1.AutoMlClient; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.UUID; import java.util.concurrent.ExecutionException; -import com.google.cloud.automl.v1.AutoMlClient; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java index 65ffe0adacd..4e53eed6bb5 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/LanguageTextClassificationCreateModelTest.java @@ -19,13 +19,14 @@ import static com.google.common.truth.Truth.assertThat; import static junit.framework.TestCase.assertNotNull; +import com.google.cloud.automl.v1.AutoMlClient; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.UUID; import java.util.concurrent.ExecutionException; -import com.google.cloud.automl.v1.AutoMlClient; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; diff --git a/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java index ecf0df92c63..1ed242d2dca 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/VisionClassificationCreateModelTest.java @@ -19,13 +19,14 @@ import static com.google.common.truth.Truth.assertThat; import static junit.framework.TestCase.assertNotNull; +import com.google.cloud.automl.v1.AutoMlClient; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.UUID; import java.util.concurrent.ExecutionException; -import com.google.cloud.automl.v1.AutoMlClient; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; diff --git a/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java index e20c925c49f..65c0d452249 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java @@ -19,13 +19,14 @@ import static com.google.common.truth.Truth.assertThat; import static junit.framework.TestCase.assertNotNull; +import com.google.cloud.automl.v1.AutoMlClient; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.UUID; import java.util.concurrent.ExecutionException; -import com.google.cloud.automl.v1.AutoMlClient; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; From 633782ffaace3803d803efa0bce2c0239399ad27 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Tue, 7 Jan 2020 15:29:14 -0700 Subject: [PATCH 07/10] copy paste typo --- .../example/automl/VisionObjectDetectionCreateModelTest.java | 2 +- .../automl/VisionObjectDetectionDeployModelNodeCountTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java index 65c0d452249..f938eb37202 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java @@ -75,7 +75,7 @@ public void tearDown() throws IOException { } @Test - public void testCreateDataset() throws IOException, ExecutionException, InterruptedException { + public void testVisionObjectDetectionCreateModel() throws IOException, ExecutionException, InterruptedException { // Create a random dataset name with a length of 32 characters (max allowed by AutoML) // To prevent name collisions when running tests in multiple java versions at once. // AutoML doesn't allow "-", but accepts "_" diff --git a/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java b/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java index 86f017d33d6..bff3f83503f 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionDeployModelNodeCountTest.java @@ -63,7 +63,7 @@ public void tearDown() { } @Test - public void testVisionObjectDetectionCreateModel() { + 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. From 8030ab83a2baaf679e92609c91ef61d68806e5c5 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Tue, 7 Jan 2020 15:47:18 -0700 Subject: [PATCH 08/10] License year --- .../test/java/com/example/automl/TranslateCreateModelTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automl/cloud-client/src/test/java/com/example/automl/TranslateCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/TranslateCreateModelTest.java index dadf2c60ce6..3a54765dde0 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/TranslateCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/TranslateCreateModelTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Google LLC + * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From c6eceb0ba01972b7188b2d67fb4ea46787569855 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Tue, 7 Jan 2020 16:08:24 -0700 Subject: [PATCH 09/10] Fix sample error, fix typos in test --- .../com/example/automl/VisionClassificationCreateModel.java | 5 +---- .../src/test/java/com/example/automl/BatchPredictTest.java | 2 +- .../automl/LanguageEntityExtractionCreateModelTest.java | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/automl/cloud-client/src/main/java/com/example/automl/VisionClassificationCreateModel.java b/automl/cloud-client/src/main/java/com/example/automl/VisionClassificationCreateModel.java index 020975da611..3b18dc422ff 100644 --- a/automl/cloud-client/src/main/java/com/example/automl/VisionClassificationCreateModel.java +++ b/automl/cloud-client/src/main/java/com/example/automl/VisionClassificationCreateModel.java @@ -49,10 +49,7 @@ static void createModel(String projectId, String datasetId, String displayName) LocationName projectLocation = LocationName.of(projectId, "us-central1"); // Set model metadata. ImageClassificationModelMetadata metadata = - ImageClassificationModelMetadata.newBuilder() - .setTrainBudgetMilliNodeHours( - 8) // The train budget of creating this model, expressed in hours. - .build(); + ImageClassificationModelMetadata.newBuilder().setTrainBudgetMilliNodeHours(24000).build(); Model model = Model.newBuilder() .setDisplayName(displayName) diff --git a/automl/cloud-client/src/test/java/com/example/automl/BatchPredictTest.java b/automl/cloud-client/src/test/java/com/example/automl/BatchPredictTest.java index 3d651a11e30..d46b669ac1d 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/BatchPredictTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/BatchPredictTest.java @@ -78,7 +78,7 @@ public void testBatchPredict() { // As batch prediction can take a long time. Try to batch predict on a model and confirm that // the model was not found, but other elements of the request were valid. try { - String inputUri = String.format("gs://%s/entity_extraction/input.jsonl", BUCKET_ID); + String inputUri = String.format("gs://%s/entity-extraction/input.jsonl", BUCKET_ID); String outputUri = String.format("gs://%s/TEST_BATCH_PREDICT/", BUCKET_ID); BatchPredict.batchPredict(PROJECT_ID, MODEL_ID, inputUri, outputUri); String got = bout.toString(); diff --git a/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java index 8f032861299..7165916f66a 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/LanguageEntityExtractionCreateModelTest.java @@ -79,7 +79,7 @@ public void testLanguageEntityExtractionCreateModel() { String got = bout.toString(); assertThat(got).contains("Dataset does not exist"); } catch (IOException | ExecutionException | InterruptedException e) { - assertThat(e.getMessage()).contains("Dataset does not exist\""); + assertThat(e.getMessage()).contains("Dataset does not exist"); } } } From 263081fd4d2d8b734f445f6340889549e0cd0cb3 Mon Sep 17 00:00:00 2001 From: nnegrey Date: Tue, 7 Jan 2020 16:23:53 -0700 Subject: [PATCH 10/10] lint: line length --- .../example/automl/VisionObjectDetectionCreateModelTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java b/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java index f938eb37202..7473b1a46c8 100644 --- a/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java +++ b/automl/cloud-client/src/test/java/com/example/automl/VisionObjectDetectionCreateModelTest.java @@ -75,7 +75,8 @@ public void tearDown() throws IOException { } @Test - public void testVisionObjectDetectionCreateModel() throws IOException, ExecutionException, InterruptedException { + public void testVisionObjectDetectionCreateModel() + throws IOException, ExecutionException, InterruptedException { // Create a random dataset name with a length of 32 characters (max allowed by AutoML) // To prevent name collisions when running tests in multiple java versions at once. // AutoML doesn't allow "-", but accepts "_"