Search in sources :

Example 1 with NetworkOperationFuture

use of org.bboxdb.network.client.future.NetworkOperationFuture in project bboxdb by jnidzwetzki.

the class BBoxDBConnection method handleResultPackage.

/**
 * Handle the next result package
 * @param packageHeader
 * @throws PackageEncodeException
 */
public void handleResultPackage(final ByteBuffer encodedPackage) throws PackageEncodeException {
    final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromResponsePackage(encodedPackage);
    final short packageType = NetworkPackageDecoder.getPackageTypeFromResponse(encodedPackage);
    NetworkOperationFuture future = null;
    synchronized (pendingCalls) {
        future = pendingCalls.get(Short.valueOf(sequenceNumber));
    }
    if (!serverResponseHandler.containsKey(packageType)) {
        logger.error("Unknown respose package type: {}", packageType);
        removeFutureAndReleaseSequencenumber(sequenceNumber);
        if (future != null) {
            future.setFailedState();
            future.fireCompleteEvent();
        }
    } else {
        final ServerResponseHandler handler = serverResponseHandler.get(packageType);
        final boolean removeFuture = handler.handleServerResult(this, encodedPackage, future);
        // Remove pending call
        if (removeFuture) {
            removeFutureAndReleaseSequencenumber(sequenceNumber);
        }
    }
}
Also used : ServerResponseHandler(org.bboxdb.network.client.response.ServerResponseHandler) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture)

Example 2 with NetworkOperationFuture

use of org.bboxdb.network.client.future.NetworkOperationFuture in project bboxdb by jnidzwetzki.

the class TestFuture method testOneRetry1.

@Test(timeout = 60000)
public void testOneRetry1() throws InterruptedException {
    final NetworkOperationFuture networkFuture = getFailingNetworkFuture();
    final OperationFutureImpl<Boolean> future = new OperationFutureImpl<>(networkFuture, FutureRetryPolicy.RETRY_POLICY_ONE_FUTURE);
    future.waitForAll();
    Assert.assertTrue(future.isDone());
    Assert.assertTrue(future.isFailed());
    Assert.assertEquals(OperationFuture.TOTAL_RETRIES + 1, networkFuture.getExecutions());
}
Also used : NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) OperationFutureImpl(org.bboxdb.network.client.future.OperationFutureImpl) Test(org.junit.Test)

Example 3 with NetworkOperationFuture

use of org.bboxdb.network.client.future.NetworkOperationFuture in project bboxdb by jnidzwetzki.

the class TestFuture method testNoRetry2.

@Test(timeout = 60000)
public void testNoRetry2() throws InterruptedException {
    final NetworkOperationFuture networkFuture1 = getFailingNetworkFuture();
    final NetworkOperationFuture networkFuture2 = getReadyNetworkFuture();
    final Supplier<List<NetworkOperationFuture>> supplier = () -> (Arrays.asList(networkFuture1, networkFuture2));
    final OperationFutureImpl<Boolean> future = new OperationFutureImpl<>(supplier, FutureRetryPolicy.RETRY_POLICY_NONE);
    future.waitForAll();
    Assert.assertTrue(future.isDone());
    Assert.assertTrue(future.isFailed());
    Assert.assertEquals(1, networkFuture1.getExecutions());
    Assert.assertEquals(1, networkFuture2.getExecutions());
}
Also used : NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) OperationFutureImpl(org.bboxdb.network.client.future.OperationFutureImpl) List(java.util.List) Test(org.junit.Test)

Example 4 with NetworkOperationFuture

use of org.bboxdb.network.client.future.NetworkOperationFuture in project bboxdb by jnidzwetzki.

the class TestFuture method testAllRetry1.

@Test(timeout = 60000)
public void testAllRetry1() throws InterruptedException {
    final NetworkOperationFuture networkFuture = getFailingNetworkFuture();
    final Supplier<List<NetworkOperationFuture>> supplier = () -> (Arrays.asList(networkFuture));
    final OperationFutureImpl<Boolean> future = new OperationFutureImpl<>(supplier, FutureRetryPolicy.RETRY_POLICY_ALL_FUTURES);
    future.waitForAll();
    Assert.assertTrue(future.isDone());
    Assert.assertTrue(future.isFailed());
    Assert.assertEquals(OperationFuture.TOTAL_RETRIES + 1, networkFuture.getExecutions());
}
Also used : NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) OperationFutureImpl(org.bboxdb.network.client.future.OperationFutureImpl) List(java.util.List) Test(org.junit.Test)

Example 5 with NetworkOperationFuture

use of org.bboxdb.network.client.future.NetworkOperationFuture in project bboxdb by jnidzwetzki.

the class TestFixedFutureStore method testTupleStore3.

/**
 * Add more futures in failed state and count failed callbacks
 * @throws InterruptedException
 */
@Test(timeout = 5000)
public void testTupleStore3() throws InterruptedException {
    final FixedSizeFutureStore futureStore = new FixedSizeFutureStore(10);
    final AtomicInteger atomicInteger = new AtomicInteger(0);
    futureStore.addFailedFutureCallback(c -> {
        atomicInteger.incrementAndGet();
    });
    for (int i = 0; i < 20; i++) {
        final NetworkOperationFuture networkOperationFuture = TestFuture.getFailingNetworkFuture();
        final EmptyResultFuture future = new EmptyResultFuture(networkOperationFuture);
        futureStore.put(future);
    }
    futureStore.waitForCompletion();
    Assert.assertTrue(true);
    Assert.assertEquals(20, atomicInteger.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) FixedSizeFutureStore(org.bboxdb.network.client.tools.FixedSizeFutureStore) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture) Test(org.junit.Test)

Aggregations

NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)31 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)16 List (java.util.List)12 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)12 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)11 DoNothingDuplicateResolver (org.bboxdb.storage.sstable.duplicateresolver.DoNothingDuplicateResolver)9 ArrayList (java.util.ArrayList)8 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)8 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)8 RoutingHop (org.bboxdb.network.routing.RoutingHop)8 Test (org.junit.Test)8 OperationFutureImpl (org.bboxdb.network.client.future.OperationFutureImpl)6 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)5 BBoxDBException (org.bboxdb.misc.BBoxDBException)4 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)3 BBoxDBConnection (org.bboxdb.network.client.BBoxDBConnection)2 NetworkRequestPackage (org.bboxdb.network.packages.NetworkRequestPackage)2 Tuple (org.bboxdb.storage.entity.Tuple)2 IOException (java.io.IOException)1 SocketException (java.net.SocketException)1