use of org.neo4j.kernel.api.index.NodeUpdates in project neo4j by neo4j.
the class NeoStoreIndexStoreViewTest method processAllNodeProperties.
@Test
public void processAllNodeProperties() throws Exception {
CopyUpdateVisitor propertyUpdateVisitor = new CopyUpdateVisitor();
StoreViewNodeStoreScan storeViewNodeStoreScan = new StoreViewNodeStoreScan(neoStores.getNodeStore(), locks, neoStores.getPropertyStore(), null, propertyUpdateVisitor, new int[] { labelId }, id -> true);
NodeRecord nodeRecord = new NodeRecord(-1);
neoStores.getNodeStore().getRecord(1L, nodeRecord, RecordLoad.FORCE);
storeViewNodeStoreScan.process(nodeRecord);
NodeUpdates propertyUpdates = propertyUpdateVisitor.getPropertyUpdates();
assertNotNull("Visitor should containts container with updates.", propertyUpdates);
assert propertyUpdates.forIndex(SchemaDescriptorFactory.forLabel(0, 0)).isPresent();
assert propertyUpdates.forIndex(SchemaDescriptorFactory.forLabel(0, 1)).isPresent();
assert propertyUpdates.forIndex(SchemaDescriptorFactory.forLabel(0, 0, 1)).isPresent();
assert !propertyUpdates.forIndex(SchemaDescriptorFactory.forLabel(1, 1)).isPresent();
}
use of org.neo4j.kernel.api.index.NodeUpdates in project neo4j by neo4j.
the class MultiIndexPopulationConcurrentUpdatesIT method applyConcurrentDeletesToPopulatedIndex.
@Test
public void applyConcurrentDeletesToPopulatedIndex() throws Throwable {
List<NodeUpdates> updates = new ArrayList<>(2);
updates.add(NodeUpdates.forNode(0, id(COUNTRY_LABEL)).removed(propertyId, "Sweden").build());
updates.add(NodeUpdates.forNode(3, id(COLOR_LABEL)).removed(propertyId, "green").build());
launchCustomIndexPopulation(labelsNameIdMap, propertyId, updates);
waitAndActivateIndexes(labelsNameIdMap, propertyId);
try (Transaction ignored = embeddedDatabase.beginTx()) {
Integer countryLabelId = labelsNameIdMap.get(COUNTRY_LABEL);
Integer colorLabelId = labelsNameIdMap.get(COLOR_LABEL);
try (IndexReader indexReader = getIndexReader(propertyId, countryLabelId)) {
assertEquals("Should be removed by concurrent remove.", 0, indexReader.countIndexedNodes(0, "Sweden"));
}
try (IndexReader indexReader = getIndexReader(propertyId, colorLabelId)) {
assertEquals("Should be removed by concurrent remove.", 0, indexReader.countIndexedNodes(3, "green"));
}
}
}
use of org.neo4j.kernel.api.index.NodeUpdates in project neo4j by neo4j.
the class BatchingMultipleIndexPopulatorTest method populatorMarkedAsFailedAndUpdatesNotAdded.
@Test
public void populatorMarkedAsFailedAndUpdatesNotAdded() throws Exception {
setProperty(BATCH_SIZE_NAME, 2);
NodeUpdates update1 = nodeUpdates(1, propertyId, "aaa", labelId);
NodeUpdates update2 = nodeUpdates(1, propertyId, "bbb", labelId);
NodeUpdates update3 = nodeUpdates(1, propertyId, "ccc", labelId);
NodeUpdates update4 = nodeUpdates(1, propertyId, "ddd", labelId);
NodeUpdates update5 = nodeUpdates(1, propertyId, "eee", labelId);
IndexStoreView storeView = newStoreView(update1, update2, update3, update4, update5);
RuntimeException batchFlushError = new RuntimeException("Batch failed");
BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, sameThreadExecutor(), NullLogProvider.getInstance());
IndexPopulator populator = addPopulator(batchingPopulator, index1);
doThrow(batchFlushError).when(populator).add(Arrays.asList(forIndex(update3, index1), forIndex(update4, index1)));
batchingPopulator.indexAllNodes().run();
verify(populator).add(Arrays.asList(forIndex(update1, index1), forIndex(update2, index1)));
verify(populator).add(Arrays.asList(forIndex(update3, index1), forIndex(update4, index1)));
verify(populator).markAsFailed(failure(batchFlushError).asString());
verify(populator, never()).add(singletonList(forIndex(update5, index1)));
}
use of org.neo4j.kernel.api.index.NodeUpdates in project neo4j by neo4j.
the class BatchingMultipleIndexPopulatorTest method newStoreView.
@SuppressWarnings("unchecked")
private static IndexStoreView newStoreView(NodeUpdates... updates) {
IndexStoreView storeView = mock(IndexStoreView.class);
when(storeView.visitNodes(any(), any(), any(), any(), anyBoolean())).thenAnswer(invocation -> {
Object visitorArg = invocation.getArguments()[2];
Visitor<NodeUpdates, IndexPopulationFailedKernelException> visitor = (Visitor<NodeUpdates, IndexPopulationFailedKernelException>) visitorArg;
return new IndexEntryUpdateScan(updates, visitor);
});
return storeView;
}
use of org.neo4j.kernel.api.index.NodeUpdates in project neo4j by neo4j.
the class IndexPopulationJobTest method shouldBeAbleToCancelPopulationJob.
@Test
public void shouldBeAbleToCancelPopulationJob() throws Exception {
// GIVEN
createNode(map(name, "Mattias"), FIRST);
IndexPopulator populator = mock(IndexPopulator.class);
FlippableIndexProxy index = mock(FlippableIndexProxy.class);
IndexStoreView storeView = mock(IndexStoreView.class);
ControlledStoreScan storeScan = new ControlledStoreScan();
when(storeView.visitNodes(any(int[].class), any(IntPredicate.class), Matchers.<Visitor<NodeUpdates, RuntimeException>>any(), Matchers.<Visitor<NodeLabelUpdate, RuntimeException>>any(), anyBoolean())).thenReturn(storeScan);
final IndexPopulationJob job = newIndexPopulationJob(populator, index, storeView, NullLogProvider.getInstance(), false);
OtherThreadExecutor<Void> populationJobRunner = cleanup.add(new OtherThreadExecutor<>("Population job test runner", null));
Future<Void> runFuture = populationJobRunner.executeDontWait(state -> {
job.run();
return null;
});
storeScan.latch.waitForAllToStart();
job.cancel().get();
storeScan.latch.waitForAllToFinish();
// WHEN
runFuture.get();
// THEN
verify(populator, times(1)).close(false);
verify(index, times(0)).flip(Matchers.any(), Matchers.any());
}
Aggregations