Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automl: fix old beta snippet tests #1994

Merged
merged 1 commit into from
Jan 16, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
class ClassificationDeployModel {

// Deploy a model
static void classificationDeployModel(String projectId, String modelId) {
static void classificationDeployModel(String projectId, String modelId)
throws IOException, ExecutionException, InterruptedException {
// String projectId = "YOUR_PROJECT_ID";
// String modelId = "YOUR_MODEL_ID";

Expand All @@ -54,8 +55,6 @@ static void classificationDeployModel(String projectId, String modelId) {

// Display the deployment details of model.
System.out.println("Model deployment finished");
} catch (IOException | InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
class ClassificationDeployModelNodeCount {

// Deploy a model with a specified node count
static void classificationDeployModelNodeCount(String projectId, String modelId) {
static void classificationDeployModelNodeCount(String projectId, String modelId)
throws IOException, ExecutionException, InterruptedException {
// String projectId = "YOUR_PROJECT_ID";
// String modelId = "YOUR_MODEL_ID";

Expand All @@ -54,8 +55,6 @@ static void classificationDeployModelNodeCount(String projectId, String modelId)
OperationFuture<Empty, OperationMetadata> future = client.deployModelAsync(request);
future.get();
System.out.println("Model deployment on 2 nodes finished");
} catch (IOException | InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
class ClassificationUndeployModel {

// Deploy a model
static void classificationUndeployModel(String projectId, String modelId) {
static void classificationUndeployModel(String projectId, String modelId)
throws IOException, ExecutionException, InterruptedException {
// String projectId = "YOUR_PROJECT_ID";
// String modelId = "YOUR_MODEL_ID";

Expand All @@ -54,8 +55,6 @@ static void classificationUndeployModel(String projectId, String modelId) {

// Display the deployment details of model.
System.out.println("Model undeploy finished");
} catch (IOException | InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@

class ObjectDetectionDeployModelNodeCount {

static void objectDetectionDeployModelNodeCount(String projectId, String modelId) {
static void objectDetectionDeployModelNodeCount(String projectId, String modelId)
throws IOException, ExecutionException, InterruptedException {
// String projectId = "YOUR_PROJECT_ID";
// String modelId = "YOUR_MODEL_ID";

Expand All @@ -53,8 +54,6 @@ static void objectDetectionDeployModelNodeCount(String projectId, String modelId
OperationFuture<Empty, OperationMetadata> future = client.deployModelAsync(request);
future.get();
System.out.println("Model deployment on 2 nodes finished");
} catch (IOException | InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
import static com.google.common.truth.Truth.assertThat;

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.Test;

public class ClassificationDeployModelIT {
private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String MODEL_ID = "ICN3125115511348658176";
private static final String MODEL_ID = "ICN0000000000000000000";
private ByteArrayOutputStream bout;
private PrintStream out;

Expand All @@ -45,27 +47,44 @@ public void tearDown() {

@Test
public void testClassificationDeployModelApi() {
ClassificationDeployModel.classificationDeployModel(PROJECT_ID, MODEL_ID);

String got = bout.toString();
assertThat(got).contains("Model deployment finished");
// 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 {
ClassificationDeployModel.classificationDeployModel(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");
}
}

ClassificationUndeployModel.classificationUndeployModel(PROJECT_ID, MODEL_ID);
@Test
public void testClassificationUndeployModelApi() {
// 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 {
ClassificationUndeployModel.classificationUndeployModel(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");
}

got = bout.toString();
assertThat(got).contains("Model undeploy finished");
}

@Test
public void testClassificationDeployModelNodeCountApi() {
ClassificationDeployModelNodeCount.classificationDeployModelNodeCount(PROJECT_ID, MODEL_ID);

String got = bout.toString();
assertThat(got).contains("Model deployment on 2 nodes finished");

ClassificationUndeployModel.classificationUndeployModel(PROJECT_ID, MODEL_ID);

got = bout.toString();
assertThat(got).contains("Model undeploy finished");
// 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 {
ClassificationDeployModelNodeCount.classificationDeployModelNodeCount(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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class ObjectDetectionDeployModelNodeCountIT {
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;

Expand All @@ -52,22 +52,21 @@ public void setUp() {
}

@After
public void tearDown() throws IOException, InterruptedException, ExecutionException {
public void tearDown() {
System.setOut(null);

try (AutoMlClient client = AutoMlClient.create()) {
OperationFuture<Empty, OperationMetadata> future = client.undeployModelAsync(
ModelName.of(PROJECT_ID, "us-central1", MODEL_ID).toString());

future.get();
}
}

@Test
public void testObjectDetectionDeployModelNodeCountApi() {
ObjectDetectionDeployModelNodeCount.objectDetectionDeployModelNodeCount(PROJECT_ID, MODEL_ID);

String got = bout.toString();
assertThat(got).contains("Model deployment on 2 nodes finished");
// 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 {
ObjectDetectionDeployModelNodeCount.objectDetectionDeployModelNodeCount(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");
}
}
}