summaryrefslogtreecommitdiff
path: root/cpp/src/tests/TxBufferTest.cpp
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2007-04-20 17:11:23 +0000
committerGordon Sim <gsim@apache.org>2007-04-20 17:11:23 +0000
commit53605c52439daacf4a0d96a6bf4e9c95a7425b76 (patch)
tree7c57c4153a463439a8488968eee14415c6d55253 /cpp/src/tests/TxBufferTest.cpp
parent0a7a787a38f2761e21219bf99a8a2467dfac5eef (diff)
downloadqpid-python-53605c52439daacf4a0d96a6bf4e9c95a7425b76.tar.gz
Added some dtx related unit tests
Added support for suspend and resume git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@530853 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/tests/TxBufferTest.cpp')
-rw-r--r--cpp/src/tests/TxBufferTest.cpp133
1 files changed, 1 insertions, 132 deletions
diff --git a/cpp/src/tests/TxBufferTest.cpp b/cpp/src/tests/TxBufferTest.cpp
index f58d6e356f..afe6d2b0fc 100644
--- a/cpp/src/tests/TxBufferTest.cpp
+++ b/cpp/src/tests/TxBufferTest.cpp
@@ -22,144 +22,13 @@
#include "qpid_test_plugin.h"
#include <iostream>
#include <vector>
+#include "TxMocks.h"
using namespace qpid::broker;
using boost::static_pointer_cast;
-template <class T> void assertEqualVector(std::vector<T>& expected, std::vector<T>& actual){
- unsigned int i = 0;
- while(i < expected.size() && i < actual.size()){
- CPPUNIT_ASSERT_EQUAL(expected[i], actual[i]);
- i++;
- }
- CPPUNIT_ASSERT(i == expected.size());
- CPPUNIT_ASSERT(i == actual.size());
-}
-
class TxBufferTest : public CppUnit::TestCase
{
- class MockTxOp : public TxOp{
- enum op_codes {PREPARE=2, COMMIT=4, ROLLBACK=8};
- std::vector<int> expected;
- std::vector<int> actual;
- bool failOnPrepare;
- public:
- typedef boost::shared_ptr<MockTxOp> shared_ptr;
-
- MockTxOp() : failOnPrepare(false) {}
- MockTxOp(bool _failOnPrepare) : failOnPrepare(_failOnPrepare) {}
-
- bool prepare(TransactionContext*) throw(){
- actual.push_back(PREPARE);
- return !failOnPrepare;
- }
- void commit() throw(){
- actual.push_back(COMMIT);
- }
- void rollback() throw(){
- actual.push_back(ROLLBACK);
- }
- MockTxOp& expectPrepare(){
- expected.push_back(PREPARE);
- return *this;
- }
- MockTxOp& expectCommit(){
- expected.push_back(COMMIT);
- return *this;
- }
- MockTxOp& expectRollback(){
- expected.push_back(ROLLBACK);
- return *this;
- }
- void check(){
- assertEqualVector(expected, actual);
- }
- ~MockTxOp(){}
- };
-
- class MockTransactionalStore : public TransactionalStore{
- enum op_codes {BEGIN=2, COMMIT=4, ABORT=8};
- std::vector<int> expected;
- std::vector<int> actual;
-
- enum states {OPEN = 1, COMMITTED = 2, ABORTED = 3};
- int state;
-
- class TestTransactionContext : public TransactionContext{
- MockTransactionalStore* store;
- public:
- TestTransactionContext(MockTransactionalStore* _store) : store(_store) {}
- void commit(){
- if(store->state != OPEN) throw "txn already completed";
- store->state = COMMITTED;
- }
-
- void abort(){
- if(store->state != OPEN) throw "txn already completed";
- store->state = ABORTED;
- }
- ~TestTransactionContext(){}
- };
-
-
- public:
- MockTransactionalStore() : state(OPEN){}
-
- std::auto_ptr<TPCTransactionContext> begin(const std::string&){
- throw "Operation not supported";
- }
- void prepare(TPCTransactionContext&){
- throw "Operation not supported";
- }
- void collectPreparedXids(std::set<std::string>&)
- {
- throw "Operation not supported";
- }
-
-
- std::auto_ptr<TransactionContext> begin(){
- actual.push_back(BEGIN);
- std::auto_ptr<TransactionContext> txn(new TestTransactionContext(this));
- return txn;
- }
- void commit(TransactionContext& ctxt){
- actual.push_back(COMMIT);
- dynamic_cast<TestTransactionContext&>(ctxt).commit();
- }
- void abort(TransactionContext& ctxt){
- actual.push_back(ABORT);
- dynamic_cast<TestTransactionContext&>(ctxt).abort();
- }
- MockTransactionalStore& expectBegin(){
- expected.push_back(BEGIN);
- return *this;
- }
- MockTransactionalStore& expectCommit(){
- expected.push_back(COMMIT);
- return *this;
- }
- MockTransactionalStore& expectAbort(){
- expected.push_back(ABORT);
- return *this;
- }
- void check(){
- assertEqualVector(expected, actual);
- }
-
- bool isCommitted(){
- return state == COMMITTED;
- }
-
- bool isAborted(){
- return state == ABORTED;
- }
-
- bool isOpen() const{
- return state == OPEN;
- }
- ~MockTransactionalStore(){}
- };
-
CPPUNIT_TEST_SUITE(TxBufferTest);
CPPUNIT_TEST(testCommitLocal);
CPPUNIT_TEST(testFailOnCommitLocal);