KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > users > WillemScenario


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 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): Willem Cazander.
22  * Contributor(s): Emmanuel Cecchet.
23  */

24
25 package org.objectweb.cjdbc.scenario.users;
26
27 import java.sql.Connection JavaDoc;
28 import java.sql.DriverManager JavaDoc;
29 import java.sql.SQLException JavaDoc;
30 import java.sql.Statement JavaDoc;
31 import java.util.Random JavaDoc;
32
33 /**
34  * Test case provided by Willem Cazander for a duplicate key in logtable.
35  *
36  * <pre>
37  * First create an table on both backend nodes:
38  *
39  * create table test (
40  * test integer not null
41  * );
42  *
43  * Set the initial checkpoints:
44  *
45  * m4ncluster(admin) > disable node1
46  * m4ncluster(admin) > setCheckpoint node1 emty1
47  * m4ncluster(admin) > enable node1 emty1
48  *
49  * m4ncluster(admin) > disable node2
50  * m4ncluster(admin) > setCheckpoint node2 emty2
51  * m4ncluster(admin) > enable node2 emty2
52  *
53  * Start the load test:
54  *
55  * java -cp .:c-jdbc-driver.jar WillemScenario
56  *
57  * Disable an node:
58  *
59  * m4ncluster(admin) > disable node1
60  * Disabling backend node1 with no checkpoint
61  *
62  * Then I get the following error:
63  *
64  * 2005-02-25 13:54:17,969 INFO controller.RequestManager.m4ncluster Setting new virtual database schema.
65  * 2005-02-25 14:00:10,168 INFO controller.loadbalancer.RAIDb1 Removing blocking task worker thread for backend node1
66  * 2005-02-25 14:00:10,168 INFO controller.loadbalancer.RAIDb1 Removing non blocking task worker thread for backend node1
67  * 2005-02-25 14:00:10,173 ERROR controller.backend.BackendStateListener Could not store informatione for backend:node1
68  * java.sql.SQLException: Unable to update checkpoint 'emty1' for backend:node1
69  * at org.objectweb.cjdbc.controller.recoverylog.RecoveryLog.storeBackendInfo(RecoveryLog.java:1226)
70  *
71  * </pre>
72  *
73  * @author <a HREF="mailto:willem.cazander@mbuyu.nl">Willem Cazander </a>
74  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
75  * @version 1.0
76  */

77 public class WillemScenario
78 {
79   String JavaDoc driver = "org.objectweb.cjdbc.driver.Driver";
80   String JavaDoc url = "jdbc:cjdbc://localhost/m4ncluster";
81   String JavaDoc username = "m4ncluster";
82   String JavaDoc password = "clusterm4n";
83   int records = 50000;
84   long waitTime = 100000;
85   Connection JavaDoc connection = null;
86   Random JavaDoc random = null;
87
88   /**
89    * Creates a new <code>WillemScenario</code> object
90    */

91   public WillemScenario()
92   {
93     try
94     {
95       Class.forName(driver).newInstance();
96       connection = DriverManager.getConnection(url, username, password);
97
98       random = new Random JavaDoc();
99       fillDB();
100     }
101     catch (SQLException JavaDoc e)
102     {
103       System.err.println("SQLException: " + e.getMessage());
104     }
105     catch (ClassCastException JavaDoc e)
106     {
107       System.err.println("ClassCastException: " + e.getMessage());
108     }
109     catch (ClassNotFoundException JavaDoc e)
110     {
111       System.err.println("ClassNotFoundException: " + e.getMessage());
112     }
113     catch (InstantiationException JavaDoc e)
114     {
115       System.err.println("InstantiationException: " + e.getMessage());
116     }
117     catch (IllegalAccessException JavaDoc e)
118     {
119       System.err.println("IllegalAccessException: " + e.getMessage());
120     }
121   }
122
123   /**
124    * Fill the database
125    */

126   public void fillDB()
127   {
128     try
129     {
130       Statement JavaDoc sm = connection.createStatement();
131       for (int i = 0; i < records; i++)
132       {
133         String JavaDoc sql = "insert into test (test) values ("
134             + random.nextInt(873264) + ")";
135         System.out.println("sql: " + sql);
136         sm.executeUpdate(sql);
137         // wait a bit
138
for (int r = 0; r < 3000; ++r)
139         {
140         }
141       }
142     }
143     catch (SQLException JavaDoc e)
144     {
145       System.err.println("Could not fill test: " + e.getMessage());
146     }
147   }
148
149   /**
150    * Main method
151    *
152    * @param args arguements (ignored)
153    */

154   static public void main(String JavaDoc[] args)
155   {
156     new WillemScenario();
157   }
158 }
Popular Tags