use of org.apache.derbyTesting.junit.TestConfiguration in project derby by apache.
the class DSCreateShutdownDBTest method tearDown.
public void tearDown() throws Exception {
// attempt to get rid of any databases.
// only 5 dbs (in addition to defaultdb) should actually get
// created, but just in case, try all...
TestConfiguration conf = TestConfiguration.getCurrent();
for (int i = 0; i < ADDITIONAL_DBS.length; i++) {
removeDirectory(conf.getDatabasePath("emb" + ADDITIONAL_DBS[i]));
removeDirectory(conf.getDatabasePath("srv" + ADDITIONAL_DBS[i]));
}
super.tearDown();
}
use of org.apache.derbyTesting.junit.TestConfiguration in project derby by apache.
the class PoolXADSCreateShutdownDBTest method tearDown.
public void tearDown() throws Exception {
// attempt to get rid of any databases.
// only 5 dbs (in addition to the defaultdb) should actually get
// created, but just in case...
TestConfiguration conf = TestConfiguration.getCurrent();
for (int i = 0; i < ADDITIONAL_DBS.length; i++) {
removeDirectory(conf.getDatabasePath("emb" + ADDITIONAL_DBS[i]));
removeDirectory(conf.getDatabasePath("srv" + ADDITIONAL_DBS[i]));
}
super.tearDown();
}
use of org.apache.derbyTesting.junit.TestConfiguration in project derby by apache.
the class DriverTest method tearDown.
public void tearDown() throws Exception {
// attempt to get rid of any left-over trace files
for (int i = 0; i < 2; i++) {
String traceFileName = "trace" + (i + 1) + ".out";
File traceFile = new File(traceFileName);
if (PrivilegedFileOpsForTests.exists(traceFile)) {
// if it exists, attempt to get rid of it
PrivilegedFileOpsForTests.delete(traceFile);
}
}
TestConfiguration config = TestConfiguration.getCurrent();
for (String dbName : ADDITIONAL_DBS) {
removeDirectory(config.getDatabasePath(dbName));
}
super.tearDown();
}
use of org.apache.derbyTesting.junit.TestConfiguration in project derby by apache.
the class LuceneSupportPermsTest method test_005_deleteDirectory.
/**
* <p>
* Test error messages when a lucene directory has been deleted.
* </p>
*/
public void test_005_deleteDirectory() throws Exception {
Connection dboConnection = openUserConnection(TEST_DBO);
Connection ruthConnection = openUserConnection(RUTH);
createSchema(ruthConnection, Types.INTEGER);
goodStatement(dboConnection, LOAD_TOOL);
goodStatement(ruthConnection, INDEX_POEMS);
TestConfiguration config = getTestConfiguration();
String dbName = config.getDefaultDatabaseName();
String physicalDBName = config.getPhysicalDatabaseName(dbName);
String dbPath = config.getDatabasePath(physicalDBName);
File dbDirectory = new File(dbPath);
File luceneDirectory = new File(dbDirectory, "LUCENE");
File ruthDirectory = new File(luceneDirectory, "RUTH");
File poemsDirectory = new File(ruthDirectory, "POEMS");
File poemTextIndexDirectory = new File(poemsDirectory, "POEMTEXT");
assertTrue(deleteFile(poemTextIndexDirectory));
// but that doesn't stop you from deleting the index
goodStatement(ruthConnection, DROP_POEMS_INDEX);
expectCompilationError(ruthConnection, NONEXISTENT_TABLE_FUNCTION, "select * from table( ruth.textTable__textCol( 'one two three four five six seven eight nine ten', 100, null ) ) t");
goodStatement(dboConnection, UNLOAD_TOOL);
dropSchema(ruthConnection);
}
use of org.apache.derbyTesting.junit.TestConfiguration in project derby by apache.
the class Derby5937SlaveShutdownTest method testSlaveFailoverLeak.
public void testSlaveFailoverLeak() throws Exception {
// First establish a connection so that the database is created.
getConnection().close();
// Then shut down the database cleanly so that it can be used
// to seed the replication slave.
final TestConfiguration config = TestConfiguration.getCurrent();
config.shutdownDatabase();
// Copy the database to the slave.
final String masterDb = config.getDatabasePath(MASTER_DB);
final String slaveDb = config.getDatabasePath(SLAVE_DB);
PrivilegedFileOpsForTests.copy(new File(masterDb), new File(slaveDb));
// And start the slave.
DataSource startSlaveDS = JDBCDataSource.getDataSource(SLAVE_DB);
JDBCDataSource.setBeanProperty(startSlaveDS, "connectionAttributes", "startSlave=true;slaveHost=" + config.getHostName() + ";slavePort=" + config.getPort());
SlaveThread slave = new SlaveThread(startSlaveDS);
slave.start();
// Start the master. This will fail until the slave is up, so do
// it in a loop until successful or time runs out.
DataSource startMasterDS = JDBCDataSource.getDataSource();
JDBCDataSource.setBeanProperty(startMasterDS, "connectionAttributes", "startMaster=true;slaveHost=" + config.getHostName() + ";slavePort=" + config.getPort());
long giveUp = System.currentTimeMillis() + NetworkServerTestSetup.getWaitTime();
Connection c = null;
while (c == null) {
try {
c = startMasterDS.getConnection();
} catch (SQLException sqle) {
// Exit early if the slave has failed
slave.checkError();
if (System.currentTimeMillis() > giveUp) {
fail("Master won't start", sqle);
} else {
println("Retrying after startMaster failed with: " + sqle);
Thread.sleep(RETRY_INTERVAL);
}
}
}
c.close();
// Wait for the slave thread to complete, which it will do once
// it's connected to the master.
slave.join();
slave.checkError();
// Perform fail-over.
DataSource failoverDS = JDBCDataSource.getDataSource();
JDBCDataSource.setBeanProperty(failoverDS, "connectionAttributes", "failover=true");
try {
failoverDS.getConnection();
fail("failover should receive exception");
} catch (SQLException sqle) {
assertSQLState(FAILOVER_SUCCESS, sqle);
}
// Shut down the slave database. This will fail until failover is
// complete, so do it in a loop until successful or time runs out.
giveUp = System.currentTimeMillis() + NetworkServerTestSetup.getWaitTime();
DataSource slaveShutdownDS = JDBCDataSource.getDataSource(SLAVE_DB);
JDBCDataSource.setBeanProperty(slaveShutdownDS, "shutdownDatabase", "shutdown");
while (true) {
try {
slaveShutdownDS.getConnection();
fail("Shutdown of slave database didn't throw an exception");
} catch (SQLException sqle) {
if (DB_SHUTDOWN_SUCCESS.equals(sqle.getSQLState())) {
// of the loop.
break;
} else if (System.currentTimeMillis() > giveUp) {
fail("Could not shut down slave database", sqle);
} else {
println("Retrying after failover failed with: " + sqle);
Thread.sleep(RETRY_INTERVAL);
}
}
}
// This call used to fail on Windows because one of the log files
// was still open.
assertDirectoryDeleted(new File(slaveDb));
}
Aggregations