Search in sources :

Example 1 with RequestFormatFactory

use of voldemort.client.protocol.RequestFormatFactory in project voldemort by voldemort.

the class HttpStoreTest method testBadUrlOrPort.

public <T extends Exception> void testBadUrlOrPort(String url, int port, Class<T> expected) {
    ByteArray key = new ByteArray("test".getBytes());
    RequestFormat requestFormat = new RequestFormatFactory().getRequestFormat(RequestFormatType.VOLDEMORT_V1);
    HttpParams clientParams = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(clientParams, 5000);
    HttpStore badUrlHttpStore = new HttpStore("test", url, port, httpClient, requestFormat, false);
    try {
        badUrlHttpStore.put(key, new Versioned<byte[]>("value".getBytes(), new VectorClock()), null);
    } catch (Exception e) {
        assertTrue(e.getClass().equals(expected));
    }
    try {
        badUrlHttpStore.get(key, null);
    } catch (Exception e) {
        assertTrue(e.getClass().equals(expected));
    }
    try {
        badUrlHttpStore.delete(key, new VectorClock());
    } catch (Exception e) {
        assertTrue(e.getClass().equals(expected));
    }
}
Also used : RequestFormatFactory(voldemort.client.protocol.RequestFormatFactory) HttpParams(org.apache.http.params.HttpParams) RequestFormat(voldemort.client.protocol.RequestFormat) VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray) UnreachableStoreException(voldemort.store.UnreachableStoreException)

Example 2 with RequestFormatFactory

use of voldemort.client.protocol.RequestFormatFactory 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 3 with RequestFormatFactory

use of voldemort.client.protocol.RequestFormatFactory in project voldemort by voldemort.

the class RemoteStoreComparisonTest method main.

