本文整理汇总了Java中com.google.protobuf.Int32Value类的典型用法代码示例。如果您正苦于以下问题:Java Int32Value类的具体用法?Java Int32Value怎么用?Java Int32Value使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Int32Value类属于com.google.protobuf包,在下文中一共展示了Int32Value类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
}
开发者ID:curioswitch,项目名称:curiostack,代码行数:24,代码来源:MessageMarshallerTest.java
示例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;
}
开发者ID:apache,项目名称:beam,代码行数:29,代码来源:DatastoreV1.java
示例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);
}
开发者ID:apache,项目名称:beam,代码行数:19,代码来源:DatastoreV1Test.java
示例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);
}
开发者ID:apache,项目名称:beam,代码行数:25,代码来源:DatastoreV1Test.java
示例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();
}
开发者ID:apache,项目名称:beam,代码行数:26,代码来源:V1TestUtil.java
示例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);
}
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:26,代码来源:QueryBuilderShould.java
示例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())));
}
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:21,代码来源:ProjectionShould.java
示例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();
}
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:36,代码来源:StackdriverV2ExporterHandler.java
示例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;
}
开发者ID:googleapis,项目名称:api-compiler,代码行数:40,代码来源:TypesBuilderFromDescriptor.java
示例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);
}
开发者ID:apache,项目名称:beam,代码行数:9,代码来源:DatastoreV1Test.java
示例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);
}
开发者ID:apache,项目名称:beam,代码行数:9,代码来源:DatastoreV1Test.java
示例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());
}
开发者ID:apache,项目名称:beam,代码行数:33,代码来源:DatastoreV1Test.java
示例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();
}
开发者ID:apache,项目名称:beam,代码行数:13,代码来源:DatastoreV1Test.java
示例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;
}
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:11,代码来源:RejectionEnvelopeShould.java
示例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)));
}
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:10,代码来源:ProjectionShould.java
示例16: store_filters_regarding_possible_concurrent_modifications
import com.google.protobuf.Int32Value; //导入依赖的package包/类
/**
* Tests the concurrent access to the {@linkplain io.spine.server.bus.BusFilter bus filters}.
*
* <p>The {@linkplain io.spine.server.bus.FilterChain filter chain} is a queue of the filters
* which are sequentially applied to the posted message. The first {@code Bus.post()} call
* invokes the filters lazy initialization. In the concurrent environment (which is natural for
* a {@link io.spine.server.bus.Bus Bus}), the initialization may be performed multiple times.
* Thus, some unexpected issues may appear when accessing the non-synchronously initialized
* filter chain.
*
* <p>To make sure that the chain works fine (i.e. produces no exceptions), we invoke the
* initialization multiple times from several threads.
*/
@SuppressWarnings("MethodWithMultipleLoops") // OK for such test case.
@Ignore // This test is used only to diagnose EventBus malfunctions in concurrent environment.
// It's too long to execute this test per each build, so we leave it as is for now.
// Please see build log to find out if there were some errors during the test execution.
@Test
public void store_filters_regarding_possible_concurrent_modifications()
throws InterruptedException {
final int threadCount = 50;
// "Random" more or less valid Event.
final Event event = Event.newBuilder()
.setId(EventId.newBuilder().setValue("123-1"))
.setMessage(pack(Int32Value.newBuilder()
.setValue(42)
.build()))
.build();
final StorageFactory storageFactory =
StorageFactorySwitch.newInstance(newName("baz"), false).get();
final ExecutorService executor = Executors.newFixedThreadPool(threadCount);
// Catch non-easily reproducible bugs.
for (int i = 0; i < 300; i++) {
final EventBus eventBus = EventBus.newBuilder()
.setStorageFactory(storageFactory)
.build();
for (int j = 0; j < threadCount; j++) {
executor.execute(new Runnable() {
@Override
public void run() {
eventBus.post(event);
}
});
}
// Let the system destroy all the native threads, clean up, etc.
Thread.sleep(100);
}
executor.shutdownNow();
}
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:51,代码来源:EventBusShould.java
示例17: throw_exception_if_dispatch_unknown_command
import com.google.protobuf.Int32Value; //导入依赖的package包/类
@Test(expected = IllegalStateException.class)
public void throw_exception_if_dispatch_unknown_command() {
final Int32Value unknownCommand = Int32Value.getDefaultInstance();
final CommandEnvelope envelope = CommandEnvelope.of(
requestFactory.createCommand(unknownCommand)
);
processManager.dispatchCommand(envelope);
}
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:10,代码来源:ProcessManagerShould.java
示例18: throw_exception_if_dispatch_unknown_command
import com.google.protobuf.Int32Value; //导入依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void throw_exception_if_dispatch_unknown_command() {
final Command unknownCommand =
requestFactory.createCommand(Int32Value.getDefaultInstance());
final CommandEnvelope request = CommandEnvelope.of(unknownCommand);
repository().dispatchCommand(request);
}
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:8,代码来源:ProcessManagerRepositoryShould.java
示例19: update_entity_column_values
import com.google.protobuf.Int32Value; //导入依赖的package包/类
@Test
public void update_entity_column_values() {
final Project.Status initialStatus = DONE;
final Project.Status statusAfterUpdate = CANCELLED;
final Int32Value initialStatusValue = Int32Value.newBuilder()
.setValue(initialStatus.getNumber())
.build();
final ColumnFilter status = eq("projectStatusValue", initialStatusValue);
final CompositeColumnFilter aggregatingFilter = CompositeColumnFilter.newBuilder()
.setOperator(ALL)
.addFilter(status)
.build();
final EntityFilters filters = EntityFilters.newBuilder()
.addFilter(aggregatingFilter)
.build();
final EntityQuery<I> query = EntityQueries.from(filters, getTestEntityClass());
final I id = newId();
final TestCounterEntity<I> entity = new TestCounterEntity<>(id);
entity.setStatus(initialStatus);
final EntityRecord record = newStorageRecord(id, newState(id));
final EntityRecordWithColumns recordWithColumns = create(record, entity);
final RecordStorage<I> storage = getStorage();
final FieldMask fieldMask = FieldMask.getDefaultInstance();
// Create the record.
storage.write(id, recordWithColumns);
final Iterator<EntityRecord> recordsBefore = storage.readAll(query, fieldMask);
assertSingleRecord(record, recordsBefore);
// Update the entity columns of the record.
entity.setStatus(statusAfterUpdate);
final EntityRecordWithColumns updatedRecordWithColumns = create(record, entity);
storage.write(id, updatedRecordWithColumns);
final Iterator<EntityRecord> recordsAfter = storage.readAll(query, fieldMask);
assertFalse(recordsAfter.hasNext());
}
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:41,代码来源:RecordStorageShould.java
示例20: create_set_on_varargs
import com.google.protobuf.Int32Value; //导入依赖的package包/类
@Test
public void create_set_on_varargs() {
assertEquals(3, EventClass.setOf(
BoolValue.class,
Int32Value.class,
StringValue.class).size());
}
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:8,代码来源:EventClassShould.java
注:本文中的com.google.protobuf.Int32Value类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论