use of java.util.concurrent.atomic.AtomicLong in project neo4j by neo4j.
the class ConfigurableIOLimiterTest method createIOLimiter.
private void createIOLimiter(Config config) {
pauseNanosCounter = new AtomicLong();
ObjLongConsumer<Object> pauseNanos = (blocker, nanos) -> pauseNanosCounter.getAndAdd(nanos);
limiter = new ConfigurableIOLimiter(config, pauseNanos);
}
use of java.util.concurrent.atomic.AtomicLong in project neo4j by neo4j.
the class KernelTransactionImplementationTest method shouldCallCloseListenerOnCloseWhenCommitting.
@Test
public void shouldCallCloseListenerOnCloseWhenCommitting() throws Exception {
// given
AtomicLong closeTxId = new AtomicLong(Long.MIN_VALUE);
KernelTransactionImplementation tx = newTransaction(securityContext());
tx.registerCloseListener(closeTxId::set);
// when
if (isWriteTx) {
tx.upgradeToDataWrites();
tx.txState().nodeDoCreate(42L);
}
tx.success();
tx.close();
// then
assertThat(closeTxId.get(), isWriteTx ? greaterThan(BASE_TX_ID) : equalTo(0L));
}
use of java.util.concurrent.atomic.AtomicLong in project neo4j by neo4j.
the class LegacyBatchIndexApplierTest method shouldOrderTransactionsMakingLegacyIndexChanges.
@Test
public void shouldOrderTransactionsMakingLegacyIndexChanges() throws Throwable {
// GIVEN
Map<String, Integer> names = MapUtil.genericMap("first", 0, "second", 1);
Map<String, Integer> keys = MapUtil.genericMap("key", 0);
String applierName = "test-applier";
LegacyIndexApplierLookup applierLookup = mock(LegacyIndexApplierLookup.class);
when(applierLookup.newApplier(anyString(), anyBoolean())).thenReturn(mock(TransactionApplier.class));
IndexConfigStore config = newIndexConfigStore(names, applierName);
// WHEN multiple legacy index transactions are running, they should be done in order
SynchronizedArrayIdOrderingQueue queue = new SynchronizedArrayIdOrderingQueue(10);
final AtomicLong lastAppliedTxId = new AtomicLong(-1);
Race race = new Race();
for (long i = 0; i < 100; i++) {
final long txId = i;
race.addContestant(() -> {
try (LegacyBatchIndexApplier applier = new LegacyBatchIndexApplier(config, applierLookup, queue, INTERNAL)) {
TransactionToApply txToApply = new TransactionToApply(new PhysicalTransactionRepresentation(new ArrayList<>()));
FakeCommitment commitment = new FakeCommitment(txId, mock(TransactionIdStore.class));
commitment.setHasLegacyIndexChanges(true);
txToApply.commitment(commitment, txId);
TransactionApplier txApplier = applier.startTx(txToApply);
// Make sure threads are unordered
Thread.sleep(ThreadLocalRandom.current().nextInt(5));
// THEN
assertTrue(lastAppliedTxId.compareAndSet(txId - 1, txId));
// Closing manually instead of using try-with-resources since we have no additional work to do in
// txApplier
txApplier.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
queue.offer(txId);
}
race.go();
}
use of java.util.concurrent.atomic.AtomicLong in project neo4j by neo4j.
the class Neo4jJobSchedulerTest method shouldRunWithDelay.
@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(new JobScheduler.Group("group", POOLED), new Runnable() {
@Override
public void run() {
runTime.set(System.nanoTime());
latch.countDown();
}
}, 100, TimeUnit.MILLISECONDS);
latch.await();
assertTrue(time + TimeUnit.MILLISECONDS.toNanos(100) <= runTime.get());
}
use of java.util.concurrent.atomic.AtomicLong in project neo4j by neo4j.
the class ArrayQueueOutOfOrderSequenceTest method shouldKeepItsCoolWhenMultipleThreadsAreHammeringIt.
@Test
public void shouldKeepItsCoolWhenMultipleThreadsAreHammeringIt() throws Exception {
// An interesting note is that during tests the call to sequence#offer made no difference
// in performance, so there seems to be no visible penalty in using ArrayQueueOutOfOrderSequence.
// GIVEN a sequence with intentionally low starting queue size
final AtomicLong numberSource = new AtomicLong();
final OutOfOrderSequence sequence = new ArrayQueueOutOfOrderSequence(numberSource.get(), 5, new long[1]);
final AtomicBoolean end = new AtomicBoolean();
// and a bunch of threads that will start offering numbers at the same time
final CountDownLatch startSignal = new CountDownLatch(1);
Thread[] threads = new Thread[1];
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread() {
@Override
public void run() {
await(startSignal);
while (!end.get()) {
long number = numberSource.incrementAndGet();
offer(sequence, number, new long[] { number + 2 });
}
}
};
}
// WHEN
for (Thread thread : threads) {
thread.start();
}
startSignal.countDown();
while (numberSource.get() < 10_000_000) {
sleep(1);
yield();
}
end.set(true);
for (Thread thread : threads) {
thread.join();
}
// THEN
long lastNumber = numberSource.get();
assertGet(sequence, lastNumber, new long[] { lastNumber + 2 });
}
Aggregations