001: /*
002: * This software is released under a licence similar to the Apache Software Licence.
003: * See org.logicalcobwebs.proxool.package.html for details.
004: * The latest version is available at http://proxool.sourceforge.net
005: */
006: package org.logicalcobwebs.proxool;
007:
008: import java.util.Properties;
009: import java.sql.Connection;
010: import java.sql.DriverManager;
011:
012: /**
013: * Tests whether we can kill connections when we want to
014: * @version $Revision: 1.2 $, $Date: 2006/05/23 21:33:52 $
015: * @author <a href="mailto:bill@logicalcobwebs.co.uk">Bill Horsman</a>
016: * @author $Author: billhorsman $ (current maintainer)
017: * @since Proxool 0.9
018: */
019: public class KillTest extends AbstractProxoolTest {
020: private static final boolean MERCIFUL = true;
021: private static final boolean MERCILESS = false;
022: private static final boolean DETAILED = true;
023:
024: /**
025: * @see AbstractProxoolTest
026: */
027: public KillTest(String alias) {
028: super (alias);
029: }
030:
031: /**
032: * @see ProxoolFacade#killAllConnections(java.lang.String, java.lang.String, boolean)
033: */
034: public void testKillAllMercifully() throws Exception {
035: String alias = "killAllMercifully";
036: String url = TestHelper.buildProxoolUrl(alias,
037: TestConstants.HYPERSONIC_DRIVER,
038: TestConstants.HYPERSONIC_TEST_URL);
039: Properties info = new Properties();
040: info.setProperty(ProxoolConstants.USER_PROPERTY,
041: TestConstants.HYPERSONIC_USER);
042: info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
043: TestConstants.HYPERSONIC_PASSWORD);
044: info
045: .setProperty(
046: ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY,
047: "2");
048: Connection c1 = DriverManager.getConnection(url, info);
049: Connection c2 = DriverManager.getConnection(url, info);
050: c1.close();
051: c2.close();
052: // There should now be two connections built
053: assertEquals("Connection count", 2, ProxoolFacade.getSnapshot(
054: alias, DETAILED).getConnectionInfos().length);
055: ProxoolFacade.killAllConnections(alias, "testing", MERCIFUL);
056: // None left
057: assertEquals("Connection count", 0, ProxoolFacade.getSnapshot(
058: alias, DETAILED).getConnectionInfos().length);
059: }
060:
061: /**
062: * @see ProxoolFacade#killAllConnections(java.lang.String, java.lang.String, boolean)
063: */
064: public void testKillAllMercilessly() throws Exception {
065: String alias = "killAllMercilessly";
066: String url = TestHelper.buildProxoolUrl(alias,
067: TestConstants.HYPERSONIC_DRIVER,
068: TestConstants.HYPERSONIC_TEST_URL);
069: Properties info = new Properties();
070: info.setProperty(ProxoolConstants.USER_PROPERTY,
071: TestConstants.HYPERSONIC_USER);
072: info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
073: TestConstants.HYPERSONIC_PASSWORD);
074: info
075: .setProperty(
076: ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY,
077: "2");
078: Connection c1 = DriverManager.getConnection(url, info);
079: Connection c2 = DriverManager.getConnection(url, info);
080: // There should now be two connections built
081: assertEquals("Connection count", 2, ProxoolFacade.getSnapshot(
082: alias, DETAILED).getConnectionInfos().length);
083: ProxoolFacade.killAllConnections(alias, "testing", MERCILESS);
084: // None left
085: assertEquals("Connection count", 0, ProxoolFacade.getSnapshot(
086: alias, DETAILED).getConnectionInfos().length);
087: c1.close();
088: c2.close();
089: }
090:
091: /**
092: * @see ProxoolFacade#killConnecton(java.lang.String, long, boolean)
093: */
094: public void testKillOneById() throws Exception {
095: String alias = "killOneById";
096: String url = TestHelper.buildProxoolUrl(alias,
097: TestConstants.HYPERSONIC_DRIVER,
098: TestConstants.HYPERSONIC_TEST_URL);
099: Properties info = new Properties();
100: info.setProperty(ProxoolConstants.USER_PROPERTY,
101: TestConstants.HYPERSONIC_USER);
102: info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
103: TestConstants.HYPERSONIC_PASSWORD);
104: info
105: .setProperty(
106: ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY,
107: "2");
108: Connection c1 = DriverManager.getConnection(url, info);
109: Connection c2 = DriverManager.getConnection(url, info);
110: c1.close();
111: c2.close();
112: // There should now be two connections built
113: assertEquals("Connection count", 2, ProxoolFacade.getSnapshot(
114: alias, DETAILED).getConnectionInfos().length);
115: long id1 = ProxoolFacade.getId(c1);
116: long id2 = ProxoolFacade.getId(c2);
117: ProxoolFacade.killConnecton(alias, id1, MERCIFUL);
118: // One left
119: assertEquals("Connection count", 1, ProxoolFacade.getSnapshot(
120: alias, DETAILED).getConnectionInfos().length);
121: assertEquals("Active count", 0, ProxoolFacade.getSnapshot(
122: alias, DETAILED).getActiveConnectionCount());
123: Connection c3 = DriverManager.getConnection(url, info);
124: assertEquals("Active count", 1, ProxoolFacade.getSnapshot(
125: alias, DETAILED).getActiveConnectionCount());
126: long id3 = ProxoolFacade.getId(c3);
127: Connection c4 = DriverManager.getConnection(url, info);
128: assertEquals("Active count", 2, ProxoolFacade.getSnapshot(
129: alias, DETAILED).getActiveConnectionCount());
130: long id4 = ProxoolFacade.getId(c4);
131: c3.close();
132: c4.close();
133: assertTrue("Killed ID served", id3 != id1);
134: assertTrue("Killed ID served", id4 != id1);
135: }
136:
137: /**
138: * @see ProxoolFacade#killConnecton(java.lang.String, long, boolean)
139: */
140: public void testKillOneByConnection() throws Exception {
141: String alias = "killOneByConnection";
142: String url = TestHelper.buildProxoolUrl(alias,
143: TestConstants.HYPERSONIC_DRIVER,
144: TestConstants.HYPERSONIC_TEST_URL);
145: Properties info = new Properties();
146: info.setProperty(ProxoolConstants.USER_PROPERTY,
147: TestConstants.HYPERSONIC_USER);
148: info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
149: TestConstants.HYPERSONIC_PASSWORD);
150: info
151: .setProperty(
152: ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY,
153: "2");
154: Connection c1 = DriverManager.getConnection(url, info);
155: Connection c2 = DriverManager.getConnection(url, info);
156: c1.close();
157: c2.close();
158: // There should now be two connections built
159: assertEquals("Connection count", 2, ProxoolFacade.getSnapshot(
160: alias, DETAILED).getConnectionInfos().length);
161: long id1 = ProxoolFacade.getId(c1);
162: long id2 = ProxoolFacade.getId(c2);
163: ProxoolFacade.killConnecton(c1, MERCIFUL);
164: // One left
165: assertEquals("Connection count", 1, ProxoolFacade.getSnapshot(
166: alias, DETAILED).getConnectionInfos().length);
167: Connection c3 = DriverManager.getConnection(url, info);
168: long id3 = ProxoolFacade.getId(c3);
169: Connection c4 = DriverManager.getConnection(url, info);
170: long id4 = ProxoolFacade.getId(c4);
171: c3.close();
172: c4.close();
173: assertTrue("Killed ID served", id3 != id1);
174: assertTrue("Killed ID served", id4 != id1);
175: }
176:
177: }
178: /*
179: Revision history:
180: $Log: KillTest.java,v $
181: Revision 1.2 2006/05/23 21:33:52 billhorsman
182: More asserts
183:
184: Revision 1.1 2004/03/23 21:14:24 billhorsman
185: new tests
186:
187: */
|