use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method setIamPolicyTest.
@Test
@SuppressWarnings("all")
public void setIamPolicyTest() {
int version = 351608024;
ByteString etag = ByteString.copyFromUtf8("21");
Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build();
mockIAMPolicy.addResponse(expectedResponse);
String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
Policy policy = Policy.newBuilder().build();
Policy actualResponse = client.setIamPolicy(formattedResource, policy);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockIAMPolicy.getRequests();
Assert.assertEquals(1, actualRequests.size());
SetIamPolicyRequest actualRequest = (SetIamPolicyRequest) actualRequests.get(0);
Assert.assertEquals(formattedResource, actualRequest.getResource());
Assert.assertEquals(policy, actualRequest.getPolicy());
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method getIamPolicyTest.
@Test
@SuppressWarnings("all")
public void getIamPolicyTest() {
int version = 351608024;
ByteString etag = ByteString.copyFromUtf8("21");
Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build();
mockIAMPolicy.addResponse(expectedResponse);
String formattedResource = TopicName.create("[PROJECT]", "[TOPIC]").toString();
Policy actualResponse = client.getIamPolicy(formattedResource);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockIAMPolicy.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetIamPolicyRequest actualRequest = (GetIamPolicyRequest) actualRequests.get(0);
Assert.assertEquals(formattedResource, actualRequest.getResource());
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString in project google-cloud-java by GoogleCloudPlatform.
the class DatastoreTest method testQueryPaginationWithLimit.
@Test
public void testQueryPaginationWithLimit() throws DatastoreException {
List<RunQueryResponse> responses = buildResponsesForQueryPaginationWithLimit();
List<ByteString> endCursors = Lists.newArrayListWithCapacity(responses.size());
for (RunQueryResponse response : responses) {
EasyMock.expect(rpcMock.runQuery(EasyMock.anyObject(RunQueryRequest.class))).andReturn(response);
if (response.getBatch().getMoreResults() != QueryResultBatch.MoreResultsType.NOT_FINISHED) {
endCursors.add(response.getBatch().getEndCursor());
}
}
EasyMock.replay(rpcFactoryMock, rpcMock);
Datastore datastore = rpcMockOptions.getService();
int limit = 2;
int totalCount = 0;
Iterator<ByteString> cursorIter = endCursors.iterator();
StructuredQuery<Entity> query = Query.newEntityQueryBuilder().setLimit(limit).build();
while (true) {
QueryResults<Entity> results = datastore.run(query);
int resultCount = 0;
while (results.hasNext()) {
results.next();
resultCount++;
totalCount++;
}
assertTrue(cursorIter.hasNext());
Cursor expectedEndCursor = Cursor.copyFrom(cursorIter.next().toByteArray());
assertEquals(expectedEndCursor, results.getCursorAfter());
if (resultCount < limit) {
break;
}
query = query.toBuilder().setStartCursor(results.getCursorAfter()).build();
}
assertEquals(5, totalCount);
EasyMock.verify(rpcFactoryMock, rpcMock);
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString in project google-cloud-java by GoogleCloudPlatform.
the class CreateTopicAndPublishMessages method publishMessages.
public static void publishMessages() throws Exception {
// [START pubsub_publish]
TopicName topicName = TopicName.create("my-project-id", "my-topic-id");
Publisher publisher = null;
List<ApiFuture<String>> messageIdFutures = new ArrayList<>();
try {
// Create a publisher instance with default settings bound to the topic
publisher = Publisher.defaultBuilder(topicName).build();
List<String> messages = Arrays.asList("first message", "second message");
// schedule publishing one message at a time : messages get automatically batched
for (String message : messages) {
ByteString data = ByteString.copyFromUtf8(message);
PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build();
// Once published, returns a server-assigned message id (unique within the topic)
ApiFuture<String> messageIdFuture = publisher.publish(pubsubMessage);
messageIdFutures.add(messageIdFuture);
}
} finally {
// wait on any pending publish requests.
List<String> messageIds = ApiFutures.allAsList(messageIdFutures).get();
for (String messageId : messageIds) {
System.out.println("published with message ID: " + messageId);
}
if (publisher != null) {
// When finished with the publisher, shutdown to free up resources.
publisher.shutdown();
}
}
// [END pubsub_publish]
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString in project google-cloud-java by GoogleCloudPlatform.
the class PublisherSnippets method publish.
/** Example of publishing a message. */
// [TARGET publish(PubsubMessage)]
// [VARIABLE "my_message"]
public ApiFuture<String> publish(String message) {
ByteString data = ByteString.copyFromUtf8(message);
PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build();
ApiFuture<String> messageIdFuture = publisher.publish(pubsubMessage);
ApiFutures.addCallback(messageIdFuture, new ApiFutureCallback<String>() {
public void onSuccess(String messageId) {
System.out.println("published with message id: " + messageId);
}
public void onFailure(Throwable t) {
System.out.println("failed to publish: " + t);
}
});
return messageIdFuture;
}
Aggregations