Search in sources :

Example 51 with BatchInserter

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

the class BatchInsertTest method shouldUpdateStringArrayPropertiesOnNodesUsingBatchInserter1.

@Test
public void shouldUpdateStringArrayPropertiesOnNodesUsingBatchInserter1() throws Exception {
    // Given
    BatchInserter batchInserter = globalInserter;
    String[] array1 = { "1" };
    String[] array2 = { "a" };
    long id1 = batchInserter.createNode(map("array", array1));
    long id2 = batchInserter.createNode(map());
    // When
    batchInserter.getNodeProperties(id1).get("array");
    batchInserter.setNodeProperty(id1, "array", array1);
    batchInserter.setNodeProperty(id2, "array", array2);
    batchInserter.getNodeProperties(id1).get("array");
    batchInserter.setNodeProperty(id1, "array", array1);
    batchInserter.setNodeProperty(id2, "array", array2);
    // Then
    assertThat((String[]) batchInserter.getNodeProperties(id1).get("array"), equalTo(array1));
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) Test(org.junit.Test)

Example 52 with BatchInserter

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

the class BatchInsertTest method uniquenessConstraintShouldBeCheckedOnBatchInserterShutdownAndFailIfViolated.

@Test
public void uniquenessConstraintShouldBeCheckedOnBatchInserterShutdownAndFailIfViolated() throws Exception {
    // Given
    Label label = label("Foo");
    String property = "Bar";
    String value = "Baz";
    BatchInserter inserter = newBatchInserter();
    // When
    inserter.createDeferredConstraint(label).assertPropertyIsUnique(property).create();
    inserter.createNode(Collections.<String, Object>singletonMap(property, value), label);
    inserter.createNode(Collections.<String, Object>singletonMap(property, value), label);
    // Then
    try {
        inserter.shutdown();
        fail("Node that violates uniqueness constraint was created by batch inserter");
    } catch (RuntimeException ex) {
        // good
        assertEquals(new IndexEntryConflictException(0, 1, value), ex.getCause());
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) Label(org.neo4j.graphdb.Label) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) Test(org.junit.Test)

Example 53 with BatchInserter

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

the class BatchInsertTest method shouldNotAllowCreationOfDeferredSchemaConstraintAfterIndexOnSameKeys.

@Test
public void shouldNotAllowCreationOfDeferredSchemaConstraintAfterIndexOnSameKeys() throws Exception {
    // GIVEN
    BatchInserter inserter = globalInserter;
    String labelName = "Hacker3-" + denseNodeThreshold;
    // WHEN
    inserter.createDeferredSchemaIndex(label(labelName)).on("handle").create();
    try {
        inserter.createDeferredConstraint(label(labelName)).assertPropertyIsUnique("handle").create();
        fail("Should have thrown exception.");
    } catch (ConstraintViolationException e) {
    // THEN Good
    }
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) Test(org.junit.Test)

Example 54 with BatchInserter

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

the class BatchInserterImplTest method testCreatesStoreLockFile.

@Test
public void testCreatesStoreLockFile() throws Exception {
    // Given
    File file = testDirectory.graphDbDir();
    // When
    BatchInserter inserter = BatchInserters.inserter(file.getAbsoluteFile(), fileSystemRule.get());
    // Then
    assertThat(new File(file, StoreLocker.STORE_LOCK_FILENAME).exists(), equalTo(true));
    inserter.shutdown();
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) File(java.io.File) Test(org.junit.Test)

Example 55 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)

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