Beispiel #1
0
void sessionmanager_8()
{
	SessionManager sm;
	SessionManager::TxnID txn, txn2;
	const SessionManager::SIDTIDEntry *stmap;
	int len;

	txn = sm.newTxnID(1000, true);
	txn2 = sm.newTxnID(1001, true);
	stmap = sm.SIDTIDMap(len);

	CPPUNIT_ASSERT(len == 2);

#ifdef BRM_VERBOSE
	int i;
	cerr << "len = " << len << endl;
	for (i = 0; i < len; i++) {
		cerr << "  " << i << ": txnid=" << stmap[i].txnid.id << " valid=" << 
			stmap[i].txnid.valid << " sessionid=" << stmap[i].sessionid << endl;
	}
#endif

	sm.committed(txn);
	sm.committed(txn2);
	delete [] stmap;
	stmap = sm.SIDTIDMap(len);

	CPPUNIT_ASSERT(len == 0);
	delete [] stmap;
}
Beispiel #2
0
	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();
	}