Java Code Examples for io.grpc.CallOptions#Key

The following examples show how to use io.grpc.CallOptions#Key . 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: DefaultCallOptionsClientInterceptorTest.java    From grpc-java-contrib with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void noOverwriteWorksCustomKeys() {
    CallOptions.Key<String> k1 = CallOptions.Key.of("k1", null);
    CallOptions.Key<String> k2 = CallOptions.Key.of("k2", null);
    CallOptions.Key<String> k3 = CallOptions.Key.of("k3", null);

    CallOptions baseOptions = CallOptions.DEFAULT.withOption(k1, "FOO").withOption(k3, "BAZ");
    CallOptions defaultOptions = CallOptions.DEFAULT.withOption(k2, "BAR").withOption(k3, "BOP");

    DefaultCallOptionsClientInterceptor interceptor = new DefaultCallOptionsClientInterceptor(defaultOptions);

    CallOptions patchedOptions = interceptor.patchOptions(baseOptions);

    assertThat(patchedOptions.getOption(k1)).isEqualTo("FOO");
    assertThat(patchedOptions.getOption(k2)).isEqualTo("BAR");
    assertThat(patchedOptions.getOption(k3)).isEqualTo("BAZ");
}
 
Example 2
Source File: DefaultCallOptionsClientInterceptorTest.java    From grpc-java-contrib with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void overwriteWorksCustomKeys() {
    CallOptions.Key<String> k1 = CallOptions.Key.of("k1", null);
    CallOptions.Key<String> k2 = CallOptions.Key.of("k2", null);
    CallOptions.Key<String> k3 = CallOptions.Key.of("k3", null);

    CallOptions baseOptions = CallOptions.DEFAULT.withOption(k1, "FOO").withOption(k3, "BAZ");
    CallOptions defaultOptions = CallOptions.DEFAULT.withOption(k2, "BAR").withOption(k3, "BOP");

    DefaultCallOptionsClientInterceptor interceptor = new DefaultCallOptionsClientInterceptor(defaultOptions)
            .overwriteExistingValues();

    CallOptions patchedOptions = interceptor.patchOptions(baseOptions);

    assertThat(patchedOptions.getOption(k1)).isEqualTo("FOO");
    assertThat(patchedOptions.getOption(k2)).isEqualTo("BAR");
    assertThat(patchedOptions.getOption(k3)).isEqualTo("BOP");
}
 
Example 3
Source File: DefaultCallOptionsClientInterceptorTest.java    From grpc-java-contrib with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void customKeyTransfers() {
    CallOptions.Key<String> k1 = CallOptions.Key.of("k1", null);
    CallOptions.Key<String> k2 = CallOptions.Key.of("k2", null);

    CallOptions baseOptions = CallOptions.DEFAULT.withOption(k1, "FOO");
    CallOptions defaultOptions = CallOptions.DEFAULT.withOption(k2, "BAR");

    DefaultCallOptionsClientInterceptor interceptor = new DefaultCallOptionsClientInterceptor(defaultOptions);

    CallOptions patchedOptions = interceptor.patchOptions(baseOptions);

    assertThat(patchedOptions.getOption(k1)).isEqualTo("FOO");
    assertThat(patchedOptions.getOption(k2)).isEqualTo("BAR");
}
 
Example 4
Source File: GrpcClientLimiterBuilder.java    From concurrency-limits with Apache License 2.0 4 votes vote down vote up
public GrpcClientLimiterBuilder partitionByCallOption(CallOptions.Key<String> option) {
    return partitionResolver(context -> context.getCallOptions().getOption(option));
}
 
Example 5
Source File: InternalClientCalls.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
/** Internal accessor for {@link ClientCalls#STUB_TYPE_OPTION}. */
public static CallOptions.Key<ClientCalls.StubType> getStubTypeOption() {
  return ClientCalls.STUB_TYPE_OPTION;
}
 
Example 6
Source File: AbstractStub.java    From grpc-nebula-java with Apache License 2.0 2 votes vote down vote up
/**
 * Sets a custom option to be passed to client interceptors on the channel
 * {@link io.grpc.ClientInterceptor} via the CallOptions parameter.
 *
 * @since 1.0.0
 * @param key the option being set
 * @param value the value for the key
 */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1869")
public final <T> S withOption(CallOptions.Key<T> key, T value) {
  return build(channel, callOptions.withOption(key, value));
}
 
Example 7
Source File: AbstractStub.java    From grpc-java with Apache License 2.0 2 votes vote down vote up
/**
 * Sets a custom option to be passed to client interceptors on the channel
 * {@link io.grpc.ClientInterceptor} via the CallOptions parameter.
 *
 * @since 1.0.0
 * @param key the option being set
 * @param value the value for the key
 */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1869")
public final <T> S withOption(CallOptions.Key<T> key, T value) {
  return build(channel, callOptions.withOption(key, value));
}