Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .kokoro/tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ if [[ "$SCRIPT_DEBUG" != "true" ]]; then
source "${KOKORO_GFILE_DIR}/storage-hmac-credentials.sh"
source "${KOKORO_GFILE_DIR}/dlp_secrets.txt"
source "${KOKORO_GFILE_DIR}/bigtable_secrets.txt"
source "${KOKORO_GFILE_DIR}/automl_secrets.txt"
# Activate service account
gcloud auth activate-service-account \
--key-file="$GOOGLE_APPLICATION_CREDENTIALS" \
Expand Down
23 changes: 4 additions & 19 deletions automl/cloud-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,17 @@
</parent>

<properties>
<maven.compiler.target>1.11</maven.compiler.target>
<maven.compiler.source>1.11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<!-- [START automl_java_dependencies] -->
<!-- Using libraries-bom to manage versions.
See https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/The-Google-Cloud-Platform-Libraries-BOM -->
<dependencyManagement>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the new version not in the BOM? If so do we know when it will be released?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not yet.

It is pushed to java-cloud-bom: https://github.com/googleapis/java-cloud-bom/blob/master/pom.xml#L207

Which is also in cloud-opensource-java: https://github.com/GoogleCloudPlatform/cloud-opensource-java/blob/ca1dede295e2db75fc7a8148fddadbbf102af80c/boms/cloud-oss-bom/pom.xml#L48

But not sure of their release process. But 3.3.0 did not contain it.

<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>3.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- [START automl_java_dependencies] -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-automl</artifactId>
<version>0.115.1-beta</version>
</dependency>
<!-- [END automl_java_dependencies] -->
<dependency>
Expand All @@ -77,7 +64,5 @@
<version>1.0</version>
<scope>test</scope>
</dependency>
<!-- [START automl_java_dependencies] -->
</dependencies>
<!-- [END automl_java_dependencies] -->
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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<BatchPredictResult, OperationMetadata> future =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* 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 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 DeleteDatasetTest {

private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID");
private ByteArrayOutputStream bout;
private PrintStream out;
private String datasetId;

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() throws InterruptedException, ExecutionException, IOException {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
System.setOut(out);

// Create a fake dataset to be deleted
// 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 datasetName =
String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26));
LanguageEntityExtractionCreateDataset.createDataset(PROJECT_ID, datasetName);
String got = bout.toString();
datasetId = got.split("Dataset id: ")[1].split("\n")[0];

bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
System.setOut(out);
}

@After
public void tearDown() {
System.setOut(null);
}

@Test
public void testDeleteDataset() throws IOException, ExecutionException, InterruptedException {
DeleteDataset.deleteDataset(PROJECT_ID, datasetId);
String got = bout.toString();
assertThat(got).contains("Dataset deleted.");
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -27,7 +27,6 @@
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;
Expand All @@ -37,29 +36,28 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

// Tests for Automl natural language text classification datasets.
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class LanguageTextClassificationDatasetManagementIT {
public class ExportDatasetTest {

private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID");
private static final String DATASET_ID = System.getenv("ENTITY_EXTRACTION_DATASET_ID");
private static final String BUCKET_ID = PROJECT_ID + "-lcm";
private static final String BUCKET = "gs://" + BUCKET_ID;
private ByteArrayOutputStream bout;
private PrintStream out;
private String getdatasetId = "TCN2551826603472450019";

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
public static void checkRequirements() {
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
requireEnvVar("GOOGLE_CLOUD_PROJECT");
requireEnvVar("AUTOML_PROJECT_ID");
requireEnvVar("ENTITY_EXTRACTION_DATASET_ID");
}

@Before
Expand All @@ -71,68 +69,7 @@ public void setUp() {

@After
public void tearDown() {
System.setOut(null);
}

@Test
public void testCreateImportDeleteDataset()
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 datasetName =
String.format("test_%s", UUID.randomUUID().toString().replace("-", "_").substring(0, 26));

// Act
LanguageTextClassificationCreateDataset.createDataset(PROJECT_ID, datasetName);

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

// Act
ImportDataset.importDataset(PROJECT_ID, datasetId, BUCKET + "/happiness.csv");

// Assert
got = bout.toString();
assertThat(got).contains("Dataset id:");

// Act
DeleteDataset.deleteDataset(PROJECT_ID, datasetId);

// Assert
got = bout.toString();
assertThat(got).contains("Dataset deleted.");
}

@Test
public void testListDataset() throws IOException {
// Act
ListDatasets.listDatasets(PROJECT_ID);

// Assert
String got = bout.toString();
assertThat(got).contains("Dataset id:");
}

@Test
public void testGetDataset() throws IOException {
// Act
GetDataset.getDataset(PROJECT_ID, getdatasetId);

// Assert
String got = bout.toString();

assertThat(got).contains("Dataset id:");
}

@Test
public void testExportDataset() throws IOException, ExecutionException, InterruptedException {
ExportDataset.exportDataset(PROJECT_ID, getdatasetId, BUCKET + "/TEST_EXPORT_OUTPUT/");

String got = bout.toString();
assertThat(got).contains("Dataset exported.");

// Delete the created files from GCS
Storage storage = StorageOptions.getDefaultInstance().getService();
Page<Blob> blobs =
storage.list(
Expand All @@ -152,5 +89,14 @@ public void testExportDataset() throws IOException, ExecutionException, Interrup
}
}
}

System.setOut(null);
}

@Test
public void testExportDataset() throws IOException, ExecutionException, InterruptedException {
ExportDataset.exportDataset(PROJECT_ID, DATASET_ID, BUCKET + "/TEST_EXPORT_OUTPUT/");
String got = bout.toString();
assertThat(got).contains("Dataset exported.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
// Tests for Automl models.
@RunWith(JUnit4.class)
public class GenericModelManagementIT {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID");
private String modelId;
private String modelEvaluationId;
private ByteArrayOutputStream bout;
Expand All @@ -50,7 +50,7 @@ private static void requireEnvVar(String varName) {
@BeforeClass
public static void checkRequirements() {
requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS");
requireEnvVar("GOOGLE_CLOUD_PROJECT");
requireEnvVar("AUTOML_PROJECT_ID");
}

@Before
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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 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 GetDatasetTest {

private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID");
private static final String DATASET_ID = System.getenv("ENTITY_EXTRACTION_DATASET_ID");
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");
requireEnvVar("ENTITY_EXTRACTION_DATASET_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 testGetDataset() throws IOException {
GetDataset.getDataset(PROJECT_ID, DATASET_ID);
String got = bout.toString();
assertThat(got).contains("Dataset id:");
}
}
Loading