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:io.spring.cloud.BatchEventsApplicationTests.java
@Test public void testExecution() throws Exception { SpringApplication.run(JobExecutionListenerBinding.class, "--spring.main.web-environment=false"); SpringApplication.run(BatchEventsApplication.class, "--server.port=0", "--spring.cloud.stream.bindings.output.producer.requiredGroups=testgroup"); Assert.assertTrue("The latch did not count down to zero before timeout", jobExecutionLatch.await(60, TimeUnit.SECONDS)); }
From source file:com.loopj.android.http.sample.AsyncBackgroundThreadSample.java
@Override public RequestHandle executeSample(final AsyncHttpClient client, final String URL, final Header[] headers, HttpEntity entity, final ResponseHandlerInterface responseHandler) { final Activity ctx = this; FutureTask<RequestHandle> future = new FutureTask<>(new Callable<RequestHandle>() { public RequestHandle call() { Log.d(LOG_TAG, "Executing GET request on background thread"); return client.get(ctx, URL, headers, null, responseHandler); }/* w w w. j a va2s. co m*/ }); executor.execute(future); RequestHandle handle = null; try { handle = future.get(5, TimeUnit.SECONDS); Log.d(LOG_TAG, "Background thread for GET request has finished"); } catch (Exception e) { Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show(); e.printStackTrace(); } return handle; }
From source file:com.dycody.android.idealnote.utils.GeocodeHelper.java
public static void getLocation(OnGeoUtilResultListener onGeoUtilResultListener) { SmartLocation.LocationControl bod = SmartLocation.with(IdealNote.getAppContext()) .location(GeoCodeProviderFactory.getProvider(IdealNote.getAppContext())) .config(LocationParams.NAVIGATION).oneFix(); Observable<Location> locations = ObservableFactory.from(bod).timeout(2, TimeUnit.SECONDS); locations.subscribe(new Subscriber<Location>() { @Override/*from ww w.j a va2s. c o m*/ public void onNext(Location location) { onGeoUtilResultListener.onLocationRetrieved(location); unsubscribe(); } @Override public void onCompleted() { } @Override public void onError(Throwable e) { onGeoUtilResultListener.onLocationUnavailable(); unsubscribe(); } }); }
From source file:org.trustedanalytics.routermetrics.GatherMetricsIT.java
@Test public void appGatherDataEvery2Seconds_wait5Seconds_dataShouldBeDownloaded2to3times() throws InterruptedException { TimeUnit.SECONDS.sleep(5); assertThat(GorouterMock.firstGorouterCallCount, greaterThanOrEqualTo(2)); assertThat(GorouterMock.firstGorouterCallCount, lessThanOrEqualTo(3)); assertThat(GorouterMock.secondGorouterCallCount, greaterThanOrEqualTo(2)); assertThat(GorouterMock.secondGorouterCallCount, lessThanOrEqualTo(3)); verify(loadStore, invokedBetween(2, 3)).save(0.25); }
From source file:gobblin.source.extractor.extract.google.GoogleAnalyticsUnsampledExtractorTest.java
public void testPollForCompletion() throws IOException { wuState = new WorkUnitState(); wuState.setProp(POLL_RETRY_PREFIX + RETRY_TIME_OUT_MS, TimeUnit.SECONDS.toMillis(30L)); wuState.setProp(POLL_RETRY_PREFIX + RETRY_INTERVAL_MS, 1L); GoogleAnalyticsUnsampledExtractor extractor = setup(ReportCreationStatus.COMPLETED, wuState, false); UnsampledReport requestedReport = new UnsampledReport().setAccountId("testAccountId") .setWebPropertyId("testWebPropertyId").setProfileId("testProfileId").setId("testId"); String actualFileId = extractor.pollForCompletion(wuState, gaService, requestedReport) .getDriveDownloadDetails().getDocumentId(); Assert.assertEquals(actualFileId, EXPECTED_FILE_ID); verify(getReq, atLeast(5)).execute(); }
From source file:io.bitsquare.common.util.Utilities.java
public static ThreadPoolExecutor getThreadPoolExecutor(String name, int corePoolSize, int maximumPoolSize, long keepAliveTimeInSec) { final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(name).setDaemon(true).build(); ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTimeInSec, TimeUnit.SECONDS, new ArrayBlockingQueue<>(maximumPoolSize), threadFactory); executor.allowCoreThreadTimeOut(true); executor.setRejectedExecutionHandler((r, e) -> { log.debug("RejectedExecutionHandler called"); });//from w w w. j a va 2s. com return executor; }
From source file:io.github.bonigarcia.wdm.PhantomJsDriverManager.java
@Override public List<URL> getDrivers() throws Exception { String phantomjsDriverUrl = WdmConfig.getString("wdm.phantomjsDriverUrl"); log.debug("Reading {} to find out the latest version of PhantomJS driver", phantomjsDriverUrl); // Switch off HtmlUnit logging LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog"); java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF); java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF); // Using HtmlUnitDriver to read package URL WebDriver driver = new HtmlUnitDriver(); driver.manage().timeouts().implicitlyWait(WdmConfig.getInt("wdm.timeout"), TimeUnit.SECONDS); driver.get(phantomjsDriverUrl);//from ww w . j a va 2 s . c om WebElement downloadsTable = driver.findElement(By.id("available-downloads")); List<WebElement> links = downloadsTable.findElements(By .xpath("//table[@id='uploaded-files']/tbody/tr[@class='iterable-item']/td[@class='name']" + "/a")); List<URL> urlList = new ArrayList<>(links.size()); for (WebElement element : links) { String href = element.getAttribute("href"); urlList.add(new URL(href)); } return urlList; }
From source file:se.omegapoint.facepalm.infrastructure.FilePolicyRepository.java
@Override public Optional<Policy> retrievePolicyWith(final String filename) { notBlank(filename);//from w w w . j a v a 2 s . co m final ExecutorService executorService = Executors.newSingleThreadExecutor(); final Command command = commandBasedOnOperatingSystem(filename); final Future<String> future = executorService.submit(command); try { eventService.publish(new GenericEvent(format("About to execute command[%s]", command.command))); return Optional.of(new Policy(future.get(TIMEOUT, TimeUnit.SECONDS))); } catch (Exception e) { return Optional.empty(); } }
From source file:com.example.FirestoreSampleAppTests.java
@Test public void testSample() { String expectedString = "read: {name=Ada, phones=[123, 456]}\n" + "read: User{name='Joe', phones=[Phone{number=12345, type=CELL}, Phone{number=54321, type=WORK}]}\n" + "removing: ada\n" + "removing: joe"; Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> baos.toString().contains(expectedString)); }
From source file:org.trustedanalytics.modelcatalog.ApplicationConfiguration.java
@Bean public LoadingCache<H2oInstanceCredentials, H2oInstance> getH2oInstanceCache() { return CacheBuilder.newBuilder().maximumSize(maximumCacheSize) .expireAfterWrite(cacheExpirationTimeS, TimeUnit.SECONDS) .build(new H2oInstanceCacheLoader(clientSupplier())); }