use of org.neo4j.kernel.impl.transaction.state.IndexUpdates in project neo4j by neo4j.
the class IndexingServiceTest method recoveredUpdatesShouldBeApplied.
@SuppressWarnings("unchecked")
@Test
public void recoveredUpdatesShouldBeApplied() throws Exception {
// Given
final long nodeId1 = 1;
final long nodeId2 = 2;
final PrimitiveLongSet nodeIds = setOf(nodeId1, nodeId2);
final NodeUpdates nodeUpdate1 = addNodeUpdate(nodeId1, "foo");
final NodeUpdates nodeUpdate2 = addNodeUpdate(nodeId2, "bar");
final Set<NodeUpdates> nodeUpdates = asSet(nodeUpdate1, nodeUpdate2);
final AtomicBoolean applyingRecoveredDataCalled = new AtomicBoolean();
final AtomicBoolean appliedRecoveredDataCalled = new AtomicBoolean();
// Mockito not used here because it does not work well with mutable objects (set of recovered node ids in
// this case, which is cleared at the end of recovery).
// See https://code.google.com/p/mockito/issues/detail?id=126 and
// https://groups.google.com/forum/#!topic/mockito/_A4BpsEAY9s
IndexingService.Monitor monitor = new IndexingService.MonitorAdapter() {
@Override
public void applyingRecoveredData(PrimitiveLongSet recoveredNodeIds) {
assertEquals(nodeIds, recoveredNodeIds);
applyingRecoveredDataCalled.set(true);
}
@Override
public void appliedRecoveredData(Iterable<NodeUpdates> updates) {
assertEquals(nodeUpdates, Iterables.asSet(updates));
appliedRecoveredDataCalled.set(true);
}
};
IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, accessor, withData(), monitor);
doAnswer(nodeUpdatesAnswer(nodeUpdate1)).when(storeView).nodeAsUpdates(eq(nodeId1), any(Collection.class));
doAnswer(nodeUpdatesAnswer(nodeUpdate2)).when(storeView).nodeAsUpdates(eq(nodeId2), any(Collection.class));
// When
life.init();
IndexUpdates updates = nodeIdsAsIndexUpdates(nodeIds);
indexing.apply(updates);
life.start();
// Then
assertTrue("applyingRecoveredData was not called", applyingRecoveredDataCalled.get());
assertTrue("appliedRecoveredData was not called", appliedRecoveredDataCalled.get());
}
use of org.neo4j.kernel.impl.transaction.state.IndexUpdates in project neo4j by neo4j.
the class IndexingService method applyRecoveredUpdates.
private void applyRecoveredUpdates() throws IOException, IndexEntryConflictException {
if (log.isDebugEnabled()) {
log.debug("Applying recovered updates: " + recoveredNodeIds);
}
monitor.applyingRecoveredData(recoveredNodeIds);
if (!recoveredNodeIds.isEmpty()) {
try (IndexUpdaterMap updaterMap = indexMapRef.createIndexUpdaterMap(IndexUpdateMode.RECOVERY)) {
for (IndexUpdater updater : updaterMap) {
updater.remove(recoveredNodeIds);
}
IndexUpdates updates = readRecoveredUpdatesFromStore();
apply(updates, IndexUpdateMode.RECOVERY);
monitor.appliedRecoveredData(updates);
}
}
recoveredNodeIds.clear();
}
Aggregations