Package voldemort.server

Examples of voldemort.server.AbstractSocketService


    }

    @Test
    public void testSocketPoolLimitSomeTimeout() throws Exception {
        // start a dummy server
        AbstractSocketService server = ServerTestUtils.getSocketService(useNio,
                                                                        new SocketRequestHandlerFactory(null,
                                                                                                        null,
                                                                                                        null,
                                                                                                        null,
                                                                                                        null,
                                                                                                        null,
                                                                                                        null),
                                                                        7666,
                                                                        50,
                                                                        50,
                                                                        1000);

        server.start();

        final ResourcePoolConfig config = new ResourcePoolConfig().setTimeout(50,
                                                                              TimeUnit.MILLISECONDS)
                                                                  .setMaxPoolSize(20);

        ResourceFactory<SocketDestination, SocketAndStreams> factory = ResourcePoolTestUtils.getSocketPoolFactory();
        final AbstractSocketPoolTest<SocketDestination, SocketAndStreams> test = new AbstractSocketPoolTest<SocketDestination, SocketAndStreams>() {

            @Override
            protected void doSomethingWithResource(SocketDestination key, SocketAndStreams resource)
                    throws Exception {
                Thread.sleep(100);
                int random = (int) (Math.random() * 10);
                if(random >= 5)
                    resource.getSocket().close();
            }

            @Override
            protected SocketDestination getRequestKey() throws Exception {
                return new SocketDestination("localhost", 7666, RequestFormatType.VOLDEMORT_V1);
            }

        };

        // borrow timeout >> doSomething() no timeout expected
        TestStats testStats = test.startTest(factory, config, 50, 200);
        assertEquals("We should see some timeoutRequests", true, testStats.timeoutRequests > 0);
        server.stop();
    }
View Full Code Here


    }

    @Test
    public void testClientRequestExecutorLimitSomeTimeout() throws Exception {
        // start a dummy server
        AbstractSocketService server = ServerTestUtils.getSocketService(useNio,
                                                                        new SocketRequestHandlerFactory(null,
                                                                                                        null,
                                                                                                        null,
                                                                                                        null,
                                                                                                        null,
                                                                                                        null,
                                                                                                        null),
                                                                        7666,
                                                                        50,
                                                                        50,
                                                                        1000);

        server.start();

        final ResourcePoolConfig config = new ResourcePoolConfig().setTimeout(50,
                                                                              TimeUnit.MILLISECONDS)
                                                                  .setMaxPoolSize(20);

        ClientRequestExecutorPool clientRequestExecutorPool = new ClientRequestExecutorPool(config.getMaxPoolSize(),
                                                                                            (int) config.getTimeout(TimeUnit.MILLISECONDS),
                                                                                            100,
                                                                                            1000);

        try {
            ResourceFactory<SocketDestination, ClientRequestExecutor> factory = clientRequestExecutorPool.getFactory();
            final AbstractSocketPoolTest<SocketDestination, ClientRequestExecutor> test = new AbstractSocketPoolTest<SocketDestination, ClientRequestExecutor>() {

                @Override
                protected void doSomethingWithResource(SocketDestination key,
                                                       ClientRequestExecutor resource)
                        throws Exception {
                    Thread.sleep(100);
                    int random = (int) (Math.random() * 10);
                    if(random >= 5)
                        resource.close();
                }

                @Override
                protected SocketDestination getRequestKey() throws Exception {
                    return new SocketDestination("localhost", 7666, RequestFormatType.VOLDEMORT_V1);
                }

            };

            // borrow timeout >> doSomething() no timeout expected
            TestStats testStats = test.startTest(factory, config, 50, 200);
            assertEquals("We should see some timeoutRequests", true, testStats.timeoutRequests > 0);
            server.stop();
        } finally {
            clientRequestExecutorPool.close();
        }
    }
View Full Code Here

        int freePort = ServerTestUtils.findFreePort();
        String clusterXml = VoldemortTestConstants.getOneNodeClusterXml();
        clusterXml = clusterXml.replace("<socket-port>6666</socket-port>", "<socket-port>"
                                                                           + freePort
                                                                           + "</socket-port>");
        AbstractSocketService socketService = ServerTestUtils.getSocketService(useNio,
                                                                               clusterXml,
                                                                               VoldemortTestConstants.getCompressedStoreDefinitionsXml(),
                                                                               "test",
                                                                               freePort);
        socketService.start();

        Thread.sleep(1000);

        SocketStoreClientFactory storeClientFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls("tcp://localhost:"
                                                                                                                       + freePort)
                                                                                                     .setMaxBootstrapRetries(10));
        StoreClient<String, String> storeClient = storeClientFactory.getStoreClient("test");
        storeClient.put("someKey", "someValue");
        assertEquals(storeClient.getValue("someKey"), "someValue");
        socketService.stop();
    }
View Full Code Here

                                                                                 "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,
View Full Code Here

                                                         RequestHandlerFactory requestHandlerFactory,
                                                         int port,
                                                         int coreConnections,
                                                         int maxConnections,
                                                         int bufferSize) {
        AbstractSocketService socketService = null;

        if(useNio) {
            socketService = new NioSocketService(requestHandlerFactory,
                                                 port,
                                                 bufferSize,
View Full Code Here

TOP

Related Classes of voldemort.server.AbstractSocketService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.