use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldNotAllowCreationOfDeferredSchemaIndexAfterConstraintOnSameKeys.
@Test
public void shouldNotAllowCreationOfDeferredSchemaIndexAfterConstraintOnSameKeys() throws Exception {
// GIVEN
BatchInserter inserter = globalInserter;
String labelName = "Hacker4-" + denseNodeThreshold;
// WHEN
inserter.createDeferredConstraint(label(labelName)).assertPropertyIsUnique("handle").create();
try {
inserter.createDeferredSchemaIndex(label(labelName)).on("handle").create();
fail("Should have thrown exception.");
} catch (ConstraintViolationException e) {
// THEN Good
}
}
use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldRepopulatePreexistingIndexed.
@Test
public void shouldRepopulatePreexistingIndexed() throws Throwable {
// GIVEN
long jakewins = dbWithIndexAndSingleIndexedNode();
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));
long boggle = inserter.createNode(map("handle", "b0ggl3"), 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(jakewins, internalIndex.schema(), "Jakewins")));
verify(populator).add(singletonList(IndexEntryUpdate.add(boggle, internalIndex.schema(), "b0ggl3")));
verify(populator).verifyDeferredConstraints(any(PropertyAccessor.class));
verify(populator).close(true);
verify(provider).stop();
verify(provider).shutdown();
verifyNoMoreInteractions(populator);
}
use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldNotAllowCreationOfDuplicateIndex.
@Test
public void shouldNotAllowCreationOfDuplicateIndex() throws Exception {
// GIVEN
BatchInserter inserter = globalInserter;
String labelName = "Hacker1-" + denseNodeThreshold;
// WHEN
inserter.createDeferredSchemaIndex(label(labelName)).on("handle").create();
try {
inserter.createDeferredSchemaIndex(label(labelName)).on("handle").create();
fail("Should have thrown exception.");
} catch (ConstraintViolationException e) {
// THEN Good
}
}
use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method shouldCreateConsistentUniquenessConstraint.
@Test
public void shouldCreateConsistentUniquenessConstraint() throws Exception {
// given
BatchInserter inserter = newBatchInserter();
// when
inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
// then
GraphDatabaseAPI graphdb = (GraphDatabaseAPI) switchToEmbeddedGraphDatabaseService(inserter);
try {
NeoStores neoStores = graphdb.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
SchemaStore store = neoStores.getSchemaStore();
SchemaStorage storage = new SchemaStorage(store);
List<Long> inUse = new ArrayList<>();
DynamicRecord record = store.nextRecord();
for (long i = 1, high = store.getHighestPossibleIdInUse(); i <= high; i++) {
store.getRecord(i, record, RecordLoad.FORCE);
if (record.inUse() && record.isStartRecord()) {
inUse.add(i);
}
}
assertEquals("records in use", 2, inUse.size());
SchemaRule rule0 = storage.loadSingleSchemaRule(inUse.get(0));
SchemaRule rule1 = storage.loadSingleSchemaRule(inUse.get(1));
IndexRule indexRule;
ConstraintRule constraintRule;
if (rule0 instanceof IndexRule) {
indexRule = (IndexRule) rule0;
constraintRule = (ConstraintRule) rule1;
} else {
constraintRule = (ConstraintRule) rule0;
indexRule = (IndexRule) rule1;
}
assertEquals("index should reference constraint", constraintRule.getId(), indexRule.getOwningConstraint().longValue());
assertEquals("constraint should reference index", indexRule.getId(), constraintRule.getOwnedIndex());
} finally {
graphdb.shutdown();
}
}
use of org.neo4j.unsafe.batchinsert.BatchInserter in project neo4j by neo4j.
the class BatchInsertTest method testCleanupEmptyPropertyRecords.
/**
* Test checks that during node property set we will cleanup not used property records
* During initial node creation properties will occupy 5 property records.
* Last property record will have only empty array for email.
* During first update email property will be migrated to dynamic property and last property record will become
* empty. That record should be deleted form property chain or otherwise on next node load user will get an
* property record not in use exception.
* @throws Exception
*/
@Test
public void testCleanupEmptyPropertyRecords() throws Exception {
BatchInserter inserter = globalInserter;
Map<String, Object> properties = new HashMap<>();
properties.put("id", 1099511659993L);
properties.put("firstName", "Edward");
properties.put("lastName", "Shevchenko");
properties.put("gender", "male");
properties.put("birthday", new SimpleDateFormat("yyyy-MM-dd").parse("1987-11-08").getTime());
properties.put("birthday_month", 11);
properties.put("birthday_day", 8);
properties.put("creationDate", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").parse("2010-04-22T18:05:40.912+0000").getTime());
properties.put("locationIP", "46.151.255.205");
properties.put("browserUsed", "Firefox");
properties.put("email", new String[0]);
properties.put("languages", new String[0]);
long personNodeId = inserter.createNode(properties);
assertEquals("Shevchenko", inserter.getNodeProperties(personNodeId).get("lastName"));
assertThat((String[]) inserter.getNodeProperties(personNodeId).get("email"), is(emptyArray()));
inserter.setNodeProperty(personNodeId, "email", new String[] { "Edward1099511659993@gmail.com" });
assertThat((String[]) inserter.getNodeProperties(personNodeId).get("email"), arrayContaining("Edward1099511659993@gmail.com"));
inserter.setNodeProperty(personNodeId, "email", new String[] { "Edward1099511659993@gmail.com", "backup@gmail.com" });
assertThat((String[]) inserter.getNodeProperties(personNodeId).get("email"), arrayContaining("Edward1099511659993@gmail.com", "backup@gmail.com"));
}
Aggregations