List of usage examples for java.util.concurrent TimeUnit MILLISECONDS
TimeUnit MILLISECONDS
To view the source code for java.util.concurrent TimeUnit MILLISECONDS.
Click Source Link
From source file:com.github.lburgazzoli.quickfixj.transport.FIXSessionHelper.java
/** * *//*from w w w . j av a2 s.c o m*/ public void startSessionTimer() { if (m_taskFuture == null) { m_taskFuture = getContext().getScheduler().scheduleAtFixedRate(m_task, 0, 1000L, TimeUnit.MILLISECONDS); LOGGER.info("SessionTimer started"); } }
From source file:org.sonatype.nexus.apachehttpclient.EvictingThreadTest.java
/** * Verify that eviction thread will continue to run even if calls on ClientConnectionManager fails. * * @throws Exception unexpected/*from ww w . ja v a 2 s . c om*/ */ @Test public void evictionContinuesWhenConnectionManagerFails() throws Exception { final HttpClientConnectionManager clientConnectionManager = mock(HttpClientConnectionManager.class); doThrow(new RuntimeException("closeExpiredConnections")).when(clientConnectionManager) .closeExpiredConnections(); doThrow(new RuntimeException("closeIdleConnections")).when(clientConnectionManager) .closeIdleConnections(1000, TimeUnit.MILLISECONDS); final EvictingThread underTest = new EvictingThread(clientConnectionManager, 1000, 100); underTest.start(); Thread.sleep(300); verify(clientConnectionManager, atLeast(2)).closeExpiredConnections(); verify(clientConnectionManager, atLeast(2)).closeIdleConnections(1000, TimeUnit.MILLISECONDS); underTest.interrupt(); }
From source file:com.github.restdriver.clientdriver.integration.VerifyWithinTest.java
@Test public void verifyingSingleRequestWithinATimePeriodWorks() throws Exception { clientDriver.addExpectation(onRequestTo("/foo"), giveEmptyResponse().within(2000, TimeUnit.MILLISECONDS)); Thread thread = new Thread(new Runnable() { @Override/*from w ww .ja v a 2s.com*/ public void run() { schnooze(500, TimeUnit.MILLISECONDS); hitThat(clientDriver.getBaseUrl() + "/foo"); } }); thread.setDaemon(true); thread.start(); clientDriver.verify(); }
From source file:com.github.seleniumpm.Selenium10.java
public Selenium waitForPresent(Object locator, long waitTime) throws NotFoundException { long currentTime = System.nanoTime(); long endTime = currentTime + TimeUnit.MILLISECONDS.toNanos(elementWaitTime); while (currentTime <= endTime) { if (isPresent(locator)) return this; try {//from w ww . ja va 2s . c om Thread.sleep(sleepTimeInMilis); } catch (InterruptedException ie) { throw new NotFoundException("An InterruptedException occured!"); } currentTime = System.nanoTime(); } throw new NotFoundException(locator + "was not found in " + elementWaitTime + "ms!"); }
From source file:com.watchrabbit.scanner.supervisor.service.AttackerServiceImpl.java
@Override public AttackResult performAttack(String originalAdress, RemoteWebDriver driver, AttackData data) { data.getForm().getFields().stream().filter(field -> field.getField().isDisplayed()) .filter(field -> field.getField().isEnabled()).forEach(this::fill); data.getFields().forEach(this::fillAttacked); Stopwatch stopwatch = Stopwatch.createStarted(() -> { data.getForm().getSendButton().submit(); loaderService.waitFor(driver);/* w ww .java 2 s . c om*/ }); Vulnerability vulnerability = data.getVerificationStrategy().verify(driver, stopwatch.getExecutionTime(TimeUnit.MILLISECONDS)); boolean sent = isFormSent(originalAdress, driver.getCurrentUrl()); return new AttackResult.Builder().withAttackData(data).withResultAddress(driver.getCurrentUrl()) .withVulnerability(vulnerability).withFormSent(sent).build(); }
From source file:net.sf.jasperreports.phantomjs.ProcessOutputReader.java
public boolean waitConfirmation(int processStartTimeout) { try {/*www . ja v a 2s . c o m*/ boolean done = startLatch.await(processStartTimeout, TimeUnit.MILLISECONDS); if (log.isDebugEnabled()) { log.debug(processId + " done " + done + ", confirmed " + confirmed); } return confirmed; } catch (InterruptedException e) { throw new JRRuntimeException(e); } }
From source file:com.crossbusiness.resiliency.aspect.AnnotationTimeoutAspectTest.java
@Test public void method_that_takes_1000ms_and_annotated_with_timeout_of_2000ms_will_succeed() throws InterruptedException { doAnswer(new Answer<Object>() { public Object answer(InvocationOnMock invocation) throws InterruptedException { Object[] args = invocation.getArguments(); TimeUnit.MILLISECONDS.sleep(1000); return args[0] + " back"; }//from w ww . j a v a2 s. co m }).when(delegateMock).mockedMethod(anyString()); String result = testService.timeout_2000ms("testArg"); assertEquals("testArg back", result); verify(delegateMock).mockedMethod("testArg"); verifyZeroInteractions(delegateMock); }
From source file:org.ventiv.docker.manager.metrics.store.InfluxDbAdditionalMetricsStore.java
@Override public List<AdditionalMetricsStorage> getAdditionalMetricsBetween(ServiceInstance serviceInstance, Long startTime, Long endTime) { StringBuilder queryStr = new StringBuilder("select * from ").append(serviceInstance.getName()) .append(" where "); if (startTime != null) queryStr.append("time > ").append(startTime).append("ms AND"); if (endTime != null) queryStr.append("time < ").append(endTime).append("ms AND"); queryStr.append("tierName = '").append(serviceInstance.getTierName()).append("' ") .append("AND environmentName = '").append(serviceInstance.getEnvironmentName()).append("' ") .append("AND applicationId = '").append(serviceInstance.getApplicationId()).append("' ") .append("AND \"name\" = '").append(serviceInstance.getName()).append("' ") .append("AND instanceNumber = '").append(serviceInstance.getInstanceNumber()).append("' "); Query q = new Query(queryStr.toString(), template.getDatabase()); QueryResult result = template.query(q, TimeUnit.MILLISECONDS); Map<Date, AdditionalMetricsStorage> additionalMetrics = new HashMap<>(); for (QueryResult.Result queryResult : result.getResults()) { for (QueryResult.Series series : queryResult.getSeries()) { for (List<Object> values : series.getValues()) { Date time = new Date(((Number) values.get(0)).longValue()); for (int i = 1; i < values.size(); i++) { Object value = values.get(i); if (value instanceof Double) { AdditionalMetricsStorage additionalMetric = additionalMetrics.get(time); String additionalMetricName = series.getColumns().get(i); if (additionalMetric == null) { additionalMetric = new AdditionalMetricsStorage(); additionalMetric.setId(time.getTime()); additionalMetric.setTimestamp(time.getTime()); additionalMetric.setAdditionalMetrics(new HashMap<String, BigDecimal>()); additionalMetrics.put(time, additionalMetric); }//from w ww .j a v a2s. c om additionalMetric.getAdditionalMetrics().put(additionalMetricName, new BigDecimal((Double) value)); } } } } } return new ArrayList<>(additionalMetrics.values()); }
From source file:org.jetbrains.webdemo.authorization.AuthorizationFacebookHelper.java
@Override @Nullable/*from w w w .j a v a 2s .co m*/ public UserInfo verify(String oauthVerifier) { UserInfo userInfo = null; try { Verifier verifier = new Verifier(oauthVerifier); Token accessToken = facebookService.getAccessToken(EMPTY_TOKEN, verifier); OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); request.setConnectTimeout(TIMEOUT, TimeUnit.MILLISECONDS); facebookService.signRequest(accessToken, request); Response response = request.send(); JsonNode object = new ObjectMapper().readTree(response.getBody()); userInfo = new UserInfo(); userInfo.login(object.get("name").textValue(), object.get("id").asText(), TYPE); } catch (Throwable e) { ErrorWriter.ERROR_WRITER.writeExceptionToExceptionAnalyzer(e, SessionInfo.TypeOfRequest.AUTHORIZATION.name(), "unknown", "facebook: " + oauthVerifier); } return userInfo; }