List of usage examples for java.util.concurrent.atomic AtomicBoolean AtomicBoolean
public AtomicBoolean()
From source file:io.vertx.config.git.GitConfigStoreTest.java
@After public void tearDown() { AtomicBoolean done = new AtomicBoolean(); if (retriever != null) { retriever.close();// www . ja va2s . c o m } if (git != null) { git.close(); } if (bare != null) { bare.close(); } vertx.close(v -> done.set(true)); await().untilAtomic(done, is(true)); }
From source file:com.collaborne.jsonschema.generator.pojo.PojoGeneratorTest.java
@Test public void generateInternalExistingTypeReturnsExistingTypeWithoutGeneration() throws CodeGenerationException, IOException { JsonNode schemaNode = jsonNodeReader.fromReader(new StringReader("{\"type\": \"string\"}")); SchemaTree schema = schemaLoader.load(schemaNode); Mapping mapping = new Mapping(URI.create("http://example.com/type.json#"), ClassName.create(TestClass.class)); final AtomicBoolean writeSourceCalled = new AtomicBoolean(); PojoGenerator generator = new PojoGenerator(null, null, null) { @Override//from w ww.ja v a2 s . co m protected void writeSource(URI type, ClassName className, Buffer buffer) throws IOException { writeSourceCalled.set(true); } }; ClassName className = generator.generateInternal(mapping.getTarget(), schema, mapping); assertEquals(mapping.getClassName(), className); assertFalse(writeSourceCalled.get()); }
From source file:ch.cyberduck.core.pool.DefaultSessionPoolTest.java
@Test public void testCheckReconnectSocketFailure() throws Exception { final AtomicBoolean interrupt = new AtomicBoolean(); final Host bookmark = new Host(new TestProtocol()); final TestLoginConnectionService connect = new TestLoginConnectionService() { @Override/*w w w.j a v a2 s . c o m*/ public boolean check(final Session<?> session, final Cache<Path> cache, final CancelCallback callback) throws BackgroundException { return true; } }; final DefaultSessionPool pool = new DefaultSessionPool(connect, new DefaultVaultRegistry(new DisabledPasswordCallback()), PathCache.empty(), new DisabledTranscriptListener(), bookmark, new GenericObjectPool<Session>(new PooledSessionFactory(connect, new DisabledX509TrustManager(), new DefaultX509KeyManager(), PathCache.empty(), bookmark, new DefaultVaultRegistry(new DisabledPasswordCallback())) { @Override public Session create() { return new NullSession(bookmark) { @Override public void interrupt() throws BackgroundException { interrupt.set(true); super.interrupt(); } }; } })); final Session<?> session = pool.borrow(BackgroundActionState.running); pool.release(session, new BackgroundException("m", new SocketException("m"))); assertTrue(interrupt.get()); }
From source file:ch.cyberduck.core.worker.SingleTransferWorkerTest.java
@Test public void testTransferredSizeRepeat() throws Exception { final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); final byte[] content = new byte[62768]; new Random().nextBytes(content); final OutputStream out = local.getOutputStream(false); IOUtils.write(content, out);// www .j ava 2 s. c o m out.close(); final Host host = new Host(new DAVProtocol(), "test.cyberduck.ch", new Credentials(System.getProperties().getProperty("webdav.user"), System.getProperties().getProperty("webdav.password"))); host.setDefaultPath("/dav/basic"); final AtomicBoolean failed = new AtomicBoolean(); final DAVSession session = new DAVSession(host) { final DAVUploadFeature upload = new DAVUploadFeature(new DAVWriteFeature(this)) { @Override protected InputStream decorate(final InputStream in, final MessageDigest digest) throws IOException { if (failed.get()) { // Second attempt successful return in; } return new CountingInputStream(in) { @Override protected void beforeRead(final int n) throws IOException { super.beforeRead(n); if (this.getByteCount() >= 32768L) { failed.set(true); throw new SocketTimeoutException(); } } }; } }; @Override @SuppressWarnings("unchecked") public <T> T _getFeature(final Class<T> type) { if (type == Upload.class) { return (T) upload; } return super._getFeature(type); } }; session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Path test = new Path(new DefaultHomeFinderService(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final Transfer t = new UploadTransfer(new Host(new TestProtocol()), test, local); final BytecountStreamListener counter = new BytecountStreamListener(new DisabledStreamListener()); assertTrue(new SingleTransferWorker(session, session, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() { @Override public TransferAction prompt(final TransferItem file) { return TransferAction.overwrite; } }, new DisabledTransferErrorCallback(), new DisabledProgressListener(), counter, new DisabledLoginCallback(), new DisabledPasswordCallback(), TransferItemCache.empty()) { }.run(session, session)); local.delete(); assertEquals(62768L, counter.getSent(), 0L); assertEquals(62768L, new DAVAttributesFinderFeature(session).find(test).getSize()); assertTrue(failed.get()); new DAVDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
From source file:com.microsoft.tfs.core.clients.versioncontrol.engines.internal.BaselineFileDownloadOutput.java
/** * {@inheritDoc}//from w ww .jav a 2 s. c o m */ @Override public synchronized OutputStream getOutputStream() throws IOException { if (outputStream == null) { final String contentType = getActualContentType(); Check.notNull(contentType, "Cannot open output stream until actual content type is set"); //$NON-NLS-1$ String path = baselineFileNoSuffix.getAbsolutePath(); if (contentType.equals(DownloadContentTypes.APPLICATION_GZIP)) { path = path + BaselineFolder.getGzipExtension(); } else if (contentType.equals(DownloadContentTypes.APPLICATION_OCTET_STREAM)) { path = path + BaselineFolder.getRawExtension(); } else { throw new VersionControlException(MessageFormat.format( Messages.getString("VersionControlClient.UnsupportedContentTypeFormat"), //$NON-NLS-1$ contentType)); } final AtomicBoolean tempCreated = new AtomicBoolean(); final AtomicReference<String> pathReference = new AtomicReference<String>(path); outputStream = BaselineFolderCollection.createFile(pathReference, true, null /* ignored */, tempCreated); path = pathReference.get(); outputStreamFile = new File(path); tempFileCreatedInsteadOfBaseline = tempCreated.get(); } return outputStream; }
From source file:io.vertx.config.vault.utils.VaultProcess.java
private void startServer() { String line = executable.getAbsolutePath() + " server -config=src/test/resources/config.json"; System.out.println(">> " + line); CommandLine parse = CommandLine.parse(line); DefaultExecutor executor = new DefaultExecutor(); DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); AtomicBoolean ready = new AtomicBoolean(); PumpStreamHandler pump = new PumpStreamHandler(new VaultOutputStream().addExtractor(l -> { if (l.contains("Vault server started!")) { ready.set(true);//ww w. jav a 2 s . c o m } }), System.err); watchDog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); executor.setWatchdog(watchDog); executor.setStreamHandler(pump); try { executor.execute(parse, resultHandler); } catch (IOException e) { throw new RuntimeException(e); } await().untilAtomic(ready, is(true)); System.out.println("Vault Server ready - but not yet initialized"); }
From source file:com.marklogic.contentpump.LocalJobRunner.java
public LocalJobRunner(Job job, CommandLine cmdline, Command cmd) { this.job = job; this.cmd = cmd; threadCount = DEFAULT_THREAD_COUNT;/* w w w . ja v a 2 s . c o m*/ if (cmdline.hasOption(THREAD_COUNT)) { threadCount = Integer.parseInt(cmdline.getOptionValue(THREAD_COUNT)); } if (threadCount > 1) { pool = Executors.newFixedThreadPool(threadCount); if (LOG.isDebugEnabled()) { LOG.debug("Thread pool size: " + threadCount); } } if (cmdline.hasOption(THREADS_PER_SPLIT)) { threadsPerSplit = Integer.parseInt(cmdline.getOptionValue(THREADS_PER_SPLIT)); } Configuration conf = job.getConfiguration(); minThreads = conf.getInt(CONF_MIN_THREADS, minThreads); jobComplete = new AtomicBoolean(); startTime = System.currentTimeMillis(); }
From source file:ch.cyberduck.core.sftp.auth.SFTPPublicKeyAuthenticationTest.java
@Test(expected = LoginFailureException.class) public void testAuthenticatePuTTYKeyWithWrongPassword() throws Exception { final Credentials credentials = new Credentials(System.getProperties().getProperty("sftp.user"), ""); final Local key = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); try {/*from w w w . j av a 2 s. co m*/ credentials.setIdentity(key); new DefaultLocalTouchFeature().touch(key); IOUtils.copy(new StringReader(System.getProperties().getProperty("sftp.key.putty")), key.getOutputStream(false), Charset.forName("UTF-8")); final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch", credentials); final SFTPSession session = new SFTPSession(host); session.open(new DisabledHostKeyCallback()); final AtomicBoolean p = new AtomicBoolean(); assertFalse(new SFTPPublicKeyAuthentication(session).authenticate(host, new DisabledPasswordStore(), new DisabledLoginCallback() { @Override public Credentials prompt(final Host bookmark, String username, String title, String reason, LoginOptions options) throws LoginCanceledException { p.set(true); throw new LoginCanceledException(); } }, new DisabledCancelCallback())); assertTrue(p.get()); session.close(); } finally { key.delete(); } }
From source file:io.cettia.DefaultServer.java
private DefaultServerSocket createSocket(ServerTransport transport) { Map<String, String> options = new LinkedHashMap<>(); options.put("heartbeat", Integer.toString(heartbeat)); options.put("_heartbeat", Integer.toString(_heartbeat)); final DefaultServerSocket socket = new DefaultServerSocket(options); // socket.uri should be available on socket event #4 socket.transport = transport;/*from w w w .jav a 2 s .c om*/ // A temporal implementation of 'once' final AtomicBoolean done = new AtomicBoolean(); socket.onopen(new VoidAction() { @Override public void on() { if (!done.getAndSet(true)) { sockets.put(socket.id, socket); socket.ondelete(new VoidAction() { @Override public void on() { sockets.remove(socket.id); } }); } } }); return socket; }
From source file:ch.cyberduck.core.http.DelayedHttpMultipartEntity.java
public void writeTo(final OutputStream out) throws IOException { try {//from www .j ava 2 s.com stream = new OutputStream() { private final AtomicBoolean close = new AtomicBoolean(); @Override public void write(final byte[] b, final int off, final int len) throws IOException { out.write(b, off, len); } @Override public void write(final int b) throws IOException { out.write(b); } @Override public void write(final byte[] b) throws IOException { out.write(b); } @Override public void close() throws IOException { if (close.get()) { log.warn(String.format("Skip double close of stream %s", this)); return; } try { out.write(footer); super.close(); } finally { // Signal finished writing to stream exit.countDown(); close.set(true); } } }; stream.write(header); } finally { final CountDownLatch entry = this.getEntry(); // Signal stream is ready for writing entry.countDown(); } // Wait for signal when content has been written to the pipe try { exit.await(); } catch (InterruptedException e) { log.error(String.format("Error waiting for exit signal %s", e.getMessage())); throw new IOException(e); } // Entity written to server consumed = true; }