public static SnapshotName parse(String formattedString) { if (formattedString.isEmpty()) { return null; } Map<String, String> matchMap = PATH_TEMPLATE.validatedMatch( formattedString, "SnapshotName.parse: formattedString not in valid format"); return of( matchMap.get("project"), matchMap.get("instance"), matchMap.get("cluster"), matchMap.get("snapshot")); }
@Test @SuppressWarnings("all") public void getSnapshotExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockBigtableTableAdmin.addException(exception); try { SnapshotName name = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); client.getSnapshot(name); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Test @SuppressWarnings("all") public void deleteSnapshotExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockBigtableTableAdmin.addException(exception); try { SnapshotName name = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); client.deleteSnapshot(name); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } } }
@Test @SuppressWarnings("all") public void createTableFromSnapshotExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockBigtableTableAdmin.addException(exception); try { InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]"); String tableId = "tableId-895419604"; SnapshotName sourceSnapshot = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); client.createTableFromSnapshotAsync(parent, tableId, sourceSnapshot).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } }
@Test @SuppressWarnings("all") public void snapshotTableExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockBigtableTableAdmin.addException(exception); try { TableName name = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]"); ClusterName cluster = ClusterName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]"); SnapshotName snapshotId = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); String description = "description-1724546052"; client.snapshotTableAsync(name, cluster, snapshotId, description).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } }
@Test @SuppressWarnings("all") public void deleteSnapshotTest() { Empty expectedResponse = Empty.newBuilder().build(); mockBigtableTableAdmin.addResponse(expectedResponse); SnapshotName name = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); client.deleteSnapshot(name); List<GeneratedMessageV3> actualRequests = mockBigtableTableAdmin.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteSnapshotRequest actualRequest = (DeleteSnapshotRequest) actualRequests.get(0); Assert.assertEquals(name, SnapshotName.parse(actualRequest.getName())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void getSnapshotTest() { SnapshotName name2 = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); long dataSizeBytes = 2110122398L; String description = "description-1724546052"; Snapshot expectedResponse = Snapshot.newBuilder() .setName(name2.toString()) .setDataSizeBytes(dataSizeBytes) .setDescription(description) .build(); mockBigtableTableAdmin.addResponse(expectedResponse); SnapshotName name = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); Snapshot actualResponse = client.getSnapshot(name); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockBigtableTableAdmin.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetSnapshotRequest actualRequest = (GetSnapshotRequest) actualRequests.get(0); Assert.assertEquals(name, SnapshotName.parse(actualRequest.getName())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void snapshotTableTest() throws Exception { SnapshotName name2 = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); long dataSizeBytes = 2110122398L; String description2 = "description2568623279"; SnapshotName snapshotId = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]"); String description = "description-1724546052";
String tableId = "tableId-895419604"; SnapshotName sourceSnapshot = SnapshotName.of("[PROJECT]", "[INSTANCE]", "[CLUSTER]", "[SNAPSHOT]");
public static SnapshotName parse(String formattedString) { if (formattedString.isEmpty()) { return null; } Map<String, String> matchMap = PATH_TEMPLATE.validatedMatch( formattedString, "SnapshotName.parse: formattedString not in valid format"); return of( matchMap.get("project"), matchMap.get("instance"), matchMap.get("cluster"), matchMap.get("snapshot")); }