/
ConcurrentHClientPoolTest.java
59 lines (50 loc) · 1.89 KB
/
ConcurrentHClientPoolTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package me.prettyprint.cassandra.connection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import me.prettyprint.cassandra.BaseEmbededServerSetupTest;
import me.prettyprint.cassandra.connection.client.HClient;
import me.prettyprint.cassandra.connection.factory.HClientFactory;
import me.prettyprint.cassandra.connection.factory.HThriftClientFactoryImpl;
import me.prettyprint.cassandra.service.CassandraHost;
import me.prettyprint.cassandra.service.CassandraClientMonitor;
import me.prettyprint.hector.api.exceptions.HInactivePoolException;
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];
HClientFactory factory = new HThriftClientFactoryImpl();
clientPool = new ConcurrentHClientPool(factory, cassandraHost, new CassandraClientMonitor(connectionManager));
}
@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());
try {
clientPool.borrowClient();
fail();
} catch (HInactivePoolException e) {
// Good !
}
}
@Test
public void testBorrowRelease() {
HClient client = clientPool.borrowClient();
assertEquals(1, clientPool.getNumActive());
clientPool.releaseClient(client);
assertEquals(0, clientPool.getNumActive());
}
}