Search in sources :

Example 1 with GetClientRequest

use of voldemort.store.socket.clientrequest.GetClientRequest in project voldemort by voldemort.

the class ClientRequestExecutorPoolTest method testCloseWithOutstandingQueue.

@Test
public void testCloseWithOutstandingQueue() {
    final int MAX_CONNECTIONS = 2;
    ClientRequestExecutorPool execPool = new ClientRequestExecutorPool(2, MAX_CONNECTIONS, CONNECTION_TIMEOUT_MS, SOCKET_TIMEOUT_MS, IDLE_CONNECTION_TIMEOUT_MS, 32 * 1024, false, true, new String());
    // will always wait in the queue.
    for (int i = 0; i < MAX_CONNECTIONS; i++) {
        execPool.checkout(dest1);
    }
    for (int j = 0; j < 2; j++) {
        GetClientRequest clientRequest = new GetClientRequest("sampleStore", new RequestFormatFactory().getRequestFormat(dest1.getRequestFormatType()), RequestRoutingType.ROUTED, new ByteArray(new byte[] { 1, 2, 3 }), null);
        final AtomicInteger cancelledEvents = new AtomicInteger(0);
        NonblockingStoreCallback callback = new NonblockingStoreCallback() {

            @Override
            public void requestComplete(Object result, long requestTime) {
                if (result instanceof UnreachableStoreException)
                    cancelledEvents.incrementAndGet();
                else
                    fail("The request must have failed with UnreachableException" + result);
            }
        };
        int queuedRequestCount = 20;
        for (int i = 0; i < queuedRequestCount; i++) {
            execPool.submitAsync(dest1, clientRequest, callback, 5000, "get");
        }
        int outstandingQueue = execPool.internalGetQueuedPool().getRegisteredResourceRequestCount(dest1);
        assertEquals("Queued request count should match", queuedRequestCount, outstandingQueue);
        // Now reset the queue, the outstanding requests should fail with
        // UnreachableStoreException
        execPool.close(dest1);
        outstandingQueue = execPool.internalGetQueuedPool().getRegisteredResourceRequestCount(dest1);
        assertEquals("Queued request should have been cleared", 0, outstandingQueue);
        // CancelledEvents should be
        assertEquals("All Queuedrequest must have been cancelled.", queuedRequestCount, cancelledEvents.get());
    }
}
Also used : RequestFormatFactory(voldemort.client.protocol.RequestFormatFactory) GetClientRequest(voldemort.store.socket.clientrequest.GetClientRequest) NonblockingStoreCallback(voldemort.store.nonblockingstore.NonblockingStoreCallback) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArray(voldemort.utils.ByteArray) UnreachableStoreException(voldemort.store.UnreachableStoreException) Test(org.junit.Test)

Example 2 with GetClientRequest

use of voldemort.store.socket.clientrequest.GetClientRequest in project voldemort by voldemort.

the class SocketStore method submitGetRequest.

@Override
public void submitGetRequest(ByteArray key, byte[] transforms, NonblockingStoreCallback callback, long timeoutMs) {
    StoreUtils.assertValidKey(key);
    GetClientRequest clientRequest = new GetClientRequest(getName(), requestFormat, requestRoutingType, key, transforms);
    if (logger.isDebugEnabled())
        logger.debug("GET keyRef: " + System.identityHashCode(key) + " requestRef: " + System.identityHashCode(clientRequest));
    requestAsync(clientRequest, callback, timeoutMs, "get");
}
Also used : GetClientRequest(voldemort.store.socket.clientrequest.GetClientRequest)

Example 3 with GetClientRequest

use of voldemort.store.socket.clientrequest.GetClientRequest in project voldemort by voldemort.

the class SocketStore method get.

@Override
public List<Versioned<byte[]>> get(ByteArray key, byte[] transforms) throws VoldemortException {
    StoreUtils.assertValidKey(key);
    GetClientRequest clientRequest = new GetClientRequest(getName(), requestFormat, requestRoutingType, key, transforms);
    if (logger.isDebugEnabled())
        logger.debug("GET keyRef: " + System.identityHashCode(key) + " requestRef: " + System.identityHashCode(clientRequest));
    return request(clientRequest, "get");
}
Also used : GetClientRequest(voldemort.store.socket.clientrequest.GetClientRequest)

Aggregations

GetClientRequest (voldemort.store.socket.clientrequest.GetClientRequest)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1 RequestFormatFactory (voldemort.client.protocol.RequestFormatFactory)1 UnreachableStoreException (voldemort.store.UnreachableStoreException)1 NonblockingStoreCallback (voldemort.store.nonblockingstore.NonblockingStoreCallback)1 ClientRequestExecutorPool (voldemort.store.socket.clientrequest.ClientRequestExecutorPool)1 ByteArray (voldemort.utils.ByteArray)1