public static void main(String[] args) throws Exception {
    if (args.length != 2)
        Utils.croak("USAGE: java " + RemoteStoreComparisonTest.class.getName() + " numRequests numThreads [useNio]");
    int numRequests = Integer.parseInt(args[0]);
    int numThreads = Integer.parseInt(args[1]);
    boolean useNio = args.length > 2 ? args[2].equals("true") : false;
    /** * In memory test ** */
    final Store<byte[], byte[], byte[]> memStore = new InMemoryStorageEngine<byte[], byte[], byte[]>("test");
    PerformanceTest memWriteTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            byte[] key = String.valueOf(i).getBytes();
            memStore.put(key, new Versioned<byte[]>(key), null);
        }
    };
    System.out.println("###########################################");
    System.out.println("Performing memory write test.");
    memWriteTest.run(numRequests, numThreads);
    memWriteTest.printStats();
    System.out.println();
    PerformanceTest memReadTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            try {
                memStore.get(String.valueOf(i).getBytes(), null);
            } catch (Exception e) {
                System.out.println("Failure on i = " + i);
                e.printStackTrace();
            }
        }
    };
    System.out.println("Performing memory read test.");
    memReadTest.run(numRequests, numThreads);
    memReadTest.printStats();
    System.out.println();
    System.out.println();
    /** * Do Socket tests ** */
    String storeName = "test";
    StoreRepository repository = new StoreRepository();
    repository.addLocalStore(new InMemoryStorageEngine<ByteArray, byte[], byte[]>(storeName));
    SocketStoreFactory storeFactory = new ClientRequestExecutorPool(10, 1000, 1000, 32 * 1024);
    final Store<ByteArray, byte[], byte[]> socketStore = storeFactory.create(storeName, "localhost", 6666, RequestFormatType.VOLDEMORT_V1, RequestRoutingType.NORMAL);
    RequestHandlerFactory factory = ServerTestUtils.getSocketRequestHandlerFactory(repository);
    AbstractSocketService socketService = ServerTestUtils.getSocketService(useNio, factory, 6666, 50, 50, 1000);
    socketService.start();
    PerformanceTest socketWriteTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            byte[] bytes = String.valueOf(i).getBytes();
            ByteArray key = new ByteArray(bytes);
            socketStore.put(key, new Versioned<byte[]>(bytes), null);
        }
    };
    System.out.println("###########################################");
    System.out.println("Performing socket write test.");
    socketWriteTest.run(numRequests, numThreads);
    socketWriteTest.printStats();
    System.out.println();
    PerformanceTest socketReadTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            try {
                socketStore.get(TestUtils.toByteArray(String.valueOf(i)), null);
            } catch (Exception e) {
                System.out.println("Failure on i = " + i);
                e.printStackTrace();
            }
        }
    };
    System.out.println("Performing socket read test.");
    socketReadTest.run(numRequests, 1);
    socketReadTest.printStats();
    System.out.println();
    System.out.println();
    socketStore.close();
    storeFactory.close();
    socketService.stop();
    /** * Do HTTP tests ** */
    repository.addLocalStore(new InMemoryStorageEngine<ByteArray, byte[], byte[]>(storeName));
    HttpService httpService = new HttpService(null, null, repository, RequestFormatType.VOLDEMORT_V0, numThreads, 8080);
    httpService.start();
    ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(), 10000, TimeUnit.MILLISECONDS);
    DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);
    HttpParams clientParams = httpClient.getParams();
    httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
    HttpClientParams.setCookiePolicy(clientParams, CookiePolicy.IGNORE_COOKIES);
    HttpProtocolParams.setUserAgent(clientParams, "test-agent");
    HttpProtocolParams.setVersion(clientParams, HttpVersion.HTTP_1_1);
    HttpConnectionParams.setConnectionTimeout(clientParams, 10000);
    connectionManager.setMaxTotal(numThreads);
    connectionManager.setDefaultMaxPerRoute(numThreads);
    HttpConnectionParams.setStaleCheckingEnabled(clientParams, false);
    final HttpStore httpStore = new HttpStore("test", "localhost", 8080, httpClient, new RequestFormatFactory().getRequestFormat(RequestFormatType.VOLDEMORT_V0), false);
    Thread.sleep(400);
    PerformanceTest httpWriteTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            byte[] key = String.valueOf(i).getBytes();
            httpStore.put(new ByteArray(key), new Versioned<byte[]>(key), null);
        }
    };
    System.out.println("###########################################");
    System.out.println("Performing HTTP write test.");
    httpWriteTest.run(numRequests, numThreads);
    httpWriteTest.printStats();
    System.out.println();
    PerformanceTest httpReadTest = new PerformanceTest() {

        @Override
        public void doOperation(int i) {
            httpStore.get(new ByteArray(String.valueOf(i).getBytes()), null);
        }
    };
    System.out.println("Performing HTTP read test.");
    httpReadTest.run(numRequests, numThreads);
    httpReadTest.printStats();
    httpService.stop();
    VoldemortIOUtils.closeQuietly(httpClient);
}
Also used : RequestFormatFactory(voldemort.client.protocol.RequestFormatFactory) RequestHandlerFactory(voldemort.server.protocol.RequestHandlerFactory) DefaultHttpRequestRetryHandler(org.apache.http.impl.client.DefaultHttpRequestRetryHandler) StoreRepository(voldemort.server.StoreRepository) SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpParams(org.apache.http.params.HttpParams) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) InMemoryStorageEngine(voldemort.store.memory.InMemoryStorageEngine) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) HttpService(voldemort.server.http.HttpService) HttpStore(voldemort.store.http.HttpStore) ByteArray(voldemort.utils.ByteArray) AbstractSocketService(voldemort.server.AbstractSocketService)

Aggregations

RequestFormatFactory (voldemort.client.protocol.RequestFormatFactory)3 ByteArray (voldemort.utils.ByteArray)3 HttpParams (org.apache.http.params.HttpParams)2 UnreachableStoreException (voldemort.store.UnreachableStoreException)2 ClientRequestExecutorPool (voldemort.store.socket.clientrequest.ClientRequestExecutorPool)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)1 DefaultHttpRequestRetryHandler (org.apache.http.impl.client.DefaultHttpRequestRetryHandler)1 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)1 Test (org.junit.Test)1 RequestFormat (voldemort.client.protocol.RequestFormat)1 AbstractSocketService (voldemort.server.AbstractSocketService)1 StoreRepository (voldemort.server.StoreRepository)1 HttpService (voldemort.server.http.HttpService)1 RequestHandlerFactory (voldemort.server.protocol.RequestHandlerFactory)1 HttpStore (voldemort.store.http.HttpStore)1 InMemoryStorageEngine (voldemort.store.memory.InMemoryStorageEngine)1 NonblockingStoreCallback (voldemort.store.nonblockingstore.NonblockingStoreCallback)1 SocketStoreFactory (voldemort.store.socket.SocketStoreFactory)1 GetClientRequest (voldemort.store.socket.clientrequest.GetClientRequest)1