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);
}
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());
}
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();
}
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);
}
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);
}
Aggregations