public Result() { count = new AtomicInteger(); ignoreCount = new AtomicInteger(); assumptionFailureCount = new AtomicInteger(); failures = new CopyOnWriteArrayList<Failure>(); runTime = new AtomicLong(); startTime = new AtomicLong(); }
public void updatePullFromWhichNode(final MessageQueue mq, final long brokerId) { AtomicLong suggest = this.pullFromWhichNodeTable.get(mq); if (null == suggest) { this.pullFromWhichNodeTable.put(mq, new AtomicLong(brokerId)); } else { suggest.set(brokerId); } }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest && !Telemetry.isDisabled()) { HttpServletRequest httpServletRequest = (HttpServletRequest) request; String language = httpServletRequest.getHeader("Accept-Language"); if (language != null) { if (!requestsByLanguage.containsKey(language)) { requestsByLanguage.put(language, new AtomicLong(0)); } requestsByLanguage.get(language).incrementAndGet(); } } chain.doFilter(request, response); }
@Test(timeout = 2000) public void testUnsubscribeFromSynchronousInfiniteObservable() { final AtomicLong count = new AtomicLong(); INFINITE_OBSERVABLE.take(10).subscribe(new Consumer<Long>() { @Override public void accept(Long l) { count.set(l); } }); assertEquals(10, count.get()); }
@Test public void shouldRunWithDelay() throws Throwable { // Given life.start(); final AtomicLong runTime = new AtomicLong(); final CountDownLatch latch = new CountDownLatch( 1 ); long time = System.nanoTime(); scheduler.schedule( Group.INDEX_POPULATION, () -> { runTime.set( System.nanoTime() ); latch.countDown(); }, 100, TimeUnit.MILLISECONDS ); latch.await(); assertTrue( time + TimeUnit.MILLISECONDS.toNanos( 100 ) <= runTime.get() ); }
@Test public void testCreateSequential() throws KeeperException, InterruptedException { Stat stat = new Stat(); String path = zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL_WITH_TTL, stat, 100); Assert.assertEquals(0, stat.getEphemeralOwner()); final AtomicLong fakeElapsed = new AtomicLong(0); ContainerManager containerManager = newContainerManager(fakeElapsed); containerManager.checkContainers(); Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists(path, false)); fakeElapsed.set(1000); containerManager.checkContainers(); Assert.assertNull("Ttl node should have been deleted", zk.exists(path, false)); }
@Test public void postCompleteAlreadyComplete() { TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); Queue<Integer> q = new ArrayDeque<Integer>(); q.offer(1); AtomicLong state = new AtomicLong(QueueDrainHelper.COMPLETED_MASK); QueueDrainHelper.postComplete(ts, q, state, new BooleanSupplier() { @Override public boolean getAsBoolean() throws Exception { return false; } }); } }
@Test public void testOnErrorCutsAheadOfOnNext() { for (int i = 0; i < 50; i++) { final PublishProcessor<Long> processor = PublishProcessor.create(); final AtomicLong counter = new AtomicLong(); TestSubscriber<Long> ts = new TestSubscriber<Long>(new DefaultSubscriber<Long>() { while (counter.get() < 102400) { processor.onNext(counter.get()); counter.incrementAndGet();
@Test public void multipleDelaysUsingDefaultScheduler() throws InterruptedException { AtomicLong counter = new AtomicLong(); Mono.delay(Duration.ofMillis(50)).subscribe(v -> counter.incrementAndGet()); Mono.delay(Duration.ofMillis(100)).subscribe(v -> counter.incrementAndGet()); Mono.delay(Duration.ofMillis(150)).subscribe(v -> counter.incrementAndGet()); Mono.delay(Duration.ofMillis(200)).subscribe(v -> counter.incrementAndGet()); assertThat(counter.intValue()).isEqualTo(0); Thread.sleep(110); assertThat(counter.intValue()).isEqualTo(2); Thread.sleep(110); assertThat(counter.intValue()).isEqualTo(4); }
@Test public void postCompleteWithRequest() { TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); ArrayDeque<Integer> queue = new ArrayDeque<Integer>(); AtomicLong state = new AtomicLong(); BooleanSupplier isCancelled = new BooleanSupplier() { @Override public boolean getAsBoolean() throws Exception { return false; } }; ts.onSubscribe(new BooleanSubscription()); queue.offer(1); state.getAndIncrement(); QueueDrainHelper.postComplete(ts, queue, state, isCancelled); ts.assertResult(1); }
public void pushToStream(String message) { int streamNo = (int) this.nextStream.incrementAndGet() % this.queues.size(); AtomicLong offset = this.offsets.get(streamNo); BlockingQueue<FetchedDataChunk> queue = this.queues.get(streamNo); AtomicLong thisOffset = new AtomicLong(offset.incrementAndGet()); List<Message> seq = Lists.newArrayList(); seq.add(new Message(message.getBytes(Charsets.UTF_8))); ByteBufferMessageSet messageSet = new ByteBufferMessageSet(NoCompressionCodec$.MODULE$, offset, JavaConversions.asScalaBuffer(seq)); FetchedDataChunk chunk = new FetchedDataChunk(messageSet, new PartitionTopicInfo("topic", streamNo, queue, thisOffset, thisOffset, new AtomicInteger(1), "clientId"), thisOffset.get()); queue.add(chunk); }
public RFuture<Boolean> tryLockAsync(long waitTime, long leaseTime, TimeUnit unit, long threadId) { RPromise<Boolean> result = new RedissonPromise<Boolean>(); long newLeaseTime = -1; if (leaseTime != -1) { newLeaseTime = unit.toMillis(waitTime)*2; } AtomicLong time = new AtomicLong(System.currentTimeMillis()); AtomicLong remainTime = new AtomicLong(-1); if (waitTime != -1) { remainTime.set(unit.toMillis(waitTime)); } long lockWaitTime = calcLockWaitTime(remainTime.get()); AtomicInteger failedLocksLimit = new AtomicInteger(failedLocksLimit()); List<RLock> acquiredLocks = new ArrayList<RLock>(locks.size()); tryAcquireLockAsync(locks.listIterator(), acquiredLocks, result, lockWaitTime, waitTime, leaseTime, newLeaseTime, remainTime, time, failedLocksLimit, unit, threadId); return result; }
/** * Updates the value currently associated with {@code key} with the specified function, and * returns the old value. If there is not currently a value associated with {@code key}, the * function is applied to {@code 0L}. * * @since 21.0 */ @CanIgnoreReturnValue public long getAndUpdate(K key, LongUnaryOperator updaterFunction) { checkNotNull(updaterFunction); AtomicLong holder = new AtomicLong(); map.compute( key, (k, value) -> { long oldValue = (value == null) ? 0L : value.longValue(); holder.set(oldValue); return updaterFunction.applyAsLong(oldValue); }); return holder.get(); }
private void testDeliveryOptionsLocalOnly(boolean send) { waitFor(30); startNodes(2); AtomicLong localConsumer0 = new AtomicLong(); vertices[0].eventBus().localConsumer(ADDRESS1).handler(msg -> { localConsumer0.incrementAndGet(); complete(); }); AtomicLong consumer1 = new AtomicLong(); vertices[1].eventBus().consumer(ADDRESS1).handler(msg -> { consumer1.incrementAndGet(); }).completionHandler(onSuccess(v -> { for (int i = 0; i < 30; i++) { if (send) { vertices[0].eventBus().send(ADDRESS1, "msg", new DeliveryOptions().setLocalOnly(true)); } else { vertices[0].eventBus().publish(ADDRESS1, "msg", new DeliveryOptions().setLocalOnly(true)); } } })); await(); assertEquals(30, localConsumer0.get()); assertEquals(0, consumer1.get()); }
public void testForEach() { ImmutableLongArray.of().forEach(i -> fail()); ImmutableLongArray.of(0, 1, 3).subArray(1, 1).forEach(i -> fail()); AtomicLong count = new AtomicLong(0); ImmutableLongArray.of(0, 1, 2, 3) .forEach(i -> assertThat(i).isEqualTo(count.getAndIncrement())); assertEquals(4, count.get()); }
@Test(timeout = 2000) public void testUnsubscribeFromSynchronousInfiniteFlowable() { final AtomicLong count = new AtomicLong(); INFINITE_OBSERVABLE.take(10).subscribe(new Consumer<Long>() { @Override public void accept(Long l) { count.set(l); } }); assertEquals(10, count.get()); }
@Test public void test() { final AtomicLong id = new AtomicLong(); final int ITERATIONS = 51; doInJPA( this::entityManagerFactory, entityManager -> { for ( int i = 1; i <= ITERATIONS; i++ ) { ApplicationConfiguration model = new ApplicationConfiguration(); entityManager.persist( model ); id.set( model.getId() ); } } ); assertEquals( ITERATIONS, id.get() ); }
@Test public void testCreate() throws KeeperException, InterruptedException { Stat stat = new Stat(); zk.create("/foo", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL, stat, 100); Assert.assertEquals(0, stat.getEphemeralOwner()); final AtomicLong fakeElapsed = new AtomicLong(0); ContainerManager containerManager = newContainerManager(fakeElapsed); containerManager.checkContainers(); Assert.assertNotNull("Ttl node should not have been deleted yet", zk.exists("/foo", false)); fakeElapsed.set(1000); containerManager.checkContainers(); Assert.assertNull("Ttl node should have been deleted", zk.exists("/foo", false)); }
@Test public void invalidDeferredRequest() { AtomicReference<Subscription> atomicSubscription = new AtomicReference<Subscription>(); AtomicLong r = new AtomicLong(); List<Throwable> errors = TestHelper.trackPluginErrors(); try { SubscriptionHelper.deferredRequest(atomicSubscription, r, -99); TestHelper.assertError(errors, 0, IllegalArgumentException.class, "n > 0 required but it was -99"); } finally { RxJavaPlugins.reset(); } }
@Test public void customFused() { AtomicLong counter = new AtomicLong(2); StepVerifier.create( Flux.range(0, 1000) .index((i, v) -> Tuples.of("#" + (i + 1), v)) ) .expectFusion() .expectNext(Tuples.of("#1", 0)) .expectNextMatches(t -> t.getT1().equals("#" + (t.getT2() + 1))) .thenConsumeWhile(t -> t.getT1().equals("#" + (t.getT2() + 1)), it -> counter.incrementAndGet()) .expectComplete() .verify(); assertThat(counter.get()).isEqualTo(1000); }