Search in sources :

Example 31 with IdGenerator

use of org.neo4j.kernel.impl.store.id.IdGenerator in project neo4j by neo4j.

the class IdGeneratorTest method testChurnIdBatchAtGrabSize.

@Test
public void testChurnIdBatchAtGrabSize() {
    IdGenerator idGenerator = null;
    try {
        IdGeneratorImpl.createGenerator(fs, idGeneratorFile(), 0, false);
        final int grabSize = 10, rounds = 10;
        idGenerator = new IdGeneratorImpl(fs, idGeneratorFile(), grabSize, 1000, true, 0);
        for (int i = 0; i < rounds; i++) {
            Set<Long> ids = new HashSet<>();
            for (int j = 0; j < grabSize; j++) {
                ids.add(idGenerator.nextId());
            }
            for (Long id : ids) {
                idGenerator.freeId(id);
            }
        }
        long newId = idGenerator.nextId();
        assertTrue("Expected IDs to be reused (" + grabSize + " at a time). high ID was: " + newId, newId < grabSize * rounds);
    } finally {
        if (idGenerator != null) {
            closeIdGenerator(idGenerator);
        }
        File file = idGeneratorFile();
        if (file.exists()) {
            assertTrue(file.delete());
        }
    }
}
Also used : IdGeneratorImpl(org.neo4j.kernel.impl.store.id.IdGeneratorImpl) IdGenerator(org.neo4j.kernel.impl.store.id.IdGenerator) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

IdGenerator (org.neo4j.kernel.impl.store.id.IdGenerator)31 Test (org.junit.Test)24 File (java.io.File)15 IdGeneratorImpl (org.neo4j.kernel.impl.store.id.IdGeneratorImpl)14 IdType (org.neo4j.kernel.impl.store.id.IdType)8 RequestContext (org.neo4j.com.RequestContext)6 IdRange (org.neo4j.kernel.impl.store.id.IdRange)5 IdGeneratorFactory (org.neo4j.kernel.impl.store.id.IdGeneratorFactory)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 EphemeralIdGenerator (org.neo4j.test.impl.EphemeralIdGenerator)2 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Function (java.util.function.Function)1 Collectors.toSet (java.util.stream.Collectors.toSet)1