Search in sources :

Example 56 with BatchInserter

use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.

the class FileSystemClosingBatchInserterTest method closeFileSystemOnShutdown.

@Test
public void closeFileSystemOnShutdown() throws Exception {
    BatchInserter batchInserter = mock(BatchInserter.class);
    IndexConfigStoreProvider configStoreProvider = mock(IndexConfigStoreProvider.class);
    FileSystemAbstraction fileSystem = mock(FileSystemAbstraction.class);
    FileSystemClosingBatchInserter inserter = new FileSystemClosingBatchInserter(batchInserter, configStoreProvider, fileSystem);
    inserter.shutdown();
    InOrder verificationOrder = inOrder(batchInserter, fileSystem);
    verificationOrder.verify(batchInserter).shutdown();
    verificationOrder.verify(fileSystem).close();
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) InOrder(org.mockito.InOrder) Test(org.junit.Test)

Example 57 with BatchInserter

use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.

the class BatchInsertionIT method shouldBeAbleToMakeRepeatedCallsToSetNodeProperty.

@Test
public void shouldBeAbleToMakeRepeatedCallsToSetNodeProperty() throws Exception {
    File file = new File(dbRule.getStoreDirAbsolutePath());
    BatchInserter inserter = BatchInserters.inserter(file, fileSystemRule.get());
    long nodeId = inserter.createNode(Collections.<String, Object>emptyMap());
    final Object finalValue = 87;
    inserter.setNodeProperty(nodeId, "a", "some property value");
    inserter.setNodeProperty(nodeId, "a", 42);
    inserter.setNodeProperty(nodeId, "a", 3.14);
    inserter.setNodeProperty(nodeId, "a", true);
    inserter.setNodeProperty(nodeId, "a", finalValue);
    inserter.shutdown();
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    try (Transaction ignored = db.beginTx()) {
        assertThat(db.getNodeById(nodeId).getProperty("a"), equalTo(finalValue));
    } finally {
        db.shutdown();
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) File(java.io.File) Test(org.junit.Test)

Example 58 with BatchInserter

use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.

the class BatchInsertionIT method shouldNotIndexNodesWithWrongLabel.

@Test
public void shouldNotIndexNodesWithWrongLabel() throws Exception {
    // Given
    File file = new File(dbRule.getStoreDirAbsolutePath());
    BatchInserter inserter = BatchInserters.inserter(file, fileSystemRule.get());
    inserter.createNode(map("name", "Bob"), label("User"), label("Admin"));
    inserter.createDeferredSchemaIndex(label("Banana")).on("name").create();
    // When
    inserter.shutdown();
    // Then
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    try (Transaction tx = db.beginTx()) {
        assertThat(count(db.findNodes(label("Banana"), "name", "Bob")), equalTo(0L));
    } finally {
        db.shutdown();
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) File(java.io.File) Test(org.junit.Test)

Example 59 with BatchInserter

use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.

the class BatchInsertionIT method shouldBeAbleToMakeRepeatedCallsToSetNodePropertyWithMultiplePropertiesPerBlock.

@Test
public void shouldBeAbleToMakeRepeatedCallsToSetNodePropertyWithMultiplePropertiesPerBlock() throws Exception {
    File file = new File(dbRule.getStoreDirAbsolutePath());
    BatchInserter inserter = BatchInserters.inserter(file, fileSystemRule.get());
    long nodeId = inserter.createNode(Collections.<String, Object>emptyMap());
    final Object finalValue1 = 87;
    final Object finalValue2 = 3.14;
    inserter.setNodeProperty(nodeId, "a", "some property value");
    inserter.setNodeProperty(nodeId, "a", 42);
    inserter.setNodeProperty(nodeId, "b", finalValue2);
    inserter.setNodeProperty(nodeId, "a", finalValue2);
    inserter.setNodeProperty(nodeId, "a", true);
    inserter.setNodeProperty(nodeId, "a", finalValue1);
    inserter.shutdown();
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    try (Transaction ignored = db.beginTx()) {
        assertThat(db.getNodeById(nodeId).getProperty("a"), equalTo(finalValue1));
        assertThat(db.getNodeById(nodeId).getProperty("b"), equalTo(finalValue2));
    } finally {
        db.shutdown();
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) File(java.io.File) Test(org.junit.Test)

Example 60 with BatchInserter

use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.

the class BatchInsertionIT method makeSureCantCreateNodeWithMagicNumber.

@Test(expected = ReservedIdException.class)
public void makeSureCantCreateNodeWithMagicNumber() throws IOException {
    // given
    File path = new File(dbRule.getStoreDirAbsolutePath());
    BatchInserter inserter = BatchInserters.inserter(path, fileSystemRule.get());
    try {
        // when
        long id = IdGeneratorImpl.INTEGER_MINUS_ONE;
        inserter.createNode(id, null);
    // then throws
    } finally {
        inserter.shutdown();
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) File(java.io.File) Test(org.junit.Test)

Aggregations

BatchInserter (org.neo4j.unsafe.batchinsert.BatchInserter)60 Test (org.junit.Test)58 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)9 File (java.io.File)8 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)8 Transaction (org.neo4j.graphdb.Transaction)8 Label (org.neo4j.graphdb.Label)5 HashMap (java.util.HashMap)4 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)4 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)4 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)4 BatchRelationship (org.neo4j.unsafe.batchinsert.BatchRelationship)4 HashSet (java.util.HashSet)3 Matchers.anyLong (org.mockito.Matchers.anyLong)3 Node (org.neo4j.graphdb.Node)3 PropertyAccessor (org.neo4j.kernel.api.index.PropertyAccessor)3 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)3 Set (java.util.Set)2