use of org.apache.derby.iapi.services.context.ContextManager in project derby by apache.
the class T_RawStoreFactory method runTestSet.
/**
* run the test
*
* @exception T_Fail Unexpected behaviour from the API
*/
protected void runTestSet() throws T_Fail {
// get a utility helper
t_util = new T_Util(factory, lf, contextService);
ContextManager cm1 = contextService.newContextManager();
contextService.setCurrentContextManager(cm1);
try {
// Run the tests with data not logged for purges.
REPORT("Running tests with no data logged for purges");
// logged by default
openMode = 0;
runPurgeWithNoDataLoggesTests();
// Run the tests in normal logged mode
REPORT("Running tests with logging requested");
// logged by default
openMode = 0;
runEachTest();
// run the tests on temp tables
REPORT("Running tests for temp tables");
// obviously, we can't test rollback if we are not logging
testRollback = false;
runTempTests();
// Run the tests in unlogged mode
REPORT("Running tests in unlogged mode");
openMode = ContainerHandle.MODE_UNLOGGED | ContainerHandle.MODE_CREATE_UNLOGGED;
// obviously, we can't test rollback if we are not logging
testRollback = false;
runEachTest();
// if more runs are added here then you probably want to reset testRollback to
// its initial value, or add the runs before the unlogged mode.
} catch (StandardException se) {
// Assume database is not active. DERBY-4856 thread dump
cm1.cleanupOnError(se, false);
throw T_Fail.exceptionFail(se);
} finally {
contextService.resetCurrentContextManager(cm1);
}
}
use of org.apache.derby.iapi.services.context.ContextManager in project derby by apache.
the class commit_method method XATest_5.
/**
* Very simple testing of the recover() call.
* <p>
* @exception StandardException Standard exception policy.
*/
void XATest_5(commit_method commit_method) throws StandardException, T_Fail {
REPORT("(XATest_5) starting");
// Should be no prepared transactions when we first start.
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN).length != 0) {
throw T_Fail.testFailMsg("recover incorrectly returned prepared xacts.");
}
// Should be no prepared transactions when we first start.
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMNOFLAGS).length != 0) {
throw T_Fail.testFailMsg("NOFLAGS should always return 0.");
}
ContextManager cm = getContextService().getCurrentContextManager();
// COMMIT AN IDLE TRANSACTION.
// Start a global transaction
XATransactionController xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// Should be no prepared transactions, there is one idle global xact.
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN).length != 0) {
throw T_Fail.testFailMsg("recover incorrectly returned prepared xacts.");
}
// commit an idle transaction - using onePhase optimization.
commit_method.commit(true, 42, global_id, branch_id, xa_tc);
// done with this xact.
xa_tc.destroy();
// COMMIT AN UPDATE ONLY TRANSACTION.
// Start a global transaction
xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// Create a heap conglomerate.
T_AccessRow template_row = new T_AccessRow(1);
long conglomid = xa_tc.createConglomerate(// create a heap conglomerate
"heap", // 1 column template.
template_row.getRowArray(), // column sort order - not required for heap
null, // default collation
null, // default properties
null, // not temporary
TransactionController.IS_DEFAULT);
// Should be no prepared transactions, there is one update global xact.
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN).length != 0) {
throw T_Fail.testFailMsg("recover incorrectly returned prepared xacts.");
}
// commit an idle transaction - using onePhase optimization.
commit_method.commit(true, 42, global_id, branch_id, xa_tc);
// done with this xact.
xa_tc.destroy();
// COMMIT A READ ONLY TRANSACTION.
// Start a global transaction
xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// Open a scan on the conglomerate.
ScanController scan1 = xa_tc.openScan(conglomid, // don't hold
false, // not for update
0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
(FormatableBitSet) null, // start position - first row in conglomerate
null, // unused if start position is null.
0, // qualifier - accept all rows
null, // stop position - last row in conglomerate
null, // unused if stop position is null.
0);
scan1.next();
scan1.close();
// Should be no prepared transactions, there is one update global xact.
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN).length != 0) {
throw T_Fail.testFailMsg("recover incorrectly returned prepared xacts.");
}
// commit an idle transaction - using onePhase optimization.
commit_method.commit(true, 42, global_id, branch_id, xa_tc);
// done with this xact.
xa_tc.destroy();
// PREPARE AN UPDATE TRANSACTION.
// Start a global transaction
xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// Create a heap conglomerate.
template_row = new T_AccessRow(1);
conglomid = xa_tc.createConglomerate(// create a heap conglomerate
"heap", // 1 column template.
template_row.getRowArray(), // column sort order - not required for heap
null, // default collation
null, // default properties
null, // not temporary
TransactionController.IS_DEFAULT);
// Should be no prepared transactions, there is one update global xact.
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN).length != 0) {
throw T_Fail.testFailMsg("recover incorrectly returned prepared xacts.");
}
// prepare the update xact.
if (xa_tc.xa_prepare() != XATransactionController.XA_OK) {
throw T_Fail.testFailMsg("prepare of update xact did not return XA_OK.");
}
try {
// Open a scan on the conglomerate.
scan1 = xa_tc.openScan(conglomid, // don't hold
false, // not for update
0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
(FormatableBitSet) null, // start position - first row in conglomerate
null, // unused if start position is null.
0, // qualifier - accept all rows
null, // stop position - last row in conglomerate
null, // unused if stop position is null.
0);
scan1.next();
scan1.close();
throw T_Fail.testFailMsg("Should not be able to do anything on xact after prepare.");
} catch (StandardException se) {
// expected exception, fall through.
}
// Should be no prepared transactions, there is one update global xact.
Xid[] prepared_xacts = ((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN);
if (prepared_xacts.length != 1) {
throw T_Fail.testFailMsg("recover incorrectly returned wrong prepared xacts.");
}
if (prepared_xacts[0].getFormatId() != 42)
throw T_Fail.testFailMsg("bad format id = " + prepared_xacts[0].getFormatId());
byte[] gid = prepared_xacts[0].getGlobalTransactionId();
if (!java.util.Arrays.equals(gid, global_id)) {
throw T_Fail.testFailMsg("bad global id = " + org.apache.derbyTesting.unitTests.util.BitUtil.hexDump(gid));
}
byte[] bid = prepared_xacts[0].getBranchQualifier();
if (!java.util.Arrays.equals(bid, branch_id)) {
throw T_Fail.testFailMsg("bad branch id = " + org.apache.derbyTesting.unitTests.util.BitUtil.hexDump(bid));
}
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMNOFLAGS).length != 0) {
throw T_Fail.testFailMsg("NOFLAGS should always return 0.");
}
// commit a prepared transaction - using two phase.
commit_method.commit(false, 42, global_id, branch_id, xa_tc);
// Should be no prepared transactions, there is one update global xact.
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN).length != 0) {
throw T_Fail.testFailMsg("recover incorrectly returned prepared xacts.");
}
// done with this xact.
xa_tc.destroy();
// Should be no prepared transactions, there is one update global xact.
if (((XAResourceManager) store.getXAResourceManager()).recover(XAResource.TMSTARTRSCAN).length != 0) {
throw T_Fail.testFailMsg("recover incorrectly returned prepared xacts.");
}
REPORT("(XATest_5) finishing");
}
use of org.apache.derby.iapi.services.context.ContextManager in project derby by apache.
the class commit_method method XATest_1.
/**
************************************************************************
* Utility methods.
**************************************************************************
*/
/**
************************************************************************
* Test Cases.
**************************************************************************
*/
/**
* one phase commit xa transaction.
* <p>
* @exception StandardException Standard exception policy.
*/
void XATest_1(commit_method commit_method) throws StandardException, T_Fail {
REPORT("(XATest_1) starting");
ContextManager cm = getContextService().getCurrentContextManager();
// COMMIT AN IDLE TRANSACTION.
// Start a global transaction
XATransactionController xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// commit an idle transaction - using onePhase optimization.
commit_method.commit(true, 42, global_id, branch_id, xa_tc);
// done with this xact.
xa_tc.destroy();
// COMMIT AN UPDATE ONLY TRANSACTION.
// Start a global transaction
xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// Create a heap conglomerate.
T_AccessRow template_row = new T_AccessRow(1);
long conglomid = xa_tc.createConglomerate(// create a heap conglomerate
"heap", // 1 column template.
template_row.getRowArray(), // column sort order - not required for heap
null, // default collation
null, // default properties
null, // not temporary
TransactionController.IS_DEFAULT);
// commit an idle transaction - using onePhase optimization.
commit_method.commit(true, 42, global_id, branch_id, xa_tc);
// done with this xact.
xa_tc.destroy();
// COMMIT A READ ONLY TRANSACTION.
// Start a global transaction
xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// Open a scan on the conglomerate.
ScanController scan1 = xa_tc.openScan(conglomid, // don't hold
false, // not for update
0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
(FormatableBitSet) null, // start position - first row in conglomerate
null, // unused if start position is null.
0, // qualifier - accept all rows
null, // stop position - last row in conglomerate
null, // unused if stop position is null.
0);
scan1.next();
scan1.close();
// commit an idle transaction - using onePhase optimization.
commit_method.commit(true, 42, global_id, branch_id, xa_tc);
// done with this xact.
xa_tc.destroy();
REPORT("(XATest_1) finishing");
}
use of org.apache.derby.iapi.services.context.ContextManager in project derby by apache.
the class commit_method method XATest_2.
/**
* simple two phase commit xa transaction.
* <p>
* @exception StandardException Standard exception policy.
*/
void XATest_2(commit_method commit_method) throws StandardException, T_Fail {
REPORT("(XATest_2) starting");
ContextManager cm = getContextService().getCurrentContextManager();
// COMMIT AN IDLE TRANSACTION.
// Start a global transaction
XATransactionController xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
if (!xa_tc.isGlobal()) {
throw T_Fail.testFailMsg("should be a global transaction.");
}
// This prepare will commit the idle transaction.
if (xa_tc.xa_prepare() != XATransactionController.XA_RDONLY) {
throw T_Fail.testFailMsg("prepare of idle xact did not return XA_RDONLY.");
}
// commit an idle transaction - using onePhase optimization.
try {
// this should fail as the xact has been committed, so committing
// it in 2 phase mode should fail. This test can't be run in
// offline mode, no transaction will be found. Pass null as
// global_id to make that test not run.
commit_method.commit(false, 42, null, null, xa_tc);
throw T_Fail.testFailMsg("A XA_RDONLY prepare-committed xact cant be 2P xa_committed.");
} catch (StandardException se) {
// expected exception - drop through.
}
// should not be able to find this global xact, it has been committed
if (((XAResourceManager) store.getXAResourceManager()).find(new XAXactId(42, global_id, branch_id)) != null) {
throw T_Fail.testFailMsg("A XA_RDONLY prepare-committed xact should not be findable.");
}
// done with this xact.
xa_tc.destroy();
// COMMIT AN UPDATE ONLY TRANSACTION.
// Start a global transaction
xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// Create a heap conglomerate.
T_AccessRow template_row = new T_AccessRow(1);
long conglomid = xa_tc.createConglomerate(// create a heap conglomerate
"heap", // 1 column template.
template_row.getRowArray(), // column sort order - not required for heap
null, // default collation
null, // default properties
null, // not temporary
TransactionController.IS_DEFAULT);
// prepare the update xact.
if (xa_tc.xa_prepare() != XATransactionController.XA_OK) {
throw T_Fail.testFailMsg("prepare of update xact did not return XA_OK.");
}
// commit an idle transaction - using onePhase optimization.
commit_method.commit(false, 42, global_id, branch_id, xa_tc);
// done with this xact.
xa_tc.destroy();
// COMMIT A READ ONLY TRANSACTION.
// Start a global transaction
xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// Open a scan on the conglomerate.
ScanController scan1 = xa_tc.openScan(conglomid, // don't hold
false, // not for update
0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
(FormatableBitSet) null, // start position - first row in conglomerate
null, // unused if start position is null.
0, // qualifier - accept all rows
null, // stop position - last row in conglomerate
null, // unused if stop position is null.
0);
scan1.next();
scan1.close();
// This prepare will commit the idle transaction.
if (xa_tc.xa_prepare() != XATransactionController.XA_RDONLY) {
throw T_Fail.testFailMsg("prepare of idle xact did not return XA_RDONLY.");
}
// commit an idle transaction - using onePhase optimization.
try {
// this should fail as the xact has been committed, so committing
// it in 2 phase mode should fail. This test can't be run in
// offline mode, no transaction will be found. Pass null as
// global_id to make that test not run.
commit_method.commit(false, 42, null, null, xa_tc);
throw T_Fail.testFailMsg("A XA_RDONLY prepare-committed xact cant be 2P xa_committed.");
} catch (StandardException se) {
// expected exception - drop through.
}
// should not be able to find this global xact, it has been committed
if (((XAResourceManager) store.getXAResourceManager()).find(new XAXactId(42, global_id, branch_id)) != null) {
throw T_Fail.testFailMsg("A XA_RDONLY prepare-committed xact should not be findable.");
}
// done with this xact.
xa_tc.destroy();
REPORT("(XATest_2) finishing");
}
use of org.apache.derby.iapi.services.context.ContextManager in project derby by apache.
the class commit_method method XATest_4.
/**
* Test aborts of prepared two phase commit xa transaction.
* <p>
* @exception StandardException Standard exception policy.
*/
void XATest_4(commit_method commit_method) throws StandardException, T_Fail {
REPORT("(XATest_4) starting");
ContextManager cm = getContextService().getCurrentContextManager();
// ABORT AN IDLE TRANSACTION.
// Start a global transaction
XATransactionController xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// This prepare will commit the idle transaction.
if (xa_tc.xa_prepare() != XATransactionController.XA_RDONLY) {
throw T_Fail.testFailMsg("prepare of idle xact did not return XA_RDONLY.");
}
// nothing to do, will just abort the next current idle xact.
// after prepare/readonly we cna continue to use transaction
commit_method.commit(true, 42, null, null, xa_tc);
// should not be able to find this global xact, it has been committed
if (((XAResourceManager) store.getXAResourceManager()).find(new XAXactId(42, global_id, branch_id)) != null) {
throw T_Fail.testFailMsg("A XA_RDONLY prepare-committed xact should not be findable.");
}
// done with this xact.
xa_tc.destroy();
// ABORT AN UPDATE ONLY TRANSACTION.
// Start a global transaction
xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// Create a heap conglomerate.
T_AccessRow template_row = new T_AccessRow(1);
long conglomid = xa_tc.createConglomerate(// create a heap conglomerate
"heap", // 1 column template.
template_row.getRowArray(), // column sort order - not required for heap
null, // default collation
null, // default properties
null, // not temporary
TransactionController.IS_DEFAULT);
// Open a scan on the conglomerate, to verify the create happened,
// and to show that the same openScan done after abort fails.
ScanController scan1 = xa_tc.openScan(conglomid, // don't hold
false, // not for update
0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
(FormatableBitSet) null, // start position - first row in conglomerate
null, // unused if start position is null.
0, // qualifier - accept all rows
null, // stop position - last row in conglomerate
null, // unused if stop position is null.
0);
scan1.next();
scan1.close();
// prepare the update xact.
if (xa_tc.xa_prepare() != XATransactionController.XA_OK) {
throw T_Fail.testFailMsg("prepare of update xact did not return XA_OK.");
}
try {
// Open a scan on the conglomerate.
scan1 = xa_tc.openScan(conglomid, // don't hold
false, // not for update
0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
(FormatableBitSet) null, // start position - first row in conglomerate
null, // unused if start position is null.
0, // qualifier - accept all rows
null, // stop position - last row in conglomerate
null, // unused if stop position is null.
0);
scan1.next();
scan1.close();
throw T_Fail.testFailMsg("Should not be able to do anything on xact after prepare.");
} catch (StandardException se) {
// expected exception, fall through.
}
// commit an idle transaction - using onePhase optimization.
commit_method.rollback(42, global_id, branch_id, xa_tc);
commit_method.commit(true, 42, null, null, xa_tc);
// should not be able to find this global xact, it has been committed
if (((XAResourceManager) store.getXAResourceManager()).find(new XAXactId(42, global_id, branch_id)) != null) {
throw T_Fail.testFailMsg("A xa_rollbacked xact should not be findable.");
}
// done with this xact.
xa_tc.destroy();
// Start a global transaction
xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
try {
// Open a scan on the conglomerate.
scan1 = xa_tc.openScan(conglomid, // don't hold
false, // not for update
0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
(FormatableBitSet) null, // start position - first row in conglomerate
null, // unused if start position is null.
0, // qualifier - accept all rows
null, // stop position - last row in conglomerate
null, // unused if stop position is null.
0);
scan1.next();
scan1.close();
throw T_Fail.testFailMsg("Should not be able to open conglom, the create was aborted.");
} catch (StandardException se) {
// expected exception, fall through.
}
xa_tc.destroy();
// ABORT A READ ONLY TRANSACTION.
// Start a global transaction
xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// Create a heap conglomerate.
template_row = new T_AccessRow(1);
conglomid = xa_tc.createConglomerate(// create a heap conglomerate
"heap", // 1 column template.
template_row.getRowArray(), // column sort order - not required for heap
null, // default collation
null, // default properties
null, // not temporary
TransactionController.IS_DEFAULT);
commit_method.commit(true, 42, global_id, branch_id, xa_tc);
xa_tc.destroy();
// Start a global transaction
xa_tc = (XATransactionController) store.startXATransaction(cm, // fake format id
42, global_id, branch_id);
// Open a scan on the conglomerate.
scan1 = xa_tc.openScan(conglomid, // don't hold
false, // not for update
0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
(FormatableBitSet) null, // start position - first row in conglomerate
null, // unused if start position is null.
0, // qualifier - accept all rows
null, // stop position - last row in conglomerate
null, // unused if stop position is null.
0);
scan1.next();
scan1.close();
// This prepare will commit the idle transaction.
if (xa_tc.xa_prepare() != XATransactionController.XA_RDONLY) {
throw T_Fail.testFailMsg("prepare of idle xact did not return XA_RDONLY.");
}
// commit an idle transaction - using onePhase optimization.
commit_method.commit(true, 42, null, null, xa_tc);
// should not be able to find this global xact, it has been committed
if (((XAResourceManager) store.getXAResourceManager()).find(new XAXactId(42, global_id, branch_id)) != null) {
throw T_Fail.testFailMsg("A XA_RDONLY prepare-committed xact should not be findable.");
}
// done with this xact.
xa_tc.destroy();
REPORT("(XATest_5) finishing");
}
Aggregations