Search in sources :

Example 11 with IndexDefineCommand

use of org.neo4j.kernel.impl.index.IndexDefineCommand in project neo4j by neo4j.

the class LuceneCommandApplierTest method shouldHandleMultipleIdSpaces.

@Test
public void shouldHandleMultipleIdSpaces() throws Exception {
    // GIVEN
    fs.get().mkdirs(dir);
    String indexName = "name", key = "key";
    IndexConfigStore configStore = new IndexConfigStore(dir, fs.get());
    configStore.set(Node.class, indexName, EXACT_CONFIG);
    LuceneDataSource dataSource = life.add(spy(new LuceneDataSource(dir, Config.embeddedDefaults(stringMap(LuceneDataSource.Configuration.ephemeral.name(), Settings.TRUE)), configStore, fs.get())));
    try (LuceneCommandApplier applier = new LuceneCommandApplier(dataSource, false)) {
        // WHEN issuing a command where the index name is mapped to a certain id
        IndexDefineCommand definitions = definitions(MapUtil.<String, Integer>genericMap(indexName, 0), MapUtil.<String, Integer>genericMap(key, 0));
        applier.visitIndexDefineCommand(definitions);
        applier.visitIndexAddNodeCommand(addNodeToIndex(definitions, indexName, 0L));
        // and then later issuing a command for that same index, but in another transaction where
        // the local index name id is a different one
        definitions = definitions(MapUtil.<String, Integer>genericMap(indexName, 1), MapUtil.<String, Integer>genericMap(key, 0));
        applier.visitIndexDefineCommand(definitions);
        applier.visitIndexAddNodeCommand(addNodeToIndex(definitions, indexName, 1L));
    }
    // THEN both those updates should have been directed to the same index
    verify(dataSource, times(1)).getIndexSearcher(any(IndexIdentifier.class));
}
Also used : IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) Test(org.junit.Test)

Example 12 with IndexDefineCommand

use of org.neo4j.kernel.impl.index.IndexDefineCommand in project neo4j by neo4j.

the class LuceneCommandApplierTest method definitions.

private static IndexDefineCommand definitions(Map<String, Integer> names, Map<String, Integer> keys) {
    IndexDefineCommand definitions = new IndexDefineCommand();
    definitions.init(names, keys);
    return definitions;
}
Also used : IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand)

Example 13 with IndexDefineCommand

use of org.neo4j.kernel.impl.index.IndexDefineCommand in project neo4j by neo4j.

the class LegacyBatchIndexApplierTest method definitions.

private static IndexDefineCommand definitions(Map<String, Integer> names, Map<String, Integer> keys) {
    IndexDefineCommand definitions = new IndexDefineCommand();
    definitions.init(names, keys);
    return definitions;
}
Also used : IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand)

Example 14 with IndexDefineCommand

use of org.neo4j.kernel.impl.index.IndexDefineCommand in project neo4j by neo4j.

the class LegacyIndexTransactionStateImplTest method nodeIndexDeletionRemovesCommands.

@Test
public void nodeIndexDeletionRemovesCommands() {
    LegacyIndexTransactionStateImpl state = newLegacyIndexTxState();
    state.addNode("index", 1, "key", "value1");
    state.addNode("index", 2, "key", "value2");
    state.removeNode("index", 3, "key", "value3");
    state.deleteIndex(IndexEntityType.Node, "index");
    IndexDefineCommand indexDefinedCommand = new IndexDefineCommand();
    indexDefinedCommand.getOrAssignIndexNameId("index");
    indexDefinedCommand.getOrAssignKeyId("key");
    IndexCommand.DeleteCommand delete = new IndexCommand.DeleteCommand();
    delete.init(1, IndexEntityType.Node.id());
    Set<Command> expectedCommands = new HashSet<>(Arrays.asList(indexDefinedCommand, delete));
    assertEquals(expectedCommands, extractCommands(state));
}
Also used : IndexCommand(org.neo4j.kernel.impl.index.IndexCommand) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) IndexCommand(org.neo4j.kernel.impl.index.IndexCommand) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with IndexDefineCommand

use of org.neo4j.kernel.impl.index.IndexDefineCommand in project neo4j by neo4j.

the class LegacyIndexTransactionStateImplTest method tracksNodeCommands.

@Test
public void tracksNodeCommands() {
    LegacyIndexTransactionStateImpl state = newLegacyIndexTxState();
    state.addNode("index1", 1, "key1", "value1");
    state.removeNode("index1", 1, "key2", "value2");
    state.addNode("index1", 2, "key1", "value3");
    state.addNode("index1", 3, "key2", "value4");
    state.removeNode("index2", 4, "key1", "value5");
    IndexDefineCommand indexDefinedCommand = new IndexDefineCommand();
    indexDefinedCommand.getOrAssignIndexNameId("index1");
    indexDefinedCommand.getOrAssignIndexNameId("index2");
    indexDefinedCommand.getOrAssignKeyId("key1");
    indexDefinedCommand.getOrAssignKeyId("key2");
    Set<Command> expectedCommands = new HashSet<>(Arrays.asList(indexDefinedCommand, addNode(1, 1, 1, "value1"), removeNode(1, 1, 2, "value2"), addNode(1, 2, 1, "value3"), addNode(1, 3, 2, "value4"), removeNode(2, 4, 1, "value5")));
    assertEquals(expectedCommands, extractCommands(state));
}
Also used : IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) StorageCommand(org.neo4j.storageengine.api.StorageCommand) Command(org.neo4j.kernel.impl.transaction.command.Command) IndexCommand(org.neo4j.kernel.impl.index.IndexCommand) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

IndexDefineCommand (org.neo4j.kernel.impl.index.IndexDefineCommand)18 Test (org.junit.Test)11 StorageCommand (org.neo4j.storageengine.api.StorageCommand)7 HashSet (java.util.HashSet)6 IndexCommand (org.neo4j.kernel.impl.index.IndexCommand)6 Command (org.neo4j.kernel.impl.transaction.command.Command)6 IoPrimitiveUtils.read2bLengthAndString (org.neo4j.kernel.impl.util.IoPrimitiveUtils.read2bLengthAndString)5 IoPrimitiveUtils.read3bLengthAndString (org.neo4j.kernel.impl.util.IoPrimitiveUtils.read3bLengthAndString)5 IndexConfigStore (org.neo4j.kernel.impl.index.IndexConfigStore)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors.newCachedThreadPool (java.util.concurrent.Executors.newCachedThreadPool)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 After (org.junit.After)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1