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());
}
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();
}
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>();
}
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());
}
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());
}
Aggregations