use of org.neo4j.storageengine.api.IndexUpdateListener in project neo4j by neo4j.
the class IntegrityValidatorTest method relationshipPropertyIndexesNotAllowedForOldKernelVersions.
@Test
void relationshipPropertyIndexesNotAllowedForOldKernelVersions() {
// Given
NeoStores store = mock(NeoStores.class);
MetaDataStore metaDataStore = mock(MetaDataStore.class);
when(store.getMetaDataStore()).thenReturn(metaDataStore);
when(metaDataStore.kernelVersion()).thenReturn(KernelVersion.V4_2);
IndexUpdateListener indexes = mock(IndexUpdateListener.class);
IntegrityValidator validator = new IntegrityValidator(store);
validator.setIndexValidator(indexes);
var index = IndexPrototype.forSchema(SchemaDescriptor.forRelType(3, 14)).withIndexType(IndexType.BTREE).withName("any name").materialise(4);
// When
assertThatThrownBy(() -> validator.validateSchemaRule(index)).isInstanceOf(TransactionFailureException.class).hasMessageContaining("Required kernel version for this transaction is V4_3_D4, but actual version was V4_2.");
}
use of org.neo4j.storageengine.api.IndexUpdateListener in project neo4j by neo4j.
the class IntegrityValidatorTest method shouldValidateUniquenessIndexes.
@Test
void shouldValidateUniquenessIndexes() throws Exception {
// Given
NeoStores store = mock(NeoStores.class);
IndexUpdateListener indexes = mock(IndexUpdateListener.class);
IntegrityValidator validator = new IntegrityValidator(store);
validator.setIndexValidator(indexes);
UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel(1, 1);
doThrow(new ConstraintViolationException("error", new RuntimeException())).when(indexes).validateIndex(2L);
ConstraintDescriptor record = constraint.withId(1).withOwnedIndexId(2);
// When
assertThrows(Exception.class, () -> validator.validateSchemaRule(record));
}
use of org.neo4j.storageengine.api.IndexUpdateListener in project neo4j by neo4j.
the class IndexTransactionApplierFactoryTest method shouldRegisterIndexesToActivateIntoTheActivator.
@Test
void shouldRegisterIndexesToActivateIntoTheActivator() throws Exception {
// given
IndexUpdateListener indexUpdateListener = mock(IndexUpdateListener.class);
IndexActivator indexActivator = new IndexActivator(indexUpdateListener);
long indexId1 = 1;
long indexId2 = 2;
long indexId3 = 3;
long constraintId1 = 10;
long constraintId2 = 11;
long constraintId3 = 12;
String providerKey = "index-key";
String providerVersion = "v1";
IndexDescriptor rule1 = uniqueForSchema(forLabel(1, 1), providerKey, providerVersion, indexId1, constraintId1);
IndexDescriptor rule2 = uniqueForSchema(forLabel(2, 1), providerKey, providerVersion, indexId2, constraintId2);
IndexDescriptor rule3 = uniqueForSchema(forLabel(3, 1), providerKey, providerVersion, indexId3, constraintId3);
IndexTransactionApplierFactory applier = new IndexTransactionApplierFactory(indexUpdateListener);
var batchContext = mock(BatchContext.class);
when(batchContext.getLockGroup()).thenReturn(new LockGroup());
when(batchContext.indexUpdates()).thenReturn(mock(IndexUpdates.class));
when(batchContext.getIndexActivator()).thenReturn(indexActivator);
try (var txApplier = applier.startTx(new GroupOfCommands(), batchContext)) {
// activate index 1
txApplier.visitSchemaRuleCommand(new Command.SchemaRuleCommand(new SchemaRecord(rule1.getId()), asSchemaRecord(rule1, true), rule1));
// activate index 2
txApplier.visitSchemaRuleCommand(new Command.SchemaRuleCommand(new SchemaRecord(rule2.getId()), asSchemaRecord(rule2, true), rule2));
// activate index 3
txApplier.visitSchemaRuleCommand(new Command.SchemaRuleCommand(new SchemaRecord(rule3.getId()), asSchemaRecord(rule3, true), rule3));
// drop index 2
txApplier.visitSchemaRuleCommand(new Command.SchemaRuleCommand(asSchemaRecord(rule2, true), asSchemaRecord(rule2, false), rule2));
}
verify(indexUpdateListener).dropIndex(rule2);
indexActivator.close();
verify(indexUpdateListener).activateIndex(rule1);
verify(indexUpdateListener).activateIndex(rule3);
verifyNoMoreInteractions(indexUpdateListener);
}
use of org.neo4j.storageengine.api.IndexUpdateListener in project neo4j by neo4j.
the class IntegrityValidatorTest method tokenIndexesNotAllowedForOldKernelVersions.
@Test
void tokenIndexesNotAllowedForOldKernelVersions() {
// Given
NeoStores store = mock(NeoStores.class);
MetaDataStore metaDataStore = mock(MetaDataStore.class);
when(store.getMetaDataStore()).thenReturn(metaDataStore);
when(metaDataStore.kernelVersion()).thenReturn(KernelVersion.V4_2);
IndexUpdateListener indexes = mock(IndexUpdateListener.class);
IntegrityValidator validator = new IntegrityValidator(store);
validator.setIndexValidator(indexes);
var index = IndexPrototype.forSchema(SchemaDescriptor.forAnyEntityTokens(EntityType.NODE)).withIndexType(IndexType.LOOKUP).withName("any name").materialise(4);
// When
assertThatThrownBy(() -> validator.validateSchemaRule(index)).isInstanceOf(TransactionFailureException.class).hasMessageContaining("Required kernel version for this transaction is V4_3_D4, but actual version was V4_2.");
}
use of org.neo4j.storageengine.api.IndexUpdateListener in project neo4j by neo4j.
the class IndexTransactionApplierFactoryTest method shouldProvideTokenIndexUpdatesSortedByNodeId.
@Test
void shouldProvideTokenIndexUpdatesSortedByNodeId() throws Exception {
// GIVEN
OrderVerifyingUpdateListener indexUpdateListener = new OrderVerifyingUpdateListener(10, 15, 20);
WorkSync<IndexUpdateListener, IndexUpdatesWork> indexUpdatesSync = spy(new WorkSync<>(indexUpdateListener));
PropertyStore propertyStore = mock(PropertyStore.class);
IndexTransactionApplierFactory applier = new IndexTransactionApplierFactory(indexUpdateListener);
final SchemaCache mock = mock(SchemaCache.class);
when(mock.getTokenIndex(EntityType.NODE)).thenReturn(IndexDescriptor.INJECTED_NLI);
try (var batchContext = new BatchContextImpl(indexUpdateListener, indexUpdatesSync, mock(NodeStore.class), propertyStore, mock(RecordStorageEngine.class), mock, NULL, INSTANCE, mock(IdUpdateListener.class))) {
try (TransactionApplier txApplier = applier.startTx(new GroupOfCommands(), batchContext)) {
// WHEN
txApplier.visitNodeCommand(node(15));
txApplier.visitNodeCommand(node(20));
txApplier.visitNodeCommand(node(10));
}
}
indexUpdateListener.done();
// THEN all assertions happen inside the UpdateListener and #close
verify(indexUpdatesSync).apply(any());
}
Aggregations