use of org.neo4j.kernel.impl.index.IndexConfigStore in project neo4j by neo4j.
the class LegacyIndexTransactionStateImplTest method newLegacyIndexTxState.
private static LegacyIndexTransactionStateImpl newLegacyIndexTxState() {
IndexConfigStore indexConfigStore = mock(IndexConfigStore.class);
when(indexConfigStore.get(eq(Node.class), anyString())).thenReturn(singletonMap(IndexManager.PROVIDER, "test"));
when(indexConfigStore.get(eq(Relationship.class), anyString())).thenReturn(singletonMap(IndexManager.PROVIDER, "test"));
Function<String, IndexImplementation> providerLookup = s -> mock(IndexImplementation.class);
return new LegacyIndexTransactionStateImpl(indexConfigStore, providerLookup);
}
use of org.neo4j.kernel.impl.index.IndexConfigStore 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 org.neo4j.kernel.impl.index.IndexConfigStore in project neo4j by neo4j.
the class LegacyBatchIndexApplierTest method newIndexConfigStore.
private IndexConfigStore newIndexConfigStore(Map<String, Integer> names, String providerName) {
File dir = new File("conf");
EphemeralFileSystemAbstraction fileSystem = fs.get();
fileSystem.mkdirs(dir);
IndexConfigStore store = life.add(new IndexConfigStore(dir, fileSystem));
for (Map.Entry<String, Integer> name : names.entrySet()) {
store.set(Node.class, name.getKey(), stringMap(IndexManager.PROVIDER, providerName));
store.set(Relationship.class, name.getKey(), stringMap(IndexManager.PROVIDER, providerName));
}
return store;
}
use of org.neo4j.kernel.impl.index.IndexConfigStore in project neo4j by neo4j.
the class LegacyBatchIndexApplierTest method shouldOnlyCreateOneApplierPerProvider.
@Test
public void shouldOnlyCreateOneApplierPerProvider() throws Exception {
// GIVEN
Map<String, Integer> names = MapUtil.genericMap("first", 0, "second", 1);
Map<String, Integer> keys = MapUtil.genericMap("key", 0);
String applierName = "test-applier";
Commitment commitment = mock(Commitment.class);
when(commitment.hasLegacyIndexChanges()).thenReturn(true);
IndexConfigStore config = newIndexConfigStore(names, applierName);
LegacyIndexApplierLookup applierLookup = mock(LegacyIndexApplierLookup.class);
when(applierLookup.newApplier(anyString(), anyBoolean())).thenReturn(mock(TransactionApplier.class));
try (LegacyBatchIndexApplier applier = new LegacyBatchIndexApplier(config, applierLookup, BYPASS, INTERNAL)) {
TransactionToApply tx = new TransactionToApply(null, 2);
tx.commitment(commitment, 2);
try (TransactionApplier txApplier = applier.startTx(tx)) {
// WHEN
IndexDefineCommand definitions = definitions(names, keys);
txApplier.visitIndexDefineCommand(definitions);
txApplier.visitIndexAddNodeCommand(addNodeToIndex(definitions, "first"));
txApplier.visitIndexAddNodeCommand(addNodeToIndex(definitions, "second"));
txApplier.visitIndexAddRelationshipCommand(addRelationshipToIndex(definitions, "second"));
}
}
// THEN
verify(applierLookup, times(1)).newApplier(eq(applierName), anyBoolean());
}
use of org.neo4j.kernel.impl.index.IndexConfigStore in project neo4j by neo4j.
the class ReadOnlyIndexReferenceFactoryTest method setupIndexInfrastructure.
private void setupIndexInfrastructure() throws IOException {
File storeDir = getStoreDir();
indexStore = new IndexConfigStore(storeDir, fileSystemRule.get());
indexStore.set(Node.class, INDEX_NAME, MapUtil.stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext"));
LuceneDataSource luceneDataSource = new LuceneDataSource(storeDir, Config.embeddedDefaults(MapUtil.stringMap()), indexStore, fileSystemRule.get());
try {
luceneDataSource.init();
luceneDataSource.getIndexSearcher(indexIdentifier);
} finally {
luceneDataSource.shutdown();
}
}
Aggregations