Search in sources :

Example 6 with StandardIDPool

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

the class IDPoolTest method testStandardIDPool2.

@Test
public void testStandardIDPool2() throws InterruptedException {
    final MockIDAuthority idauth = new MockIDAuthority(10000, Integer.MAX_VALUE, 2000);
    testIDPoolWith(new IDPoolFactory() {

        @Override
        public StandardIDPool get(int partitionID) {
            return new StandardIDPool(idauth, partitionID, partitionID, Integer.MAX_VALUE, Duration.ofMillis(4000), 0.1);
        }
    }, 2, 5, 10000);
}
Also used : StandardIDPool(com.thinkaurelius.titan.graphdb.database.idassigner.StandardIDPool) Test(org.junit.Test)

Example 7 with StandardIDPool

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

the class IDPoolTest method testAllocationTimeoutAndRecovery.

@Test
public void testAllocationTimeoutAndRecovery() throws BackendException {
    IMocksControl ctrl = EasyMock.createStrictControl();
    final int partition = 42;
    final int idNamespace = 777;
    final Duration timeout = Duration.ofSeconds(1L);
    final IDAuthority mockAuthority = ctrl.createMock(IDAuthority.class);
    // Sleep for two seconds, then throw a backendexception
    // this whole delegate could be deleted if we abstracted StandardIDPool's internal executor and stopwatches
    expect(mockAuthority.getIDBlock(partition, idNamespace, timeout)).andDelegateTo(new IDAuthority() {

        @Override
        public IDBlock getIDBlock(int partition, int idNamespace, Duration timeout) throws BackendException {
            try {
                Thread.sleep(2000L);
            } catch (InterruptedException e) {
                fail();
            }
            throw new TemporaryBackendException("slow backend");
        }

        @Override
        public List<KeyRange> getLocalIDPartition() throws BackendException {
            throw new IllegalArgumentException();
        }

        @Override
        public void setIDBlockSizer(IDBlockSizer sizer) {
            throw new IllegalArgumentException();
        }

        @Override
        public void close() throws BackendException {
            throw new IllegalArgumentException();
        }

        @Override
        public String getUniqueID() {
            throw new IllegalArgumentException();
        }

        @Override
        public boolean supportsInterruption() {
            return true;
        }
    });
    expect(mockAuthority.getIDBlock(partition, idNamespace, timeout)).andReturn(new IDBlock() {

        @Override
        public long numIds() {
            return 2;
        }

        @Override
        public long getId(long index) {
            return 200;
        }
    });
    expect(mockAuthority.supportsInterruption()).andStubReturn(true);
    ctrl.replay();
    StandardIDPool pool = new StandardIDPool(mockAuthority, partition, idNamespace, Integer.MAX_VALUE, timeout, 0.1);
    try {
        pool.nextID();
        fail();
    } catch (TitanException e) {
    }
    long nextID = pool.nextID();
    assertEquals(200, nextID);
    ctrl.verify();
}
Also used : IDBlockSizer(com.thinkaurelius.titan.graphdb.database.idassigner.IDBlockSizer) Duration(java.time.Duration) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) IMocksControl(org.easymock.IMocksControl) StandardIDPool(com.thinkaurelius.titan.graphdb.database.idassigner.StandardIDPool) TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) IDAuthority(com.thinkaurelius.titan.diskstorage.IDAuthority) IDBlock(com.thinkaurelius.titan.diskstorage.IDBlock) TitanException(com.thinkaurelius.titan.core.TitanException) List(java.util.List) Test(org.junit.Test)

Example 8 with StandardIDPool

use of com.thinkaurelius.titan.graphdb.database.idassigner.StandardIDPool 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)

Aggregations

StandardIDPool (com.thinkaurelius.titan.graphdb.database.idassigner.StandardIDPool)8 Test (org.junit.Test)7 TitanException (com.thinkaurelius.titan.core.TitanException)2 IDPoolExhaustedException (com.thinkaurelius.titan.graphdb.database.idassigner.IDPoolExhaustedException)2 BackendException (com.thinkaurelius.titan.diskstorage.BackendException)1 IDAuthority (com.thinkaurelius.titan.diskstorage.IDAuthority)1 IDBlock (com.thinkaurelius.titan.diskstorage.IDBlock)1 TemporaryBackendException (com.thinkaurelius.titan.diskstorage.TemporaryBackendException)1 IDBlockSizer (com.thinkaurelius.titan.graphdb.database.idassigner.IDBlockSizer)1 IntHashSet (com.thinkaurelius.titan.util.datastructures.IntHashSet)1 IntSet (com.thinkaurelius.titan.util.datastructures.IntSet)1 Duration (java.time.Duration)1 List (java.util.List)1 Random (java.util.Random)1 IMocksControl (org.easymock.IMocksControl)1