use of com.google.bigtable.admin.v2.Snapshot in project java-pubsub by googleapis.
the class SubscriptionAdminClientTest method createSnapshotTest.
@Test
public void createSnapshotTest() throws Exception {
Snapshot expectedResponse = Snapshot.newBuilder().setName(SnapshotName.of("[PROJECT]", "[SNAPSHOT]").toString()).setTopic(TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]").toString()).setExpireTime(Timestamp.newBuilder().build()).putAllLabels(new HashMap<String, String>()).build();
mockSubscriber.addResponse(expectedResponse);
SnapshotName name = SnapshotName.of("[PROJECT]", "[SNAPSHOT]");
SubscriptionName subscription = SubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
Snapshot actualResponse = client.createSnapshot(name, subscription);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateSnapshotRequest actualRequest = ((CreateSnapshotRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertEquals(subscription.toString(), actualRequest.getSubscription());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.bigtable.admin.v2.Snapshot in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method createSnapshotTest.
@Test
@SuppressWarnings("all")
public void createSnapshotTest() {
SnapshotName name2 = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
Snapshot expectedResponse = Snapshot.newBuilder().setNameWithSnapshotName(name2).setTopicWithTopicName(topic).build();
mockSubscriber.addResponse(expectedResponse);
SnapshotName name = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
Snapshot actualResponse = client.createSnapshot(name, subscription);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateSnapshotRequest actualRequest = (CreateSnapshotRequest) actualRequests.get(0);
Assert.assertEquals(name, actualRequest.getNameAsSnapshotName());
Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
}
use of com.google.bigtable.admin.v2.Snapshot in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method listSnapshotsTest.
@Test
@SuppressWarnings("all")
public void listSnapshotsTest() {
String nextPageToken = "";
Snapshot snapshotsElement = Snapshot.newBuilder().build();
List<Snapshot> snapshots = Arrays.asList(snapshotsElement);
ListSnapshotsResponse expectedResponse = ListSnapshotsResponse.newBuilder().setNextPageToken(nextPageToken).addAllSnapshots(snapshots).build();
mockSubscriber.addResponse(expectedResponse);
ProjectName project = ProjectName.create("[PROJECT]");
ListSnapshotsPagedResponse pagedListResponse = client.listSnapshots(project);
List<Snapshot> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getSnapshotsList().get(0), resources.get(0));
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListSnapshotsRequest actualRequest = (ListSnapshotsRequest) actualRequests.get(0);
Assert.assertEquals(project, actualRequest.getProjectAsProjectName());
}
use of com.google.bigtable.admin.v2.Snapshot in project java-docs-samples by GoogleCloudPlatform.
the class SnippetsIT method createSnapshot.
private static Snapshot createSnapshot(Disk srcDisk) throws IOException, InterruptedException, ExecutionException {
try (SnapshotsClient snapshotsClient = SnapshotsClient.create();
DisksClient disksClient = DisksClient.create()) {
Snapshot snapshot = Snapshot.newBuilder().setName("test-snap-" + UUID.randomUUID()).build();
OperationFuture<Operation, Operation> operation = disksClient.createSnapshotAsync(PROJECT_ID, ZONE, srcDisk.getName(), snapshot);
operation.get();
return snapshotsClient.get(PROJECT_ID, snapshot.getName());
}
}
use of com.google.bigtable.admin.v2.Snapshot in project java-docs-samples by GoogleCloudPlatform.
the class InstancesAdvancedIT method createSnapshot.
private static Snapshot createSnapshot(Disk srcDisk) throws IOException, InterruptedException, ExecutionException, TimeoutException {
try (SnapshotsClient snapshotsClient = SnapshotsClient.create();
DisksClient disksClient = DisksClient.create()) {
Snapshot snapshot = Snapshot.newBuilder().setName("test-snap-" + UUID.randomUUID()).build();
OperationFuture<Operation, Operation> operation = disksClient.createSnapshotAsync(PROJECT_ID, ZONE, srcDisk.getName(), snapshot);
operation.get(3, TimeUnit.MINUTES);
return snapshotsClient.get(PROJECT_ID, snapshot.getName());
}
}
Aggregations