1 24 25 package org.objectweb.cjdbc.scenario.raidb1.recovery; 26 27 import java.sql.Connection ; 28 import java.sql.PreparedStatement ; 29 import java.sql.ResultSet ; 30 import java.sql.ResultSetMetaData ; 31 32 import org.objectweb.cjdbc.scenario.templates.Raidb1RecoveryTemplate; 33 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility; 34 35 41 public class TableRecoveryScenario extends Raidb1RecoveryTemplate 42 { 43 private static final String BACKUP_LOGIN = "user"; 44 private static final String BACKUP_PASSWORD = ""; 45 private static final String BACKUPER = "Octopus"; 46 private static final String BACKUP_PATH = "../backup"; 47 48 53 public void testListTables() throws Exception 54 { 55 String dump = "dump" + System.currentTimeMillis(); 57 mainVdb.backupBackend("localhost", BACKUP_LOGIN, BACKUP_PASSWORD, dump, 58 BACKUPER, BACKUP_PATH, null); 59 60 String backendName = "localhost2"; 62 mainVdb.forceDisableBackend(backendName); 63 mainVdb.restoreDumpOnBackend("localhost", BACKUP_LOGIN, BACKUP_PASSWORD, 64 dump, null); 65 mainVdb.enableBackendFromCheckpoint("localhost"); 66 67 String [] types = new String []{"TABLE", "VIEW"}; 68 69 Connection con1 = getHypersonicConnection(9001); 70 ResultSet rs1 = con1.getMetaData().getTables(null, null, "%", types); 71 72 Connection con2 = getHypersonicConnection(9002); 73 ResultSet rs2 = con2.getMetaData().getTables(null, null, "%", types); 74 75 assertTrue("Metadata is different for tables", ScenarioUtility.checkEquals( 76 rs1, rs2)); 77 78 ResultSet rs = getHypersonicConnection(9001).getMetaData().getTables(null, 80 null, "%", types); 81 while (rs.next()) 82 { 83 String tableName = rs.getString(3); 85 String sql = "Select * from " + tableName; 86 System.out.println("Checking content of table:" + tableName); 87 88 PreparedStatement ps1 = con1.prepareStatement(sql); 89 PreparedStatement ps2 = con2.prepareStatement(sql); 90 91 94 rs1 = ps1.executeQuery(); 95 rs2 = ps2.executeQuery(); 96 97 assertTrue("Data is different for table:" + tableName, ScenarioUtility 98 .checkEquals(rs1, rs2)); 99 100 ResultSetMetaData rsmd1 = rs1.getMetaData(); 101 ResultSetMetaData rsmd2 = rs2.getMetaData(); 102 assertEquals("meta data column count are different for table:" 103 + tableName, rsmd1.getColumnCount(), rsmd2.getColumnCount()); 104 int colCount = rsmd1.getColumnCount(); 105 for (int i = 1; i <= colCount; i++) 106 { 107 String colName = rsmd1.getColumnName(i); 108 System.out.println("Checking metadata for column:" + colName); 109 assertEquals(rsmd1.getCatalogName(i), rsmd2.getCatalogName(i)); 110 assertEquals(rsmd1.getColumnDisplaySize(i), rsmd2 113 .getColumnDisplaySize(i)); 114 assertEquals(rsmd1.getColumnLabel(i), rsmd2.getColumnLabel(i)); 115 assertEquals(rsmd1.getColumnName(i), rsmd2.getColumnName(i)); 116 assertEquals(rsmd1.getColumnType(i), rsmd2.getColumnType(i)); 117 assertEquals(rsmd1.getColumnTypeName(i), rsmd2.getColumnTypeName(i)); 118 } 119 } 120 } 121 } | Popular Tags |