/** Verifies that we can only have MaxTxns (1000 right now) active transactions at any given time */ void sessionManager_2() { int i; SessionManager *sm; SessionManager::TxnID txns[1001]; string filename; // destroySemaphores(); // destroyShmseg(); sm = new SessionManager(); filename = sm->getTxnIDFilename(); delete sm; sm = new SessionManager(); for (i = 0; i < 1000; i++) { txns[i] = sm->newTxnID(i, false); CPPUNIT_ASSERT(txns[i].valid == true); //CPPUNIT_ASSERT(sm->verID() == txns[i].id); } txns[1000] = sm->newTxnID(i, false); CPPUNIT_ASSERT(txns[1000].valid == false); for (i = 999; i >= 0; i--) { SessionManager::TxnID tmp = sm->getTxnID(i); CPPUNIT_ASSERT(tmp.valid == txns[i].valid == true); CPPUNIT_ASSERT(tmp.id == txns[i].id); sm->committed(txns[i]); tmp = sm->getTxnID(i); CPPUNIT_ASSERT(tmp.valid == false); CPPUNIT_ASSERT(txns[i].valid == false); } try { sm->committed(txns[1000]); } // expected exception catch(invalid_argument& e) { } delete sm; // destroySemaphores(); // destroyShmseg(); }
/** Verifies that transaction IDs get saved and restored correctly across "reboots" */ void sessionManager_3() { SessionManager *sm; string filename; SessionManager::TxnID txnid; // scrub env sm = new SessionManager(); filename = sm->getTxnIDFilename(); delete sm; // destroyShmseg(); // destroySemaphores(); sm = new SessionManager(); txnid = sm->newTxnID(0); // CPPUNIT_ASSERT(txnid.id == 1); delete sm; // destroyShmseg(); // destroySemaphores(); sm = new SessionManager(); sm->committed(txnid); txnid = sm->newTxnID(1); // CPPUNIT_ASSERT(txnid.id == 2); delete sm; sm = new SessionManager(); sm->committed(txnid); // destroyShmseg(); // destroySemaphores(); }
void sessionManager_1() { SessionManager *sm = NULL; SessionManager::TxnID txn; const SessionManager::SIDTIDEntry* activeTxns; int len; string filename; // destroySemaphores(); // destroyShmseg(); try { sm = new SessionManager(); //CPPUNIT_ASSERT(sm->verID() == 0); filename = sm->getTxnIDFilename(); delete sm; sm = new SessionManager(); txn = sm->newTxnID(0); CPPUNIT_ASSERT(txn.valid == true); // CPPUNIT_ASSERT(txn.id == 1); // CPPUNIT_ASSERT(sm->verID() == 1); txn = sm->newTxnID(1); CPPUNIT_ASSERT(txn.valid == true); // CPPUNIT_ASSERT(txn.id == 2); // CPPUNIT_ASSERT(sm->verID() == 2); activeTxns = sm->SIDTIDMap(len); CPPUNIT_ASSERT(activeTxns != NULL); CPPUNIT_ASSERT(len == 2); txn = sm->getTxnID(0); CPPUNIT_ASSERT(txn.valid == true); // CPPUNIT_ASSERT(txn.id == 1); CPPUNIT_ASSERT(txn.valid == activeTxns[0].txnid.valid); // CPPUNIT_ASSERT(txn.id == activeTxns[0].txnid.id); txn = sm->getTxnID(1); CPPUNIT_ASSERT(txn.valid == true); // CPPUNIT_ASSERT(txn.id == 2); CPPUNIT_ASSERT(txn.valid == activeTxns[1].txnid.valid); // CPPUNIT_ASSERT(txn.id == activeTxns[1].txnid.id); delete [] activeTxns; //make sure it's consistent across invocations delete sm; sm = new SessionManager(); activeTxns = sm->SIDTIDMap(len); CPPUNIT_ASSERT(activeTxns != NULL); CPPUNIT_ASSERT(len == 2); txn = sm->getTxnID(0); CPPUNIT_ASSERT(txn.valid == true); // CPPUNIT_ASSERT(txn.id == 1); CPPUNIT_ASSERT(txn.valid == activeTxns[0].txnid.valid); // CPPUNIT_ASSERT(txn.id == activeTxns[0].txnid.id); txn = sm->getTxnID(1); CPPUNIT_ASSERT(txn.valid == true); // CPPUNIT_ASSERT(txn.id == 2); CPPUNIT_ASSERT(txn.valid == activeTxns[1].txnid.valid); // CPPUNIT_ASSERT(txn.id == activeTxns[1].txnid.id); sm->rolledback(txn); CPPUNIT_ASSERT(txn.valid == false); txn = sm->getTxnID(0); sm->committed(txn); CPPUNIT_ASSERT(txn.valid == false); delete [] activeTxns; activeTxns = sm->SIDTIDMap(len); CPPUNIT_ASSERT(len == 0); delete [] activeTxns; } catch(runtime_error &e) { cout << "caught runtime_error (why doesn't cppunit notice these?): " << e.what() << endl; if (sm != NULL) delete sm; // destroySemaphores(); // destroyShmseg(); throw logic_error("Hey! Stop!"); } catch(exception &e) { cout << "caught exception: " << e.what() << endl; if (sm != NULL) delete sm; // destroySemaphores(); // destroyShmseg(); throw; } delete sm; // destroySemaphores(); // destroyShmseg(); }