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 testWithZeroStreamingIdleTimeout() { Duration timeout = Duration.ZERO; Truth.assertThat( GrpcCallContext.createDefault().withStreamIdleTimeout(timeout).getStreamIdleTimeout()) .isEqualTo(timeout); }
@Test public void testWithStreamingIdleTimeout() { Duration timeout = Duration.ofSeconds(15); GrpcCallContext context = GrpcCallContext.createDefault().withStreamIdleTimeout(timeout); Truth.assertThat(context.getStreamIdleTimeout()).isEqualTo(timeout); }
@Test public void testMergeWithNullStreamingIdleTimeout() { Duration timeout = Duration.ofSeconds(10); GrpcCallContext baseContext = GrpcCallContext.createDefault().withStreamIdleTimeout(timeout); GrpcCallContext defaultOverlay = GrpcCallContext.createDefault(); Truth.assertThat(baseContext.merge(defaultOverlay).getStreamIdleTimeout()).isEqualTo(timeout); GrpcCallContext explicitNullOverlay = GrpcCallContext.createDefault().withStreamIdleTimeout(null); Truth.assertThat(baseContext.merge(explicitNullOverlay).getStreamIdleTimeout()) .isEqualTo(timeout); }
@Test public void testMergeWithStreamingIdleTimeout() { Duration timeout = Duration.ofSeconds(19); GrpcCallContext ctx1 = GrpcCallContext.createDefault(); GrpcCallContext ctx2 = GrpcCallContext.createDefault().withStreamIdleTimeout(timeout); Truth.assertThat(ctx1.merge(ctx2).getStreamIdleTimeout()).isEqualTo(timeout); }