Search in sources :

Example 1 with SocketAndStreams

use of voldemort.client.protocol.admin.SocketAndStreams in project voldemort by voldemort.

the class SocketPoolTest method testTwoCheckoutsGetTheSameSocket.

@Test
public void testTwoCheckoutsGetTheSameSocket() throws Exception {
    SocketAndStreams sas1 = pool.checkout(dest1);
    pool.checkin(dest1, sas1);
    System.out.println("Socket 1" + sas1.getSocket());
    SocketAndStreams sas2 = pool.checkout(dest1);
    System.out.println("Socket 2" + sas2.getSocket());
    assertTrue(sas1 == sas2);
}
Also used : SocketAndStreams(voldemort.client.protocol.admin.SocketAndStreams) Test(org.junit.Test)

Example 2 with SocketAndStreams

use of voldemort.client.protocol.admin.SocketAndStreams in project voldemort by voldemort.

the class SocketPoolTest method testCloseWithInFlightSockets.

@Test
public void testCloseWithInFlightSockets() throws Exception {
    List<SocketAndStreams> list = new ArrayList<SocketAndStreams>();
    for (int i = 0; i < maxConnectionsPerNode; i++) list.add(pool.checkout(dest1));
    assertEquals(list.size(), pool.getNumberSocketsCreated());
    assertEquals(list.size(), pool.getNumberOfActiveConnections());
    pool.close(dest1);
    assertEquals(list.size(), pool.getNumberOfActiveConnections());
    assertEquals(0, pool.getNumberSocketsDestroyed());
    for (SocketAndStreams sas : list) pool.checkin(dest1, sas);
    assertEquals(0, pool.getNumberOfActiveConnections());
    assertEquals(list.size(), pool.getNumberSocketsDestroyed());
    assertEquals(0, pool.getNumberOfCheckedInConnections());
}
Also used : SocketAndStreams(voldemort.client.protocol.admin.SocketAndStreams) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with SocketAndStreams

use of voldemort.client.protocol.admin.SocketAndStreams in project voldemort by voldemort.

the class SimpleSocketPoolTest method testSocketPoolLimitSomeTimeout.

@Test
public void testSocketPoolLimitSomeTimeout() throws Exception {
    // start a dummy server
    AbstractSocketService server = ServerTestUtils.getSocketService(useNio, new ClientRequestHandlerFactory(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();
}
Also used : SocketAndStreams(voldemort.client.protocol.admin.SocketAndStreams) SocketDestination(voldemort.store.socket.SocketDestination) ClientRequestHandlerFactory(voldemort.server.protocol.ClientRequestHandlerFactory) AbstractSocketService(voldemort.server.AbstractSocketService) TestStats(voldemort.socketpool.AbstractSocketPoolTest.TestStats) ResourcePoolConfig(voldemort.utils.pool.ResourcePoolConfig) Test(org.junit.Test)

Example 4 with SocketAndStreams

use of voldemort.client.protocol.admin.SocketAndStreams in project voldemort by voldemort.

the class SocketPoolTest method testSocketClosedWhenCheckedInAfterPoolKeyClosed.

@Test
public void testSocketClosedWhenCheckedInAfterPoolKeyClosed() throws Exception {
    SocketAndStreams sas1 = pool.checkout(dest1);
    SocketAndStreams sas2 = pool.checkout(dest1);
    assertTrue(sas1 != sas2);
    pool.checkin(dest1, sas1);
    pool.close(dest1);
    pool.checkin(dest1, sas2);
    pool.close(dest1);
}
Also used : SocketAndStreams(voldemort.client.protocol.admin.SocketAndStreams) Test(org.junit.Test)

Example 5 with SocketAndStreams

use of voldemort.client.protocol.admin.SocketAndStreams in project voldemort by voldemort.

the class SocketPoolTest method testClosingDeactivates.

@Test
public void testClosingDeactivates() throws Exception {
    SocketAndStreams sas1 = pool.checkout(dest1);
    sas1.getSocket().close();
    pool.checkin(dest1, sas1);
    SocketAndStreams sas2 = pool.checkout(dest1);
    assertTrue(sas1 != sas2);
}
Also used : SocketAndStreams(voldemort.client.protocol.admin.SocketAndStreams) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 SocketAndStreams (voldemort.client.protocol.admin.SocketAndStreams)6 SocketDestination (voldemort.store.socket.SocketDestination)2 ArrayList (java.util.ArrayList)1 RequestFormatType (voldemort.client.protocol.RequestFormatType)1 AbstractSocketService (voldemort.server.AbstractSocketService)1 ClientRequestHandlerFactory (voldemort.server.protocol.ClientRequestHandlerFactory)1 TestStats (voldemort.socketpool.AbstractSocketPoolTest.TestStats)1 ResourcePoolConfig (voldemort.utils.pool.ResourcePoolConfig)1