Refine search
@SuppressWarnings("unchecked") ReplaySubscriber(ReplayBuffer<T> buffer) { this.buffer = buffer; this.management = new AtomicInteger(); this.subscribers = new AtomicReference<InnerSubscription<T>[]>(EMPTY); this.shouldConnect = new AtomicBoolean(); }
@Override public void dispose() { if (stopWindows.compareAndSet(false, true)) { disposeBoundary(); if (windows.decrementAndGet() == 0) { upstream.dispose(); } } }
@Override protected void subscribeActual(Subscriber<? super T> t) { CacheSubscription<T> consumer = new CacheSubscription<T>(t, this); t.onSubscribe(consumer); add(consumer); if (!once.get() && once.compareAndSet(false, true)) { source.subscribe(this); } else { replay(consumer); } }
assertThat(metrics.numberOfIdleThreads(), is(getOptions().getInternalBlockingPoolSize())); AtomicInteger counter = new AtomicInteger(); AtomicBoolean hadWaitingQueue = new AtomicBoolean(); AtomicBoolean hadIdle = new AtomicBoolean(); AtomicBoolean hadRunning = new AtomicBoolean(); int count = num * 5; for (int i = 0; i < count; i++) { CountDownLatch latch = latches.computeIfAbsent(i / num, k -> new CountDownLatch(num)); v.executeBlockingInternal(fut -> { latch.countDown(); try { awaitLatch(latch); hadRunning.set(true); hadWaitingQueue.set(true); hadIdle.set(true); if (counter.incrementAndGet() == count) { testComplete(); assertTrue(hadIdle.get()); assertTrue(hadWaitingQueue.get()); assertTrue(hadRunning.get());
@Test(timeout = 1000) public void testUnSubscribeObservableOfObservables() throws InterruptedException { final AtomicBoolean unsubscribed = new AtomicBoolean(); final CountDownLatch latch = new CountDownLatch(1); final AtomicInteger count = new AtomicInteger(); Observable.merge(source).take(6).blockingForEach(new Consumer<Long>() { latch.await(1000, TimeUnit.MILLISECONDS); System.out.println("unsubscribed: " + unsubscribed.get()); assertTrue(unsubscribed.get());
AtomicBoolean computationShouldWait = new AtomicBoolean(); CountDownLatch computationLatch = new CountDownLatch(1); QueuingRemovalListener<String, String> listener = queuingRemovalListener(); final LoadingCache<String, String> cache = expectedKeys.add(s); computationShouldWait.set(true); final AtomicInteger computedCount = new AtomicInteger(); ExecutorService threadPool = Executors.newFixedThreadPool(nThreads); final CountDownLatch tasksFinished = new CountDownLatch(nTasks); for (int i = 0; i < nTasks; i++) { final String s = "a" + i; computationLatch.countDown(); while (computedCount.get() < nThreads) { Thread.yield();
assertTrue(serverMetric.get().socket.connected.get()); req.bodyHandler(buff -> { assertEquals(contentLength, buff.length()); HttpServerResponse resp = req.response().setChunked(true); AtomicInteger numBuffer = new AtomicInteger(numBuffers); vertx.setPeriodic(1, timerID -> { Buffer chunk = TestUtils.randomBuffer(chunkSize); if (numBuffer.decrementAndGet() == 0) { resp.end(chunk); assertNull(serverMetrics.getMetric(req)); assertTrue(clientMetric.get().socket.connected.get()); assertEquals((Integer)1, metrics.connectionCount("localhost:8080")); resp.bodyHandler(buff -> { assertNull(metrics.getMetric(resp.request())); assertEquals(contentLength, buff.length()); latch.countDown(); }); })) AsyncTestBase.assertWaitUntil(() -> metrics.endpoints().isEmpty()); assertEquals(null, metrics.connectionCount("localhost:8080")); AsyncTestBase.assertWaitUntil(() -> !serverMetric.get().socket.connected.get()); AsyncTestBase.assertWaitUntil(() -> contentLength == serverMetric.get().socket.bytesRead.get()); AsyncTestBase.assertWaitUntil(() -> contentLength == serverMetric.get().socket.bytesWritten.get()); AsyncTestBase.assertWaitUntil(() -> !clientMetric.get().socket.connected.get()); assertEquals(contentLength, clientMetric.get().socket.bytesRead.get());
final SerialDisposable task = new SerialDisposable(); try { final CountDownLatch finished = new CountDownLatch(1); final int COUNT = 30; final CountDownLatch timeHasPassed = new CountDownLatch(COUNT); final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger count = new AtomicInteger(0); final Flowable<Integer> obs = Flowable.unsafeCreate(new Publisher<Integer>() { timeHasPassed.await(8000, TimeUnit.MILLISECONDS); running.set(false); finished.await();
public SyncWithLoadTest() throws Exception { String resetDb = System.getProperty("reset.db.onFirstRun"); String overrideConfigPath = System.getProperty("override.config.res"); if (Boolean.parseBoolean(resetDb)) { resetDBOnFirstRun.setValue(true); } else if (resetDb != null && resetDb.equalsIgnoreCase("false")) { resetDBOnFirstRun.setValue(false); } if (overrideConfigPath != null) configPath.setValue(overrideConfigPath); statTimer.scheduleAtFixedRate(() -> { // Adds error if no successfully imported blocks for LAST_IMPORT_TIMEOUT long currentMillis = System.currentTimeMillis(); if (lastImport.get() != 0 && currentMillis - lastImport.get() > LAST_IMPORT_TIMEOUT) { testLogger.error("No imported block for {} seconds", LAST_IMPORT_TIMEOUT / 1000); fatalErrors.incrementAndGet(); } try { if (fatalErrors.get() > 0) { statTimer.shutdownNow(); errorLatch.countDown(); } } catch (Throwable t) { SyncWithLoadTest.testLogger.error("Unhandled exception", t); } if (lastImport.get() == 0 && isRunning.get()) lastImport.set(currentMillis); if (lastImport.get() != 0 && !isRunning.get()) lastImport.set(0); }, 0, 15, TimeUnit.SECONDS); }
private static void verifyOccupiedMethodsInAnotherThread( final Monitor monitor, boolean expectedIsOccupied, boolean expectedIsOccupiedByCurrentThread, int expectedOccupiedDepth) { final AtomicBoolean actualIsOccupied = new AtomicBoolean(); final AtomicBoolean actualIsOccupiedByCurrentThread = new AtomicBoolean(); final AtomicInteger actualOccupiedDepth = new AtomicInteger(); final AtomicReference<Throwable> thrown = new AtomicReference<>(); joinUninterruptibly( startThread( new Runnable() { @Override public void run() { try { actualIsOccupied.set(monitor.isOccupied()); actualIsOccupiedByCurrentThread.set(monitor.isOccupiedByCurrentThread()); actualOccupiedDepth.set(monitor.getOccupiedDepth()); } catch (Throwable t) { thrown.set(t); } } })); assertNull(thrown.get()); assertEquals(expectedIsOccupied, actualIsOccupied.get()); assertEquals(expectedIsOccupiedByCurrentThread, actualIsOccupiedByCurrentThread.get()); assertEquals(expectedOccupiedDepth, actualOccupiedDepth.get()); } }
if (windows.get() == 0) { queue.clear(); window = null; if (!stopWindows.get()) { if (emitted != requested.get()) { w = UnicastProcessor.create(capacityHint, this); window = w; windows.getAndIncrement(); if (boundarySubscriber.compareAndSet(null, bo)) { otherSource.subscribe(bo);
@Test(timeout = 5000) public void subscribeActionNormal() { final AtomicBoolean run = new AtomicBoolean(); normal.completable.subscribe(new Action() { @Override public void run() { run.set(true); } }); Assert.assertTrue("Not completed", run.get()); }
WindowBoundaryMainSubscriber(Subscriber<? super Flowable<T>> downstream, int capacityHint, Callable<? extends Publisher<B>> other) { this.downstream = downstream; this.capacityHint = capacityHint; this.boundarySubscriber = new AtomicReference<WindowBoundaryInnerSubscriber<T, B>>(); this.windows = new AtomicInteger(1); this.queue = new MpscLinkedQueue<Object>(); this.errors = new AtomicThrowable(); this.stopWindows = new AtomicBoolean(); this.other = other; this.requested = new AtomicLong(); }
WindowOverlapSubscriber(Subscriber<? super Flowable<T>> actual, long size, long skip, int bufferSize) { super(1); this.downstream = actual; this.size = size; this.skip = skip; this.queue = new SpscLinkedArrayQueue<UnicastProcessor<T>>(bufferSize); this.windows = new ArrayDeque<UnicastProcessor<T>>(); this.once = new AtomicBoolean(); this.firstRequest = new AtomicBoolean(); this.requested = new AtomicLong(); this.wip = new AtomicInteger(); this.bufferSize = bufferSize; }
@Override public void invokeGcOccasionally() { long currentTime = System.currentTimeMillis(); if (averagingEnabled.get()) intervals.add((int) (currentTime - lastGcTime.get())); // not sure if we want to conform autoGcWindow here... if (frequency.get() > 0) if (freqCounter.incrementAndGet() % frequency.get() == 0 && currentTime > getLastGcTime() + getAutoGcWindow()) { System.gc(); lastGcTime.set(System.currentTimeMillis()); } if (averagingEnabled.get()) if (intervals.size() > intervalTail) intervals.remove(); }
@Override public void run() { ex1.active(true); try { checkTopology(2); startLatch.countDown(); IgniteCache<Object, Object> cache1 = ex1.cache(DEFAULT_CACHE_NAME); int key = keyCnt.get(); while (!stop.get()) { if (key > 0 && (key % 500 == 0)) { U.sleep(5); System.out.println("key = " + key); } cache1.put(key, -key); key = keyCnt.incrementAndGet(); } } catch (Throwable th) { th.printStackTrace(); } doneLatch.countDown(); } });
protected void unparkIfNeeded(long size) { long acc_bytes=size > 0? accumulated_bytes.addAndGet(size) : accumulated_bytes.get(); boolean size_exceeded=acc_bytes >= transport.getMaxBundleSize() && accumulated_bytes.compareAndSet(acc_bytes, 0); boolean no_other_threads=num_threads.decrementAndGet() == 0; boolean unpark=size_exceeded || no_other_threads; // only 2 threads at a time should do this in parallel (1st cond and 2nd cond) if(unpark && unparking.compareAndSet(false, true)) { Thread thread=bundler_thread.getThread(); if(thread != null) LockSupport.unpark(thread); unparking.set(false); } }
@Override public void run() { if (sync.decrementAndGet() != 0) { while (sync.get() != 0) { } } try { Thread.sleep(1000); } catch (InterruptedException ex) { isInterrupted.set(true); } } });