Java Code Examples for io.grpc.CallCredentials#MetadataApplier

The following examples show how to use io.grpc.CallCredentials#MetadataApplier . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CallCredentialsApplyingTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void applyMetadata_delayed() {
  when(mockTransport.getAttributes()).thenReturn(Attributes.EMPTY);

  // Will call applyRequestMetadata(), which is no-op.
  DelayedStream stream = (DelayedStream) transport.newStream(method, origHeaders, callOptions);

  ArgumentCaptor<CallCredentials.MetadataApplier> applierCaptor = ArgumentCaptor.forClass(null);
  verify(mockCreds).applyRequestMetadata(same(method), any(Attributes.class),
      same(mockExecutor), applierCaptor.capture());
  verify(mockTransport, never()).newStream(method, origHeaders, callOptions);

  Metadata headers = new Metadata();
  headers.put(CREDS_KEY, CREDS_VALUE);
  applierCaptor.getValue().apply(headers);

  verify(mockTransport).newStream(method, origHeaders, callOptions);
  assertSame(mockStream, stream.getRealStream());
  assertEquals(CREDS_VALUE, origHeaders.get(CREDS_KEY));
  assertEquals(ORIG_HEADER_VALUE, origHeaders.get(ORIG_HEADER_KEY));
}
 
Example 2
Source File: CallCredentialsApplyingTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void fail_delayed() {
  when(mockTransport.getAttributes()).thenReturn(Attributes.EMPTY);

  // Will call applyRequestMetadata(), which is no-op.
  DelayedStream stream = (DelayedStream) transport.newStream(method, origHeaders, callOptions);

  ArgumentCaptor<CallCredentials.MetadataApplier> applierCaptor = ArgumentCaptor.forClass(null);
  verify(mockCreds).applyRequestMetadata(same(method), any(Attributes.class),
      same(mockExecutor), applierCaptor.capture());

  Status error = Status.FAILED_PRECONDITION.withDescription("channel not secure for creds");
  applierCaptor.getValue().fail(error);

  verify(mockTransport, never()).newStream(method, origHeaders, callOptions);
  FailingClientStream failingStream = (FailingClientStream) stream.getRealStream();
  assertSame(error, failingStream.getError());
}
 
Example 3
Source File: CallCredentialsApplyingTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void applyMetadata_delayed() {
  when(mockTransport.getAttributes()).thenReturn(Attributes.EMPTY);

  // Will call applyRequestMetadata(), which is no-op.
  DelayedStream stream = (DelayedStream) transport.newStream(method, origHeaders, callOptions);

  ArgumentCaptor<CallCredentials.MetadataApplier> applierCaptor = ArgumentCaptor.forClass(null);
  verify(mockCreds).applyRequestMetadata(any(RequestInfo.class),
      same(mockExecutor), applierCaptor.capture());
  verify(mockTransport, never()).newStream(method, origHeaders, callOptions);

  Metadata headers = new Metadata();
  headers.put(CREDS_KEY, CREDS_VALUE);
  applierCaptor.getValue().apply(headers);

  verify(mockTransport).newStream(method, origHeaders, callOptions);
  assertSame(mockStream, stream.getRealStream());
  assertEquals(CREDS_VALUE, origHeaders.get(CREDS_KEY));
  assertEquals(ORIG_HEADER_VALUE, origHeaders.get(ORIG_HEADER_KEY));
}
 
Example 4
Source File: CallCredentialsApplyingTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void fail_delayed() {
  when(mockTransport.getAttributes()).thenReturn(Attributes.EMPTY);

  // Will call applyRequestMetadata(), which is no-op.
  DelayedStream stream = (DelayedStream) transport.newStream(method, origHeaders, callOptions);

  ArgumentCaptor<CallCredentials.MetadataApplier> applierCaptor = ArgumentCaptor.forClass(null);
  verify(mockCreds).applyRequestMetadata(any(RequestInfo.class),
      same(mockExecutor), applierCaptor.capture());

  Status error = Status.FAILED_PRECONDITION.withDescription("channel not secure for creds");
  applierCaptor.getValue().fail(error);

  verify(mockTransport, never()).newStream(method, origHeaders, callOptions);
  FailingClientStream failingStream = (FailingClientStream) stream.getRealStream();
  assertSame(error, failingStream.getError());
}