public void registerCrossPlatformClassBinaryCache( String fulLQName, byte[] binary ) { try { while (cplock.compareAndSet(false, true)) { } // spin minBinNamesBytez.put(fulLQName, binary); } finally { cplock.set(false); } }
@Test public void globalResourcesWithConsumer() throws Exception { AtomicBoolean invoked = new AtomicBoolean(false); this.resourceFactory.addGlobalResourcesConsumer(httpResources -> invoked.set(true)); this.resourceFactory.afterPropertiesSet(); assertTrue(invoked.get()); this.resourceFactory.destroy(); }
@Test public void mustRetryCloseIfFailure() throws Exception { // GIVEN AtomicBoolean throwOnNext = new AtomicBoolean(); IOException exception = new IOException( "My failure" ); PageCache pageCache = pageCacheThatThrowExceptionWhenToldTo( exception, throwOnNext ); try ( GBPTree<MutableLong, MutableLong> ignored = index( pageCache ).build() ) { // WHEN throwOnNext.set( true ); } }
/** * If {@code key} is not already associated with a value or if {@code key} is associated with * zero, associate it with {@code newValue}. Returns the previous value associated with {@code * key}, or zero if there was no mapping for {@code key}. */ long putIfAbsent(K key, long newValue) { AtomicBoolean noValue = new AtomicBoolean(false); Long result = map.compute( key, (k, oldValue) -> { if (oldValue == null || oldValue == 0) { noValue.set(true); return newValue; } else { return oldValue; } }); return noValue.get() ? 0L : result.longValue(); }
if (this.active.get() && this.closed.compareAndSet(false, true)) { if (logger.isDebugEnabled()) { logger.debug("Closing " + this); this.active.set(false);
public void testDelegateRejection() { final AtomicInteger numCalls = new AtomicInteger(); final AtomicBoolean reject = new AtomicBoolean(true); final SequentialExecutor executor = new SequentialExecutor( reject.set(false); executor.execute(task); assertEquals(1, numCalls.get());
private static AtomicBoolean addPage(ClientBuffer buffer, Page page) { AtomicBoolean dereferenced = new AtomicBoolean(true); SerializedPageReference serializedPageReference = new SerializedPageReference(PAGES_SERDE.serialize(page), 1, () -> dereferenced.set(false)); buffer.enqueuePages(ImmutableList.of(serializedPageReference)); serializedPageReference.dereferencePage(); return dereferenced; }
@Test public void myTid_backgroundThread_returnsCurrentThreadId() throws Exception { AtomicBoolean ok = new AtomicBoolean(false); Thread thread = new Thread( () -> { ok.set(android.os.Process.myTid() == Thread.currentThread().getId()); }); thread.start(); thread.join(); assertThat(ok.get()).isTrue(); }
public byte[] getCrossPlatformBinaryCache(String symbolicName) { try { while ( cplock.compareAndSet(false, true)) { } // spin return minBinNamesBytez.get(symbolicName); } finally { cplock.set(false); } }
public AsyncQueue<InternalHiveSplit> queueFor(OptionalInt bucketNumber) { checkArgument(bucketNumber.isPresent()); AtomicBoolean isNew = new AtomicBoolean(); AsyncQueue<InternalHiveSplit> queue = queues.computeIfAbsent(bucketNumber.getAsInt(), ignored -> { isNew.set(true); return new AsyncQueue<>(estimatedOutstandingSplitsPerBucket, executor); }); if (isNew.get() && finished.get()) { // Check `finished` and invoke `queue.finish` after the `queue` is added to the map. // Otherwise, `queue.finish` may not be invoked if `finished` is set while the lambda above is being evaluated. queue.finish(); } return queue; } },
@Test public void testDelimitedMaxRecordSize() { doTestDelimitedMaxRecordSize(Buffer.buffer("ABCD\nEFGH\n"), Buffer.buffer("\n"), new Integer[] { 2 }, 4, null, Buffer.buffer("ABCD"), Buffer.buffer("EFGH")); doTestDelimitedMaxRecordSize(Buffer.buffer("A\nBC10\nDEFGHIJKLM\n"), Buffer.buffer("\n"), new Integer[] { 2 }, 10, null, Buffer.buffer("A"), Buffer.buffer("BC10"), Buffer.buffer("DEFGHIJKLM")); doTestDelimitedMaxRecordSize(Buffer.buffer("AB\nC\n\nDEFG\n\n"), Buffer.buffer("\n\n"), new Integer[] { 2 }, 4, null, Buffer.buffer("AB\nC"), Buffer.buffer("DEFG")); doTestDelimitedMaxRecordSize(Buffer.buffer("AB--C---D-"), Buffer.buffer("-"), new Integer[] { 3 }, 2, null, Buffer.buffer("AB"), Buffer.buffer(""), Buffer.buffer("C"), Buffer.buffer(""), Buffer.buffer(""), Buffer.buffer("D")); try { doTestDelimitedMaxRecordSize(Buffer.buffer("ABCD--"), Buffer.buffer("--"), new Integer[] { 2 }, 3, null, Buffer.buffer()); fail("should throw exception"); } catch (IllegalStateException ex) { /*OK*/ } AtomicBoolean handled = new AtomicBoolean(); Handler<Throwable> exHandler = throwable -> handled.set(true); doTestDelimitedMaxRecordSize(Buffer.buffer("ABCD--"), Buffer.buffer("--"), new Integer[] { 2 }, 3, exHandler, Buffer.buffer("ABCD")); assertTrue(handled.get()); }
/** * Wakeup an active poll. This will cause the polling thread to throw an exception either * on the current poll if one is active, or the next poll. */ public void wakeup() { // wakeup should be safe without holding the client lock since it simply delegates to // Selector's wakeup, which is thread-safe log.debug("Received user wakeup"); this.wakeup.set(true); this.client.wakeup(); }