KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > smartlib > pool > core > MultiPoolImplTest


1 package org.smartlib.pool.core;
2
3 import org.apache.log4j.Logger;
4
5 import java.sql.Connection JavaDoc;
6
7 /**
8  * Created by IntelliJ IDEA.
9  * User: kerneldebugger
10  * Date: Oct 1, 2005
11  * Time: 11:53:36 PM
12  * To change this template use File | Settings | File Templates.
13  */

14 public class MultiPoolImplTest extends PoolTestFixture {
15
16     private static Logger logger = Logger.getLogger(MultiPoolImplTest.class);
17
18     MultiPool multiPool = null;
19     protected void setUp() throws Exception JavaDoc {
20         super.setUp();
21         logger.debug("=====================Start==============================");
22     }
23
24     protected void tearDown() throws Exception JavaDoc {
25         logger.debug("======================End===============================");
26         super.tearDown();
27         try {
28             multiPool.shutDown();
29         } catch (Exception JavaDoc e) {
30             logger.debug("Exception in tear down",e);
31         }
32
33     }
34
35     public void testBasicConnection() throws Exception JavaDoc {
36         PoolConfig config = getBasicPoolConfig();
37         multiPool = new MultiPoolImpl(config);
38         Connection JavaDoc conn = multiPool.getConnection();
39         assertNotNull("Connection cannot be null", conn);
40         testConnection(conn);
41         conn.close();
42     }
43
44     public void testIfRandomConnectionsAreObtained() throws Exception JavaDoc {
45         PoolConfig config = getPoolConfigWithMultiplePools();
46         multiPool = new MultiPoolImpl(config);
47         Connection JavaDoc conn = multiPool.getConnection();
48         testConnection(conn);
49         assertNotNull("Connection cannot be null", conn);
50         String JavaDoc subPoolName = ((SmartConnection)conn).getPoolName();
51         logger.debug("Connection was picked from: " + subPoolName);
52         conn.close();
53
54         conn = multiPool.getConnection();
55         testConnection(conn);
56         assertNotNull("Connection cannot be null", conn);
57         String JavaDoc subPoolName1 = ((SmartConnection)conn).getPoolName();
58         logger.debug("Connection was picked from: " + subPoolName1);
59         conn.close();
60         assertNotSame("The two pools cannot be same", subPoolName, subPoolName1);
61
62     }
63
64     public void testIfThreadSkickinessIsMaintained() throws Exception JavaDoc {
65
66         PoolConfig config = getPoolConfigWithMultiplePools();
67         config.setThreadStickiness(true);
68         multiPool = new MultiPoolImpl(config);
69         Connection JavaDoc conn = multiPool.getConnection();
70         testConnection(conn);
71         assertNotNull("Connection cannot be null", conn);
72         String JavaDoc subPoolName = ((SmartConnection)conn).getPoolName();
73         logger.debug("Connection 1 was picked from pool: " + subPoolName);
74         String JavaDoc insanceName = getInstanceName(conn);
75         logger.debug("Connection 1 was picked from instance: " + insanceName);
76         conn.close();
77
78         conn = multiPool.getConnection();
79         testConnection(conn);
80         assertNotNull("Connection cannot be null", conn);
81         String JavaDoc subPoolName1 = ((SmartConnection)conn).getPoolName();
82         logger.debug("Connection 2 was picked from pool: " + subPoolName1);
83         String JavaDoc insanceName1 = getInstanceName(conn);
84         logger.debug("Connection 2 was picked from instance: " + insanceName1);
85         conn.close();
86         assertEquals("The two pools should be same", subPoolName, subPoolName1);
87         assertEquals("The two instances should be same", insanceName, insanceName1);
88
89     }
90
91
92     public void testIfRandomConnectionsAreObtainedForExternalPooling() throws Exception JavaDoc {
93
94         PoolConfig config = getPoolConfigWithMultipleExternalPools();
95         multiPool = new MultiPoolImpl(config);
96         Connection JavaDoc conn = multiPool.getConnection();
97         testConnection(conn);
98         assertNotNull("Connection cannot be null", conn);
99         String JavaDoc subPoolName = ((SmartConnection)conn).getPoolName();
100         logger.debug("Connection was picked from: " + subPoolName);
101         String JavaDoc insanceName = getInstanceName(conn);
102         logger.debug("Connection 1 was picked from instance: " + insanceName);
103         conn.close();
104
105         conn = multiPool.getConnection();
106         testConnection(conn);
107         assertNotNull("Connection cannot be null", conn);
108         String JavaDoc subPoolName1 = ((SmartConnection)conn).getPoolName();
109         logger.debug("Connection was picked from: " + subPoolName1);
110         String JavaDoc insanceName1 = getInstanceName(conn);
111         logger.debug("Connection 2 was picked from instance: " + insanceName1);
112         conn.close();
113         assertNotSame("The two pools cannot be same", subPoolName, subPoolName1);
114         assertNotSame("The two instances should be same", insanceName, insanceName1);
115
116     }
117
118     public void testIfThreadSkickinessIsMaintainedForExternalPooling() throws Exception JavaDoc {
119
120         PoolConfig config = getPoolConfigWithMultipleExternalPools();
121         config.setThreadStickiness(true);
122         multiPool = new MultiPoolImpl(config);
123         Connection JavaDoc conn = multiPool.getConnection();
124         testConnection(conn);
125         assertNotNull("Connection cannot be null", conn);
126         String JavaDoc subPoolName = ((SmartConnection)conn).getPoolName();
127         logger.debug("Connection 1 was picked from pool: " + subPoolName);
128         String JavaDoc insanceName = getInstanceName(conn);
129         logger.debug("Connection 1 was picked from instance: " + insanceName);
130         conn.close();
131
132         conn = multiPool.getConnection();
133         testConnection(conn);
134         assertNotNull("Connection cannot be null", conn);
135         String JavaDoc subPoolName1 = ((SmartConnection)conn).getPoolName();
136         logger.debug("Connection 2 was picked from pool: " + subPoolName1);
137         String JavaDoc insanceName1 = getInstanceName(conn);
138         logger.debug("Connection 2 was picked from instance: " + insanceName1);
139         conn.close();
140         assertEquals("The two pools should be same", subPoolName, subPoolName1);
141         assertEquals("The two instances should be same", insanceName, insanceName1);
142
143     }
144
145
146 }
147
Popular Tags