List of usage examples for java.util.concurrent TimeUnit SECONDS
TimeUnit SECONDS
To view the source code for java.util.concurrent TimeUnit SECONDS.
Click Source Link
From source file:com.github.jrialland.ajpclient.servlet.TestWrongHost.java
/** * tries to make a request to an unknown host, verifies that the request * fails (the library does not hangs) and that we have a 502 error * //from ww w. ja v a 2 s . c om * @throws Exception */ @Test public void testWrongTargetHost() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("GET"); request.setRequestURI("/dizzy.mp4"); final MockHttpServletResponse response = new MockHttpServletResponse(); final Future<Integer> statusFuture = Executors.newSingleThreadExecutor().submit(new Callable<Integer>() { @Override public Integer call() throws Exception { AjpServletProxy.forHost("unknownhost.inexistentdomain.com", 8415).forward(request, response); return response.getStatus(); } }); final long start = System.currentTimeMillis(); // should finish in less that seconds final int status = statusFuture.get(10, TimeUnit.SECONDS); Assert.assertTrue(System.currentTimeMillis() - start < 8000); Assert.assertEquals(HttpServletResponse.SC_BAD_GATEWAY, status); }
From source file:com.amazon.speech.speechlet.servlet.ServletSpeechletRequestHandler.java
/** * Returns a {@link TimestampSpeechletRequestVerifier} configured using timestamp tolerance * defined by the system property {@link Sdk#TIMESTAMP_TOLERANCE_SYSTEM_PROPERTY}. If a valid * timestamp tolerance is missing in the system properties, then {@code null} is returned. * * @return a configured TimestampSpeechletRequestVerifier or null *//* ww w . j av a 2 s . c o m*/ private static TimestampSpeechletRequestVerifier getTimestampVerifier() { String timestampToleranceAsString = System.getProperty(Sdk.TIMESTAMP_TOLERANCE_SYSTEM_PROPERTY); if (!StringUtils.isBlank(timestampToleranceAsString)) { try { long timestampTolerance = Long.parseLong(timestampToleranceAsString); return new TimestampSpeechletRequestVerifier(timestampTolerance, TimeUnit.SECONDS); } catch (NumberFormatException ex) { log.warn("The configured timestamp tolerance {} is invalid, " + "disabling timestamp verification", timestampToleranceAsString); } } else { log.warn("No timestamp tolerance has been configured, " + "disabling timestamp verification"); } return null; }
From source file:com.baasbox.service.dbmanager.DbManagerService.java
/** * This method generate a full dump of the db in an asyncronus task. * /* w ww . j a v a 2 s . c o m*/ * The async nature of the method DOES NOT ensure the creation of the file * so, querying for the file name with the /admin/db/:filename could return a 404 * @param appcode * @return * @throws FileNotFoundException */ public static String exportDb(String appcode) throws FileNotFoundException { java.io.File dir = new java.io.File(backupDir); if (!dir.exists()) { boolean createdDir = dir.mkdirs(); if (!createdDir) { throw new FileNotFoundException("unable to create backup dir"); } } SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss"); String fileName = String.format("%s-%s.zip", sdf.format(new Date()), FileSystemPathUtil.escapeName(appcode)); //Async task Akka.system().scheduler().scheduleOnce(Duration.create(1, TimeUnit.SECONDS), new ExportJob(dir.getAbsolutePath() + fileSeparator + fileName, appcode), Akka.system().dispatcher()); return fileName; }
From source file:demo.RxJavaTransformer.java
@Bean public RxJavaProcessor<String, String> processor() { return inputStream -> inputStream.map(data -> { return data; }).buffer(10, 10, TimeUnit.SECONDS).map(data -> processData(data)); }
From source file:org.elasticsearch.example.SiteContentsIT.java
public void test() throws Exception { TestCluster cluster = cluster();/*from www .jav a 2 s .c o m*/ assumeTrue( "this test will not work from an IDE unless you pass tests.cluster pointing to a running instance", cluster instanceof ExternalTestCluster); ExternalTestCluster externalCluster = (ExternalTestCluster) cluster; try (CloseableHttpClient httpClient = HttpClients .createMinimal(new PoolingHttpClientConnectionManager(15, TimeUnit.SECONDS))) { for (InetSocketAddress address : externalCluster.httpAddresses()) { RestResponse restResponse = new RestResponse( new HttpRequestBuilder(httpClient).host(NetworkAddress.format(address.getAddress())) .port(address.getPort()).path("/_plugin/site-example/").method("GET").execute()); assertEquals(200, restResponse.getStatusCode()); String body = restResponse.getBodyAsString(); assertTrue("unexpected body contents: " + body, body.contains("<body>Page body</body>")); } } }
From source file:com.ottogroup.bi.spqr.metrics.MetricsReporterFactory.java
/** * Attaches a {@link GraphiteReporter} to provided {@link MetricsHandler} * @param metricsHandler/* w ww. jav a2s . c om*/ * @param id * @param period * @param host * @param port * @throws RequiredInputMissingException */ private static void attachGraphiteReporter(final MetricsHandler metricsHandler, final String id, final int period, final String host, final int port) throws RequiredInputMissingException { ////////////////////////////////////////////////////////////////////////// // validate input if (StringUtils.isBlank(id)) throw new RequiredInputMissingException("Missing required metric reporter id"); if (metricsHandler == null) throw new RequiredInputMissingException("Missing required metrics handler"); if (StringUtils.isBlank(host)) throw new RequiredInputMissingException("Missing required graphite host"); if (port < 0) throw new RequiredInputMissingException("Missing required graphite port"); ////////////////////////////////////////////////////////////////////////// final Graphite graphite = new Graphite(new InetSocketAddress(host, port)); final GraphiteReporter reporter = GraphiteReporter.forRegistry(metricsHandler.getRegistry()) .convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL) .build(graphite); reporter.start((period > 0 ? period : 1), TimeUnit.SECONDS); metricsHandler.addScheduledReporter(id, reporter); }
From source file:ufo.remote.calls.benchmark.server.vertx.service.EchoVerticleTest.java
@Test public void testGetEchoServer() throws InterruptedException { Vertx vertx = context.getBean(VertxService.class).vertx(); final String message = UUID.randomUUID().toString(); vertx.eventBus().send("echo", message, (AsyncResult<Message<String>> response) -> { assertTrue(response.succeeded()); logger.info("expected text [{}], received text [{}]", message, response.result().body()); assertEquals(message, response.result().body()); testComplete();/*from ww w . j a v a 2s . c om*/ }); await(30, TimeUnit.SECONDS); }
From source file:com.fusesource.examples.dm_bundle.CamelMockedRouteTest.java
@Test public void testRespondToMessageUsingMocks() throws Exception { context.getRouteDefinition("respondToMessage").adviceWith(context, new RouteBuilder() { @Override//from ww w .j a v a2 s . c om public void configure() throws Exception { // intercept sending to mock:foo and do something else interceptSendToEndpoint("activemq:out").skipSendToOriginalEndpoint().to("mock:out"); } }); MockEndpoint mockOut = getMockEndpoint("mock:out"); mockOut.expectedMessageCount(1); inbox.sendBody("foo"); mockOut.await(3, TimeUnit.SECONDS); mockOut.assertIsSatisfied(); }
From source file:com.github.mjeanroy.springmvc.uadetector.configuration.parsers.cache.guava.GuavaCacheParserConfiguration.java
protected UADetectorCache cache(UserAgentStringParser parser) { CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().maximumSize(getMaximumSize()) .expireAfterWrite(getTimeToLiveInSeconds(), TimeUnit.SECONDS); return new GuavaCache(builder, parser); }
From source file:tachyon.metrics.sink.MetricsServlet.java
/** * Creates a MetricsServlet with a Properties and MetricRegistry. * * @param properties the properties which may contain path property. * @param registry the metric registry to register. *///from w ww .ja v a 2s . com public MetricsServlet(Properties properties, MetricRegistry registry) { mProperties = properties; mMetricsRegistry = registry; mObjectMapper = new ObjectMapper() .registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.MILLISECONDS, false)); }