Search in sources :

Example 6 with Randoms

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();
}
Also used : Randoms(org.neo4j.test.Randoms) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Randoms (org.neo4j.test.Randoms)6 Random (java.util.Random)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Group (org.neo4j.unsafe.impl.batchimport.input.Group)2 SimpleInputIterator (org.neo4j.unsafe.impl.batchimport.input.SimpleInputIterator)2 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 MutableLong (org.apache.commons.lang3.mutable.MutableLong)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)1 InputNode (org.neo4j.unsafe.impl.batchimport.input.InputNode)1 InputRelationship (org.neo4j.unsafe.impl.batchimport.input.InputRelationship)1