当前位置: 首页>>代码示例>>Java>>正文


Java Empty类代码示例

本文整理汇总了Java中com.google.protobuf.Empty的典型用法代码示例。如果您正苦于以下问题:Java Empty类的具体用法?Java Empty怎么用?Java Empty使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Empty类属于com.google.protobuf包,在下文中一共展示了Empty类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: clientCanCancelServerStreamExplicitly

import com.google.protobuf.Empty; //导入依赖的package包/类
@Test
public void clientCanCancelServerStreamExplicitly() throws InterruptedException {
    AtomicInteger lastNumberConsumed = new AtomicInteger(Integer.MAX_VALUE);
    ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(channel);
    Flux<NumberProto.Number> test = stub
            .responsePressure(Mono.just(Empty.getDefaultInstance()))
            .doOnNext(number -> {lastNumberConsumed.set(number.getNumber(0)); System.out.println("C: " + number.getNumber(0));})
            .doOnError(throwable -> System.out.println(throwable.getMessage()))
            .doOnComplete(() -> System.out.println("Completed"))
            .doOnCancel(() -> System.out.println("Client canceled"));

    Disposable subscription = test.publish().connect();

    Thread.sleep(1000);
    subscription.dispose();
    Thread.sleep(1000);

    // Cancellation may or may not deliver the last generated message due to delays in the gRPC processing thread
    assertThat(Math.abs(lastNumberConsumed.get() - svc.getLastNumberProduced())).isLessThanOrEqualTo(3);
    assertThat(svc.wasCanceled()).isTrue();
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:22,代码来源:CancellationPropagationIntegrationTest.java

示例2: clientCanCancelServerStreamExplicitly

import com.google.protobuf.Empty; //导入依赖的package包/类
@Test
public void clientCanCancelServerStreamExplicitly() throws InterruptedException {
    RxNumbersGrpc.RxNumbersStub stub = RxNumbersGrpc.newRxStub(channel);
    TestSubscriber<NumberProto.Number> subscription = stub
            .responsePressure(Single.just(Empty.getDefaultInstance()))
            .doOnNext(number -> System.out.println(number.getNumber(0)))
            .doOnError(throwable -> System.out.println(throwable.getMessage()))
            .doOnComplete(() -> System.out.println("Completed"))
            .doOnCancel(() -> System.out.println("Client canceled"))
            .test();

    Thread.sleep(250);
    subscription.dispose();
    Thread.sleep(250);

    subscription.awaitTerminalEvent(3, TimeUnit.SECONDS);
    // Cancellation may or may not deliver the last generated message due to delays in the gRPC processing thread
    assertThat(Math.abs(subscription.valueCount() - svc.getLastNumberProduced())).isLessThanOrEqualTo(3);
    assertThat(svc.wasCanceled()).isTrue();
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:21,代码来源:CancellationPropagationIntegrationTest.java

示例3: clientCanCancelServerStreamImplicitly

import com.google.protobuf.Empty; //导入依赖的package包/类
@Test
public void clientCanCancelServerStreamImplicitly() throws InterruptedException {
    RxNumbersGrpc.RxNumbersStub stub = RxNumbersGrpc.newRxStub(channel);
    TestSubscriber<NumberProto.Number> subscription = stub
            .responsePressure(Single.just(Empty.getDefaultInstance()))
            .doOnNext(number -> System.out.println(number.getNumber(0)))
            .doOnError(throwable -> System.out.println(throwable.getMessage()))
            .doOnComplete(() -> System.out.println("Completed"))
            .doOnCancel(() -> System.out.println("Client canceled"))
            .take(10)
            .test();

    // Consume some work
    Thread.sleep(TimeUnit.SECONDS.toMillis(1));
    subscription.dispose();

    subscription.awaitTerminalEvent(3, TimeUnit.SECONDS);
    subscription.assertValueCount(10);
    subscription.assertTerminated();
    assertThat(svc.wasCanceled()).isTrue();
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:22,代码来源:CancellationPropagationIntegrationTest.java

示例4: serverToClientBackpressure

import com.google.protobuf.Empty; //导入依赖的package包/类
@Test
public void serverToClientBackpressure() throws InterruptedException {
    RxNumbersGrpc.RxNumbersStub stub = RxNumbersGrpc.newRxStub(channel);

    Single<Empty> rxRequest = Single.just(Empty.getDefaultInstance());

    TestSubscriber<NumberProto.Number> rxResponse = stub.responsePressure(rxRequest)
            .doOnNext(n -> System.out.println(n.getNumber(0) + "  <--"))
            .doOnNext(n -> waitIfValuesAreEqual(n.getNumber(0), 3))
            .test();

    rxResponse.awaitTerminalEvent(5, TimeUnit.SECONDS);
    rxResponse.assertComplete()
            .assertValueCount(NUMBER_OF_STREAM_ELEMENTS);

    assertThat(numberOfWaits.get()).isEqualTo(1);
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:18,代码来源:BackpressureIntegrationTest.java

示例5: clientCanCancelServerStreamImplicitly

import com.google.protobuf.Empty; //导入依赖的package包/类
@Test
public void clientCanCancelServerStreamImplicitly() throws InterruptedException {
    ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(channel);
    Flux<NumberProto.Number> test = stub
            .responsePressure(Mono.just(Empty.getDefaultInstance()))
            .doOnNext(number -> System.out.println(number.getNumber(0)))
            .doOnError(throwable -> System.out.println(throwable.getMessage()))
            .doOnComplete(() -> System.out.println("Completed"))
            .doOnCancel(() -> System.out.println("Client canceled"))
            .take(10);

    Disposable subscription = test.publish().connect();

    Thread.sleep(1000);

    assertThat(svc.wasCanceled()).isTrue();
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:18,代码来源:CancellationPropagationIntegrationTest.java

示例6: serverToClientBackpressure

import com.google.protobuf.Empty; //导入依赖的package包/类
@Test
public void serverToClientBackpressure() throws InterruptedException {
    ReactorNumbersGrpc.ReactorNumbersStub stub = ReactorNumbersGrpc.newReactorStub(channel);

    Mono<Empty> reactorRequest = Mono.just(Empty.getDefaultInstance());

    Flux<NumberProto.Number> reactorResponse = stub.responsePressure(reactorRequest)
            .doOnNext(n -> System.out.println(n.getNumber(0) + "  <--"))
            .doOnNext(n -> waitIfValuesAreEqual(n.getNumber(0), 3));

    StepVerifier.create(reactorResponse)
            .expectNextCount(NUMBER_OF_STREAM_ELEMENTS)
            .expectComplete()
            .verify(Duration.ofSeconds(5));

    assertThat(numberOfWaits.get()).isEqualTo(1);
}
 
开发者ID:salesforce,项目名称:reactive-grpc,代码行数:18,代码来源:BackpressureIntegrationTest.java

示例7: flush

import com.google.protobuf.Empty; //导入依赖的package包/类
@Override
public void flush() {
  List<Span> spans = new ArrayList<>();
  queue.drain(spans::add);
  if (spans.isEmpty()) {
    return;
  }
  PatchTracesRequest request =
      PatchTracesRequest.newBuilder()
          .setProjectId(projectId)
          .setTraces(Traces.newBuilder().addAllTraces(translator.translateSpans(spans)))
          .build();
  ApiFutures.addCallback(
      traceServiceClient.patchTracesCallable().futureCall(request),
      new ApiFutureCallback<Empty>() {
        @Override
        public void onFailure(Throwable t) {
          logger.warn("Error reporting traces.", t);
        }

        @Override
        public void onSuccess(Empty result) {
          logger.info("Successfully reported traces.");
        }
      });
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:27,代码来源:StackdriverReporter.java

示例8: main

import com.google.protobuf.Empty; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    String host = args[0];
    int port = Integer.parseInt(args[1]);

    String abstractName = "mesh://timeService";

    // Open a channel to the server
    Channel channel = ManagedChannelBuilder
            .forTarget(abstractName)
            .nameResolverFactory(StaticResolver.factory(new InetSocketAddress(host, port)))
            .usePlaintext(true)
            .build();

    // Create a CompletableFuture-based stub
    TimeServiceGrpc8.TimeServiceCompletableFutureStub stub = TimeServiceGrpc8.newCompletableFutureStub(channel);

    // Call the service
    CompletableFuture<TimeReply> completableFuture = stub.getTime(Empty.getDefaultInstance());
    TimeReply timeReply = completableFuture.get();

    // Convert to JDK8 types
    Instant now = MoreTimestamps.toInstantUtc(timeReply.getTime());
    System.out.println("The time is " + now);
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:25,代码来源:TimeClient.java

示例9: getAllAuthoritiesRejected

import com.google.protobuf.Empty; //导入依赖的package包/类
@Test
public void getAllAuthoritiesRejected() throws Exception {
    Authentication authentication = new UsernamePasswordAuthenticationToken(
        DEFAULT_EMAIL,
        DEFAULT_PASSWORD,
        Collections.singletonList(new SimpleGrantedAuthority(AuthoritiesConstants.USER))
    );
    SecurityContextHolder.getContext().setAuthentication(authentication);

    try {
        List<String> roles = new ArrayList<>();
        stub.getAllAuthorities(Empty.getDefaultInstance()).forEachRemaining(role -> roles.add(role.getValue()));
        failBecauseExceptionWasNotThrown(StatusRuntimeException.class);
    } catch (StatusRuntimeException e){
        assertThat(e.getStatus().getCode()).isEqualTo(Status.Code.PERMISSION_DENIED);
    }
}
 
开发者ID:cbornet,项目名称:generator-jhipster-grpc,代码行数:18,代码来源:_UserGrpcServiceIntTest.java

示例10: getMetrics

import com.google.protobuf.Empty; //导入依赖的package包/类
@Override
public Flux<Metric> getMetrics(Mono<Empty> request) {
    return request
        .flatMapIterable(empty -> publicMetrics)
        .flatMapIterable(PublicMetrics::metrics)
        .map(metric -> {
            Metric.Builder builder = Metric.newBuilder()
                .setName(metric.getName());
            if (metric.getTimestamp() != null) {
                builder.setTimestamp(ProtobufMappers.dateToTimestamp(metric.getTimestamp()));
            }
            if (metric.getValue() instanceof Long || metric.getValue() instanceof Integer) {
                builder.setLongValue(metric.getValue().longValue());
            } else if (metric.getValue() instanceof Float || metric.getValue() instanceof Double) {
                builder.setDoubleValue((metric.getValue()).doubleValue());
            } else {
                builder.setStringValue(metric.getValue().toString());
            }
            return builder.build();
        });
}
 
开发者ID:cbornet,项目名称:generator-jhipster-grpc,代码行数:22,代码来源:_MetricService.java

示例11: testPollInRegularCase

import com.google.protobuf.Empty; //导入依赖的package包/类
/**
 * Tests that when ackMessages() succeeds and the subsequent call to poll() has no messages, that
 * the subscriber does not invoke ackMessages because there should be no acks.
 */
@Test
public void testPollInRegularCase() throws Exception {
  task.start(props);
  ReceivedMessage rm1 = createReceivedMessage(ACK_ID1, CPS_MESSAGE, new HashMap<String, String>());
  PullResponse stubbedPullResponse = PullResponse.newBuilder().addReceivedMessages(rm1).build();
  when(subscriber.pull(any(PullRequest.class)).get()).thenReturn(stubbedPullResponse);
  List<SourceRecord> result = task.poll();
  assertEquals(1, result.size());
  stubbedPullResponse = PullResponse.newBuilder().build();
  ListenableFuture<Empty> goodFuture = Futures.immediateFuture(Empty.getDefaultInstance());
  when(subscriber.ackMessages(any(AcknowledgeRequest.class))).thenReturn(goodFuture);
  when(subscriber.pull(any(PullRequest.class)).get()).thenReturn(stubbedPullResponse);
  result = task.poll();
  assertEquals(0, result.size());
  result = task.poll();
  assertEquals(0, result.size());
  verify(subscriber, times(1)).ackMessages(any(AcknowledgeRequest.class));
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:23,代码来源:CloudPubSubSourceTaskTest.java

示例12: rescheduleForTenant

import com.google.protobuf.Empty; //导入依赖的package包/类
private void rescheduleForTenant(final TenantId tenantId) {
    final TenantAwareFunction0<Iterator<Command>> func =
            new TenantAwareFunction0<Iterator<Command>>(tenantId) {
                @Override
                public Iterator<Command> apply() {
                    return commandStore().iterator(SCHEDULED);
                }
            };

    final Iterator<Command> commands = func.execute(Empty.getDefaultInstance());

    final TenantAwareOperation op = new TenantAwareOperation(tenantId) {
        @Override
        public void run() {
            while (commands.hasNext()) {
                final Command command = commands.next();
                reschedule(command);
            }
        }
    };
    op.execute();
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:23,代码来源:Rescheduler.java

示例13: callCompletionStatusesAreRecorded

import com.google.protobuf.Empty; //导入依赖的package包/类
@Test
public void callCompletionStatusesAreRecorded() throws InterruptedException {
  CallCompletionStatusInterceptor interceptor = new CallCompletionStatusInterceptor();

  when(channelStub.newCall(BigtableServiceGrpc.CONFIG.mutateRow)).thenReturn(callStub);

  CompletionStatusGatheringCall<MutateRowRequest, Empty> wrappedCall =
      interceptor.interceptCall(BigtableServiceGrpc.CONFIG.mutateRow, channelStub);

  Listener<Empty> statusGatheringListener =
      wrappedCall.createGatheringListener(responseListenerStub);

  statusGatheringListener.onClose(Status.INTERNAL, new Metadata.Trailers());

  CallCompletionStatusInterceptor.CallCompletionStatus expectedStatusEntry =
      new CallCompletionStatusInterceptor.CallCompletionStatus(
          BigtableServiceGrpc.CONFIG.mutateRow, Status.INTERNAL);

  Assert.assertEquals(1, interceptor.getCallCompletionStatuses().count(expectedStatusEntry));
}
 
开发者ID:dmmcerlean,项目名称:cloud-bigtable-client,代码行数:21,代码来源:CallCompletionStatusInterceptorTest.java

示例14: successfulCallsAreNotRetried

import com.google.protobuf.Empty; //导入依赖的package包/类
@Test
public void successfulCallsAreNotRetried() {
  RetryListener<MutateRowRequest, Empty> listener =
      new RetryListener<>(
          mockRetryingCall,
          request,
          new Headers.Headers(),
          true, // always retriable for testing
          mockResponseListener);

  listener.onHeaders(new Headers.Headers());
  listener.onPayload(response);
  listener.onClose(Status.OK, new Trailers.Trailers());

  // Validate that the listener did not attempt to start a new call on the channel:
  verifyNoMoreInteractions(mockRetryingCall);

  // Verify that the mockResponseListener was informed of the payload and closed:
  verify(mockResponseListener, times(1)).onPayload(eq(response));
  verify(mockResponseListener, times(1)).onClose(eq(Status.OK), any(Trailers.Trailers.class));
}
 
开发者ID:dmmcerlean,项目名称:cloud-bigtable-client,代码行数:22,代码来源:RetryListenerTest.java

示例15: failuresAfterHeadersAreReceivedIsNotRetried

import com.google.protobuf.Empty; //导入依赖的package包/类
@Test
public void failuresAfterHeadersAreReceivedIsNotRetried() {
  Headers requestHeaders = new Headers.Headers();
  RetryListener<MutateRowRequest, Empty> listener =
      new RetryListener<>(
          mockRetryingCall,
          request,
          requestHeaders,
          true, // always retriable for testing
          mockResponseListener);

  Headers responseHeaders = new Headers.Headers();
  listener.onHeaders(responseHeaders);
  listener.onPayload(response);
  listener.onClose(Status.INTERNAL, new Trailers.Trailers());

  // Validate that the listener did not attempt to start a new call on the channel:
  verifyNoMoreInteractions(mockRetryingCall);

  // Verify that the mockResponseListener was informed of the payload and closed:
  verify(mockResponseListener, times(1)).onHeaders(eq(responseHeaders));
  verify(mockResponseListener, times(1)).onPayload(eq(response));
  verify(mockResponseListener, times(1)).onClose(
      eq(Status.INTERNAL), any(Trailers.Trailers.class));
}
 
开发者ID:dmmcerlean,项目名称:cloud-bigtable-client,代码行数:26,代码来源:RetryListenerTest.java


注:本文中的com.google.protobuf.Empty类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。