use of com.google.cloud.bigtable.admin.v2.models.CreateAppProfileRequest in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientTest method testCreateAppProfileAddMultipleClusterIds.
@Test
public void testCreateAppProfileAddMultipleClusterIds() {
// Setup
Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable);
com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder().setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)).setAppProfileId(APP_PROFILE_ID).setAppProfile(com.google.bigtable.admin.v2.AppProfile.newBuilder().setDescription("my description").setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder().addClusterIds("cluster-id-1").addClusterIds("cluster-id-2"))).build();
com.google.bigtable.admin.v2.AppProfile expectedResponse = com.google.bigtable.admin.v2.AppProfile.newBuilder().setName(APP_PROFILE_NAME).setDescription("my description").setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder().addClusterIds("cluster-id-1").addClusterIds("cluster-id-2")).build();
Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
// Execute
AppProfile actualResult = adminClient.createAppProfile(CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID).setDescription("my description").setRoutingPolicy(MultiClusterRoutingPolicy.of("cluster-id-1", "cluster-id-2")));
// Verify
assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse));
}
use of com.google.cloud.bigtable.admin.v2.models.CreateAppProfileRequest in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientTest method testCreateAppProfileAddSingleClusterId.
@Test
public void testCreateAppProfileAddSingleClusterId() {
// Setup
Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable);
com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder().setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)).setAppProfileId(APP_PROFILE_ID).setAppProfile(com.google.bigtable.admin.v2.AppProfile.newBuilder().setDescription("my description").setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder().addClusterIds("cluster-id-1"))).build();
com.google.bigtable.admin.v2.AppProfile expectedResponse = com.google.bigtable.admin.v2.AppProfile.newBuilder().setName(APP_PROFILE_NAME).setDescription("my description").setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder().addClusterIds("cluster-id-1")).build();
Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
// Execute
AppProfile actualResult = adminClient.createAppProfile(CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID).setDescription("my description").setRoutingPolicy(MultiClusterRoutingPolicy.of("cluster-id-1")));
// Verify
assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse));
}
use of com.google.cloud.bigtable.admin.v2.models.CreateAppProfileRequest in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientTest method testCreateAppProfile.
@Test
public void testCreateAppProfile() {
// Setup
Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable);
com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder().setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)).setAppProfileId(APP_PROFILE_ID).setAppProfile(com.google.bigtable.admin.v2.AppProfile.newBuilder().setDescription("my description").setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.getDefaultInstance())).build();
com.google.bigtable.admin.v2.AppProfile expectedResponse = com.google.bigtable.admin.v2.AppProfile.newBuilder().setName(APP_PROFILE_NAME).setDescription("my description").setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.getDefaultInstance()).build();
Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
// Execute
AppProfile actualResult = adminClient.createAppProfile(CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID).setDescription("my description").setRoutingPolicy(MultiClusterRoutingPolicy.of()));
// Verify
assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse));
}
use of com.google.cloud.bigtable.admin.v2.models.CreateAppProfileRequest in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientTest method testCreateAppProfileAddMultipleClusterIdsWithList.
@Test
public void testCreateAppProfileAddMultipleClusterIdsWithList() {
// Setup
Mockito.when(mockStub.createAppProfileCallable()).thenReturn(mockCreateAppProfileCallable);
com.google.bigtable.admin.v2.CreateAppProfileRequest expectedRequest = com.google.bigtable.admin.v2.CreateAppProfileRequest.newBuilder().setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)).setAppProfileId(APP_PROFILE_ID).setAppProfile(com.google.bigtable.admin.v2.AppProfile.newBuilder().setDescription("my description").setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder().addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2")))).build();
com.google.bigtable.admin.v2.AppProfile expectedResponse = com.google.bigtable.admin.v2.AppProfile.newBuilder().setName(APP_PROFILE_NAME).setDescription("my description").setMultiClusterRoutingUseAny(com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder().addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2"))).build();
Mockito.when(mockCreateAppProfileCallable.futureCall(expectedRequest)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
// Execute
AppProfile actualResult = adminClient.createAppProfile(CreateAppProfileRequest.of(INSTANCE_ID, APP_PROFILE_ID).setDescription("my description").setRoutingPolicy(MultiClusterRoutingPolicy.of("cluster-id-1", "cluster-id-2")));
// Verify
assertThat(actualResult).isEqualTo(AppProfile.fromProto(expectedResponse));
}
use of com.google.cloud.bigtable.admin.v2.models.CreateAppProfileRequest in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientIT method appProfileTestMultiClusterWithIds.
@Test
public void appProfileTestMultiClusterWithIds() {
String newInstanceId = prefixGenerator.newPrefix();
String newClusterId = newInstanceId + "-c1";
String newClusterId2 = newInstanceId + "-c2";
client.createInstance(CreateInstanceRequest.of(newInstanceId).addCluster(newClusterId, testEnvRule.env().getPrimaryZone(), 1, StorageType.SSD).addCluster(newClusterId2, testEnvRule.env().getSecondaryZone(), 1, StorageType.SSD).setDisplayName("Multi-Cluster-Instance-Test").addLabel("state", "readytodelete").setType(Type.PRODUCTION));
try {
assertThat(client.exists(newInstanceId)).isTrue();
String testAppProfile = "test-app-profile";
CreateAppProfileRequest request = CreateAppProfileRequest.of(newInstanceId, testAppProfile).setRoutingPolicy(AppProfile.MultiClusterRoutingPolicy.of(newClusterId)).setDescription("This is to test app profile");
AppProfile newlyCreatedAppProfile = client.createAppProfile(request);
AppProfile updated = client.updateAppProfile(UpdateAppProfileRequest.of(newlyCreatedAppProfile).setDescription("new description"));
AppProfile freshAppProfile = client.getAppProfile(newInstanceId, testAppProfile);
assertThat(freshAppProfile.getDescription()).isEqualTo(updated.getDescription());
AppProfile.MultiClusterRoutingPolicy freshAppProfilePolicy = (AppProfile.MultiClusterRoutingPolicy) freshAppProfile.getPolicy();
AppProfile.MultiClusterRoutingPolicy updatedAppProfilePolicy = (AppProfile.MultiClusterRoutingPolicy) updated.getPolicy();
assertThat(freshAppProfilePolicy.getClusterIds()).containsExactly(newClusterId);
assertThat(freshAppProfilePolicy.getClusterIds()).isEqualTo(updatedAppProfilePolicy.getClusterIds());
assertThat(freshAppProfilePolicy).isEqualTo(updatedAppProfilePolicy);
assertThat(client.listAppProfiles(newInstanceId)).contains(freshAppProfile);
// update again with routing policy
AppProfile updated2 = client.updateAppProfile(UpdateAppProfileRequest.of(updated).setRoutingPolicy(AppProfile.MultiClusterRoutingPolicy.of(newClusterId2)));
AppProfile freshAppProfile2 = client.getAppProfile(newInstanceId, testAppProfile);
assertThat(freshAppProfile2.getDescription()).isEqualTo(updated2.getDescription());
AppProfile.MultiClusterRoutingPolicy freshAppProfilePolicy2 = (AppProfile.MultiClusterRoutingPolicy) freshAppProfile2.getPolicy();
AppProfile.MultiClusterRoutingPolicy updatedAppProfilePolicy2 = (AppProfile.MultiClusterRoutingPolicy) updated2.getPolicy();
assertThat(freshAppProfilePolicy2.getClusterIds()).containsExactly(newClusterId2);
assertThat(freshAppProfilePolicy2.getClusterIds()).isEqualTo(updatedAppProfilePolicy2.getClusterIds());
assertThat(freshAppProfilePolicy2).isEqualTo(updatedAppProfilePolicy2);
assertThat(client.listAppProfiles(newInstanceId)).contains(freshAppProfile2);
// update to single routing policy
AppProfile updated3 = client.updateAppProfile(UpdateAppProfileRequest.of(updated).setRoutingPolicy(AppProfile.SingleClusterRoutingPolicy.of(newClusterId)));
AppProfile freshAppProfile3 = client.getAppProfile(newInstanceId, testAppProfile);
assertThat(freshAppProfile3.getDescription()).isEqualTo(updated3.getDescription());
AppProfile.SingleClusterRoutingPolicy freshAppProfilePolicy3 = (AppProfile.SingleClusterRoutingPolicy) freshAppProfile3.getPolicy();
AppProfile.SingleClusterRoutingPolicy updatedAppProfilePolicy3 = (AppProfile.SingleClusterRoutingPolicy) updated3.getPolicy();
assertThat(freshAppProfilePolicy3.getClusterId()).isEqualTo(newClusterId);
assertThat(freshAppProfilePolicy3.getClusterId()).isEqualTo(updatedAppProfilePolicy3.getClusterId());
assertThat(freshAppProfilePolicy3).isEqualTo(updatedAppProfilePolicy3);
assertThat(client.listAppProfiles(newInstanceId)).contains(freshAppProfile3);
} finally {
if (client.exists(newInstanceId)) {
client.deleteInstance(newInstanceId);
}
}
}
Aggregations