Java Code Examples for io.dropwizard.util.Duration#milliseconds()
The following examples show how to use
io.dropwizard.util.Duration#milliseconds() .
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: ClientTimeoutTest.java From tenacity with Apache License 2.0 | 6 votes |
@Test public void tenacityDoesntRaceWithJerseyTimeout() { clientConfiguration.setTimeout(Duration.milliseconds(1)); tenacityConfiguration.setExecutionIsolationThreadTimeoutInMillis(300); registerTenacityProperties(); final Client client = tenacityClientBuilder.build(buildClient()); final WebTarget spyTarget = spy(client.target(uri)); final VoidCommand command = new VoidCommand(spyTarget, Duration.milliseconds(500)); boolean timeoutFailure = false; try { command.execute(); } catch (HystrixRuntimeException err) { timeoutFailure = err.getFailureType().equals(HystrixRuntimeException.FailureType.TIMEOUT); } assertTrue(timeoutFailure); assertTrue(command.isResponseTimedOut()); }
Example 2
Source File: GrpcServerTests.java From dropwizard-grpc with Apache License 2.0 | 5 votes |
@Test public void shouldCompleteRequestIfShutdownPeriodLongerThanLongRunningRequest() throws Exception { final Duration shutdownPeriod = Duration.milliseconds(3000L); final Duration slowRequestDuration = Duration.milliseconds(1000L); testShutdownPeriodHonoured(shutdownPeriod, slowRequestDuration, (requestDurationFut, shutdownDurationFut) -> { try { final Duration requestDuration = requestDurationFut.get(add(slowRequestDuration, DELTA).toMilliseconds(), TimeUnit.MILLISECONDS); assertEqualsWithTolerance(requestDuration, slowRequestDuration, DELTA); } catch (final Exception e) { throw new RuntimeException(e); } }); }
Example 3
Source File: GrpcServerTests.java From dropwizard-grpc with Apache License 2.0 | 5 votes |
@Test public void shouldHonourShutdownPeriodIfShutdownPeriodShorterThanLongRunningRequest() throws Exception { final Duration shutdownPeriod = Duration.milliseconds(1000L); final Duration slowRequestDuration = Duration.milliseconds(3000L); testShutdownPeriodHonoured(shutdownPeriod, slowRequestDuration, (requestDurationFut, shutdownDurationFut) -> { try { final Duration shutdownDuration = shutdownDurationFut.get(add(shutdownPeriod, DELTA).toMilliseconds(), TimeUnit.MILLISECONDS); assertEqualsWithTolerance(shutdownPeriod, shutdownDuration, DELTA); } catch (final Exception e) { throw new RuntimeException(e); } }); }
Example 4
Source File: TenacityObservableCommandTest.java From tenacity with Apache License 2.0 | 5 votes |
@Test public void shouldNotTimeoutAndRespectsProperties() { final TenacityConfiguration tenacityConfiguration = new TenacityConfiguration(); tenacityConfiguration.setExecutionIsolationThreadTimeoutInMillis(2000); new TenacityPropertyRegister( ImmutableMap.<TenacityPropertyKey, TenacityConfiguration>of(DependencyKey.OBSERVABLE_TIMEOUT, tenacityConfiguration), new BreakerboxConfiguration()) .register(); final TenacityObservableCommand<Boolean> command = new TimeoutObservable(Duration.milliseconds(1250)); assertTrue(command.toObservable().toBlocking().single()); }
Example 5
Source File: QueryClient.java From airpal with Apache License 2.0 | 4 votes |
public QueryClient(QueryRunner queryRunner, org.joda.time.Duration timeout, String query) { this(queryRunner, Duration.milliseconds(timeout.getMillis()), query); }
Example 6
Source File: TenacityObservableCommandTest.java From tenacity with Apache License 2.0 | 4 votes |
@Test public void shouldNotTimeout() { final TenacityObservableCommand<Boolean> command = new TimeoutObservable(Duration.milliseconds(100)); assertTrue(command.toObservable().toBlocking().single()); }
Example 7
Source File: TenacityObservableCommandTest.java From tenacity with Apache License 2.0 | 4 votes |
@Test public void whenUsingObservableCommandsExperienceRejectionsIfSemaphoreLimitBreached() throws InterruptedException { final TenacityConfiguration tenacityConfiguration = new TenacityConfiguration(); tenacityConfiguration.setExecutionIsolationThreadTimeoutInMillis(3000); tenacityConfiguration.setExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE); new TenacityPropertyRegister( ImmutableMap.<TenacityPropertyKey, TenacityConfiguration>of(DependencyKey.OBSERVABLE_TIMEOUT, tenacityConfiguration), new BreakerboxConfiguration()) .register(); new TimeoutObservable(Duration.milliseconds(500)) .getCumulativeCommandEventCounterStream() .startCachingStreamValuesIfUnstarted(); final int defaultSemaphoreMaxConcurrentRequests = new SemaphoreConfiguration().getMaxConcurrentRequests(); final ImmutableList.Builder<Observable<Boolean>> observables = ImmutableList.builder(); for (int i = 0; i < defaultSemaphoreMaxConcurrentRequests * 2; ++i) { final TimeoutObservable command = new TimeoutObservable(Duration.milliseconds(500)); observables.add(command.observe()); } for (Observable<Boolean> observable : observables.build()) { try { assertTrue(observable.toBlocking().single()); } catch (HystrixRuntimeException err) { assertThat(err).isInstanceOf(HystrixRuntimeException.class); assertThat(err.getFailureType()) .isIn(HystrixRuntimeException.FailureType.REJECTED_SEMAPHORE_EXECUTION, HystrixRuntimeException.FailureType.TIMEOUT); } } //Wait for metrics to be available Thread.sleep(1000); assertThat(TenacityObservableCommand .getCommandMetrics(DependencyKey.OBSERVABLE_TIMEOUT) .getCumulativeCount(HystrixRollingNumberEvent.SEMAPHORE_REJECTED)) .isGreaterThan(0); assertThat(TenacityObservableCommand .getCommandMetrics(DependencyKey.OBSERVABLE_TIMEOUT) .getCumulativeCount(HystrixRollingNumberEvent.TIMEOUT)) .isEqualTo(0); assertThat(TenacityObservableCommand .getCommandMetrics(DependencyKey.OBSERVABLE_TIMEOUT) .getCumulativeCount(HystrixRollingNumberEvent.SUCCESS)) .isGreaterThan(0); }
Example 8
Source File: TenacityObservableCommandTest.java From tenacity with Apache License 2.0 | 4 votes |
@Test public void observableCommandCanAdjustSemaphoreMaxConcurrentExecutions() throws InterruptedException { final SemaphoreConfiguration semaphoreConfiguration = new SemaphoreConfiguration(); semaphoreConfiguration.setMaxConcurrentRequests(50); final TenacityConfiguration tenacityConfiguration = new TenacityConfiguration(); tenacityConfiguration.setSemaphore(semaphoreConfiguration); tenacityConfiguration.setExecutionIsolationThreadTimeoutInMillis(3000); new TenacityPropertyRegister( ImmutableMap.<TenacityPropertyKey, TenacityConfiguration>of(DependencyKey.OBSERVABLE_TIMEOUT, tenacityConfiguration), new BreakerboxConfiguration()) .register(); new TimeoutObservable(Duration.milliseconds(500)) .getCumulativeCommandEventCounterStream() .startCachingStreamValuesIfUnstarted(); final int defaultSemaphoreMaxConcurrentRequests = new SemaphoreConfiguration().getMaxConcurrentRequests(); final ImmutableList.Builder<Observable<Boolean>> observables = ImmutableList.builder(); for (int i = 0; i < defaultSemaphoreMaxConcurrentRequests * 2; ++i) { final TimeoutObservable command = new TimeoutObservable(Duration.milliseconds(500)); observables.add(command.observe()); } for (Observable<Boolean> observable : observables.build()) { try { assertTrue(observable.toBlocking().single()); } catch (HystrixRuntimeException err) { fail("Failed to execute an observe: " + err); } } Thread.sleep(1000); assertThat(TenacityObservableCommand .getCommandMetrics(DependencyKey.OBSERVABLE_TIMEOUT) .getCumulativeCount(HystrixRollingNumberEvent.SEMAPHORE_REJECTED)) .isEqualTo(0); assertThat(TenacityObservableCommand .getCommandMetrics(DependencyKey.OBSERVABLE_TIMEOUT) .getCumulativeCount(HystrixRollingNumberEvent.TIMEOUT)) .isEqualTo(0); assertThat(TenacityObservableCommand .getCommandMetrics(DependencyKey.OBSERVABLE_TIMEOUT) .getCumulativeCount(HystrixRollingNumberEvent.SUCCESS)) .isEqualTo(observables.build().size()); }