use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldDropIndexInAnotherTransaction.
@Test
public void shouldDropIndexInAnotherTransaction() throws Exception {
// given
StubKernel kernel = new StubKernel();
IndexingService indexingService = mock(IndexingService.class);
NewIndexDescriptor index = NewIndexDescriptorFactory.uniqueForLabel(123, 456);
PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, false);
// when
creator.dropUniquenessConstraintIndex(index);
// then
assertEquals(1, kernel.statements.size());
verify(kernel.statements.get(0).txState()).indexDoDrop(index);
verifyZeroInteractions(indexingService);
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class IndexingServiceTest method shouldWaitForRecoveredUniquenessConstraintIndexesToBeFullyPopulated.
@Test
public void shouldWaitForRecoveredUniquenessConstraintIndexesToBeFullyPopulated() throws Exception {
// I.e. when a uniqueness constraint is created, but database crashes before that schema record
// ends up in the store, so that next start have no choice but to rebuild it.
// GIVEN
final DoubleLatch latch = new DoubleLatch();
ControlledIndexPopulator populator = new ControlledIndexPopulator(latch);
final AtomicLong indexId = new AtomicLong(-1);
IndexingService.Monitor monitor = new IndexingService.MonitorAdapter() {
@Override
public void awaitingPopulationOfRecoveredIndex(long index, NewIndexDescriptor descriptor) {
// When we see that we start to await the index to populate, notify the slow-as-heck
// populator that it can actually go and complete its job.
indexId.set(index);
latch.startAndWaitForAllToStart();
}
};
// leaving out the IndexRule here will have the index being populated from scratch
IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, accessor, withData(addNodeUpdate(0, "value", 1)), monitor);
// WHEN initializing, i.e. preparing for recovery
life.init();
// simulating an index being created as part of applying recovered transactions
long fakeOwningConstraintRuleId = 1;
indexing.createIndexes(constraintIndexRule(2, labelId, propertyKeyId, PROVIDER_DESCRIPTOR, fakeOwningConstraintRuleId));
// and then starting, i.e. considering recovery completed
life.start();
// THEN afterwards the index should be ONLINE
assertEquals(2, indexId.get());
assertEquals(ONLINE, indexing.getIndexProxy(indexId.get()).getState());
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class IndexIT method shouldDisallowDroppingIndexThatDoesNotExist.
@Test
public void shouldDisallowDroppingIndexThatDoesNotExist() throws Exception {
// given
NewIndexDescriptor index;
{
SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
index = statement.indexCreate(SchemaBoundary.map(descriptor));
commit();
}
{
SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
statement.indexDrop(index);
commit();
}
// when
try {
SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
statement.indexDrop(index);
commit();
}// then
catch (SchemaKernelException e) {
assertEquals("Unable to drop index on :label[" + labelId + "](property[" + propertyKeyId + "]): " + "No such INDEX ON :label[" + labelId + "](property[" + propertyKeyId + "]).", e.getMessage());
}
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class IndexPopulationJobTest method indexDescriptor.
private NewIndexDescriptor indexDescriptor(Label label, String propertyKey, boolean constraint) throws TransactionFailureException {
try (KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
Statement statement = tx.acquireStatement()) {
int labelId = statement.readOperations().labelGetForName(label.name());
int propertyKeyId = statement.readOperations().propertyKeyGetForName(propertyKey);
NewIndexDescriptor descriptor = constraint ? NewIndexDescriptorFactory.uniqueForLabel(labelId, propertyKeyId) : NewIndexDescriptorFactory.forLabel(labelId, propertyKeyId);
tx.success();
return descriptor;
}
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class IndexStatisticsTest method shouldProvideIndexStatisticsWhenIndexIsBuiltViaPopulationAndConcurrentAdditionsAndDeletions.
@Test
public void shouldProvideIndexStatisticsWhenIndexIsBuiltViaPopulationAndConcurrentAdditionsAndDeletions() throws Exception {
// given some initial data
long[] nodes = repeatCreateNamedPeopleFor(NAMES.length * CREATION_MULTIPLIER);
int initialNodes = nodes.length;
// when populating while creating
NewIndexDescriptor index = createIndex("Person", "name");
UpdatesTracker updatesTracker = executeCreationsAndDeletions(nodes, index, CREATION_MULTIPLIER);
awaitOnline(index);
// then
int seenWhilePopulating = initialNodes + updatesTracker.createdDuringPopulation() - updatesTracker.deletedDuringPopulation();
double expectedSelectivity = UNIQUE_NAMES / seenWhilePopulating;
assertCorrectIndexSelectivity(expectedSelectivity, indexSelectivity(index));
assertCorrectIndexSize(seenWhilePopulating, indexSize(index));
int expectedIndexUpdates = updatesTracker.deletedAfterPopulation() + updatesTracker.createdAfterPopulation();
assertCorrectIndexUpdates(expectedIndexUpdates, indexUpdates(index));
}
Aggregations