Search in sources :

Example 1 with StandardIDPool

use of org.janusgraph.graphdb.database.idassigner.StandardIDPool in project janusgraph by JanusGraph.

the class IDPoolTest method testStandardIDPool1.

@Test
public void testStandardIDPool1() throws InterruptedException {
    final MockIDAuthority idAuthority = new MockIDAuthority(200);
    testIDPoolWith(partitionID -> new StandardIDPool(idAuthority, partitionID, partitionID, Integer.MAX_VALUE, Duration.ofMillis(2000L), 0.2), 1000, 6, 100000);
}
Also used : StandardIDPool(org.janusgraph.graphdb.database.idassigner.StandardIDPool) Test(org.junit.jupiter.api.Test)

Example 2 with StandardIDPool

use of org.janusgraph.graphdb.database.idassigner.StandardIDPool in project janusgraph by JanusGraph.

the class IDPoolTest method testAllocationTimeout.

@Test
public void testAllocationTimeout() {
    final MockIDAuthority idAuthority = new MockIDAuthority(10000, Integer.MAX_VALUE, 5000);
    StandardIDPool pool = new StandardIDPool(idAuthority, 1, 1, Integer.MAX_VALUE, Duration.ofMillis(4000), 0.1);
    assertThrows(JanusGraphException.class, pool::nextID);
}
Also used : StandardIDPool(org.janusgraph.graphdb.database.idassigner.StandardIDPool) Test(org.junit.jupiter.api.Test)

Example 3 with StandardIDPool

use of org.janusgraph.graphdb.database.idassigner.StandardIDPool in project janusgraph by JanusGraph.

the class IDPoolTest method testPoolExhaustion2.

@Test
public void testPoolExhaustion2() {
    int idUpper = 10000;
    MockIDAuthority idAuthority = new MockIDAuthority(200, idUpper);
    StandardIDPool pool = new StandardIDPool(idAuthority, 0, 1, Integer.MAX_VALUE, Duration.ofMillis(2000), 0.2);
    for (int i = 1; i < idUpper * 2; i++) {
        try {
            long id = pool.nextID();
            assertTrue(id < idUpper);
        } catch (IDPoolExhaustedException e) {
            assertEquals(idUpper, i);
            break;
        }
    }
}
Also used : StandardIDPool(org.janusgraph.graphdb.database.idassigner.StandardIDPool) IDPoolExhaustedException(org.janusgraph.graphdb.database.idassigner.IDPoolExhaustedException) Test(org.junit.jupiter.api.Test)

Example 4 with StandardIDPool

use of org.janusgraph.graphdb.database.idassigner.StandardIDPool in project janusgraph by JanusGraph.

the class IDPoolTest method testStandardIDPool3.

@Test
public void testStandardIDPool3() throws InterruptedException {
    final MockIDAuthority idAuthority = new MockIDAuthority(200);
    testIDPoolWith(partitionID -> new StandardIDPool(idAuthority, partitionID, partitionID, Integer.MAX_VALUE, Duration.ofMillis(2000), 0.2), 10, 20, 100000);
}
Also used : StandardIDPool(org.janusgraph.graphdb.database.idassigner.StandardIDPool) Test(org.junit.jupiter.api.Test)

Example 5 with StandardIDPool

use of org.janusgraph.graphdb.database.idassigner.StandardIDPool in project janusgraph by JanusGraph.

the class IDPoolTest method testIDPoolWith.

private void testIDPoolWith(IDPoolFactory poolFactory, final int numPartitions, final int numThreads, final int attemptsPerThread) throws InterruptedException {
    final Random random = new Random();
    final IntSet[] ids = new IntSet[numPartitions];
    final StandardIDPool[] idPools = new StandardIDPool[numPartitions];
    for (int i = 0; i < numPartitions; i++) {
        ids[i] = new IntHashSet(attemptsPerThread * numThreads / numPartitions);
        int partition = i * 100;
        idPools[i] = poolFactory.get(partition);
    }
    Thread[] threads = new Thread[numThreads];
    for (int i = 0; i < numThreads; i++) {
        threads[i] = new Thread(() -> {
            for (int attempt = 0; attempt < attemptsPerThread; attempt++) {
                int offset = random.nextInt(numPartitions);
                long id = idPools[offset].nextID();
                assertTrue(id < Integer.MAX_VALUE);
                IntSet idSet = ids[offset];
                synchronized (idSet) {
                    assertFalse(idSet.contains((int) id));
                    idSet.add((int) id);
                }
            }
        });
        threads[i].start();
    }
    for (int i = 0; i < numThreads; i++) threads[i].join();
    for (final StandardIDPool idPool : idPools) idPool.close();
    // Verify consecutive id assignment
    for (int i = 0; i < ids.length; i++) {
        IntSet set = ids[i];
        int max = 0;
        int[] all = set.getAll();
        for (int id : all) if (id > max)
            max = id;
        for (int j = 1; j <= max; j++) assertTrue(set.contains(j), i + " contains: " + j);
    }
}
Also used : StandardIDPool(org.janusgraph.graphdb.database.idassigner.StandardIDPool) Random(java.util.Random) IntSet(org.janusgraph.graphdb.util.IntSet) IntHashSet(org.janusgraph.graphdb.util.IntHashSet)

Aggregations

StandardIDPool (org.janusgraph.graphdb.database.idassigner.StandardIDPool)8 Test (org.junit.jupiter.api.Test)7 IDPoolExhaustedException (org.janusgraph.graphdb.database.idassigner.IDPoolExhaustedException)2 Duration (java.time.Duration)1 List (java.util.List)1 Random (java.util.Random)1 IMocksControl (org.easymock.IMocksControl)1 BackendException (org.janusgraph.diskstorage.BackendException)1 IDAuthority (org.janusgraph.diskstorage.IDAuthority)1 IDBlock (org.janusgraph.diskstorage.IDBlock)1 TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)1 IDBlockSizer (org.janusgraph.graphdb.database.idassigner.IDBlockSizer)1 IntHashSet (org.janusgraph.graphdb.util.IntHashSet)1 IntSet (org.janusgraph.graphdb.util.IntSet)1