Search in sources :

Example 6 with IDPoolExhaustedException

use of com.thinkaurelius.titan.graphdb.database.idassigner.IDPoolExhaustedException in project titan by thinkaurelius.

the class IDPoolTest method testPoolExhaustion2.

@Test
public void testPoolExhaustion2() {
    int idUpper = 10000;
    MockIDAuthority idauth = new MockIDAuthority(200, idUpper);
    StandardIDPool pool = new StandardIDPool(idauth, 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(com.thinkaurelius.titan.graphdb.database.idassigner.StandardIDPool) IDPoolExhaustedException(com.thinkaurelius.titan.graphdb.database.idassigner.IDPoolExhaustedException) Test(org.junit.Test)

Example 7 with IDPoolExhaustedException

use of com.thinkaurelius.titan.graphdb.database.idassigner.IDPoolExhaustedException in project titan by thinkaurelius.

the class VertexIDAssignerTest method testIDAssignment.

@Test
public void testIDAssignment() {
    LongSet vertexIds = new LongHashSet();
    LongSet relationIds = new LongHashSet();
    int totalRelations = 0;
    int totalVertices = 0;
    for (int trial = 0; trial < 10; trial++) {
        for (boolean flush : new boolean[] { true, false }) {
            TitanGraph graph = getInMemoryGraph();
            int numVertices = 1000;
            List<TitanVertex> vertices = new ArrayList<TitanVertex>(numVertices);
            List<InternalRelation> relations = new ArrayList<InternalRelation>();
            TitanVertex old = null;
            totalRelations += 2 * numVertices;
            totalVertices += numVertices;
            try {
                for (int i = 0; i < numVertices; i++) {
                    TitanVertex next = graph.addVertex();
                    InternalRelation edge = null;
                    if (old != null) {
                        edge = (InternalRelation) old.addEdge("knows", next);
                    }
                    InternalRelation property = (InternalRelation) next.property("age", 25);
                    if (flush) {
                        idAssigner.assignID((InternalVertex) next, next.vertexLabel());
                        idAssigner.assignID(property);
                        if (edge != null)
                            idAssigner.assignID(edge);
                    }
                    relations.add(property);
                    if (edge != null)
                        relations.add(edge);
                    vertices.add(next);
                    old = next;
                }
                if (!flush)
                    idAssigner.assignIDs(relations);
                //Check if we should have exhausted the id pools
                if (totalRelations > maxIDAssignments || totalVertices > maxIDAssignments)
                    fail();
                //Verify that ids are set and unique
                for (TitanVertex v : vertices) {
                    assertTrue(v.hasId());
                    long id = v.longId();
                    assertTrue(id > 0 && id < Long.MAX_VALUE);
                    assertTrue(vertexIds.add(id));
                }
                for (InternalRelation r : relations) {
                    assertTrue(r.hasId());
                    long id = r.longId();
                    assertTrue(id > 0 && id < Long.MAX_VALUE);
                    assertTrue(relationIds.add(id));
                }
            } catch (IDPoolExhaustedException e) {
                //Since the id assignment process is randomized, we divide by 3/2 to account for minor variations
                assertTrue("Max Avail: " + maxIDAssignments + " vs. [" + totalVertices + "," + totalRelations + "]", totalRelations >= maxIDAssignments / 3 * 2 || totalVertices >= maxIDAssignments / 3 * 2);
            } finally {
                graph.tx().rollback();
                graph.close();
            }
        }
    }
}
Also used : TitanGraph(com.thinkaurelius.titan.core.TitanGraph) LongHashSet(com.carrotsearch.hppc.LongHashSet) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) LongSet(com.carrotsearch.hppc.LongSet) ArrayList(java.util.ArrayList) IDPoolExhaustedException(com.thinkaurelius.titan.graphdb.database.idassigner.IDPoolExhaustedException) InternalRelation(com.thinkaurelius.titan.graphdb.internal.InternalRelation) Test(org.junit.Test)

Example 8 with IDPoolExhaustedException

use of com.thinkaurelius.titan.graphdb.database.idassigner.IDPoolExhaustedException in project titan by thinkaurelius.

the class IDAuthorityTest method testIDExhaustion.

@Test
public void testIDExhaustion() throws BackendException {
    final int chunks = 30;
    final IDBlockSizer blockSizer = new IDBlockSizer() {

        @Override
        public long getBlockSize(int idNamespace) {
            return ((1l << (idUpperBoundBitWidth - uidBitWidth)) - 1) / chunks;
        }

        @Override
        public long getIdUpperBound(int idNamespace) {
            return idUpperBound;
        }
    };
    idAuthorities[0].setIDBlockSizer(blockSizer);
    if (hasFixedUid) {
        for (int i = 0; i < chunks; i++) {
            idAuthorities[0].getIDBlock(0, 0, GET_ID_BLOCK_TIMEOUT);
        }
        try {
            idAuthorities[0].getIDBlock(0, 0, GET_ID_BLOCK_TIMEOUT);
            Assert.fail();
        } catch (IDPoolExhaustedException e) {
        }
    } else {
        for (int i = 0; i < (chunks * Math.max(1, (1 << uidBitWidth) / 10)); i++) {
            idAuthorities[0].getIDBlock(0, 0, GET_ID_BLOCK_TIMEOUT);
        }
        try {
            for (int i = 0; i < (chunks * Math.max(1, (1 << uidBitWidth) * 9 / 10)); i++) {
                idAuthorities[0].getIDBlock(0, 0, GET_ID_BLOCK_TIMEOUT);
            }
            Assert.fail();
        } catch (IDPoolExhaustedException e) {
        }
    }
}
Also used : IDBlockSizer(com.thinkaurelius.titan.graphdb.database.idassigner.IDBlockSizer) IDPoolExhaustedException(com.thinkaurelius.titan.graphdb.database.idassigner.IDPoolExhaustedException) Test(org.junit.Test)

Aggregations

IDPoolExhaustedException (com.thinkaurelius.titan.graphdb.database.idassigner.IDPoolExhaustedException)8 Test (org.junit.Test)4 StandardIDPool (com.thinkaurelius.titan.graphdb.database.idassigner.StandardIDPool)2 ArrayList (java.util.ArrayList)2 LongHashSet (com.carrotsearch.hppc.LongHashSet)1 LongSet (com.carrotsearch.hppc.LongSet)1 TitanGraph (com.thinkaurelius.titan.core.TitanGraph)1 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)1 TitanVertexProperty (com.thinkaurelius.titan.core.TitanVertexProperty)1 KeySliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)1 StoreTransaction (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction)1 TemporaryLockingException (com.thinkaurelius.titan.diskstorage.locking.TemporaryLockingException)1 IDBlockSizer (com.thinkaurelius.titan.graphdb.database.idassigner.IDBlockSizer)1 InternalRelation (com.thinkaurelius.titan.graphdb.internal.InternalRelation)1 Duration (java.time.Duration)1 List (java.util.List)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1