KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > raidb1 > startup > ControllerStopScenario


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.raidb1.startup;
26
27 import java.sql.Connection JavaDoc;
28 import java.sql.PreparedStatement JavaDoc;
29 import java.sql.ResultSet JavaDoc;
30 import java.util.ArrayList JavaDoc;
31
32 import org.objectweb.cjdbc.controller.core.Controller;
33 import org.objectweb.cjdbc.scenario.templates.Raidb1Template;
34
35 /**
36  * This class defines a ControllerStopScenario
37  *
38  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
39  * @version 1.0
40  */

41 public class ControllerStopScenario extends Raidb1Template
42 {
43   /**
44    * Test reconnect after the restart of the controller
45    *
46    * @throws Exception if fails
47    */

48
49   public void testReconnectAfterFailure() throws Exception JavaDoc
50   {
51
52     ArrayList JavaDoc list = new ArrayList JavaDoc();
53
54     // Get a Connection
55
Connection JavaDoc con = getCJDBCConnection();
56     PreparedStatement JavaDoc stmt = con
57         .prepareStatement("create table ATEST (id int, text varchar(1000))");
58     stmt.executeUpdate();
59
60     stmt = con.prepareStatement("insert into ATEST (id,text) values (?,?)");
61
62     for (int i = 0; i < 100; i++)
63     {
64
65       stmt.setInt(1, i);
66       stmt
67           .setString(
68               2,
69               "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus quam nunc, dignissim sit amet, placerat at, feugiat quis, purus. Vivamus suscipit elementum velit. Nam ac libero. Mauris fermentum ultricies felis. Suspendisse tempor consectetuer risus. Aenean rutrum, orci sit amet tristique congue, mauris libero luctus nibh, vitae malesuada magna nulla nec velit. Etiam dapibus aliquet justo. Pellentesque posuere urna sit amet nunc. Fusce augue quam, venenatis a, ornare id, convallis non, leo. Aliquam laoreet tortor sit amet wisi. Donec dolor.");
70       stmt.execute();
71     }
72
73     ResultSet JavaDoc rs = stmt.executeQuery("select * from ATEST");
74     while (rs.next())
75     {
76       list.add(rs.getString("text"));
77     }
78
79     // Stop the controller
80
cm.stop(25322);
81
82     // Reload the controller
83
controller = (Controller) cm.start("25322").getProcess();
84     cm.loaddatabase("25322", "hsqldb-raidb1.xml");
85     mainVdb = controller.getVirtualDatabase("myDB");
86     mainVdb.enableAllBackends();
87
88     //ScenarioUtility.getSingleQueryResult("select * from DOCUMENT", con);
89

90     // Resend a query with the same connection as before
91
stmt.setFetchSize(5);
92     for (int i = 0; i < 1000; i++)
93     {
94       System.out.println("continue " + i + " "
95           + Runtime.getRuntime().freeMemory() / 1000000f);
96       stmt.setInt(1, i);
97       stmt
98           .setString(
99               2,
100               "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus quam nunc, dignissim sit amet, placerat at, feugiat quis, purus. Vivamus suscipit elementum velit. Nam ac libero. Mauris fermentum ultricies felis. Suspendisse tempor consectetuer risus. Aenean rutrum, orci sit amet tristique congue, mauris libero luctus nibh, vitae malesuada magna nulla nec velit. Etiam dapibus aliquet justo. Pellentesque posuere urna sit amet nunc. Fusce augue quam, venenatis a, ornare id, convallis non, leo. Aliquam laoreet tortor sit amet wisi. Donec dolor.");
101       stmt.execute();
102       
103       // Execute a query
104
rs = stmt.executeQuery("select * from ATEST");
105 // while (rs.next())
106
// {
107
// //list.add(rs.getString("text"));
108
// }
109
}
110   }
111 }
112
Popular Tags