Skip to content
This repository
Browse code

Merge pull request #606 from dmdevito/fixingfirewallconnectioncut_4

adding another test for the code that renew too long connections
  • Loading branch information...
commit 1eb113d5ba6ac5d3f6f38cc64371f16670350e2a 2 parents d850a2e + 034a88a
Nate McCall authored
2  ...yprint/cassandra/connection/HClientRenewTest.java → ...ra/connection/HClientIdleConnectionRenewTest.java
@@ -15,7 +15,7 @@
15 15
 import org.junit.Before;
16 16
 import org.junit.Test;
17 17
 
18  
-public class HClientRenewTest extends BaseEmbededServerSetupTest {
  18
+public class HClientIdleConnectionRenewTest extends BaseEmbededServerSetupTest {
19 19
     
20 20
   private CassandraHost cassandraHost;
21 21
   private ConcurrentHClientPool clientPool;
56  core/src/test/java/me/prettyprint/cassandra/connection/HClientTooLongConnectionRenewTest.java
... ...
@@ -0,0 +1,56 @@
  1
+package me.prettyprint.cassandra.connection;
  2
+
  3
+import static org.junit.Assert.assertEquals;
  4
+import static org.junit.Assert.assertNotSame;
  5
+import static org.junit.Assert.fail;
  6
+import me.prettyprint.cassandra.BaseEmbededServerSetupTest;
  7
+import me.prettyprint.cassandra.connection.client.HClient;
  8
+import me.prettyprint.cassandra.connection.factory.HClientFactory;
  9
+import me.prettyprint.cassandra.connection.factory.HThriftClientFactoryImpl;
  10
+import me.prettyprint.cassandra.service.CassandraHost;
  11
+import me.prettyprint.cassandra.service.CassandraClientMonitor;
  12
+import me.prettyprint.cassandra.service.CassandraHostConfigurator;
  13
+import me.prettyprint.hector.api.exceptions.HInactivePoolException;
  14
+
  15
+import org.junit.Before;
  16
+import org.junit.Test;
  17
+
  18
+public class HClientTooLongConnectionRenewTest extends BaseEmbededServerSetupTest {
  19
+    
  20
+  private CassandraHost cassandraHost;
  21
+  private ConcurrentHClientPool clientPool;
  22
+  private CassandraClientMonitor monitor;
  23
+  
  24
+  @Before
  25
+  public void setupTest() {
  26
+    setupClient();
  27
+    cassandraHost = cassandraHostConfigurator.buildCassandraHosts()[0];
  28
+    HClientFactory factory = new HThriftClientFactoryImpl();
  29
+    monitor = new CassandraClientMonitor(connectionManager);
  30
+    clientPool = new ConcurrentHClientPool(factory, cassandraHost, monitor);
  31
+  } 
  32
+  
  33
+  protected void configure(CassandraHostConfigurator configurator) {
  34
+    configurator.setMaxActive(1);
  35
+    configurator.setMaxConnectTimeMillis(3 * 1000);
  36
+  }
  37
+  
  38
+  @Test
  39
+  public void testBorrowAndRenew() {
  40
+    HClient client1 = clientPool.borrowClient();
  41
+    assertEquals(1, clientPool.getNumActive());
  42
+	client1.updateLastSuccessTime();
  43
+    clientPool.releaseClient(client1);
  44
+    assertEquals(0, clientPool.getNumActive());
  45
+    int count = monitor.getNumRenewedTooLongConnections();
  46
+	try {
  47
+	  Thread.sleep(4 * 1000);
  48
+    } catch(InterruptedException ex) {
  49
+	  fail();
  50
+	}
  51
+    HClient client2 = clientPool.borrowClient();
  52
+    assertEquals(1, clientPool.getNumActive());
  53
+    assertEquals(count + 1, monitor.getNumRenewedTooLongConnections());
  54
+	assertNotSame(client1, client2);
  55
+  }
  56
+}

0 notes on commit 1eb113d

Please sign in to comment.
Something went wrong with that request. Please try again.