use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.
the class NativeImageBigtableTest method setUp.
@Before
public void setUp() throws IOException {
// Create instance if not present
BigtableInstanceAdminSettings instanceAdminSettings = BigtableInstanceAdminSettings.newBuilder().setProjectId(PROJECT_ID).build();
BigtableInstanceAdminClient instanceAdminClient = BigtableInstanceAdminClient.create(instanceAdminSettings);
if (!instanceAdminClient.exists(INSTANCE_NAME)) {
instanceAdminClient.createInstance(CreateInstanceRequest.of(INSTANCE_NAME).addCluster("cluster", "us-central1-f", 3, StorageType.SSD).setType(Instance.Type.PRODUCTION).addLabel("example", "instance_admin"));
}
BigtableTableAdminSettings adminClientSettings = BigtableTableAdminSettings.newBuilder().setInstanceId(INSTANCE_NAME).setProjectId(PROJECT_ID).build();
BigtableDataSettings clientSettings = BigtableDataSettings.newBuilder().setInstanceId(INSTANCE_NAME).setProjectId(PROJECT_ID).build();
adminClient = BigtableTableAdminClient.create(adminClientSettings);
tableName = TABLE_SUFFIX + UUID.randomUUID().toString().replace("-", "");
NativeImageBigtableSample.createTable(adminClient, tableName);
dataClient = BigtableDataClient.create(clientSettings);
// To test output stream
originalOut = System.out;
bout = new ByteArrayOutputStream();
System.setOut(new PrintStream(bout));
}
use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.
the class InstanceAdminExample method getInstance.
/**
* Demonstrates how to get an instance.
*/
public Instance getInstance() {
System.out.println("\nGet Instance");
// [START bigtable_get_instance]
Instance instance = null;
try {
instance = adminClient.getInstance(instanceId);
System.out.println("Instance ID: " + instance.getId());
System.out.println("Display Name: " + instance.getDisplayName());
System.out.print("Labels: ");
Map<String, String> labels = instance.getLabels();
for (String key : labels.keySet()) {
System.out.printf("%s - %s", key, labels.get(key));
}
System.out.println("\nState: " + instance.getState());
System.out.println("Type: " + instance.getType());
} catch (NotFoundException e) {
System.err.println("Failed to get non-existent instance: " + e.getMessage());
}
// [END bigtable_get_instance]
return instance;
}
use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.
the class BaseBigtableInstanceAdminClientTest method listAppProfilesTest.
@Test
public void listAppProfilesTest() throws Exception {
AppProfile responsesElement = AppProfile.newBuilder().build();
ListAppProfilesResponse expectedResponse = ListAppProfilesResponse.newBuilder().setNextPageToken("").addAllAppProfiles(Arrays.asList(responsesElement)).build();
mockBigtableInstanceAdmin.addResponse(expectedResponse);
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
ListAppProfilesPagedResponse pagedListResponse = client.listAppProfiles(parent);
List<AppProfile> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getAppProfilesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListAppProfilesRequest actualRequest = ((ListAppProfilesRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.
the class BaseBigtableTableAdminClientTest method listTablesTest.
@Test
public void listTablesTest() throws Exception {
Table responsesElement = Table.newBuilder().build();
ListTablesResponse expectedResponse = ListTablesResponse.newBuilder().setNextPageToken("").addAllTables(Arrays.asList(responsesElement)).build();
mockBigtableTableAdmin.addResponse(expectedResponse);
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
ListTablesPagedResponse pagedListResponse = client.listTables(parent);
List<Table> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getTablesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListTablesRequest actualRequest = ((ListTablesRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.bigtable.admin.v2.models.Instance in project java-bigtable by googleapis.
the class BigtableInstanceAdminClientTest method testUpdateInstance.
@Test
public void testUpdateInstance() {
// Setup
Mockito.when(mockStub.partialUpdateInstanceOperationCallable()).thenReturn(mockUpdateInstanceCallable);
com.google.bigtable.admin.v2.PartialUpdateInstanceRequest expectedRequest = com.google.bigtable.admin.v2.PartialUpdateInstanceRequest.newBuilder().setUpdateMask(FieldMask.newBuilder().addPaths("display_name")).setInstance(com.google.bigtable.admin.v2.Instance.newBuilder().setName(INSTANCE_NAME).setDisplayName("new display name")).build();
com.google.bigtable.admin.v2.Instance expectedResponse = com.google.bigtable.admin.v2.Instance.newBuilder().setName(INSTANCE_NAME).build();
mockOperationResult(mockUpdateInstanceCallable, expectedRequest, expectedResponse);
// Execute
Instance actualResult = adminClient.updateInstance(UpdateInstanceRequest.of(INSTANCE_ID).setDisplayName("new display name"));
// Verify
assertThat(actualResult).isEqualTo(Instance.fromProto(expectedResponse));
}
Aggregations