package me.prettyprint.cassandra.connection;

import static org.junit.Assert.assertEquals;
import me.prettyprint.cassandra.BaseEmbededServerSetupTest;
import me.prettyprint.cassandra.service.CassandraHost;

import org.junit.Before;
import org.junit.Test;

public class ConcurrentHClientPoolTest extends BaseEmbededServerSetupTest {
    
  private CassandraHost cassandraHost;
  private ConcurrentHClientPool clientPool;
  
  @Before
  public void setupTest() {
    setupClient();
    cassandraHost = cassandraHostConfigurator.buildCassandraHosts()[0];
    clientPool = new ConcurrentHClientPool(cassandraHost);
  }
  
  @Test
  public void testSpinUp() {
    assertEquals(16, clientPool.getNumIdle());
    assertEquals(50, clientPool.getNumBeforeExhausted());
    assertEquals(0, clientPool.getNumBlockedThreads());
    assertEquals(0, clientPool.getNumActive());
  }
  
  @Test
  public void testShutdown() {
    clientPool.shutdown();
    assertEquals(0, clientPool.getNumIdle());
    assertEquals(0, clientPool.getNumBlockedThreads());
    assertEquals(0, clientPool.getNumActive());
  }
  
  @Test
  public void testBorrowRelease() {
    HThriftClient client = clientPool.borrowClient();
    assertEquals(1, clientPool.getNumActive());
    clientPool.releaseClient(client);
    assertEquals(0, clientPool.getNumActive());
  }
}

@@ -84,16 +84,53 @@
 Equals;%0A
+import static org.junit.Assert.fail;%0A
 import m
@@ -235,16 +235,84 @@
 draHost;
+%0Aimport me.prettyprint.hector.api.exceptions.HInactivePoolException;
 %0A%0Aimport
@@ -1177,32 +1177,157 @@
 etNumActive());%0A
+    %0A    try %7B%0A      clientPool.borrowClient();%0A      fail();%0A    %7D catch (HInactivePoolException e) %7B%0A      // Good !%0A    %7D%0A
   %7D%0A  %0A  @Test%0A 

Add test case