use of org.neo4j.kernel.api.index.NodeUpdates in project neo4j by neo4j.
the class MultiIndexPopulationConcurrentUpdatesIT method applyConcurrentAddsToPopulatedIndex.
@Test
public void applyConcurrentAddsToPopulatedIndex() throws Throwable {
List<NodeUpdates> updates = new ArrayList<>(2);
updates.add(NodeUpdates.forNode(6, id(COUNTRY_LABEL)).added(propertyId, "Denmark").build());
updates.add(NodeUpdates.forNode(7, id(CAR_LABEL)).added(propertyId, "BMW").build());
launchCustomIndexPopulation(labelsNameIdMap, propertyId, updates);
waitAndActivateIndexes(labelsNameIdMap, propertyId);
try (Transaction ignored = embeddedDatabase.beginTx()) {
Integer countryLabelId = labelsNameIdMap.get(COUNTRY_LABEL);
Integer carLabelId = labelsNameIdMap.get(CAR_LABEL);
try (IndexReader indexReader = getIndexReader(propertyId, countryLabelId)) {
assertEquals("Should be added by concurrent add.", 1, indexReader.countIndexedNodes(6, "Denmark"));
}
try (IndexReader indexReader = getIndexReader(propertyId, carLabelId)) {
assertEquals("Should be added by concurrent add.", 1, indexReader.countIndexedNodes(7, "BMW"));
}
}
}
use of org.neo4j.kernel.api.index.NodeUpdates in project neo4j by neo4j.
the class BatchingMultipleIndexPopulatorTest method batchIsFlushedWhenThresholdReached.
@Test
public void batchIsFlushedWhenThresholdReached() throws Exception {
setProperty(BATCH_SIZE_NAME, 2);
NodeUpdates update1 = nodeUpdates(1, propertyId, "foo", labelId);
NodeUpdates update2 = nodeUpdates(2, propertyId, "bar", labelId);
NodeUpdates update3 = nodeUpdates(3, propertyId, "baz", labelId);
IndexStoreView storeView = newStoreView(update1, update2, update3);
BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, sameThreadExecutor(), NullLogProvider.getInstance());
IndexPopulator populator = addPopulator(batchingPopulator, index1);
batchingPopulator.indexAllNodes().run();
verify(populator).add(Arrays.asList(forIndex(update1, index1), forIndex(update2, index1)));
verify(populator).add(singletonList(forIndex(update3, index1)));
}
use of org.neo4j.kernel.api.index.NodeUpdates 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.api.index.NodeUpdates 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.index.NodeUpdates in project neo4j by neo4j.
the class TransactionRecordStateTest method shouldConvertMixedLabelAdditionAndSetPropertyToNodePropertyUpdates.
@Test
public void shouldConvertMixedLabelAdditionAndSetPropertyToNodePropertyUpdates() throws Exception {
// GIVEN
NeoStores neoStores = neoStoresRule.open();
long nodeId = 0;
TransactionRecordState recordState = newTransactionRecordState(neoStores);
recordState.nodeCreate(nodeId);
recordState.nodeAddProperty(nodeId, propertyId1, value1);
addLabelsToNode(recordState, nodeId, oneLabelId);
apply(neoStores, recordState);
// WHEN
recordState = newTransactionRecordState(neoStores);
recordState.nodeAddProperty(nodeId, propertyId2, value2);
addLabelsToNode(recordState, nodeId, secondLabelId);
Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
// THEN
NodeUpdates expected = NodeUpdates.forNode(nodeId, oneLabelId, bothLabelIds).added(propertyId2, value2).buildWithExistingProperties(Property.stringProperty(propertyId1, value1));
assertEquals(expected, Iterables.single(indexUpdates));
}
Aggregations