use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.
the class IndexingServiceTest method shouldFailToStartIfMissingIndexProvider.
@Test
public void shouldFailToStartIfMissingIndexProvider() throws Exception {
// GIVEN an indexing service that has a schema index provider X
String otherProviderKey = "something-completely-different";
SchemaIndexProvider.Descriptor otherDescriptor = new SchemaIndexProvider.Descriptor(otherProviderKey, "no-version");
IndexRule rule = indexRule(1, 2, 3, otherDescriptor);
IndexingService indexing = newIndexingServiceWithMockedDependencies(mock(IndexPopulator.class), mock(IndexAccessor.class), new DataUpdates(), rule);
// WHEN trying to start up and initialize it with an index from provider Y
try {
life.init();
fail("initIndexes with mismatching index provider should fail");
} catch (LifecycleException e) {
// THEN starting up should fail
assertThat(e.getCause().getMessage(), containsString("existing index"));
assertThat(e.getCause().getMessage(), containsString(otherProviderKey));
}
}
use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.
the class IndexingServiceTest method shouldSnapshotOnlineIndexes.
@Test
public void shouldSnapshotOnlineIndexes() throws Exception {
// GIVEN
int indexId = 1;
int indexId2 = 2;
IndexRule rule1 = indexRule(indexId, 2, 3, PROVIDER_DESCRIPTOR);
IndexRule rule2 = indexRule(indexId2, 4, 5, PROVIDER_DESCRIPTOR);
IndexAccessor indexAccessor = mock(IndexAccessor.class);
IndexingService indexing = newIndexingServiceWithMockedDependencies(mock(IndexPopulator.class), indexAccessor, new DataUpdates(), rule1, rule2);
File theFile = new File("Blah");
when(indexAccessor.snapshotFiles()).thenAnswer(newResourceIterator(theFile));
when(indexProvider.getInitialState(indexId, rule1.getIndexDescriptor())).thenReturn(ONLINE);
when(indexProvider.getInitialState(indexId2, rule2.getIndexDescriptor())).thenReturn(ONLINE);
when(storeView.indexSample(anyLong(), any(DoubleLongRegister.class))).thenReturn(newDoubleLongRegister(32L, 32L));
life.start();
// WHEN
ResourceIterator<File> files = indexing.snapshotStoreFiles();
// THEN
// We get a snapshot per online index
assertThat(asCollection(files), equalTo(asCollection(iterator(theFile, theFile))));
}
use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.
the class IndexingServiceTest method shouldLogIndexStateOnInit.
@Test
public void shouldLogIndexStateOnInit() throws Exception {
// given
SchemaIndexProvider provider = mock(SchemaIndexProvider.class);
when(provider.getProviderDescriptor()).thenReturn(PROVIDER_DESCRIPTOR);
when(provider.getOnlineAccessor(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(mock(IndexAccessor.class));
SchemaIndexProviderMap providerMap = new DefaultSchemaIndexProviderMap(provider);
TokenNameLookup mockLookup = mock(TokenNameLookup.class);
IndexRule onlineIndex = indexRule(1, 1, 1, PROVIDER_DESCRIPTOR);
IndexRule populatingIndex = indexRule(2, 1, 2, PROVIDER_DESCRIPTOR);
IndexRule failedIndex = indexRule(3, 2, 2, PROVIDER_DESCRIPTOR);
life.add(IndexingServiceFactory.createIndexingService(Config.empty(), mock(JobScheduler.class), providerMap, mock(IndexStoreView.class), mockLookup, asList(onlineIndex, populatingIndex, failedIndex), logProvider, IndexingService.NO_MONITOR, DO_NOTHING_CALLBACK));
when(provider.getInitialState(onlineIndex.getId(), onlineIndex.getIndexDescriptor())).thenReturn(ONLINE);
when(provider.getInitialState(populatingIndex.getId(), populatingIndex.getIndexDescriptor())).thenReturn(InternalIndexState.POPULATING);
when(provider.getInitialState(failedIndex.getId(), failedIndex.getIndexDescriptor())).thenReturn(InternalIndexState.FAILED);
when(mockLookup.labelGetName(1)).thenReturn("LabelOne");
when(mockLookup.labelGetName(2)).thenReturn("LabelTwo");
when(mockLookup.propertyKeyGetName(1)).thenReturn("propertyOne");
when(mockLookup.propertyKeyGetName(2)).thenReturn("propertyTwo");
// when
life.init();
// then
logProvider.assertExactly(logMatch.info("IndexingService.init: index 1 on :LabelOne(propertyOne) is ONLINE"), logMatch.info("IndexingService.init: index 2 on :LabelOne(propertyTwo) is POPULATING"), logMatch.info("IndexingService.init: index 3 on :LabelTwo(propertyTwo) is FAILED"));
}
use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.
the class NeoStoreTransactionApplierTest method shouldApplyUpdateIndexRuleSchemaRuleCommandToTheStoreInRecovery.
@Test
public void shouldApplyUpdateIndexRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception {
// given
final BatchTransactionApplier applier = newApplierFacade(newIndexApplier(), newApplier(true));
final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
final IndexRule rule = constraintIndexRule(0, 1, 2, new SchemaIndexProvider.Descriptor("K", "X.Y"), 42L);
final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
// when
boolean result = apply(applier, command::handle, transactionToApply);
// then
assertFalse(result);
verify(schemaStore, times(1)).setHighestPossibleIdInUse(record.getId());
verify(schemaStore, times(1)).updateRecord(record);
verify(indexingService, times(1)).activateIndex(rule.getId());
verify(cacheAccess, times(1)).addSchemaRule(rule);
}
use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.
the class NeoStoreTransactionApplierTest method shouldApplyDeleteIndexRuleSchemaRuleCommandToTheStoreInRecovery.
@Test
public void shouldApplyDeleteIndexRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception {
// given
final BatchTransactionApplier applier = newApplierFacade(newIndexApplier(), newApplier(true));
final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
record.setInUse(false);
final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
final IndexRule rule = indexRule(0, 1, 2, new SchemaIndexProvider.Descriptor("K", "X.Y"));
final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
// when
boolean result = apply(applier, command::handle, transactionToApply);
// then
assertFalse(result);
verify(schemaStore, times(1)).setHighestPossibleIdInUse(record.getId());
verify(schemaStore, times(1)).updateRecord(record);
verify(indexingService, times(1)).dropIndex(rule);
verify(cacheAccess, times(1)).removeSchemaRuleFromCache(command.getKey());
}
Aggregations