use of org.apache.beam.vendor.grpc.v1p26p0.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.v1p26p0.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.v1p26p0.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.v1p26p0.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;
}
use of org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.ByteString in project compiler by boalang.
the class JsonFormat method printUnknownFields.
protected static void printUnknownFields(UnknownFieldSet unknownFields, JsonGenerator generator) throws IOException {
boolean firstField = true;
for (Map.Entry<Integer, UnknownFieldSet.Field> entry : unknownFields.asMap().entrySet()) {
UnknownFieldSet.Field field = entry.getValue();
if (firstField) {
firstField = false;
} else {
generator.print(", ");
}
generator.print("\"");
generator.print(entry.getKey().toString());
generator.print("\"");
generator.print(": [");
boolean firstValue = true;
for (long value : field.getVarintList()) {
if (firstValue) {
firstValue = false;
} else {
generator.print(", ");
}
generator.print(unsignedToString(value));
}
for (int value : field.getFixed32List()) {
if (firstValue) {
firstValue = false;
} else {
generator.print(", ");
}
generator.print(String.format((Locale) null, "0x%08x", value));
}
for (long value : field.getFixed64List()) {
if (firstValue) {
firstValue = false;
} else {
generator.print(", ");
}
generator.print(String.format((Locale) null, "0x%016x", value));
}
for (ByteString value : field.getLengthDelimitedList()) {
if (firstValue) {
firstValue = false;
} else {
generator.print(", ");
}
generator.print("\"");
generator.print(escapeBytes(value));
generator.print("\"");
}
for (UnknownFieldSet value : field.getGroupList()) {
if (firstValue) {
firstValue = false;
} else {
generator.print(", ");
}
generator.print("{\n");
printUnknownFields(value, generator);
generator.print("}\n");
}
generator.print("]");
}
}
Aggregations