List of usage examples for java.util.concurrent.atomic AtomicBoolean AtomicBoolean
public AtomicBoolean(boolean initialValue)
From source file:backup.integration.MiniClusterTestBase.java
@Test public void testIntegrationBasic() throws Exception { File hdfsDir = setupHdfsLocalDir(); Configuration conf = setupConfig(hdfsDir); MiniDFSCluster hdfsCluster = new MiniDFSCluster.Builder(conf).build(); Thread thread = null;//w w w . j ava2 s . co m try { DistributedFileSystem fileSystem = hdfsCluster.getFileSystem(); Path path = new Path("/testing.txt"); writeFile(fileSystem, path); Thread.sleep(TimeUnit.SECONDS.toMillis(5)); AtomicBoolean success = new AtomicBoolean(false); thread = new Thread(new Runnable() { @Override public void run() { boolean beginTest = true; while (true) { try { try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { try (FSDataInputStream inputStream = fileSystem.open(path)) { IOUtils.copy(inputStream, output); } if (beginTest) { hdfsCluster.startDataNodes(conf, 1, true, null, null); hdfsCluster.stopDataNode(0); beginTest = false; } else { LOG.info("Missing block restored."); success.set(true); return; } } } catch (IOException e) { LOG.error(e.getMessage()); } try { Thread.sleep(1000); } catch (InterruptedException e) { return; } } } }); thread.start(); thread.join(TimeUnit.MINUTES.toMillis(2)); if (!success.get()) { fail(); } } finally { if (thread != null) { thread.interrupt(); } hdfsCluster.shutdown(); destroyBackupStore(conf); } }
From source file:com.adaptris.core.fs.NonDeletingFsConsumerTest.java
public void testConsumeNotReprocessed() throws Exception { String subDir = new GuidGenerator().safeUUID(); MockMessageListener stub = new MockMessageListener(10); NonDeletingFsConsumer fs = createConsumer(subDir, "testConsume"); AtomicBoolean pollFired = new AtomicBoolean(false); fs.setPoller(/*from w ww . ja v a 2s . c o m*/ new FixedIntervalPoller(new TimeInterval(500L, TimeUnit.MILLISECONDS)).withPollerCallback(e -> { if (e == 0) { pollFired.set(true); } })); StandaloneConsumer sc = new StandaloneConsumer(fs); sc.registerAdaptrisMessageListener(stub); int count = 10; File parentDir = FsHelper .createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true)); try { File baseDir = new File(parentDir, subDir); LifecycleHelper.init(sc); createFiles(baseDir, ".xml", count); LifecycleHelper.start(sc); waitForMessages(stub, count); // The next call back should be on the next poll, when messages == 0; waitForPollCallback(pollFired); // that we don't reprocess them. assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml"))); } catch (Exception e) { log.warn(e.getMessage(), e); } finally { stop(sc); FileUtils.deleteQuietly(new File(parentDir, subDir)); } }
From source file:com.netflix.dyno.connectionpool.impl.lb.CircularListTest.java
@Test public void testMultipleThreads() throws Exception { final AtomicBoolean stop = new AtomicBoolean(false); final CyclicBarrier barrier = new CyclicBarrier(5); final List<Future<Map<Integer, Integer>>> futures = new ArrayList<Future<Map<Integer, Integer>>>(); for (int i = 0; i < 5; i++) { futures.add(threadPool.submit(new Callable<Map<Integer, Integer>>() { @Override//from w w w .j av a2 s. co m public Map<Integer, Integer> call() throws Exception { barrier.await(); TestWorker worker = new TestWorker(); while (!stop.get()) { worker.process(); } return worker.map; } })); } Thread.sleep(200); stop.set(true); Map<Integer, Integer> totalMap = getTotalMap(futures); checkValues(new ArrayList<Integer>(totalMap.values())); }
From source file:it.grid.storm.info.SpaceInfoManager.java
public int startTest(List<String> absPaths) { int result = 0; testMode = new AtomicBoolean(true); SpaceInfoManager.getInstance().fakeSAtoAnalyze(absPaths); result = SpaceInfoManager.getInstance().bDUTasks.howManyTask(); SpaceInfoManager.getInstance().submitTasks(SpaceInfoManager.getInstance().bDUTasks); return result; }
From source file:com.netflix.spinnaker.fiat.shared.FiatPermissionEvaluator.java
public UserPermission.View getPermission(String username) { UserPermission.View view = null; if (StringUtils.isEmpty(username)) { return null; }//from ww w . ja v a 2 s. c om try { AtomicBoolean cacheHit = new AtomicBoolean(true); view = permissionsCache.get(username, () -> { cacheHit.set(false); return AuthenticatedRequest.propagate(() -> fiatService.getUserPermission(username)).call(); }); log.debug("Fiat permission cache hit: " + cacheHit.get()); } catch (ExecutionException | UncheckedExecutionException ee) { String message = String.format("Cannot get whole user permission for user %s. Cause: %s", username, ee.getCause().getMessage()); if (log.isDebugEnabled()) { log.debug(message, ee.getCause()); } else { log.info(message); } } return view; }
From source file:sample.ClientConfig.java
boolean waitForCacheServerToStart(final String host, final int port, long duration) { return waitOnCondition(new Condition() { AtomicBoolean connected = new AtomicBoolean(false); public boolean evaluate() { Socket socket = null; try { // NOTE: this code is not intended to be an atomic, compound action (a // possible race condition); // opening another connection (at the expense of using system // resources) after connectivity // has already been established is not detrimental in this use case if (!connected.get()) { socket = new Socket(host, port); connected.set(true); }// w ww .j av a2s . c om } catch (IOException ignore) { } finally { GemFireUtils.close(socket); } return connected.get(); } }, duration); }
From source file:info.archinnov.achilles.it.TestNativeQueries.java
@Test public void should_iterate_regular_typed_query() throws Exception { //Given//from ww w .ja v a2s .c o m final Map<String, Object> values = new HashMap<>(); final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE); values.put("id", id); values.put("date1", "'2015-10-01 00:00:00+0000'"); values.put("date2", "'2015-10-02 00:00:00+0000'"); values.put("date3", "'2015-10-03 00:00:00+0000'"); values.put("date4", "'2015-10-04 00:00:00+0000'"); values.put("date5", "'2015-10-05 00:00:00+0000'"); values.put("date6", "'2015-10-06 00:00:00+0000'"); values.put("date7", "'2015-10-07 00:00:00+0000'"); values.put("date8", "'2015-10-08 00:00:00+0000'"); values.put("date9", "'2015-10-09 00:00:00+0000'"); scriptExecutor.executeScriptTemplate("SimpleEntity/insert_many_rows.cql", values); final SimpleStatement statement = new SimpleStatement("SELECT * FROM simple WHERE id = :id LIMIT 100"); //When final Iterator<TypedMap> iter = manager.query().nativeQuery(statement, id).iterator(); //Then final AtomicBoolean foundEntity = new AtomicBoolean(false); iter.forEachRemaining(instance -> { foundEntity.getAndSet(true); assertThat(instance).isNotNull(); assertThat(instance.<String>getTyped("value")).contains("id - date"); }); assertThat(foundEntity.get()).isTrue(); }
From source file:com.nridge.core.app.mgr.AppMgr.java
/** * Constructor suitable for use within Servlet Container where the default * paths for the application are difficult to derive automatically. * * @param aInsPathName Installation path name. * @param aCfgPathName Configuration path name. * @param aLogPathName Log file output path name. * @param aDSPathName Data source path name. *//* w w w . j a va2 s . c om*/ public AppMgr(String aInsPathName, String aCfgPathName, String aLogPathName, String aDSPathName) { mIsPathsExplicit = true; mIsAlive = new AtomicBoolean(true); mPropertyMap = new HashMap<String, Object>(); if (StringUtils.isNotEmpty(aInsPathName)) mInsPathName = aInsPathName; else mInsPathName = System.getProperty("user.dir"); if (StringUtils.isNotEmpty(aCfgPathName)) mCfgPathName = aCfgPathName; else mCfgPathName = String.format("%s%ccfg", mInsPathName, File.separatorChar); if (StringUtils.isNotEmpty(aLogPathName)) mLogPathName = aLogPathName; else mLogPathName = String.format("%s%clog", mInsPathName, File.separatorChar); if (StringUtils.isNotEmpty(aDSPathName)) mDSPathName = aDSPathName; else mDSPathName = String.format("%s%cds", mInsPathName, File.separatorChar); mRDBMSPathName = String.format("%s%crdb", mInsPathName, File.separatorChar); mGraphPathName = String.format("%s%cgdb", mInsPathName, File.separatorChar); }
From source file:com.spectralogic.ds3client.helpers.FileObjectPutter_Test.java
@Test public void testThatFileReportsAsRegularOnWindows() throws IOException, InterruptedException { Assume.assumeTrue(Platform.isWindows()); final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final String A_FILE_NAME = "aFile.txt"; final AtomicBoolean caughtException = new AtomicBoolean(false); try {/*from w ww. j a v a 2 s. c om*/ Files.createFile(Paths.get(tempDirectory.toString(), A_FILE_NAME)); new FileObjectPutter(tempDirectory).buildChannel(A_FILE_NAME); } catch (final UnrecoverableIOException e) { assertTrue(e.getMessage().contains(A_FILE_NAME)); caughtException.set(true); } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } assertFalse(caughtException.get()); }
From source file:io.restassured.examples.springmvc.controller.AutoSpringSecurityConfigurerITest.java
@Test public void doesnt_add_spring_security_configurer_automatically_when_a_spring_security_configurer_has_been_manually_applied() { final AtomicBoolean filterUsed = new AtomicBoolean(false); RestAssuredMockMvc.given().webAppContextSetup(context, springSecurity(), springSecurity(new Filter() { public void init(FilterConfig filterConfig) throws ServletException { }// ww w .jav a 2 s.c o m public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { filterUsed.set(true); chain.doFilter(request, response); } public void destroy() { } })).postProcessors(httpBasic("username", "password")).param("name", "Johan").when().get("/secured/greeting") .then().statusCode(200).body("content", equalTo("Hello, Johan!")) .expect(authenticated().withUsername("username")); assertThat(filterUsed.get(), is(true)); }