use of org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException in project neo4j by neo4j.
the class BatchingMultipleIndexPopulatorTest method executorShutdownAfterStoreScanCompletes.
@Test
public void executorShutdownAfterStoreScanCompletes() throws Exception {
NodeUpdates update = nodeUpdates(1, propertyId, "foo", labelId);
IndexStoreView storeView = newStoreView(update);
ExecutorService executor = mock(ExecutorService.class);
when(executor.awaitTermination(anyLong(), any())).thenReturn(true);
BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, executor, NullLogProvider.getInstance());
StoreScan<IndexPopulationFailedKernelException> storeScan = batchingPopulator.indexAllNodes();
verify(executor, never()).shutdown();
storeScan.run();
verify(executor).shutdown();
verify(executor).awaitTermination(anyLong(), any());
}
use of org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException in project neo4j by neo4j.
the class BatchingMultipleIndexPopulatorTest method executorForcefullyShutdownIfStoreScanFails.
@Test
@SuppressWarnings("unchecked")
public void executorForcefullyShutdownIfStoreScanFails() throws Exception {
IndexStoreView storeView = mock(IndexStoreView.class);
StoreScan<Exception> failingStoreScan = mock(StoreScan.class);
RuntimeException scanError = new RuntimeException();
doThrow(scanError).when(failingStoreScan).run();
when(storeView.visitNodes(any(), any(), any(), any(), anyBoolean())).thenReturn(failingStoreScan);
ExecutorService executor = mock(ExecutorService.class);
when(executor.awaitTermination(anyLong(), any())).thenReturn(true);
BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, executor, NullLogProvider.getInstance());
StoreScan<IndexPopulationFailedKernelException> storeScan = batchingPopulator.indexAllNodes();
verify(executor, never()).shutdown();
try {
storeScan.run();
fail("Exception expected");
} catch (Throwable t) {
assertSame(scanError, t);
}
verify(executor).shutdownNow();
verify(executor).awaitTermination(anyLong(), any());
}
use of org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldDropIndexIfPopulationFails.
@Test
void shouldDropIndexIfPopulationFails() throws Exception {
// given
IndexingService indexingService = mock(IndexingService.class);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
when(indexProxy.getDescriptor()).thenReturn(index);
when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX, index);
IndexEntryConflictException cause = new IndexEntryConflictException(2, 1, Values.of("a"));
doThrow(new IndexPopulationFailedKernelException("some index", cause)).when(indexProxy).awaitStoreScanCompleted(anyLong(), any());
when(schemaRead.index(any(SchemaDescriptor.class))).thenReturn(// first claim it doesn't exist, because it doesn't... so
Iterators.emptyResourceIterator()).thenReturn(// then after it failed claim it does exist
Iterators.iterator(index));
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
// when
KernelTransactionImplementation transaction = createTransaction();
UniquePropertyValueValidationException exception = assertThrows(UniquePropertyValueValidationException.class, () -> creator.createUniquenessConstraintIndex(transaction, constraint, prototype));
assertEquals("Existing data does not satisfy Constraint( name='constraint', type='UNIQUENESS', schema=(:Label {prop}) ): " + "Both node 2 and node 1 share the property value ( String(\"a\") )", exception.getMessage());
assertEquals(2, kernel.transactions.size());
KernelTransactionImplementation tx1 = kernel.transactions.get(0);
verify(tx1).indexUniqueCreate(prototype);
verify(schemaRead, times(2)).indexGetForName(constraint.getName());
verifyNoMoreInteractions(schemaRead);
KernelTransactionImplementation kti2 = kernel.transactions.get(1);
verify(kti2).addIndexDoDropToTxState(index);
}
use of org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException in project neo4j by neo4j.
the class MultipleIndexPopulator method indexAllNodes.
public StoreScan<IndexPopulationFailedKernelException> indexAllNodes() {
int[] labelIds = labelIds();
int[] propertyKeyIds = propertyKeyIds();
IntPredicate propertyKeyIdFilter = (propertyKeyId) -> contains(propertyKeyIds, propertyKeyId);
storeScan = storeView.visitNodes(labelIds, propertyKeyIdFilter, new NodePopulationVisitor(), null, false);
storeScan.configure(populations);
return storeScan;
}
use of org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException in project neo4j by neo4j.
the class NeoStoreTransactionApplierTest method shouldApplyUpdateIndexRuleSchemaRuleCommandToTheStoreThrowingIndexProblem.
@Test
public void shouldApplyUpdateIndexRuleSchemaRuleCommandToTheStoreThrowingIndexProblem() throws IOException, IndexNotFoundKernelException, IndexPopulationFailedKernelException, IndexActivationFailedKernelException {
// given
final BatchTransactionApplier applier = newIndexApplier();
doThrow(new IndexNotFoundKernelException("")).when(indexingService).activateIndex(anyLong());
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
try {
apply(applier, command::handle, transactionToApply);
fail("should have thrown");
} catch (Exception e) {
// then
assertTrue(e.getCause() instanceof IndexNotFoundKernelException);
}
}
Aggregations