Search in sources :

Example 36 with Metadata

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project sonarlint-core by SonarSource.

the class ConnectedDaemonTest method getLogs.

private ClientCall<Void, LogEvent> getLogs(LogCollector collector, Channel channel) {
    ClientCall<Void, LogEvent> call = channel.newCall(StandaloneSonarLintGrpc.METHOD_STREAM_LOGS, CallOptions.DEFAULT);
    call.start(collector, new Metadata());
    call.sendMessage(Void.newBuilder().build());
    call.halfClose();
    call.request(Integer.MAX_VALUE);
    return call;
}
Also used : LogEvent(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.LogEvent) Metadata(io.grpc.Metadata) Void(org.sonarsource.sonarlint.daemon.proto.SonarlintDaemon.Void)

Example 37 with Metadata

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project google-cloud-java by GoogleCloudPlatform.

the class WatchdogInterceptorTest method callerCancelsBeforeTimeout.

@Test
public void callerCancelsBeforeTimeout() {
    ClientCall<Void, Void> call = startCall();
    // Cancel the call before the watchdog does.
    call.cancel("Cancelled by user", null);
    ticker.advance(TIMEOUT_NANOS + 1);
    // Finish RPC with CANCELLED.
    Metadata trailers = new Metadata();
    innerListener.getValue().onClose(Status.CANCELLED, trailers);
    watchdog.tick();
    // The call should be cancelled exactly once.
    verify(innerCall, times(1)).cancel(anyString(), Mockito.<Throwable>any());
    // No translation, since the user beat the watchdog.
    verify(listener).onClose(argThat(isStatusWithCode(Status.Code.CANCELLED)), same(trailers));
}
Also used : Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 38 with Metadata

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project google-cloud-java by GoogleCloudPlatform.

the class WatchdogInterceptorTest method failureAfterTimeout.

@Test
public void failureAfterTimeout() {
    startCall();
    ticker.advance(TIMEOUT_NANOS + 1);
    watchdog.tick();
    // The call should be cancelled exactly once.
    verify(innerCall, times(1)).cancel(anyString(), Mockito.<Throwable>any());
    // Finish RPC with error.
    Metadata trailers = new Metadata();
    innerListener.getValue().onClose(Status.DATA_LOSS, trailers);
    // No translation expected.
    verify(listener).onClose(argThat(isStatusWithCode(Status.Code.DATA_LOSS)), same(trailers));
}
Also used : Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 39 with Metadata

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project google-cloud-java by GoogleCloudPlatform.

the class WatchdogInterceptorTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    ticker = new FakeTicker();
    watchdog = new WatchdogInterceptor(TIMEOUT_NANOS, TimeUnit.NANOSECONDS, ticker);
    // Nothing special about the deadline: we just want a particular CallOptions instance to expect.
    options = CallOptions.DEFAULT.withDeadlineAfter(10, TimeUnit.SECONDS);
    metadata = new Metadata();
}
Also used : Metadata(io.grpc.Metadata) FakeTicker(com.google.common.testing.FakeTicker) Before(org.junit.Before)

Example 40 with Metadata

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project google-cloud-java by GoogleCloudPlatform.

the class WatchdogInterceptorTest method timeout.

@Test
public void timeout() {
    startCall();
    ticker.advance(TIMEOUT_NANOS + 1);
    watchdog.tick();
    verify(innerCall, times(1)).cancel(anyString(), Mockito.<Throwable>any());
    // Finish RPC with CANCELLED.
    Metadata trailers = new Metadata();
    innerListener.getValue().onClose(Status.CANCELLED, trailers);
    // Should translate to UNAVAILABLE.
    verify(listener).onClose(argThat(isStatusWithCode(Status.Code.UNAVAILABLE)), same(trailers));
}
Also used : Metadata(io.grpc.Metadata) Test(org.junit.Test)

Aggregations

Metadata (io.grpc.Metadata)701 Test (org.junit.Test)559 Status (io.grpc.Status)190 CallOptions (io.grpc.CallOptions)56 ClientStreamTracer (io.grpc.ClientStreamTracer)51 ServerCall (io.grpc.ServerCall)48 PickSubchannelArgs (io.grpc.LoadBalancer.PickSubchannelArgs)44 InOrder (org.mockito.InOrder)41 Subchannel (io.grpc.LoadBalancer.Subchannel)40 ByteArrayInputStream (java.io.ByteArrayInputStream)40 InputStream (java.io.InputStream)38 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)33 IOException (java.io.IOException)32 AtomicReference (java.util.concurrent.atomic.AtomicReference)32 Context (io.grpc.Context)31 MockClientTransportInfo (io.grpc.internal.TestUtils.MockClientTransportInfo)31 InternalMetadata (io.grpc.InternalMetadata)30 MethodDescriptor (io.grpc.MethodDescriptor)30 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)29 ManagedChannel (io.grpc.ManagedChannel)27