use of io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method authorityPropagatedToStream.
@Test
public void authorityPropagatedToStream() {
ClientCallImpl<Void, Void> call = new ClientCallImpl<Void, Void>(method, MoreExecutors.directExecutor(), CallOptions.DEFAULT.withAuthority("overridden-authority"), statsTraceCtx, provider, deadlineCancellationExecutor).setDecompressorRegistry(decompressorRegistry);
call.start(callListener, new Metadata());
verify(stream).setAuthority("overridden-authority");
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method callOptionsPropagatedToTransport.
@Test
public void callOptionsPropagatedToTransport() {
final CallOptions callOptions = CallOptions.DEFAULT.withAuthority("dummy_value");
final ClientCallImpl<Void, Void> call = new ClientCallImpl<Void, Void>(method, MoreExecutors.directExecutor(), callOptions, statsTraceCtx, provider, deadlineCancellationExecutor).setDecompressorRegistry(decompressorRegistry);
final Metadata metadata = new Metadata();
call.start(callListener, metadata);
verify(transport).newStream(same(method), same(metadata), same(callOptions), same(statsTraceCtx));
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method callerContextPropagatedToListener.
@Test
public void callerContextPropagatedToListener() throws Exception {
// Attach the context which is recorded when the call is created
final Context.Key<String> testKey = Context.key("testing");
Context.current().withValue(testKey, "testValue").attach();
ClientCallImpl<Void, Void> call = new ClientCallImpl<Void, Void>(method, new SerializingExecutor(Executors.newSingleThreadExecutor()), CallOptions.DEFAULT, statsTraceCtx, provider, deadlineCancellationExecutor).setDecompressorRegistry(decompressorRegistry);
Context.ROOT.attach();
// Override the value after creating the call, this should not be seen by callbacks
Context.current().withValue(testKey, "badValue").attach();
final AtomicBoolean onHeadersCalled = new AtomicBoolean();
final AtomicBoolean onMessageCalled = new AtomicBoolean();
final AtomicBoolean onReadyCalled = new AtomicBoolean();
final AtomicBoolean observedIncorrectContext = new AtomicBoolean();
final CountDownLatch latch = new CountDownLatch(1);
call.start(new ClientCall.Listener<Void>() {
@Override
public void onHeaders(Metadata headers) {
onHeadersCalled.set(true);
checkContext();
}
@Override
public void onMessage(Void message) {
onMessageCalled.set(true);
checkContext();
}
@Override
public void onClose(Status status, Metadata trailers) {
checkContext();
latch.countDown();
}
@Override
public void onReady() {
onReadyCalled.set(true);
checkContext();
}
private void checkContext() {
if (!"testValue".equals(testKey.get())) {
observedIncorrectContext.set(true);
}
}
}, new Metadata());
verify(stream).start(listenerArgumentCaptor.capture());
ClientStreamListener listener = listenerArgumentCaptor.getValue();
listener.onReady();
listener.headersRead(new Metadata());
listener.messageRead(new ByteArrayInputStream(new byte[0]));
listener.messageRead(new ByteArrayInputStream(new byte[0]));
listener.closed(Status.OK, new Metadata());
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertTrue(onHeadersCalled.get());
assertTrue(onMessageCalled.get());
assertTrue(onReadyCalled.get());
assertFalse(observedIncorrectContext.get());
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method timeoutShouldNotBeSet.
/**
* Without a context or call options deadline,
* a timeout should not be set in metadata.
*/
@Test
public void timeoutShouldNotBeSet() {
ClientCallImpl<Void, Void> call = new ClientCallImpl<Void, Void>(method, MoreExecutors.directExecutor(), CallOptions.DEFAULT, statsTraceCtx, provider, deadlineCancellationExecutor);
Metadata headers = new Metadata();
call.start(callListener, headers);
assertFalse(headers.containsKey(GrpcUtil.TIMEOUT_KEY));
}
use of io.grpc.Metadata in project grpc-java by grpc.
the class ClientCallImplTest method contextDeadlineShouldBePropagatedInMetadata.
@Test
public void contextDeadlineShouldBePropagatedInMetadata() {
long deadlineNanos = TimeUnit.SECONDS.toNanos(1);
Context context = Context.current().withDeadlineAfter(deadlineNanos, TimeUnit.NANOSECONDS, deadlineCancellationExecutor);
context.attach();
ClientCallImpl<Void, Void> call = new ClientCallImpl<Void, Void>(method, MoreExecutors.directExecutor(), CallOptions.DEFAULT, statsTraceCtx, provider, deadlineCancellationExecutor);
Metadata headers = new Metadata();
call.start(callListener, headers);
assertTrue(headers.containsKey(GrpcUtil.TIMEOUT_KEY));
Long timeout = headers.get(GrpcUtil.TIMEOUT_KEY);
assertNotNull(timeout);
long deltaNanos = TimeUnit.MILLISECONDS.toNanos(400);
assertTimeoutBetween(timeout, deadlineNanos - deltaNanos, deadlineNanos);
}
Aggregations