Search in sources :

Example 96 with Metadata

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

the class ClientCallImplTest method methodInfoDeadlinePropagatedToStream.

@Test
public void methodInfoDeadlinePropagatedToStream() {
    ArgumentCaptor<CallOptions> callOptionsCaptor = ArgumentCaptor.forClass(null);
    CallOptions callOptions = baseCallOptions.withDeadline(Deadline.after(2000, SECONDS));
    // Case: config Deadline expires later than CallOptions Deadline
    Map<String, ?> rawMethodConfig = ImmutableMap.of("timeout", "3000s");
    MethodInfo methodInfo = new MethodInfo(rawMethodConfig, false, 0, 0);
    callOptions = callOptions.withOption(MethodInfo.KEY, methodInfo);
    ClientCallImpl<Void, Void> call = new ClientCallImpl<>(method, MoreExecutors.directExecutor(), callOptions, clientStreamProvider, deadlineCancellationExecutor, channelCallTracer, configSelector).setDecompressorRegistry(decompressorRegistry);
    call.start(callListener, new Metadata());
    verify(clientStreamProvider).newStream(same(method), callOptionsCaptor.capture(), any(Metadata.class), any(Context.class));
    Deadline actualDeadline = callOptionsCaptor.getValue().getDeadline();
    assertThat(actualDeadline).isLessThan(Deadline.after(2001, SECONDS));
    // Case: config Deadline expires earlier than CallOptions Deadline
    rawMethodConfig = ImmutableMap.of("timeout", "1000s");
    methodInfo = new MethodInfo(rawMethodConfig, false, 0, 0);
    callOptions = callOptions.withOption(MethodInfo.KEY, methodInfo);
    call = new ClientCallImpl<>(method, MoreExecutors.directExecutor(), callOptions, clientStreamProvider, deadlineCancellationExecutor, channelCallTracer, configSelector).setDecompressorRegistry(decompressorRegistry);
    call.start(callListener, new Metadata());
    verify(clientStreamProvider, times(2)).newStream(same(method), callOptionsCaptor.capture(), any(Metadata.class), any(Context.class));
    actualDeadline = callOptionsCaptor.getValue().getDeadline();
    assertThat(actualDeadline).isLessThan(Deadline.after(1001, SECONDS));
}
Also used : Context(io.grpc.Context) Deadline(io.grpc.Deadline) Metadata(io.grpc.Metadata) MethodInfo(io.grpc.internal.ManagedChannelServiceConfig.MethodInfo) CallOptions(io.grpc.CallOptions) Test(org.junit.Test)

Example 97 with Metadata

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

the class ClientCallImplTest method deadlineExceededBeforeCallStarted.

@Test
public void deadlineExceededBeforeCallStarted() {
    CallOptions callOptions = baseCallOptions.withDeadlineAfter(0, TimeUnit.SECONDS);
    fakeClock.forwardTime(System.nanoTime(), TimeUnit.NANOSECONDS);
    ClientCallImpl<Void, Void> call = new ClientCallImpl<>(method, new SerializingExecutor(Executors.newSingleThreadExecutor()), callOptions, clientStreamProvider, deadlineCancellationExecutor, channelCallTracer, configSelector).setDecompressorRegistry(decompressorRegistry);
    call.start(callListener, new Metadata());
    verify(streamTracerFactory).newClientStreamTracer(any(StreamInfo.class), any(Metadata.class));
    verify(clientStreamProvider, never()).newStream((MethodDescriptor<?, ?>) any(MethodDescriptor.class), any(CallOptions.class), any(Metadata.class), any(Context.class));
    verify(callListener, timeout(1000)).onClose(statusCaptor.capture(), any(Metadata.class));
    assertEquals(Status.Code.DEADLINE_EXCEEDED, statusCaptor.getValue().getCode());
    assertThat(statusCaptor.getValue().getDescription()).startsWith("ClientCall started after deadline exceeded");
    verifyNoInteractions(clientStreamProvider);
}
Also used : Context(io.grpc.Context) Metadata(io.grpc.Metadata) StreamInfo(io.grpc.ClientStreamTracer.StreamInfo) CallOptions(io.grpc.CallOptions) Test(org.junit.Test)

Example 98 with Metadata

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

the class ClientCallImplTest method callOptionsPropagatedToTransport.

@Test
public void callOptionsPropagatedToTransport() {
    final CallOptions callOptions = baseCallOptions.withAuthority("dummy_value");
    final ClientCallImpl<Void, Void> call = new ClientCallImpl<>(method, MoreExecutors.directExecutor(), callOptions, clientStreamProvider, deadlineCancellationExecutor, channelCallTracer, configSelector).setDecompressorRegistry(decompressorRegistry);
    final Metadata metadata = new Metadata();
    call.start(callListener, metadata);
    verify(clientStreamProvider).newStream(same(method), same(callOptions), same(metadata), any(Context.class));
}
Also used : Context(io.grpc.Context) Metadata(io.grpc.Metadata) CallOptions(io.grpc.CallOptions) Test(org.junit.Test)

Example 99 with Metadata

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

the class ClientCallImplTest method contextCancellationCancelsStream.

@Test
public void contextCancellationCancelsStream() throws Exception {
    // Attach the context which is recorded when the call is created
    Context.CancellableContext cancellableContext = Context.current().withCancellation();
    Context previous = cancellableContext.attach();
    ClientCallImpl<Void, Void> call = new ClientCallImpl<>(method, new SerializingExecutor(Executors.newSingleThreadExecutor()), baseCallOptions, clientStreamProvider, deadlineCancellationExecutor, channelCallTracer, configSelector).setDecompressorRegistry(decompressorRegistry);
    cancellableContext.detach(previous);
    call.start(callListener, new Metadata());
    Throwable t = new Throwable();
    cancellableContext.cancel(t);
    verify(stream, times(1)).cancel(statusArgumentCaptor.capture());
    Status streamStatus = statusArgumentCaptor.getValue();
    assertEquals(Status.Code.CANCELLED, streamStatus.getCode());
}
Also used : Context(io.grpc.Context) Status(io.grpc.Status) Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 100 with Metadata

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

the class ClientCallImplTest method halfClosedShouldNotBeReady.

@Test
public void halfClosedShouldNotBeReady() {
    when(stream.isReady()).thenReturn(true);
    ClientCallImpl<Void, Void> call = new ClientCallImpl<>(method, MoreExecutors.directExecutor(), baseCallOptions, clientStreamProvider, deadlineCancellationExecutor, channelCallTracer, configSelector);
    call.start(callListener, new Metadata());
    assertThat(call.isReady()).isTrue();
    call.halfClose();
    assertThat(call.isReady()).isFalse();
}
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