KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > raidb2 > Raidb2CheckSchemaScenario


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.raidb2;
26
27 import java.sql.Connection JavaDoc;
28
29 import org.objectweb.cjdbc.scenario.templates.SimpleRaidb2Template;
30 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility;
31
32 /**
33  * This class defines a Raidb2CheckSchemaScenario
34  *
35  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
36  * @version 1.0
37  */

38 public class Raidb2CheckSchemaScenario extends SimpleRaidb2Template
39 {
40
41   public void testSchemaRaidb2RR() throws Exception JavaDoc
42   {
43     cm.loadVirtualDatabases(controller, "myDB", "hsqldb-raidb2.xml");
44     deepTestSchema();
45   }
46
47   public void testSchemaRaidb2LPRF() throws Exception JavaDoc
48   {
49     cm.loadVirtualDatabases(controller, "myDB", "hsqldb-raidb2-LPRF.xml");
50     deepTestSchema();
51   }
52
53   private void deepTestSchema() throws Exception JavaDoc
54   {
55     mainVdb = controller.getVirtualDatabase("myDB");
56     Connection JavaDoc con = getCJDBCConnection();
57
58     testTheSchema(con, new boolean[]{true, true, true, true, true});
59     // localhost2 has tables ADDRESS. PRODUCT, DOCUMENT, BLOB REGION
60
mainVdb.forceDisableBackend("localhost");
61     testTheSchema(con, new boolean[]{true, true, false, true, true});
62     ScenarioUtility.displayResultOnScreen(con.getMetaData().getTables(null,
63         null, null, null));
64     mainVdb.forceEnableBackend("localhost");
65     testTheSchema(con, new boolean[]{true, true, true, true, true});
66     // Localhost has PRODUCT, DOCUMENT, PPOSITION, BLOB
67
mainVdb.forceDisableBackend("localhost2");
68     testTheSchema(con, new boolean[]{true, true, true, true, false});
69     ScenarioUtility.displayResultOnScreen(con.getMetaData().getTables(null,
70         null, null, null));
71     mainVdb.forceEnableBackend("localhost2");
72     testTheSchema(con, new boolean[]{true, true, true, true, true});
73     ScenarioUtility.displayResultOnScreen(con.getMetaData().getTables(null,
74         null, null, null));
75   }
76
77   private void testTheSchema(Connection JavaDoc con, boolean[] success)
78       throws Exception JavaDoc
79   {
80     testTheTable(con, "DOCUMENT", success[0]);
81     testTheTable(con, "BLOB", success[1]);
82     testTheTable(con, "PPOSITION", success[2]);
83     testTheTable(con, "PRODUCT", success[3]);
84     testTheTable(con, "ADDRESS", success[4]);
85   }
86
87   private void testTheTable(Connection JavaDoc con, String JavaDoc table, boolean assertTrue)
88   {
89     try
90     {
91       ScenarioUtility.getSingleQueryResult("select * from " + table, con);
92       if (!assertTrue)
93         fail("failure was expected on table:" + table);
94     }
95     catch (Exception JavaDoc e)
96     {
97       if (assertTrue)
98         fail("success was expected on table:" + table);
99     }
100   }
101 }
Popular Tags