use of org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue in project neo4j by neo4j.
the class RecordStorageEngineRule method get.
private RecordStorageEngine get(FileSystemAbstraction fs, PageCache pageCache, SchemaIndexProvider schemaIndexProvider, DatabaseHealth databaseHealth, File storeDirectory, Function<BatchTransactionApplierFacade, BatchTransactionApplierFacade> transactionApplierTransformer) {
if (!fs.fileExists(storeDirectory) && !fs.mkdir(storeDirectory)) {
throw new IllegalStateException();
}
IdGeneratorFactory idGeneratorFactory = new EphemeralIdGenerator.Factory();
LabelScanStoreProvider labelScanStoreProvider = nativeLabelScanStoreProvider(storeDirectory, fs, pageCache);
LegacyIndexProviderLookup legacyIndexProviderLookup = mock(LegacyIndexProviderLookup.class);
when(legacyIndexProviderLookup.all()).thenReturn(Iterables.empty());
IndexConfigStore indexConfigStore = new IndexConfigStore(storeDirectory, fs);
JobScheduler scheduler = life.add(new Neo4jJobScheduler());
Config config = Config.defaults();
Supplier<KernelTransactionsSnapshot> txSnapshotSupplier = () -> new KernelTransactionsSnapshot(Collections.emptySet(), 0);
return life.add(new ExtendedRecordStorageEngine(storeDirectory, config, idGeneratorFactory, IdReuseEligibility.ALWAYS, new CommunityIdTypeConfigurationProvider(), pageCache, fs, NullLogProvider.getInstance(), mock(PropertyKeyTokenHolder.class), mock(LabelTokenHolder.class), mock(RelationshipTypeTokenHolder.class), () -> {
}, new StandardConstraintSemantics(), scheduler, mock(TokenNameLookup.class), new ReentrantLockService(), schemaIndexProvider, IndexingService.NO_MONITOR, databaseHealth, labelScanStoreProvider, legacyIndexProviderLookup, indexConfigStore, new SynchronizedArrayIdOrderingQueue(20), txSnapshotSupplier, transactionApplierTransformer));
}
use of org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue in project neo4j by neo4j.
the class SynchronizedArrayIdOrderingQueueStressTest method shouldWithstandHighStressAndStillKeepOrder.
@Test
public void shouldWithstandHighStressAndStillKeepOrder() throws Exception {
// GIVEN an ordering queue w/ low initial size as to also exercise resize under stress
VerifyingIdOrderingQueue queue = new VerifyingIdOrderingQueue(new SynchronizedArrayIdOrderingQueue(5));
Committer[] committers = new Committer[20];
CountDownLatch readySignal = new CountDownLatch(committers.length);
AtomicLong endTime = new AtomicLong();
CountDownLatch startSignal = new CountDownLatch(1);
PrimitiveLongIterator idSource = neverEndingIdStream();
for (int i = 0; i < committers.length; i++) {
committers[i] = new Committer(queue, idSource, endTime, readySignal, startSignal);
}
// WHEN GO!
readySignal.await();
endTime.set(currentTimeMillis() + SECONDS.toMillis(3));
startSignal.countDown();
for (Committer committer : committers) {
committer.awaitFinish();
}
// THEN there should have been at least a few ids processed. The order of those
// are verified as they go, by the VerifyingIdOrderingQueue
assertTrue("Would have wanted at least a few ids to be processed, but only saw " + queue.getNumberOfOrderlyRemovedIds(), queue.getNumberOfOrderlyRemovedIds() > 50);
}
use of org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue in project neo4j by neo4j.
the class SynchronizedArrayIdOrderingQueueTest method shouldOfferAwaitAndRemoveRoundAndRound.
@Test
public void shouldOfferAwaitAndRemoveRoundAndRound() throws Exception {
// GIVEN
IdOrderingQueue queue = new SynchronizedArrayIdOrderingQueue(5);
long offeredId = 0, awaitedId = 0;
queue.offer(offeredId++);
queue.offer(offeredId++);
// WHEN
for (int i = 0; i < 20; i++) {
queue.waitFor(awaitedId);
queue.removeChecked(awaitedId++);
queue.offer(offeredId++);
assertFalse(queue.isEmpty());
}
// THEN
queue.removeChecked(awaitedId++);
queue.removeChecked(awaitedId++);
assertTrue(queue.isEmpty());
}
use of org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue in project neo4j by neo4j.
the class SynchronizedArrayIdOrderingQueueTest method shouldExtendArrayWhenIdsAreWrappingAround.
@Test
public void shouldExtendArrayWhenIdsAreWrappingAround() throws Exception {
// GIVEN
IdOrderingQueue queue = new SynchronizedArrayIdOrderingQueue(5);
for (int i = 0; i < 3; i++) {
queue.offer(i);
queue.removeChecked(i);
}
// ^-- headIndex and offerIndex
for (int i = 3; i < 8; i++) {
queue.offer(i);
}
// Now we're at [5,6,2,3,4]
// ^-- headIndex and offerIndex%length
// WHEN offering one more, so that the queue is forced to resize
queue.offer(8);
// THEN it should have been offered as well as all the previous ids should be intact
for (int i = 3; i <= 8; i++) {
assertFalse(queue.isEmpty());
queue.removeChecked(i);
}
assertTrue(queue.isEmpty());
}
Aggregations