From 9233ae2d2726fa5dc7149f86c77876131a36886f Mon Sep 17 00:00:00 2001 From: sai-chaithu <99007515+sai-chaithu@users.noreply.github.com> Date: Fri, 23 Sep 2022 05:11:03 +0530 Subject: [PATCH] feat(sample): featurestore node updates (#1028) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(sample): featurestore node update * feat(samples): updated featurestore id and tearDown code for FeatureSamplesTest * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat(samples): updated featurestore tests * feat(samples): check style issue fix * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- .../CreateFeaturestoreSampleTest.java | 142 -------------- .../aiplatform/EntityTypeSamplesTest.java | 181 ------------------ .../java/aiplatform/FeatureSamplesTest.java | 156 --------------- .../aiplatform/FeatureValuesSamplesTest.java | 73 ++++++- .../aiplatform/FeaturestoreSamplesTest.java | 88 ++++++++- 5 files changed, 154 insertions(+), 486 deletions(-) delete mode 100644 aiplatform/snippets/src/test/java/aiplatform/CreateFeaturestoreSampleTest.java delete mode 100644 aiplatform/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java delete mode 100644 aiplatform/snippets/src/test/java/aiplatform/FeatureSamplesTest.java diff --git a/aiplatform/snippets/src/test/java/aiplatform/CreateFeaturestoreSampleTest.java b/aiplatform/snippets/src/test/java/aiplatform/CreateFeaturestoreSampleTest.java deleted file mode 100644 index daea9e339e6..00000000000 --- a/aiplatform/snippets/src/test/java/aiplatform/CreateFeaturestoreSampleTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2022 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 aiplatform; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.api.gax.longrunning.OperationFuture; -import com.google.cloud.aiplatform.v1.DeleteFeaturestoreRequest; -import com.google.cloud.aiplatform.v1.DeleteOperationMetadata; -import com.google.cloud.aiplatform.v1.FeaturestoreName; -import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient; -import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings; -import com.google.protobuf.Empty; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -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) -public class CreateFeaturestoreSampleTest { - - private static final String PROJECT_ID = System.getenv("UCAIP_PROJECT_ID"); - private static final int MIN_NODE_COUNT = 1; - private static final int MAX_NODE_COUNT = 5; - private static final boolean USE_FORCE = true; - private static final String LOCATION = "us-central1"; - private static final String ENDPOINT = "us-central1-aiplatform.googleapis.com:443"; - private static final int TIMEOUT = 900; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String featurestoreId; - - private static void requireEnvVar(String varName) { - String errorMessage = - String.format("Environment variable '%s' is required to perform these tests.", varName); - assertNotNull(errorMessage, System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("UCAIP_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - static void deleteFeaturestoreSample( - String project, - String featurestoreId, - boolean useForce, - String location, - String endpoint, - int timeout) - throws IOException, InterruptedException, ExecutionException, TimeoutException { - - FeaturestoreServiceSettings featurestoreServiceSettings = - FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build(); - - // Initialize client that will be used to send requests. This client only needs to be created - // once, and can be reused for multiple requests. After completing all of your requests, call - // the "close" method on the client to safely clean up any remaining background resources. - try (FeaturestoreServiceClient featurestoreServiceClient = - FeaturestoreServiceClient.create(featurestoreServiceSettings)) { - - DeleteFeaturestoreRequest deleteFeaturestoreRequest = - DeleteFeaturestoreRequest.newBuilder() - .setName(FeaturestoreName.of(project, location, featurestoreId).toString()) - .setForce(useForce) - .build(); - - OperationFuture operationFuture = - featurestoreServiceClient.deleteFeaturestoreAsync(deleteFeaturestoreRequest); - System.out.format("Operation name: %s%n", operationFuture.getInitialFuture().get().getName()); - System.out.println("Waiting for operation to finish..."); - operationFuture.get(timeout, TimeUnit.SECONDS); - - System.out.format("Deleted Featurestore."); - } - } - - @After - public void tearDown() - throws InterruptedException, ExecutionException, IOException, TimeoutException { - - // Delete the featurestore - deleteFeaturestoreSample(PROJECT_ID, featurestoreId, USE_FORCE, LOCATION, ENDPOINT, 60); - - // Assert - String deleteFeaturestoreResponse = bout.toString(); - assertThat(deleteFeaturestoreResponse).contains("Deleted Featurestore"); - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testCreateFeaturestoreSample() - throws IOException, InterruptedException, ExecutionException, TimeoutException { - // Create the featurestore - String tempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 26); - String id = String.format("temp_create_featurestore_test_%s", tempUuid); - CreateFeaturestoreSample.createFeaturestoreSample( - PROJECT_ID, id, MIN_NODE_COUNT, MAX_NODE_COUNT, LOCATION, ENDPOINT, TIMEOUT); - - // Assert - String createFeaturestoreResponse = bout.toString(); - assertThat(createFeaturestoreResponse).contains("Create Featurestore Response"); - featurestoreId = - createFeaturestoreResponse.split("Name: ")[1].split("featurestores/")[1].split("\n")[0] - .trim(); - } -} diff --git a/aiplatform/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java b/aiplatform/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java deleted file mode 100644 index 41227c71c93..00000000000 --- a/aiplatform/snippets/src/test/java/aiplatform/EntityTypeSamplesTest.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright 2022 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 aiplatform; - -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 java.util.concurrent.TimeoutException; -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) -public class EntityTypeSamplesTest { - - private static final String PROJECT_ID = System.getenv("UCAIP_PROJECT_ID"); - private static final int MIN_NODE_COUNT = 1; - private static final int MAX_NODE_COUNT = 5; - private static final String DESCRIPTION = "Test Description"; - private static final int MONITORING_INTERVAL_DAYS = 1; - private static final boolean USE_FORCE = true; - private static final String LOCATION = "us-central1"; - private static final String ENDPOINT = "us-central1-aiplatform.googleapis.com:443"; - private static final int TIMEOUT = 900; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String featurestoreId; - - private static void requireEnvVar(String varName) { - String errorMessage = - String.format("Environment variable '%s' is required to perform these tests.", varName); - assertNotNull(errorMessage, System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("UCAIP_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() - throws InterruptedException, ExecutionException, IOException, TimeoutException { - - // Delete the featurestore - DeleteFeaturestoreSample.deleteFeaturestoreSample( - PROJECT_ID, featurestoreId, USE_FORCE, LOCATION, ENDPOINT, 60); - - // Assert - String deleteFeaturestoreResponse = bout.toString(); - assertThat(deleteFeaturestoreResponse).contains("Deleted Featurestore"); - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testEntityTypeSamples() - throws IOException, InterruptedException, ExecutionException, TimeoutException { - // Create the featurestore - String tempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 26); - String id = String.format("temp_create_featurestore_test_%s", tempUuid); - CreateFeaturestoreSample.createFeaturestoreSample( - PROJECT_ID, id, MIN_NODE_COUNT, MAX_NODE_COUNT, LOCATION, ENDPOINT, TIMEOUT); - - // Assert - String createFeaturestoreResponse = bout.toString(); - assertThat(createFeaturestoreResponse).contains("Create Featurestore Response"); - featurestoreId = - createFeaturestoreResponse.split("Name: ")[1].split("featurestores/")[1].split("\n")[0] - .trim(); - - // Create the entity type - String entityTypeTempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 16); - String entityTypeId = String.format("temp_create_entity_type_test_%s", entityTypeTempUuid); - CreateEntityTypeSample.createEntityTypeSample( - PROJECT_ID, featurestoreId, entityTypeId, DESCRIPTION, LOCATION, ENDPOINT, TIMEOUT); - - // Assert - String createEntityTypeResponse = bout.toString(); - assertThat(createEntityTypeResponse).contains("Create Entity Type Response"); - - // Get the entity type - GetEntityTypeSample.getEntityTypeSample( - PROJECT_ID, featurestoreId, entityTypeId, LOCATION, ENDPOINT); - - // Assert - String getEntityTypeResponse = bout.toString(); - assertThat(getEntityTypeResponse).contains("Get Entity Type Response"); - - // Create the entity type - String entityTypeMonitoringTempUuid = - UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 16); - String entityTypeMonitoringId = - String.format("temp_create_entity_type_test_%s", entityTypeMonitoringTempUuid); - CreateEntityTypeMonitoringSample.createEntityTypeMonitoringSample( - PROJECT_ID, - featurestoreId, - entityTypeMonitoringId, - DESCRIPTION, - MONITORING_INTERVAL_DAYS, - LOCATION, - ENDPOINT, - TIMEOUT); - - // Assert - String createEntityTypeMonitoringResponse = bout.toString(); - assertThat(createEntityTypeMonitoringResponse) - .contains("Create Entity Type Monitoring Response"); - - // List entity types - ListEntityTypesSample.listEntityTypesSample(PROJECT_ID, featurestoreId, LOCATION, ENDPOINT); - - // Assert - String listEntityTypeResponse = bout.toString(); - assertThat(listEntityTypeResponse).contains("List Entity Types Response"); - - // Update the entity type - UpdateEntityTypeSample.updateEntityTypeSample( - PROJECT_ID, featurestoreId, entityTypeId, DESCRIPTION, LOCATION, ENDPOINT); - - // Assert - String updateEntityTypeResponse = bout.toString(); - assertThat(updateEntityTypeResponse).contains("Update Entity Type Response"); - - // Update the entity type - UpdateEntityTypeMonitoringSample.updateEntityTypeMonitoringSample( - PROJECT_ID, featurestoreId, entityTypeId, MONITORING_INTERVAL_DAYS, LOCATION, ENDPOINT); - - // Assert - String updateEntityTypeMonitoringResponse = bout.toString(); - assertThat(updateEntityTypeMonitoringResponse) - .contains("Update Entity Type Monitoring Response"); - - // List entity types - ListEntityTypesAsyncSample.listEntityTypesAsyncSample( - PROJECT_ID, featurestoreId, LOCATION, ENDPOINT); - - // Assert - String listEntityTypeAsyncResponse = bout.toString(); - assertThat(listEntityTypeAsyncResponse).contains("List Entity Types Async Response"); - - // Delete the entity type - DeleteEntityTypeSample.deleteEntityTypeSample( - PROJECT_ID, featurestoreId, entityTypeId, LOCATION, ENDPOINT, TIMEOUT); - - // Assert - String deleteEntityTypeResponse = bout.toString(); - assertThat(deleteEntityTypeResponse).contains("Deleted Entity Type"); - } -} diff --git a/aiplatform/snippets/src/test/java/aiplatform/FeatureSamplesTest.java b/aiplatform/snippets/src/test/java/aiplatform/FeatureSamplesTest.java deleted file mode 100644 index a0f93967561..00000000000 --- a/aiplatform/snippets/src/test/java/aiplatform/FeatureSamplesTest.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 2022 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 aiplatform; - -import static com.google.common.truth.Truth.assertThat; -import static junit.framework.TestCase.assertNotNull; - -import com.google.cloud.aiplatform.v1.Feature.ValueType; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.UUID; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -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) -public class FeatureSamplesTest { - - private static final String PROJECT_ID = System.getenv("UCAIP_PROJECT_ID"); - private static final ValueType VALUE_TYPE = ValueType.STRING; - private static final String DESCRIPTION = "Test Description"; - private static final String QUERY = "value_type=STRING"; - private static final String LOCATION = "us-central1"; - private static final String ENDPOINT = "us-central1-aiplatform.googleapis.com:443"; - private ByteArrayOutputStream bout; - private PrintStream out; - private PrintStream originalPrintStream; - private String featurestoreId = "featurestore_sample"; - - private static void requireEnvVar(String varName) { - String errorMessage = - String.format("Environment variable '%s' is required to perform these tests.", varName); - assertNotNull(errorMessage, System.getenv(varName)); - } - - @BeforeClass - public static void checkRequirements() { - requireEnvVar("GOOGLE_APPLICATION_CREDENTIALS"); - requireEnvVar("UCAIP_PROJECT_ID"); - } - - @Before - public void setUp() { - bout = new ByteArrayOutputStream(); - out = new PrintStream(bout); - originalPrintStream = System.out; - System.setOut(out); - } - - @After - public void tearDown() - throws InterruptedException, ExecutionException, IOException, TimeoutException { - - System.out.flush(); - System.setOut(originalPrintStream); - } - - @Test - public void testFeatureSamples() - throws IOException, InterruptedException, ExecutionException, TimeoutException { - - // Create the entity type - String entityTypeTempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 16); - String entityTypeId = String.format("temp_create_entity_type_test_%s", entityTypeTempUuid); - CreateEntityTypeSample.createEntityTypeSample( - PROJECT_ID, featurestoreId, entityTypeId, DESCRIPTION, LOCATION, ENDPOINT, 900); - - // Assert - String createEntityTypeResponse = bout.toString(); - assertThat(createEntityTypeResponse).contains("Create Entity Type Response"); - - // Create the feature - String featureTempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 26); - String featureId = String.format("temp_create_feature_test_%s", featureTempUuid); - CreateFeatureSample.createFeatureSample( - PROJECT_ID, - featurestoreId, - entityTypeId, - featureId, - DESCRIPTION, - VALUE_TYPE, - LOCATION, - ENDPOINT, - 900); - - // Assert - String createFeatureResponse = bout.toString(); - assertThat(createFeatureResponse).contains("Create Feature Response"); - - // Get the feature - GetFeatureSample.getFeatureSample( - PROJECT_ID, featurestoreId, entityTypeId, featureId, LOCATION, ENDPOINT); - - // Assert - String getFeatureResponse = bout.toString(); - assertThat(getFeatureResponse).contains("Get Feature Response"); - - // List features - ListFeaturesSample.listFeaturesSample( - PROJECT_ID, featurestoreId, entityTypeId, LOCATION, ENDPOINT); - - // Assert - String listfeatureResponse = bout.toString(); - assertThat(listfeatureResponse).contains("List Features Response"); - - // List features - ListFeaturesAsyncSample.listFeaturesAsyncSample( - PROJECT_ID, featurestoreId, entityTypeId, LOCATION, ENDPOINT); - - // Assert - String listfeatureAsyncResponse = bout.toString(); - assertThat(listfeatureAsyncResponse).contains("List Features Async Response"); - - // Search features - SearchFeaturesSample.searchFeaturesSample(PROJECT_ID, QUERY, LOCATION, ENDPOINT); - - // Assert - String searchFeaturesResponse = bout.toString(); - assertThat(searchFeaturesResponse).contains("Search Features Response"); - - // Search features - SearchFeaturesAsyncSample.searchFeaturesAsyncSample(PROJECT_ID, QUERY, LOCATION, ENDPOINT); - - // Assert - String searchFeaturesAsyncResponse = bout.toString(); - assertThat(searchFeaturesAsyncResponse).contains("Search Features Async Response"); - - // Delete the feature - DeleteFeatureSample.deleteFeatureSample( - PROJECT_ID, featurestoreId, entityTypeId, featureId, LOCATION, ENDPOINT, 300); - - // Assert - String deleteFeatureResponse = bout.toString(); - assertThat(deleteFeatureResponse).contains("Deleted Feature"); - } -} diff --git a/aiplatform/snippets/src/test/java/aiplatform/FeatureValuesSamplesTest.java b/aiplatform/snippets/src/test/java/aiplatform/FeatureValuesSamplesTest.java index 56852503b09..b4e6bba320d 100644 --- a/aiplatform/snippets/src/test/java/aiplatform/FeatureValuesSamplesTest.java +++ b/aiplatform/snippets/src/test/java/aiplatform/FeatureValuesSamplesTest.java @@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat; import static junit.framework.TestCase.assertNotNull; +import com.google.cloud.aiplatform.v1.Feature.ValueType; import com.google.cloud.bigquery.BigQuery; import com.google.cloud.bigquery.BigQuery.DatasetDeleteOption; import com.google.cloud.bigquery.BigQueryException; @@ -48,9 +49,11 @@ public class FeatureValuesSamplesTest { private static final String PROJECT_ID = System.getenv("UCAIP_PROJECT_ID"); private static final int MIN_NODE_COUNT = 1; - private static final int MAX_NODE_COUNT = 5; + private static final int MAX_NODE_COUNT = 2; private static final String DESCRIPTION = "Test Description"; private static final boolean USE_FORCE = true; + private static final ValueType VALUE_TYPE = ValueType.STRING; + private static final String QUERY = "value_type=STRING"; private static final String ENTITY_ID_FIELD = "movie_id"; private static final String FEATURE_TIME_FIELD = "update_time"; private static final String GCS_SOURCE_URI = @@ -168,8 +171,8 @@ public void tearDown() public void testFeatureValuesSamples() throws IOException, InterruptedException, ExecutionException, TimeoutException { // Create the featurestore - String tempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 26); - String id = String.format("temp_create_featurestore_test_%s", tempUuid); + String tempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 23); + String id = String.format("temp_feature_values_samples_test_%s", tempUuid); CreateFeaturestoreSample.createFeaturestoreSample( PROJECT_ID, id, MIN_NODE_COUNT, MAX_NODE_COUNT, LOCATION, ENDPOINT, 900); @@ -189,6 +192,70 @@ public void testFeatureValuesSamples() String createEntityTypeResponse = bout.toString(); assertThat(createEntityTypeResponse).contains("Create Entity Type Response"); + // Create the feature + String featureTempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 25); + String featureId = String.format("temp_feature_feature_test_%s", featureTempUuid); + CreateFeatureSample.createFeatureSample( + PROJECT_ID, + featurestoreId, + entityTypeId, + featureId, + DESCRIPTION, + VALUE_TYPE, + LOCATION, + ENDPOINT, + 900); + + // Assert + String createFeatureResponse = bout.toString(); + assertThat(createFeatureResponse).contains("Create Feature Response"); + + // Get the feature + GetFeatureSample.getFeatureSample( + PROJECT_ID, featurestoreId, entityTypeId, featureId, LOCATION, ENDPOINT); + + // Assert + String getFeatureResponse = bout.toString(); + assertThat(getFeatureResponse).contains("Get Feature Response"); + + // List features + ListFeaturesSample.listFeaturesSample( + PROJECT_ID, featurestoreId, entityTypeId, LOCATION, ENDPOINT); + + // Assert + String listfeatureResponse = bout.toString(); + assertThat(listfeatureResponse).contains("List Features Response"); + + // List features + ListFeaturesAsyncSample.listFeaturesAsyncSample( + PROJECT_ID, featurestoreId, entityTypeId, LOCATION, ENDPOINT); + + // Assert + String listfeatureAsyncResponse = bout.toString(); + assertThat(listfeatureAsyncResponse).contains("List Features Async Response"); + + // Search features + SearchFeaturesSample.searchFeaturesSample(PROJECT_ID, QUERY, LOCATION, ENDPOINT); + + // Assert + String searchFeaturesResponse = bout.toString(); + assertThat(searchFeaturesResponse).contains("Search Features Response"); + + // Search features + SearchFeaturesAsyncSample.searchFeaturesAsyncSample(PROJECT_ID, QUERY, LOCATION, ENDPOINT); + + // Assert + String searchFeaturesAsyncResponse = bout.toString(); + assertThat(searchFeaturesAsyncResponse).contains("Search Features Async Response"); + + // Delete the feature + DeleteFeatureSample.deleteFeatureSample( + PROJECT_ID, featurestoreId, entityTypeId, featureId, LOCATION, ENDPOINT, 300); + + // Assert + String deleteFeatureResponse = bout.toString(); + assertThat(deleteFeatureResponse).contains("Deleted Feature"); + // Batch create features BatchCreateFeaturesSample.batchCreateFeaturesSample( PROJECT_ID, featurestoreId, entityTypeId, LOCATION, ENDPOINT, TIMEOUT); diff --git a/aiplatform/snippets/src/test/java/aiplatform/FeaturestoreSamplesTest.java b/aiplatform/snippets/src/test/java/aiplatform/FeaturestoreSamplesTest.java index b0a207b2237..74fcbde5b01 100644 --- a/aiplatform/snippets/src/test/java/aiplatform/FeaturestoreSamplesTest.java +++ b/aiplatform/snippets/src/test/java/aiplatform/FeaturestoreSamplesTest.java @@ -37,8 +37,10 @@ public class FeaturestoreSamplesTest { private static final String PROJECT_ID = System.getenv("UCAIP_PROJECT_ID"); private static final int MIN_NODE_COUNT = 1; - private static final int MAX_NODE_COUNT = 5; - private static final int FIXED_NODE_COUNT = 5; + private static final int MAX_NODE_COUNT = 2; + private static final int FIXED_NODE_COUNT = 2; + private static final String DESCRIPTION = "Test Description"; + private static final int MONITORING_INTERVAL_DAYS = 1; private static final boolean USE_FORCE = true; private static final String LOCATION = "us-central1"; private static final String ENDPOINT = "us-central1-aiplatform.googleapis.com:443"; @@ -87,8 +89,8 @@ public void tearDown() public void testCreateFeaturestoreSample() throws IOException, InterruptedException, ExecutionException, TimeoutException { // Create the featurestore - String tempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 26); - String id = String.format("temp_create_featurestore_test_%s", tempUuid); + String tempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 25); + String id = String.format("temp_featurestore_samples_test_%s", tempUuid); CreateFeaturestoreFixedNodesSample.createFeaturestoreFixedNodesSample( PROJECT_ID, id, FIXED_NODE_COUNT, LOCATION, ENDPOINT, 900); @@ -136,5 +138,83 @@ public void testCreateFeaturestoreSample() // Assert String listFeaturestoresAsyncResponse = bout.toString(); assertThat(listFeaturestoresAsyncResponse).contains("List Featurestores Async Response"); + + // Create the entity type + String entityTypeTempUuid = UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 14); + String entityTypeId = String.format("temp_featurestore_samples_test_%s", entityTypeTempUuid); + CreateEntityTypeSample.createEntityTypeSample( + PROJECT_ID, featurestoreId, entityTypeId, DESCRIPTION, LOCATION, ENDPOINT, TIMEOUT); + + // Assert + String createEntityTypeResponse = bout.toString(); + assertThat(createEntityTypeResponse).contains("Create Entity Type Response"); + + // Get the entity type + GetEntityTypeSample.getEntityTypeSample( + PROJECT_ID, featurestoreId, entityTypeId, LOCATION, ENDPOINT); + + // Assert + String getEntityTypeResponse = bout.toString(); + assertThat(getEntityTypeResponse).contains("Get Entity Type Response"); + + // Create the entity type + String entityTypeMonitoringTempUuid = + UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 14); + String entityTypeMonitoringId = + String.format("temp_featurestore_samples_test_%s", entityTypeMonitoringTempUuid); + CreateEntityTypeMonitoringSample.createEntityTypeMonitoringSample( + PROJECT_ID, + featurestoreId, + entityTypeMonitoringId, + DESCRIPTION, + MONITORING_INTERVAL_DAYS, + LOCATION, + ENDPOINT, + TIMEOUT); + + // Assert + String createEntityTypeMonitoringResponse = bout.toString(); + assertThat(createEntityTypeMonitoringResponse) + .contains("Create Entity Type Monitoring Response"); + + // List entity types + ListEntityTypesSample.listEntityTypesSample(PROJECT_ID, featurestoreId, LOCATION, ENDPOINT); + + // Assert + String listEntityTypeResponse = bout.toString(); + assertThat(listEntityTypeResponse).contains("List Entity Types Response"); + + // Update the entity type + UpdateEntityTypeSample.updateEntityTypeSample( + PROJECT_ID, featurestoreId, entityTypeId, DESCRIPTION, LOCATION, ENDPOINT); + + // Assert + String updateEntityTypeResponse = bout.toString(); + assertThat(updateEntityTypeResponse).contains("Update Entity Type Response"); + + // Update the entity type + UpdateEntityTypeMonitoringSample.updateEntityTypeMonitoringSample( + PROJECT_ID, featurestoreId, entityTypeId, MONITORING_INTERVAL_DAYS, LOCATION, ENDPOINT); + + // Assert + String updateEntityTypeMonitoringResponse = bout.toString(); + assertThat(updateEntityTypeMonitoringResponse) + .contains("Update Entity Type Monitoring Response"); + + // List entity types + ListEntityTypesAsyncSample.listEntityTypesAsyncSample( + PROJECT_ID, featurestoreId, LOCATION, ENDPOINT); + + // Assert + String listEntityTypeAsyncResponse = bout.toString(); + assertThat(listEntityTypeAsyncResponse).contains("List Entity Types Async Response"); + + // Delete the entity type + DeleteEntityTypeSample.deleteEntityTypeSample( + PROJECT_ID, featurestoreId, entityTypeId, LOCATION, ENDPOINT, TIMEOUT); + + // Assert + String deleteEntityTypeResponse = bout.toString(); + assertThat(deleteEntityTypeResponse).contains("Deleted Entity Type"); } }