Java Code Examples for io.dropwizard.util.Duration#seconds()
The following examples show how to use
io.dropwizard.util.Duration#seconds() .
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: DefaultRateLimitedLogFactoryTest.java From emodb with Apache License 2.0 | 5 votes |
@Test public void testMultipleErrors() { Logger log = Mockito.mock(Logger.class); ScheduledExecutorService executor = Mockito.mock(ScheduledExecutorService.class); Duration seconds = Duration.seconds(30); RateLimitedLog rateLimitedLog = new DefaultRateLimitedLogFactory(executor, seconds) .from(log); Mockito.verify(executor).scheduleWithFixedDelay(Matchers.<Runnable>any(), Matchers.eq(1L), Matchers.eq(1L), Matchers.eq(TimeUnit.MINUTES)); Throwable t1 = new Throwable(); Throwable t2 = new Throwable(); Throwable t3 = new Throwable(); rateLimitedLog.error(t1, "Test error: {}", "first!"); rateLimitedLog.error(t2, "Test error: {}", "second!"); rateLimitedLog.error(t3, "Test error: {}", "third!"); // Check that the first error gets logged immediately. Mockito.verify(log).error("Test error: first!", t1); ArgumentCaptor<Runnable> captor1 = ArgumentCaptor.forClass(Runnable.class); Mockito.verify(executor).schedule(captor1.capture(), Matchers.eq(30L), Matchers.eq(TimeUnit.SECONDS)); Mockito.verifyNoMoreInteractions(log, executor); Mockito.reset(executor); // Simulate the scheduled executor service running at the scheduled time after accumulating two more errors. captor1.getValue().run(); Mockito.verify(log).error("Encountered {} {} within the last {}: {}", 2L, "errors", Duration.seconds(30), "Test error: third!", t3); ArgumentCaptor<Runnable> captor2 = ArgumentCaptor.forClass(Runnable.class); Mockito.verify(executor).schedule(captor2.capture(), Matchers.eq(30L), Matchers.eq(TimeUnit.SECONDS)); Mockito.verifyNoMoreInteractions(log, executor); // Simulate the scheduled executor service running at the scheduled time, this time with no errors to report. captor2.getValue().run(); Mockito.verifyNoMoreInteractions(log, executor); }
Example 2
Source File: TenacityConfiguredBundle.java From tenacity with Apache License 2.0 | 5 votes |
protected void configureHystrix(T configuration, Environment environment) { final ServerFactory serverFactory = configuration.getServerFactory(); final Duration shutdownGracePeriod = (serverFactory instanceof AbstractServerFactory) ? ((AbstractServerFactory) serverFactory).getShutdownGracePeriod() : Duration.seconds(30L); environment.lifecycle().manage(new ManagedHystrix(shutdownGracePeriod)); }
Example 3
Source File: DefaultRateLimitedLogFactory.java From emodb with Apache License 2.0 | 4 votes |
@Inject public DefaultRateLimitedLogFactory(LifeCycleRegistry lifeCycle) { this(defaultExecutor(lifeCycle), Duration.seconds(30)); }
Example 4
Source File: ManagedGrpcChannel.java From dropwizard-grpc with Apache License 2.0 | 4 votes |
public ManagedGrpcChannel(final ManagedChannel channel) { this(channel, Duration.seconds(5)); }
Example 5
Source File: ManagedGrpcServer.java From dropwizard-grpc with Apache License 2.0 | 4 votes |
public ManagedGrpcServer(final Server server) { this(server, Duration.seconds(5)); }
Example 6
Source File: CassandraHealthCheckTest.java From dropwizard-cassandra with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { when(cluster.connect()).thenReturn(session); healthCheck = new CassandraHealthCheck(cluster, validationQuery, Duration.seconds(1)); }
Example 7
Source File: QueryClient.java From airpal with Apache License 2.0 | 4 votes |
public QueryClient(QueryRunner queryRunner, String query) { this(queryRunner, Duration.seconds(60 * 30), query); }