1 24 25 package org.objectweb.cjdbc.scenario.raidb2; 26 27 import java.sql.Connection ; 28 29 import org.objectweb.cjdbc.scenario.templates.SimpleRaidb2Template; 30 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility; 31 32 38 public class Raidb2CheckSchemaScenario extends SimpleRaidb2Template 39 { 40 41 public void testSchemaRaidb2RR() throws Exception 42 { 43 cm.loadVirtualDatabases(controller, "myDB", "hsqldb-raidb2.xml"); 44 deepTestSchema(); 45 } 46 47 public void testSchemaRaidb2LPRF() throws Exception 48 { 49 cm.loadVirtualDatabases(controller, "myDB", "hsqldb-raidb2-LPRF.xml"); 50 deepTestSchema(); 51 } 52 53 private void deepTestSchema() throws Exception 54 { 55 mainVdb = controller.getVirtualDatabase("myDB"); 56 Connection con = getCJDBCConnection(); 57 58 testTheSchema(con, new boolean[]{true, true, true, true, true}); 59 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 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 con, boolean[] success) 78 throws Exception 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 con, String 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 e) 96 { 97 if (assertTrue) 98 fail("success was expected on table:" + table); 99 } 100 } 101 } | Popular Tags |