KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > horizontal > BasicHorizontalScalabilityScenario


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.scenario.horizontal;
26
27 import java.sql.Connection JavaDoc;
28 import java.sql.ResultSet JavaDoc;
29 import java.sql.Statement JavaDoc;
30
31 import org.objectweb.cjdbc.driver.ControllerInfo;
32 import org.objectweb.cjdbc.scenario.templates.HorizontalTemplate;
33
34 /**
35  * This class defines a BasicHorizontalScalabilityScenario
36  *
37  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modryzk </a>
38  * @version 1.0
39  */

40 public class BasicHorizontalScalabilityScenario extends HorizontalTemplate
41 {
42
43   /**
44    * test horizontal scalability starts and stop ok
45    *
46    * @throws Exception if fails
47    */

48   public void testAvailability() throws Exception JavaDoc
49   {
50     ControllerInfo[] controllers = new ControllerInfo[]{
51         new ControllerInfo("localhost", 25322),
52         new ControllerInfo("localhost", 25323)};
53     Connection JavaDoc con = getCJDBCConnection(controllers);
54     Statement JavaDoc statement = con.createStatement();
55     ResultSet JavaDoc rs = statement.executeQuery("Select * from document");
56     assertNotNull("ResultSet before failure is null", rs);
57     cm.stop(controller1.getPortNumber());
58
59     assertFalse("Controller1 should be stopped now", cm.isStarted("25322"));
60
61     Statement JavaDoc statement2 = con.createStatement();
62     ResultSet JavaDoc rs2 = statement2
63         .executeQuery("Select * from document where id='0'");
64     assertNotNull("ResultSet after failure is null", rs2);
65   }
66
67   /**
68    * Test the non availability of a backend.
69    *
70    * @throws Exception if an error occurs
71    */

72   public void testNonAvailability() throws Exception JavaDoc
73   {
74     ControllerInfo[] controllers = new ControllerInfo[]{new ControllerInfo(
75         "localhost", 25322)};
76     Connection JavaDoc con = getCJDBCConnection(controllers);
77     Statement JavaDoc statement = con.createStatement();
78     ResultSet JavaDoc rs = statement.executeQuery("Select * from document");
79     assertNotNull("ResultSet before failure is null", rs);
80     cm.stop(controller1.getPortNumber());
81
82     assertFalse("Controller1 should be stopped now", cm.isStarted("25322"));
83
84     Statement JavaDoc statement2 = con.createStatement();
85     Exception JavaDoc notexpected = null;
86     try
87     {
88       statement2.executeQuery("Select * from document where id='0'");
89     }
90     catch (Exception JavaDoc e)
91     {
92       notexpected = e;
93     }
94     assertNotNull("Should not switch to other controller [not in URL]",
95         notexpected);
96   }
97
98 }
Popular Tags