Search in sources :

Example 56 with AtomicLong

use of java.util.concurrent.atomic.AtomicLong in project RxJava by ReactiveX.

the class SingleTimerTest method timer.

@Test
public void timer() {
    final TestScheduler testScheduler = new TestScheduler();
    final AtomicLong atomicLong = new AtomicLong();
    Single.timer(2, TimeUnit.SECONDS, testScheduler).subscribe(new Consumer<Long>() {

        @Override
        public void accept(final Long value) throws Exception {
            atomicLong.incrementAndGet();
        }
    });
    assertEquals(0, atomicLong.get());
    testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    assertEquals(0, atomicLong.get());
    testScheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    assertEquals(1, atomicLong.get());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 57 with AtomicLong

use of java.util.concurrent.atomic.AtomicLong in project neo4j by neo4j.

the class CountsRotationTest method rotationShouldNotCauseUnmappedFileProblem.

@Test
public void rotationShouldNotCauseUnmappedFileProblem() throws IOException {
    // GIVEN
    GraphDatabaseAPI db = (GraphDatabaseAPI) dbBuilder.newGraphDatabase();
    DependencyResolver resolver = db.getDependencyResolver();
    RecordStorageEngine storageEngine = resolver.resolveDependency(RecordStorageEngine.class);
    CountsTracker countStore = storageEngine.testAccessNeoStores().getCounts();
    AtomicBoolean workerContinueFlag = new AtomicBoolean(true);
    AtomicLong lookupsCounter = new AtomicLong();
    int rotations = 100;
    for (int i = 0; i < 5; i++) {
        threadingRule.execute(countStoreLookup(workerContinueFlag, lookupsCounter), countStore);
    }
    long startTxId = countStore.txId();
    for (int i = 1; (i < rotations) || (lookupsCounter.get() == 0); i++) {
        try (Transaction tx = db.beginTx()) {
            db.createNode(B);
            tx.success();
        }
        checkPoint(db);
    }
    workerContinueFlag.set(false);
    assertEquals("Should perform at least 100 rotations.", rotations, Math.min(rotations, countStore.txId() - startTxId));
    assertTrue("Should perform more then 0 lookups without exceptions.", lookupsCounter.get() > 0);
    db.shutdown();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Test(org.junit.Test)

Example 58 with AtomicLong

use of java.util.concurrent.atomic.AtomicLong in project storm by nathanmarz.

the class Time method startSimulating.

public static void startSimulating() {
    simulating.set(true);
    simulatedCurrTimeMs = new AtomicLong(0);
    threadSleepTimes = new ConcurrentHashMap<Thread, AtomicLong>();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 59 with AtomicLong

use of java.util.concurrent.atomic.AtomicLong in project neo4j by neo4j.

the class PrimitiveLongCollectionsTest method shouldNotContinueToCallNextOnHasNextFalse.

@Test
public void shouldNotContinueToCallNextOnHasNextFalse() throws Exception {
    // GIVEN
    AtomicLong count = new AtomicLong(2);
    PrimitiveLongIterator iterator = new PrimitiveLongBaseIterator() {

        @Override
        protected boolean fetchNext() {
            return count.decrementAndGet() >= 0 ? next(count.get()) : false;
        }
    };
    // WHEN/THEN
    assertTrue(iterator.hasNext());
    assertTrue(iterator.hasNext());
    assertEquals(1L, iterator.next());
    assertTrue(iterator.hasNext());
    assertTrue(iterator.hasNext());
    assertEquals(0L, iterator.next());
    assertFalse(iterator.hasNext());
    assertFalse(iterator.hasNext());
    assertEquals(-1L, count.get());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) PrimitiveLongBaseIterator(org.neo4j.collection.primitive.PrimitiveLongCollections.PrimitiveLongBaseIterator) Test(org.junit.Test)

Example 60 with AtomicLong

use of java.util.concurrent.atomic.AtomicLong in project neo4j by neo4j.

the class MeasureUpdatePullingRecordAndIndexGap method shouldMeasureThatGap.

@Test
public void shouldMeasureThatGap() throws Exception {
    // GIVEN
    ManagedCluster cluster = clusterRule.startCluster();
    createIndexes(cluster.getMaster());
    cluster.sync();
    awaitIndexes(cluster);
    final AtomicBoolean halter = new AtomicBoolean();
    AtomicLong[] highIdNodes = new AtomicLong[numberOfIndexes];
    CountDownLatch endLatch = new CountDownLatch(numberOfIndexes + 1);
    for (int i = 0; i < highIdNodes.length; i++) {
        highIdNodes[i] = new AtomicLong();
    }
    startLoadOn(cluster.getMaster(), halter, highIdNodes, endLatch);
    GraphDatabaseAPI slave = cluster.getAnySlave();
    startCatchingUp(slave, halter, endLatch);
    // WHEN measuring...
    final AtomicInteger good = new AtomicInteger(), bad = new AtomicInteger(), ugly = new AtomicInteger();
    startMeasuringTheGap(good, bad, ugly, halter, highIdNodes, slave);
    for (long endTime = currentTimeMillis() + SECONDS.toMillis(30); currentTimeMillis() < endTime; ) {
        printStats(good.get(), bad.get(), ugly.get());
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    halter.set(true);
    endLatch.await();
    // THEN
    printStats(good.get(), bad.get(), ugly.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

AtomicLong (java.util.concurrent.atomic.AtomicLong)2292 Test (org.junit.Test)986 ArrayList (java.util.ArrayList)300 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)273 IOException (java.io.IOException)254 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)250 List (java.util.List)222 HashMap (java.util.HashMap)212 Map (java.util.Map)209 CountDownLatch (java.util.concurrent.CountDownLatch)185 AtomicReference (java.util.concurrent.atomic.AtomicReference)174 HashSet (java.util.HashSet)106 Arrays (java.util.Arrays)101 File (java.io.File)99 Test (org.junit.jupiter.api.Test)98 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)95 Set (java.util.Set)94 TimeUnit (java.util.concurrent.TimeUnit)91 Collections (java.util.Collections)88 Random (java.util.Random)85