Search in sources :

Example 11 with TemporaryBackendException

use of org.janusgraph.diskstorage.TemporaryBackendException in project janusgraph by JanusGraph.

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() {
            throw new IllegalArgumentException();
        }

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

        @Override
        public void close() {
            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 (JanusGraphException ignored) {
    }
    long nextID = pool.nextID();
    assertEquals(200, nextID);
    ctrl.verify();
}
Also used : IDBlockSizer(org.janusgraph.graphdb.database.idassigner.IDBlockSizer) JanusGraphException(org.janusgraph.core.JanusGraphException) Duration(java.time.Duration) BackendException(org.janusgraph.diskstorage.BackendException) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) IMocksControl(org.easymock.IMocksControl) StandardIDPool(org.janusgraph.graphdb.database.idassigner.StandardIDPool) TemporaryBackendException(org.janusgraph.diskstorage.TemporaryBackendException) IDAuthority(org.janusgraph.diskstorage.IDAuthority) IDBlock(org.janusgraph.diskstorage.IDBlock) List(java.util.List) Test(org.junit.Test)

Aggregations

TemporaryBackendException (org.janusgraph.diskstorage.TemporaryBackendException)11 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)5 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)5 IOException (java.io.IOException)4 ByteBuffer (java.nio.ByteBuffer)3 List (java.util.List)3 BackendException (org.janusgraph.diskstorage.BackendException)3 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 KeyspaceDefinition (com.netflix.astyanax.ddl.KeyspaceDefinition)2 Rows (com.netflix.astyanax.model.Rows)2 RowSliceQuery (com.netflix.astyanax.query.RowSliceQuery)2 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)2 Cluster (com.netflix.astyanax.Cluster)1 MutationBatch (com.netflix.astyanax.MutationBatch)1 ColumnFamilyDefinition (com.netflix.astyanax.ddl.ColumnFamilyDefinition)1