Search in sources :

Example 1 with IndexConfigStore

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);
}
Also used : Arrays(java.util.Arrays) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) IndexImplementation(org.neo4j.kernel.spi.legacyindex.IndexImplementation) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Function(java.util.function.Function) Node(org.neo4j.graphdb.Node) Matchers.anyString(org.mockito.Matchers.anyString) StorageCommand(org.neo4j.storageengine.api.StorageCommand) HashSet(java.util.HashSet) IndexManager(org.neo4j.graphdb.index.IndexManager) IndexEntityType(org.neo4j.kernel.impl.index.IndexEntityType) Command(org.neo4j.kernel.impl.transaction.command.Command) Relationship(org.neo4j.graphdb.Relationship) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) Matchers.eq(org.mockito.Matchers.eq) IndexCommand(org.neo4j.kernel.impl.index.IndexCommand) Collections.singletonMap(java.util.Collections.singletonMap) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) IndexImplementation(org.neo4j.kernel.spi.legacyindex.IndexImplementation) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) Matchers.anyString(org.mockito.Matchers.anyString)

Example 2 with IndexConfigStore

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();
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) AtomicLong(java.util.concurrent.atomic.AtomicLong) SynchronizedArrayIdOrderingQueue(org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue) Race(org.neo4j.test.Race) FakeCommitment(org.neo4j.kernel.impl.transaction.log.FakeCommitment) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Test(org.junit.Test)

Example 3 with IndexConfigStore

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;
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) Matchers.anyString(org.mockito.Matchers.anyString) File(java.io.File) Map(java.util.Map) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap)

Example 4 with IndexConfigStore

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());
}
Also used : IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) Matchers.anyString(org.mockito.Matchers.anyString) Commitment(org.neo4j.kernel.impl.transaction.log.Commitment) FakeCommitment(org.neo4j.kernel.impl.transaction.log.FakeCommitment) Test(org.junit.Test)

Example 5 with IndexConfigStore

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();
    }
}
Also used : IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) File(java.io.File)

Aggregations

IndexConfigStore (org.neo4j.kernel.impl.index.IndexConfigStore)12 Test (org.junit.Test)5 File (java.io.File)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Node (org.neo4j.graphdb.Node)3 Relationship (org.neo4j.graphdb.Relationship)3 IndexDefineCommand (org.neo4j.kernel.impl.index.IndexDefineCommand)3 SynchronizedArrayIdOrderingQueue (org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue)3 Config (org.neo4j.kernel.configuration.Config)2 LabelScanStoreProvider (org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider)2 FakeCommitment (org.neo4j.kernel.impl.transaction.log.FakeCommitment)2 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1