KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > logicalcobwebs > proxool > KillTest


1 /*
2  * This software is released under a licence similar to the Apache Software Licence.
3  * See org.logicalcobwebs.proxool.package.html for details.
4  * The latest version is available at http://proxool.sourceforge.net
5  */

6 package org.logicalcobwebs.proxool;
7
8 import java.util.Properties JavaDoc;
9 import java.sql.Connection JavaDoc;
10 import java.sql.DriverManager JavaDoc;
11
12 /**
13  * Tests whether we can kill connections when we want to
14  * @version $Revision: 1.2 $, $Date: 2006/05/23 21:33:52 $
15  * @author <a HREF="mailto:bill@logicalcobwebs.co.uk">Bill Horsman</a>
16  * @author $Author: billhorsman $ (current maintainer)
17  * @since Proxool 0.9
18  */

19 public class KillTest extends AbstractProxoolTest {
20     private static final boolean MERCIFUL = true;
21     private static final boolean MERCILESS = false;
22     private static final boolean DETAILED = true;
23
24     /**
25      * @see AbstractProxoolTest
26      */

27     public KillTest(String JavaDoc alias) {
28         super(alias);
29     }
30
31     /**
32      * @see ProxoolFacade#killAllConnections(java.lang.String, java.lang.String, boolean)
33      */

34     public void testKillAllMercifully() throws Exception JavaDoc {
35         String JavaDoc alias = "killAllMercifully";
36         String JavaDoc url = TestHelper.buildProxoolUrl(alias,
37                 TestConstants.HYPERSONIC_DRIVER,
38                 TestConstants.HYPERSONIC_TEST_URL);
39         Properties JavaDoc info = new Properties JavaDoc();
40         info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER);
41         info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD);
42         info.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "2");
43         Connection JavaDoc c1 = DriverManager.getConnection(url, info);
44         Connection JavaDoc c2 = DriverManager.getConnection(url, info);
45         c1.close();
46         c2.close();
47         // There should now be two connections built
48
assertEquals("Connection count", 2, ProxoolFacade.getSnapshot(alias, DETAILED).getConnectionInfos().length);
49         ProxoolFacade.killAllConnections(alias, "testing", MERCIFUL);
50         // None left
51
assertEquals("Connection count", 0, ProxoolFacade.getSnapshot(alias, DETAILED).getConnectionInfos().length);
52     }
53
54     /**
55      * @see ProxoolFacade#killAllConnections(java.lang.String, java.lang.String, boolean)
56      */

57     public void testKillAllMercilessly() throws Exception JavaDoc {
58         String JavaDoc alias = "killAllMercilessly";
59         String JavaDoc url = TestHelper.buildProxoolUrl(alias,
60                 TestConstants.HYPERSONIC_DRIVER,
61                 TestConstants.HYPERSONIC_TEST_URL);
62         Properties JavaDoc info = new Properties JavaDoc();
63         info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER);
64         info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD);
65         info.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "2");
66         Connection JavaDoc c1 = DriverManager.getConnection(url, info);
67         Connection JavaDoc c2 = DriverManager.getConnection(url, info);
68         // There should now be two connections built
69
assertEquals("Connection count", 2, ProxoolFacade.getSnapshot(alias, DETAILED).getConnectionInfos().length);
70         ProxoolFacade.killAllConnections(alias, "testing", MERCILESS);
71         // None left
72
assertEquals("Connection count", 0, ProxoolFacade.getSnapshot(alias, DETAILED).getConnectionInfos().length);
73         c1.close();
74         c2.close();
75     }
76
77     /**
78      * @see ProxoolFacade#killConnecton(java.lang.String, long, boolean)
79      */

80     public void testKillOneById() throws Exception JavaDoc {
81         String JavaDoc alias = "killOneById";
82         String JavaDoc url = TestHelper.buildProxoolUrl(alias,
83                 TestConstants.HYPERSONIC_DRIVER,
84                 TestConstants.HYPERSONIC_TEST_URL);
85         Properties JavaDoc info = new Properties JavaDoc();
86         info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER);
87         info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD);
88         info.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "2");
89         Connection JavaDoc c1 = DriverManager.getConnection(url, info);
90         Connection JavaDoc c2 = DriverManager.getConnection(url, info);
91         c1.close();
92         c2.close();
93         // There should now be two connections built
94
assertEquals("Connection count", 2, ProxoolFacade.getSnapshot(alias, DETAILED).getConnectionInfos().length);
95         long id1 = ProxoolFacade.getId(c1);
96         long id2 = ProxoolFacade.getId(c2);
97         ProxoolFacade.killConnecton(alias, id1, MERCIFUL);
98         // One left
99
assertEquals("Connection count", 1, ProxoolFacade.getSnapshot(alias, DETAILED).getConnectionInfos().length);
100         assertEquals("Active count", 0, ProxoolFacade.getSnapshot(alias, DETAILED).getActiveConnectionCount());
101         Connection JavaDoc c3 = DriverManager.getConnection(url, info);
102         assertEquals("Active count", 1, ProxoolFacade.getSnapshot(alias, DETAILED).getActiveConnectionCount());
103         long id3 = ProxoolFacade.getId(c3);
104         Connection JavaDoc c4 = DriverManager.getConnection(url, info);
105         assertEquals("Active count", 2, ProxoolFacade.getSnapshot(alias, DETAILED).getActiveConnectionCount());
106         long id4 = ProxoolFacade.getId(c4);
107         c3.close();
108         c4.close();
109         assertTrue("Killed ID served", id3 != id1);
110         assertTrue("Killed ID served", id4 != id1);
111     }
112     /**
113      * @see ProxoolFacade#killConnecton(java.lang.String, long, boolean)
114      */

115     public void testKillOneByConnection() throws Exception JavaDoc {
116         String JavaDoc alias = "killOneByConnection";
117         String JavaDoc url = TestHelper.buildProxoolUrl(alias,
118                 TestConstants.HYPERSONIC_DRIVER,
119                 TestConstants.HYPERSONIC_TEST_URL);
120         Properties JavaDoc info = new Properties JavaDoc();
121         info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER);
122         info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD);
123         info.setProperty(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY, "2");
124         Connection JavaDoc c1 = DriverManager.getConnection(url, info);
125         Connection JavaDoc c2 = DriverManager.getConnection(url, info);
126         c1.close();
127         c2.close();
128         // There should now be two connections built
129
assertEquals("Connection count", 2, ProxoolFacade.getSnapshot(alias, DETAILED).getConnectionInfos().length);
130         long id1 = ProxoolFacade.getId(c1);
131         long id2 = ProxoolFacade.getId(c2);
132         ProxoolFacade.killConnecton(c1, MERCIFUL);
133         // One left
134
assertEquals("Connection count", 1, ProxoolFacade.getSnapshot(alias, DETAILED).getConnectionInfos().length);
135         Connection JavaDoc c3 = DriverManager.getConnection(url, info);
136         long id3 = ProxoolFacade.getId(c3);
137         Connection JavaDoc c4 = DriverManager.getConnection(url, info);
138         long id4 = ProxoolFacade.getId(c4);
139         c3.close();
140         c4.close();
141         assertTrue("Killed ID served", id3 != id1);
142         assertTrue("Killed ID served", id4 != id1);
143     }
144
145 }
146 /*
147  Revision history:
148  $Log: KillTest.java,v $
149  Revision 1.2 2006/05/23 21:33:52 billhorsman
150  More asserts
151
152  Revision 1.1 2004/03/23 21:14:24 billhorsman
153  new tests
154
155 */
Popular Tags