use of org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates in project neo4j by neo4j.
the class GenerateIndexUpdatesStepTest method shouldGenerateEntityPropertyUpdatesForRelevantEntityTokens.
@Test
void shouldGenerateEntityPropertyUpdatesForRelevantEntityTokens() throws Exception {
// given
StubStorageCursors data = new StubStorageCursors();
int numNodes = 10;
MutableLongSet relevantNodeIds = LongSets.mutable.empty();
for (int i = 0; i < numNodes; i++) {
int labelId = i % 2 == 0 ? LABEL : OTHER_LABEL;
data.withNode(i).labels(labelId).properties(KEY, stringValue("name_" + i));
if (labelId == LABEL) {
relevantNodeIds.add(i);
}
}
TestPropertyScanConsumer scanConsumer = new TestPropertyScanConsumer();
GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep<>(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, scanConsumer, null, NO_LOCKING, 1, mebiBytes(1), false, PageCacheTracer.NULL, INSTANCE);
// when
CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
step.process(allNodeIds(data), sender, NULL);
// then
GeneratedIndexUpdates updates = sender.batches.get(0);
updates.completeBatch();
for (TestPropertyScanConsumer.Record update : scanConsumer.batches.get(0)) {
assertThat(relevantNodeIds.remove(update.getEntityId())).isTrue();
}
assertThat(relevantNodeIds.isEmpty()).isTrue();
}
use of org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates in project neo4j by neo4j.
the class GenerateIndexUpdatesStepTest method shouldSendSingleBatchIfBelowMaxSizeThreshold.
@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldSendSingleBatchIfBelowMaxSizeThreshold(boolean alsoWrite) throws Exception {
// given
StubStorageCursors data = someUniformData(10);
TestPropertyScanConsumer scanConsumer = new TestPropertyScanConsumer();
GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, scanConsumer, null, NO_LOCKING, 1, mebiBytes(1), alsoWrite, PageCacheTracer.NULL, INSTANCE);
// when
CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
step.process(allNodeIds(data), sender, NULL);
// then
if (alsoWrite) {
assertThat(sender.batches).isEmpty();
assertThat(scanConsumer.batches.size()).isEqualTo(1);
assertThat(scanConsumer.batches.get(0).size()).isEqualTo(10);
} else {
assertThat(sender.batches.size()).isEqualTo(1);
assertThat(scanConsumer.batches).isEmpty();
}
}
use of org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates in project neo4j by neo4j.
the class GenerateIndexUpdatesStepTest method shouldGenerateEntityTokenUpdates.
@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldGenerateEntityTokenUpdates(boolean alsoWrite) throws Exception {
// given
StubStorageCursors data = someUniformData(10);
TestTokenScanConsumer scanConsumer = new TestTokenScanConsumer();
GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep<>(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, null, scanConsumer, NO_LOCKING, 1, mebiBytes(1), alsoWrite, PageCacheTracer.NULL, INSTANCE);
Set<TestTokenScanConsumer.Record> expectedUpdates = new HashSet<>();
try (StorageNodeCursor cursor = data.allocateNodeCursor(NULL)) {
cursor.scan();
while (cursor.next()) {
expectedUpdates.add(new TestTokenScanConsumer.Record(cursor.entityReference(), cursor.labels()));
}
}
// when
CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
step.process(allNodeIds(data), sender, NULL);
// then
if (alsoWrite) {
for (TestTokenScanConsumer.Record tokenUpdate : scanConsumer.batches.get(0)) {
assertThat(expectedUpdates.remove(tokenUpdate)).isTrue();
}
} else {
GeneratedIndexUpdates updates = sender.batches.get(0);
updates.completeBatch();
for (TestTokenScanConsumer.Record tokenUpdate : scanConsumer.batches.get(0)) {
assertThat(expectedUpdates.remove(tokenUpdate)).isTrue();
}
}
assertThat(expectedUpdates).isEmpty();
}
use of org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates in project neo4j by neo4j.
the class GenerateIndexUpdatesStepTest method shouldGenerateBothEntityTokenAndPropertyUpdates.
@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldGenerateBothEntityTokenAndPropertyUpdates(boolean alsoWrite) throws Exception {
// given
int numNodes = 10;
StubStorageCursors data = someUniformData(numNodes);
TestPropertyScanConsumer propertyScanConsumer = new TestPropertyScanConsumer();
TestTokenScanConsumer tokenScanConsumer = new TestTokenScanConsumer();
GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep<>(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, propertyScanConsumer, tokenScanConsumer, NO_LOCKING, 1, mebiBytes(1), alsoWrite, PageCacheTracer.NULL, INSTANCE);
// when
CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
step.process(allNodeIds(data), sender, NULL);
// then
if (alsoWrite) {
assertThat(propertyScanConsumer.batches.size()).isEqualTo(1);
assertThat(propertyScanConsumer.batches.get(0).size()).isEqualTo(numNodes);
assertThat(tokenScanConsumer.batches.size()).isEqualTo(1);
assertThat(tokenScanConsumer.batches.get(0).size()).isEqualTo(numNodes);
} else {
GeneratedIndexUpdates updates = sender.batches.get(0);
updates.completeBatch();
assertThat(propertyScanConsumer.batches.size()).isEqualTo(1);
assertThat(propertyScanConsumer.batches.get(0).size()).isEqualTo(numNodes);
assertThat(tokenScanConsumer.batches.size()).isEqualTo(1);
assertThat(tokenScanConsumer.batches.get(0).size()).isEqualTo(numNodes);
}
}
use of org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates in project neo4j by neo4j.
the class GenerateIndexUpdatesStepTest method shouldGenerateEntityPropertyUpdates.
@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldGenerateEntityPropertyUpdates(boolean alsoWrite) throws Exception {
// given
StubStorageCursors data = someUniformData(10);
TestPropertyScanConsumer scanConsumer = new TestPropertyScanConsumer();
GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep<>(new SimpleStageControl(), DEFAULT, data, alwaysTrue(), new NodeCursorBehaviour(data), new int[] { LABEL }, scanConsumer, null, NO_LOCKING, 1, mebiBytes(1), alsoWrite, PageCacheTracer.NULL, INSTANCE);
Set<TestPropertyScanConsumer.Record> expectedUpdates = new HashSet<>();
try (StorageNodeCursor cursor = data.allocateNodeCursor(NULL);
StoragePropertyCursor propertyCursor = data.allocatePropertyCursor(NULL, INSTANCE)) {
cursor.scan();
while (cursor.next()) {
cursor.properties(propertyCursor);
Map<Integer, Value> properties = new HashMap<>();
while (propertyCursor.next()) {
properties.put(propertyCursor.propertyKey(), propertyCursor.propertyValue());
}
expectedUpdates.add(new TestPropertyScanConsumer.Record(cursor.entityReference(), cursor.labels(), properties));
}
}
// when
CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
step.process(allNodeIds(data), sender, NULL);
// then
if (alsoWrite) {
for (TestPropertyScanConsumer.Record update : scanConsumer.batches.get(0)) {
assertThat(expectedUpdates.remove(update)).isTrue();
}
} else {
GeneratedIndexUpdates updates = sender.batches.get(0);
updates.completeBatch();
for (TestPropertyScanConsumer.Record update : scanConsumer.batches.get(0)) {
assertThat(expectedUpdates.remove(update)).isTrue();
}
}
assertThat(expectedUpdates).isEmpty();
}
Aggregations