int closeTxns(const int& start, const int& end) { int first=start; int last=end; int totalClosed=0; for (int idx=first; idx<last ; idx++) { try { SessionManager::TxnID tmp = manager->getTxnID(idx+1000); if (tmp.valid == true) { manager->committed(tmp); CPPUNIT_ASSERT(tmp.valid==false); totalClosed++; } } catch (exception& e) { cerr << e.what() << endl; continue; } } return totalClosed; } //closeTxns
void sessionmanager_7() { SessionManager sm; SessionManager::TxnID txn, txn2; txn = sm.newTxnID(1000); txn2 = sm.getTxnID(1000); CPPUNIT_ASSERT(txn.id == txn2.id); CPPUNIT_ASSERT(txn.valid == txn2.valid == true); sm.rolledback(txn); CPPUNIT_ASSERT(txn.valid == false); txn2 = sm.getTxnID(1000); CPPUNIT_ASSERT(txn2.valid == false); }
/** 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(); }
CalpontSelectExecutionPlan* parseQuery(const string& query, const uint32_t sid) { //We're going to make parsing the query single-threaded for now. This makes it a lot // easier to interface with the parser and doesn;t materially affect overall query // performance (I think) mutex::scoped_lock lk(ParserMutex); boost::shared_ptr<CalpontSystemCatalog> csc = CalpontSystemCatalog::makeCalpontSystemCatalog(sid); CalpontSelectExecutionPlan* csep=0; csep = new CalpontSelectExecutionPlan(); //we use an auto_ptr here with some trepidation. We only want auto delete on an execption. //If the parseing and plan build succeed, we want the ptr to stay around. boost::scoped_ptr<> //doesn't have an API to release ownership, so we use auto_ptr... auto_ptr<CalpontSelectExecutionPlan> scsep(csep); yy_buffer_state* ybs=0; ybs = qfe_scan_string(query.c_str()); if (ybs != 0) { ParserCSEP = csep; ParserCSC = csc; if (qfeparse() != 0) throw runtime_error("syntax error"); qfe_delete_buffer(ybs); } else throw runtime_error("Internal parser memory error"); csep->data(query); SessionManager sm; TxnID txnID; txnID = sm.getTxnID(sid); if (!txnID.valid) { txnID.id = 0; txnID.valid = true; } QueryContext verID; verID = sm.verID(); csep->txnID(txnID.id); csep->verID(verID); csep->sessionID(sid); //cout << *csep << endl; scsep.release(); return csep; }
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(); }