本文整理汇总了Java中com.google.protobuf.Int32Value类的典型用法代码示例。如果您正苦于以下问题:Java Int32Value类的具体用法?Java Int32Value怎么用?Java Int32Value使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Int32Value类属于com.google.protobuf包,在下文中一共展示了Int32Value类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: anyInMaps
import com.google.protobuf.Int32Value; //导入依赖的package包/类
@Test
public void anyInMaps() throws Exception {
TestAny.Builder testAny = TestAny.newBuilder();
testAny.putAnyMap("int32_wrapper", Any.pack(Int32Value.newBuilder().setValue(123).build()));
testAny.putAnyMap("int64_wrapper", Any.pack(Int64Value.newBuilder().setValue(456).build()));
testAny.putAnyMap("timestamp", Any.pack(Timestamps.parse("1969-12-31T23:59:59Z")));
testAny.putAnyMap("duration", Any.pack(Durations.parse("12345.1s")));
testAny.putAnyMap("field_mask", Any.pack(FieldMaskUtil.fromString("foo.bar,baz")));
Value numberValue = Value.newBuilder().setNumberValue(1.125).build();
Struct.Builder struct = Struct.newBuilder();
struct.putFields("number", numberValue);
testAny.putAnyMap("struct", Any.pack(struct.build()));
Value nullValue = Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build();
testAny.putAnyMap(
"list_value",
Any.pack(ListValue.newBuilder().addValues(numberValue).addValues(nullValue).build()));
testAny.putAnyMap("number_value", Any.pack(numberValue));
testAny.putAnyMap("any_value_number", Any.pack(Any.pack(numberValue)));
testAny.putAnyMap("any_value_default", Any.pack(Any.getDefaultInstance()));
testAny.putAnyMap("default", Any.getDefaultInstance());
assertMatchesUpstream(testAny.build(), TestAllTypes.getDefaultInstance());
}
示例2: queryLatestStatisticsTimestamp
import com.google.protobuf.Int32Value; //导入依赖的package包/类
/**
* Cloud Datastore system tables with statistics are periodically updated. This method fetches
* the latest timestamp (in microseconds) of statistics update using the {@code __Stat_Total__}
* table.
*/
private static long queryLatestStatisticsTimestamp(Datastore datastore,
@Nullable String namespace) throws DatastoreException {
Query.Builder query = Query.newBuilder();
// Note: namespace either being null or empty represents the default namespace, in which
// case we treat it as not provided by the user.
if (Strings.isNullOrEmpty(namespace)) {
query.addKindBuilder().setName("__Stat_Total__");
} else {
query.addKindBuilder().setName("__Stat_Ns_Total__");
}
query.addOrder(makeOrder("timestamp", DESCENDING));
query.setLimit(Int32Value.newBuilder().setValue(1));
RunQueryRequest request = makeRequest(query.build(), namespace);
RunQueryResponse response = datastore.runQuery(request);
QueryResultBatch batch = response.getBatch();
if (batch.getEntityResultsCount() == 0) {
throw new NoSuchElementException(
"Datastore total statistics unavailable");
}
Entity entity = batch.getEntityResults(0).getEntity();
return entity.getProperties().get("timestamp").getTimestampValue().getSeconds() * 1000000;
}
示例3: testSplitQueryFnWithQueryLimit
import com.google.protobuf.Int32Value; //导入依赖的package包/类
/**
* Tests {@link DatastoreV1.Read.SplitQueryFn} when the query has a user specified limit.
*/
@Test
public void testSplitQueryFnWithQueryLimit() throws Exception {
Query queryWithLimit = QUERY.toBuilder()
.setLimit(Int32Value.newBuilder().setValue(1))
.build();
SplitQueryFn splitQueryFn = new SplitQueryFn(V_1_OPTIONS, 10, mockDatastoreFactory);
DoFnTester<Query, Query> doFnTester = DoFnTester.of(splitQueryFn);
doFnTester.setCloningBehavior(CloningBehavior.DO_NOT_CLONE);
List<Query> queries = doFnTester.processBundle(queryWithLimit);
assertEquals(queries.size(), 1);
verifyNoMoreInteractions(mockDatastore);
verifyNoMoreInteractions(mockQuerySplitter);
}
示例4: testReadFnRetriesErrors
import com.google.protobuf.Int32Value; //导入依赖的package包/类
/** Tests that {@link ReadFn} retries after an error. */
@Test
public void testReadFnRetriesErrors() throws Exception {
// An empty query to read entities.
Query query = Query.newBuilder().setLimit(
Int32Value.newBuilder().setValue(1)).build();
// Use mockResponseForQuery to generate results.
when(mockDatastore.runQuery(any(RunQueryRequest.class)))
.thenThrow(
new DatastoreException("RunQuery", Code.DEADLINE_EXCEEDED, "", null))
.thenAnswer(new Answer<RunQueryResponse>() {
@Override
public RunQueryResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
Query q = ((RunQueryRequest) invocationOnMock.getArguments()[0]).getQuery();
return mockResponseForQuery(q);
}
});
ReadFn readFn = new ReadFn(V_1_OPTIONS, mockDatastoreFactory);
DoFnTester<Query, Entity> doFnTester = DoFnTester.of(readFn);
doFnTester.setCloningBehavior(CloningBehavior.DO_NOT_CLONE);
List<Entity> entities = doFnTester.processBundle(query);
}
示例5: getIteratorAndMoveCursor
import com.google.protobuf.Int32Value; //导入依赖的package包/类
private Iterator<EntityResult> getIteratorAndMoveCursor() throws DatastoreException {
Query.Builder query = this.query.toBuilder();
query.setLimit(Int32Value.newBuilder().setValue(QUERY_BATCH_LIMIT));
if (currentBatch != null && !currentBatch.getEndCursor().isEmpty()) {
query.setStartCursor(currentBatch.getEndCursor());
}
RunQueryRequest request = makeRequest(query.build(), namespace);
RunQueryResponse response = datastore.runQuery(request);
currentBatch = response.getBatch();
int numFetch = currentBatch.getEntityResultsCount();
// All indications from the API are that there are/may be more results.
moreResults = ((numFetch == QUERY_BATCH_LIMIT)
|| (currentBatch.getMoreResults() == NOT_FINISHED));
// May receive a batch of 0 results if the number of records is a multiple
// of the request limit.
if (numFetch == 0) {
return null;
}
return currentBatch.getEntityResultsList().iterator();
}
示例6: create_queries_with_param
import com.google.protobuf.Int32Value; //导入依赖的package包/类
@Test
public void create_queries_with_param() {
final String columnName = "myImaginaryColumn";
final Object columnValue = 42;
final Query query = factory().query()
.select(TestEntity.class)
.where(eq(columnName, columnValue))
.build();
assertNotNull(query);
final Target target = query.getTarget();
assertFalse(target.getIncludeAll());
final EntityFilters entityFilters = target.getFilters();
final List<CompositeColumnFilter> aggregatingColumnFilters = entityFilters.getFilterList();
assertSize(1, aggregatingColumnFilters);
final CompositeColumnFilter aggregatingColumnFilter = aggregatingColumnFilters.get(0);
final Collection<ColumnFilter> columnFilters = aggregatingColumnFilter.getFilterList();
assertSize(1, columnFilters);
final Any actualValue = findByName(columnFilters, columnName).getValue();
assertNotNull(columnValue);
final Int32Value messageValue = AnyPacker.unpack(actualValue);
final int actualGenericValue = messageValue.getValue();
assertEquals(columnValue, actualGenericValue);
}
示例7: expose_playing_events_to_the_package
import com.google.protobuf.Int32Value; //导入依赖的package包/类
@Test
public void expose_playing_events_to_the_package() {
final TestEventFactory eventFactory = TestEventFactory.newInstance(getClass());
final StringValue strValue = StringValue.newBuilder()
.setValue("eins zwei drei")
.build();
final Int32Value intValue = Int32Value.newBuilder().setValue(123).build();
final Version nextVersion = Versions.increment(projection.getVersion());
final Event e1 = eventFactory.createEvent(strValue, nextVersion);
final Event e2 = eventFactory.createEvent(intValue, Versions.increment(nextVersion));
final boolean projectionChanged = Projection.play(projection, ImmutableList.of(e1, e2));
final String projectionState = projection.getState()
.getValue();
assertTrue(projectionChanged);
assertTrue(projectionState.contains(strValue.getValue()));
assertTrue(projectionState.contains(String.valueOf(intValue.getValue())));
}
示例8: generateSpan
import com.google.protobuf.Int32Value; //导入依赖的package包/类
@VisibleForTesting
Span generateSpan(SpanData spanData) {
SpanContext context = spanData.getContext();
final String traceIdHex = encodeTraceId(context.getTraceId());
final String spanIdHex = encodeSpanId(context.getSpanId());
SpanName spanName =
SpanName.newBuilder().setProject(projectId).setTrace(traceIdHex).setSpan(spanIdHex).build();
Span.Builder spanBuilder =
Span.newBuilder()
.setNameWithSpanName(spanName)
.setSpanId(encodeSpanId(context.getSpanId()))
.setDisplayName(toTruncatableStringProto(spanData.getName()))
.setStartTime(toTimestampProto(spanData.getStartTimestamp()))
.setAttributes(toAttributesProto(spanData.getAttributes()))
.setTimeEvents(
toTimeEventsProto(spanData.getAnnotations(), spanData.getNetworkEvents()));
io.opencensus.trace.Status status = spanData.getStatus();
if (status != null) {
spanBuilder.setStatus(toStatusProto(status));
}
Timestamp end = spanData.getEndTimestamp();
if (end != null) {
spanBuilder.setEndTime(toTimestampProto(end));
}
spanBuilder.setLinks(toLinksProto(spanData.getLinks()));
Integer childSpanCount = spanData.getChildSpanCount();
if (childSpanCount != null) {
spanBuilder.setChildSpanCount(Int32Value.newBuilder().setValue(childSpanCount).build());
}
if (spanData.getParentSpanId() != null && spanData.getParentSpanId().isValid()) {
spanBuilder.setParentSpanId(encodeSpanId(spanData.getParentSpanId()));
}
return spanBuilder.build();
}
示例9: createAdditionalServiceTypes
import com.google.protobuf.Int32Value; //导入依赖的package包/类
/**
* Creates additional types (Value, Struct and ListValue) to be added to the Service config.
* TODO (guptasu): Fix this hack. Find a better way to add the predefined types.
* TODO (guptasu): Add them only when required and not in all cases.
*/
static Iterable<Type> createAdditionalServiceTypes() {
Map<String, DescriptorProto> additionalMessages = Maps.newHashMap();
additionalMessages.put(Struct.getDescriptor().getFullName(),
Struct.getDescriptor().toProto());
additionalMessages.put(Value.getDescriptor().getFullName(),
Value.getDescriptor().toProto());
additionalMessages.put(ListValue.getDescriptor().getFullName(),
ListValue.getDescriptor().toProto());
additionalMessages.put(Empty.getDescriptor().getFullName(),
Empty.getDescriptor().toProto());
additionalMessages.put(Int32Value.getDescriptor().getFullName(),
Int32Value.getDescriptor().toProto());
additionalMessages.put(DoubleValue.getDescriptor().getFullName(),
DoubleValue.getDescriptor().toProto());
additionalMessages.put(BoolValue.getDescriptor().getFullName(),
BoolValue.getDescriptor().toProto());
additionalMessages.put(StringValue.getDescriptor().getFullName(),
StringValue.getDescriptor().toProto());
for (Descriptor descriptor : Struct.getDescriptor().getNestedTypes()) {
additionalMessages.put(descriptor.getFullName(), descriptor.toProto());
}
// TODO (guptasu): Remove this hard coding. Without this, creation of Model from Service throws.
// Needs investigation.
String fileName = "struct.proto";
List<Type> additionalTypes = Lists.newArrayList();
for (String typeName : additionalMessages.keySet()) {
additionalTypes.add(TypesBuilderFromDescriptor.createType(typeName,
additionalMessages.get(typeName), fileName));
}
return additionalTypes;
}
示例10: testReadValidationFailsQueryLimitZero
import com.google.protobuf.Int32Value; //导入依赖的package包/类
@Test
public void testReadValidationFailsQueryLimitZero() throws Exception {
Query invalidLimit = Query.newBuilder().setLimit(Int32Value.newBuilder().setValue(0)).build();
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Invalid query limit 0: must be positive");
DatastoreIO.v1().read().withQuery(invalidLimit);
}
示例11: testReadValidationFailsQueryLimitNegative
import com.google.protobuf.Int32Value; //导入依赖的package包/类
@Test
public void testReadValidationFailsQueryLimitNegative() throws Exception {
Query invalidLimit = Query.newBuilder().setLimit(Int32Value.newBuilder().setValue(-5)).build();
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Invalid query limit -5: must be positive");
DatastoreIO.v1().read().withQuery(invalidLimit);
}
示例12: readFnTest
import com.google.protobuf.Int32Value; //导入依赖的package包/类
/** Helper function to run a test reading from a {@link ReadFn}. */
private void readFnTest(int numEntities) throws Exception {
// An empty query to read entities.
Query query = Query.newBuilder().setLimit(
Int32Value.newBuilder().setValue(numEntities)).build();
// Use mockResponseForQuery to generate results.
when(mockDatastore.runQuery(any(RunQueryRequest.class)))
.thenAnswer(new Answer<RunQueryResponse>() {
@Override
public RunQueryResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
Query q = ((RunQueryRequest) invocationOnMock.getArguments()[0]).getQuery();
return mockResponseForQuery(q);
}
});
ReadFn readFn = new ReadFn(V_1_OPTIONS, mockDatastoreFactory);
DoFnTester<Query, Entity> doFnTester = DoFnTester.of(readFn);
/**
* Although Datastore client is marked transient in {@link ReadFn}, when injected through
* mock factory using a when clause for unit testing purposes, it is not serializable
* because it doesn't have a no-arg constructor. Thus disabling the cloning to prevent the
* test object from being serialized.
*/
doFnTester.setCloningBehavior(CloningBehavior.DO_NOT_CLONE);
List<Entity> entities = doFnTester.processBundle(query);
int expectedNumCallsToRunQuery = (int) Math.ceil((double) numEntities / QUERY_BATCH_LIMIT);
verify(mockDatastore, times(expectedNumCallsToRunQuery)).runQuery(any(RunQueryRequest.class));
// Validate the number of results.
assertEquals(numEntities, entities.size());
}
示例13: makeLatestTimestampQuery
import com.google.protobuf.Int32Value; //导入依赖的package包/类
/** Builds a latest timestamp statistics query. */
private static Query makeLatestTimestampQuery(String namespace) {
Query.Builder timestampQuery = Query.newBuilder();
if (namespace == null) {
timestampQuery.addKindBuilder().setName("__Stat_Total__");
} else {
timestampQuery.addKindBuilder().setName("__Stat_Ns_Total__");
}
timestampQuery.addOrder(makeOrder("timestamp", DESCENDING));
timestampQuery.setLimit(Int32Value.newBuilder().setValue(1));
return timestampQuery.build();
}
示例14: outerObject
import com.google.protobuf.Int32Value; //导入依赖的package包/类
@Override
protected Rejection outerObject() {
final Message commandMessage = Int32Value.getDefaultInstance();
final Command command = requestFactory.command().create(commandMessage);
final Message rejectionMessage = CannotPerformBusinessOperation.newBuilder()
.setOperationId(newUuid())
.build();
final Rejection rejection = Rejections.createRejection(rejectionMessage, command);
return rejection;
}
示例15: return_event_classes_which_it_handles
import com.google.protobuf.Int32Value; //导入依赖的package包/类
@Test
public void return_event_classes_which_it_handles() {
final Set<EventClass> classes = ProjectionClass.of(TestProjection.class)
.getEventSubscriptions();
assertEquals(TestProjection.HANDLING_EVENT_COUNT, classes.size());
assertTrue(classes.contains(EventClass.of(StringValue.class)));
assertTrue(classes.contains(EventClass.of(Int32Value.class)));
}