Search in sources :

Example 11 with BatchInserter

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

the class BatchInsertTest method shouldCreateDeferredUniquenessConstraintInEmptyDatabase.

@Test
public void shouldCreateDeferredUniquenessConstraintInEmptyDatabase() throws Exception {
    // GIVEN
    BatchInserter inserter = newBatchInserter();
    // WHEN
    ConstraintDefinition definition = inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
    // THEN
    assertEquals("Hacker", definition.getLabel().name());
    assertEquals(ConstraintType.UNIQUENESS, definition.getConstraintType());
    assertEquals(asSet("handle"), Iterables.asSet(definition.getPropertyKeys()));
    inserter.shutdown();
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) Test(org.junit.Test)

Example 12 with BatchInserter

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

the class BatchInsertTest method shouldRunIndexPopulationJobAtShutdown.

@Test
public void shouldRunIndexPopulationJobAtShutdown() throws Throwable {
    // GIVEN
    IndexPopulator populator = mock(IndexPopulator.class);
    SchemaIndexProvider provider = mock(SchemaIndexProvider.class);
    when(provider.getProviderDescriptor()).thenReturn(InMemoryIndexProviderFactory.PROVIDER_DESCRIPTOR);
    when(provider.getPopulator(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(populator);
    BatchInserter inserter = newBatchInserterWithSchemaIndexProvider(singleInstanceSchemaIndexProviderFactory(InMemoryIndexProviderFactory.KEY, provider));
    inserter.createDeferredSchemaIndex(label("Hacker")).on("handle").create();
    long nodeId = inserter.createNode(map("handle", "Jakewins"), label("Hacker"));
    // WHEN
    inserter.shutdown();
    // THEN
    verify(provider).init();
    verify(provider).start();
    verify(provider).getPopulator(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class));
    verify(populator).create();
    verify(populator).add(singletonList(IndexEntryUpdate.add(nodeId, internalIndex.schema(), "Jakewins")));
    verify(populator).verifyDeferredConstraints(any(PropertyAccessor.class));
    verify(populator).close(true);
    verify(provider).stop();
    verify(provider).shutdown();
    verifyNoMoreInteractions(populator);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) Test(org.junit.Test)

Example 13 with BatchInserter

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

the class BatchInsertTest method messagesLogGetsClosed.

@Test
public void messagesLogGetsClosed() throws Exception {
    File storeDir = this.storeDir.graphDbDir();
    BatchInserter inserter = BatchInserters.inserter(storeDir, fileSystemRule.get(), stringMap());
    inserter.shutdown();
    assertTrue(new File(storeDir, StoreLogService.INTERNAL_LOG_NAME).delete());
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) File(java.io.File) Test(org.junit.Test)

Example 14 with BatchInserter

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

the class BatchInsertTest method createEntitiesWithDynamicPropertiesMap.

@Test
public void createEntitiesWithDynamicPropertiesMap() throws Exception {
    BatchInserter inserter = globalInserter;
    setAndGet(inserter, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
    setAndGet(inserter, intArray(20));
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) Test(org.junit.Test)

Example 15 with BatchInserter

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

the class BatchInsertTest method createEntitiesWithEmptyPropertiesMap.

@Test
public void createEntitiesWithEmptyPropertiesMap() throws Exception {
    BatchInserter inserter = globalInserter;
    // Assert for node
    long nodeId = inserter.createNode(map());
    inserter.getNodeProperties(nodeId);
    //cp=N U http://www.w3.org/1999/02/22-rdf-syntax-ns#type, c=N
    // Assert for relationship
    long anotherNodeId = inserter.createNode(null);
    long relId = inserter.createRelationship(nodeId, anotherNodeId, RelTypes.BATCH_TEST, map());
    inserter.getRelationshipProperties(relId);
}
Also used : BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) 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