use of org.neo4j.test.Randoms in project neo4j by neo4j.
the class InputCacheTest method shouldCacheAndRetrieveNodes.
@Test
public void shouldCacheAndRetrieveNodes() throws Exception {
// GIVEN
try (InputCache cache = new InputCache(fileSystemRule.get(), dir.directory(), Standard.LATEST_RECORD_FORMATS, withMaxProcessors(50), (int) ByteUnit.kibiBytes(8), BATCH_SIZE)) {
List<InputNode> nodes = new ArrayList<>();
Randoms random = getRandoms();
try (Receiver<InputNode[], IOException> cacher = cache.cacheNodes(MAIN)) {
InputNode[] batch = new InputNode[BATCH_SIZE];
for (int b = 0; b < BATCHES; b++) {
for (int i = 0; i < BATCH_SIZE; i++) {
InputNode node = randomNode(random);
batch[i] = node;
nodes.add(node);
}
cacher.receive(batch);
}
}
// WHEN/THEN
try (InputIterator<InputNode> reader = cache.nodes(MAIN, true).iterator()) {
reader.processors(50 - reader.processors(0));
Iterator<InputNode> expected = nodes.iterator();
while (expected.hasNext()) {
assertTrue(reader.hasNext());
InputNode expectedNode = expected.next();
InputNode node = reader.next();
assertNodesEquals(expectedNode, node);
}
assertFalse(reader.hasNext());
}
}
assertNoFilesLeftBehind();
}
Aggregations