use of org.neo4j.storageengine.api.schema.LabelScanReader in project neo4j by neo4j.
the class StoreStatementTest method shouldCloseOpenedLabelScanReader.
@Test
public void shouldCloseOpenedLabelScanReader() throws Exception {
// given
Supplier<LabelScanReader> scanStore = mock(Supplier.class);
LabelScanReader scanReader = mock(LabelScanReader.class);
when(scanStore.get()).thenReturn(scanReader);
StoreStatement statement = new StoreStatement(MockedNeoStores.basicMockedNeoStores(), mock(Supplier.class), scanStore, LockService.NO_LOCK_SERVICE);
statement.acquire();
// when
LabelScanReader actualReader = statement.getLabelScanReader();
// then
assertEquals(scanReader, actualReader);
// when
statement.close();
// then
verify(scanStore).get();
verifyNoMoreInteractions(scanStore);
verify(scanReader).close();
verifyNoMoreInteractions(scanReader);
}
use of org.neo4j.storageengine.api.schema.LabelScanReader in project neo4j by neo4j.
the class LabelScanStoreTest method shouldFindDecentAmountOfNodesForALabel.
@Test
public void shouldFindDecentAmountOfNodesForALabel() throws Exception {
// GIVEN
// 16 is the magic number of the page iterator
// 32 is the number of nodes in each lucene document
final int labelId = 1, nodeCount = 32 * 16 + 10;
start();
write(new PrefetchingIterator<NodeLabelUpdate>() {
private int i = -1;
@Override
protected NodeLabelUpdate fetchNextOrNull() {
return ++i < nodeCount ? labelChanges(i, NO_LABELS, new long[] { labelId }) : null;
}
});
// WHEN
Set<Long> nodeSet = new TreeSet<>();
LabelScanReader reader = store.newReader();
PrimitiveLongIterator nodes = reader.nodesWithLabel(labelId);
while (nodes.hasNext()) {
nodeSet.add(nodes.next());
}
reader.close();
// THEN
assertEquals("Found gaps in node id range: " + gaps(nodeSet, nodeCount), nodeCount, nodeSet.size());
}
use of org.neo4j.storageengine.api.schema.LabelScanReader in project neo4j by neo4j.
the class LabelScanStoreTest method shouldFindNodesWithAllGivenLabels.
@Test
public void shouldFindNodesWithAllGivenLabels() throws Exception {
// GIVEN
int labelId1 = 3, labelId2 = 5, labelId3 = 13;
start();
// WHEN
write(iterator(labelChanges(5, EMPTY_LONG_ARRAY, new long[] { labelId1, labelId2, labelId3 }), labelChanges(8, EMPTY_LONG_ARRAY, new long[] { labelId3 }), labelChanges(3, EMPTY_LONG_ARRAY, new long[] { labelId1 }), labelChanges(6, EMPTY_LONG_ARRAY, new long[] { labelId2 }), labelChanges(1, EMPTY_LONG_ARRAY, new long[] { labelId1 }), labelChanges(7, EMPTY_LONG_ARRAY, new long[] { labelId2 }), labelChanges(4, EMPTY_LONG_ARRAY, new long[] { labelId1, labelId3 }), labelChanges(2, EMPTY_LONG_ARRAY, new long[] { labelId1, labelId2 }), labelChanges(9, EMPTY_LONG_ARRAY, new long[] { labelId3 })));
// THEN
try (LabelScanReader reader = store.newReader()) {
assertArrayEquals(new long[] { 2, 5 }, PrimitiveLongCollections.asArray(reader.nodesWithAllLabels(labelId1, labelId2)));
assertArrayEquals(new long[] { 4, 5 }, PrimitiveLongCollections.asArray(reader.nodesWithAllLabels(labelId1, labelId3)));
assertArrayEquals(new long[] { 5 }, PrimitiveLongCollections.asArray(reader.nodesWithAllLabels(labelId1, labelId2, labelId3)));
}
}
use of org.neo4j.storageengine.api.schema.LabelScanReader in project neo4j by neo4j.
the class LabelScanStoreTest method shouldWorkWithAFullRange.
@Test
public void shouldWorkWithAFullRange() throws Exception {
// given
long labelId = 0;
List<NodeLabelUpdate> updates = new ArrayList<>();
Set<Long> nodes = new HashSet<>();
for (int i = 0; i < 34; i++) {
updates.add(NodeLabelUpdate.labelChanges(i, new long[] {}, new long[] { labelId }));
nodes.add((long) i);
}
start(updates);
// when
LabelScanReader reader = store.newReader();
Set<Long> nodesWithLabel = PrimitiveLongCollections.toSet(reader.nodesWithLabel((int) labelId));
// then
assertEquals(nodes, nodesWithLabel);
}
use of org.neo4j.storageengine.api.schema.LabelScanReader in project neo4j by neo4j.
the class LabelScanStoreTest method shouldFindNodesWithAnyOfGivenLabels.
@Test
public void shouldFindNodesWithAnyOfGivenLabels() throws Exception {
// GIVEN
int labelId1 = 3, labelId2 = 5, labelId3 = 13;
start();
// WHEN
write(iterator(labelChanges(2, EMPTY_LONG_ARRAY, new long[] { labelId1, labelId2 }), labelChanges(1, EMPTY_LONG_ARRAY, new long[] { labelId1 }), labelChanges(4, EMPTY_LONG_ARRAY, new long[] { labelId1, labelId3 }), labelChanges(5, EMPTY_LONG_ARRAY, new long[] { labelId1, labelId2, labelId3 }), labelChanges(3, EMPTY_LONG_ARRAY, new long[] { labelId1 }), labelChanges(7, EMPTY_LONG_ARRAY, new long[] { labelId2 }), labelChanges(8, EMPTY_LONG_ARRAY, new long[] { labelId3 }), labelChanges(6, EMPTY_LONG_ARRAY, new long[] { labelId2 }), labelChanges(9, EMPTY_LONG_ARRAY, new long[] { labelId3 })));
// THEN
try (LabelScanReader reader = store.newReader()) {
assertArrayEquals(new long[] { 1, 2, 3, 4, 5, 6, 7 }, PrimitiveLongCollections.asArray(reader.nodesWithAnyOfLabels(labelId1, labelId2)));
assertArrayEquals(new long[] { 1, 2, 3, 4, 5, 8, 9 }, PrimitiveLongCollections.asArray(reader.nodesWithAnyOfLabels(labelId1, labelId3)));
assertArrayEquals(new long[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, PrimitiveLongCollections.asArray(reader.nodesWithAnyOfLabels(labelId1, labelId2, labelId3)));
}
}
Aggregations