private GrpcCallContext newCallContext(@Nullable Map<Option, ?> options, String resource) { GrpcCallContext context = GrpcCallContext.createDefault(); if (options != null) { context = context.withChannelAffinity(Option.CHANNEL_HINT.getLong(options).intValue()); } context = context.withExtraHeaders(metadataProvider.newExtraHeaders(resource, projectName)); return context.withStreamWaitTimeout(waitTimeout).withStreamIdleTimeout(idleTimeout); }
private GrpcCallContext newCallContext(@Nullable Map<Option, ?> options, String resource) { GrpcCallContext context = GrpcCallContext.createDefault(); if (options != null) { context = context.withChannelAffinity(Option.CHANNEL_HINT.getLong(options).intValue()); } context = context.withExtraHeaders(metadataProvider.newExtraHeaders(resource, projectName)); return context.withStreamWaitTimeout(waitTimeout).withStreamIdleTimeout(idleTimeout); }
@Test public void testWithZeroStreamingWaitTimeout() { Duration timeout = Duration.ZERO; Truth.assertThat( GrpcCallContext.createDefault().withStreamWaitTimeout(timeout).getStreamWaitTimeout()) .isEqualTo(timeout); }
@Test public void testWithStreamingWaitTimeout() { Duration timeout = Duration.ofSeconds(15); GrpcCallContext context = GrpcCallContext.createDefault().withStreamWaitTimeout(timeout); Truth.assertThat(context.getStreamWaitTimeout()).isEqualTo(timeout); }
@Test public void testMergeWithNullStreamingWaitTimeout() { Duration timeout = Duration.ofSeconds(10); GrpcCallContext baseContext = GrpcCallContext.createDefault().withStreamWaitTimeout(timeout); GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); Truth.assertThat(baseContext.merge(defaultOverlay).getStreamWaitTimeout()).isEqualTo(timeout); GrpcCallContext explicitNullOverlay = GrpcCallContext.createDefault().withStreamWaitTimeout(null); Truth.assertThat(baseContext.merge(explicitNullOverlay).getStreamWaitTimeout()) .isEqualTo(timeout); }
@Test public void testMergeWithStreamingWaitTimeout() { Duration timeout = Duration.ofSeconds(19); GrpcCallContext ctx1 = GrpcCallContext.createDefault(); GrpcCallContext ctx2 = GrpcCallContext.createDefault().withStreamWaitTimeout(timeout); Truth.assertThat(ctx1.merge(ctx2).getStreamWaitTimeout()).isEqualTo(timeout); }