From 95b86aff23fdfde85f26d79ab33ca815d0d65f96 Mon Sep 17 00:00:00 2001 From: Bhupesh Bansal Date: Wed, 21 Oct 2009 11:02:49 -0700 Subject: [PATCH] Fixed simpleSocketPoolTest to fail() more reliabily. --- .../socketpool/AbstractSocketPoolTest.java | 14 ++++++++++---- .../voldemort/socketpool/SimpleSocketPoolTest.java | 6 +++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/test/integration/voldemort/socketpool/AbstractSocketPoolTest.java b/test/integration/voldemort/socketpool/AbstractSocketPoolTest.java index 3938a5b8ad..736b47725d 100644 --- a/test/integration/voldemort/socketpool/AbstractSocketPoolTest.java +++ b/test/integration/voldemort/socketpool/AbstractSocketPoolTest.java @@ -1,11 +1,11 @@ package voldemort.socketpool; -import java.util.Date; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import junit.framework.TestCase; @@ -33,6 +33,7 @@ public TestStats startTest(final ResourceFactory factory, final ConcurrentHashMap resourceInHand = new ConcurrentHashMap(); ExecutorService executor = Executors.newFixedThreadPool(nThreads); final TestStats testStats = new TestStats(); + final AtomicBoolean passed = new AtomicBoolean(true); for(int i = 0; i < nRequests; i++) { final K key = getRequestKey(); @@ -44,10 +45,13 @@ public void run() { // borrow resource V resource = pool.checkout(key); resourceInHand.get(key).incrementAndGet(); - System.out.println("Borrowing of " + key + " completed at " + new Date()); // assert that resourceInHand is less than equal to pool // Size + if(resourceInHand.get(key).get() > config.getMaxPoolSize()) { + passed.set(false); + } + assertEquals("resources In Hand(" + resourceInHand.get(key).get() + ") should be less than equal to pool size(" + config.getMaxPoolSize() + ")", @@ -60,8 +64,6 @@ public void run() { // return pool.checkin(key, resource); resourceInHand.get(key).decrementAndGet(); - System.out.println("return completed" + key + " resource:" + resource - + " at " + new Date()); } catch(TimeoutException e) { ++testStats.timeoutRequests; return; @@ -74,6 +76,10 @@ public void run() { executor.shutdown(); executor.awaitTermination(5 * 60, TimeUnit.SECONDS); + + if(!passed.get()) { + fail(); + } return testStats; } diff --git a/test/integration/voldemort/socketpool/SimpleSocketPoolTest.java b/test/integration/voldemort/socketpool/SimpleSocketPoolTest.java index f402d5f9b8..1eaf9c26b5 100644 --- a/test/integration/voldemort/socketpool/SimpleSocketPoolTest.java +++ b/test/integration/voldemort/socketpool/SimpleSocketPoolTest.java @@ -64,7 +64,7 @@ protected String getRequestKey() throws Exception { public void testSocketPoolLimitSomeTimeout() throws Exception { // start a dummy server - SocketServer server = new SocketServer(6666, 50, 50, 1000, new RequestHandlerFactory(null, + SocketServer server = new SocketServer(7666, 50, 50, 1000, new RequestHandlerFactory(null, null, null)); server.start(); @@ -81,13 +81,13 @@ protected void doSomethingWithResource(SocketDestination key, SocketAndStreams r throws Exception { Thread.sleep(100); int random = (int) (Math.random() * 10); - if(random == 7) + if(random >= 5) resource.getSocket().close(); } @Override protected SocketDestination getRequestKey() throws Exception { - return new SocketDestination("localhost", 6666, RequestFormatType.VOLDEMORT_V1); + return new SocketDestination("localhost", 7666, RequestFormatType.VOLDEMORT_V1); } };