|
reSIProcate/repro
9694
|


Public Member Functions | |
| DummyTU (resip::SipStack *stack) | |
| virtual | ~DummyTU () |
| virtual void | go () |
| virtual const resip::Data & | name () const |
Private Attributes | |
| repro::Dispatcher * | mDispatcher |
| resip::SipStack * | mStack |
| resip::Data | mName |
Definition at line 94 of file testDispatcher.cxx.
| test::DummyTU::DummyTU | ( | resip::SipStack * | stack | ) | [inline] |
Definition at line 97 of file testDispatcher.cxx.
{
mName="DummyTU";
mStack=stack;
mStack->registerTransactionUser(*this);
DummyWorker* dw = new DummyWorker;
std::auto_ptr<repro::Worker> worker(dw);
mDispatcher = new repro::Dispatcher(worker,mStack,3,false);
}
| virtual test::DummyTU::~DummyTU | ( | ) | [inline, virtual] |
Definition at line 107 of file testDispatcher.cxx.
{
delete mDispatcher;
}
| virtual void test::DummyTU::go | ( | ) | [inline, virtual] |
Definition at line 112 of file testDispatcher.cxx.
{
assert(mDispatcher);
DummyWorkMessage* lost = new DummyWorkMessage(this);
//Dispatcher should not be accepting work yet
assert(!mDispatcher->post(std::auto_ptr<resip::ApplicationMessage>(lost)));
mDispatcher->startAll();
DummyWorkMessage* a = new DummyWorkMessage(this,"A");
DummyWorkMessage* b = new DummyWorkMessage(this,"B");
DummyWorkMessage* c = new DummyWorkMessage(this,"C");
DummyWorkMessage* d = new DummyWorkMessage(this,"D");
std::auto_ptr<resip::ApplicationMessage> aa(a);
std::auto_ptr<resip::ApplicationMessage> ab(b);
std::auto_ptr<resip::ApplicationMessage> ac(c);
std::auto_ptr<resip::ApplicationMessage> ad(d);
assert(mDispatcher->post(aa));
assert(mDispatcher->post(ab));
assert(mDispatcher->post(ac));
assert(mDispatcher->post(ad));
bool gotA=false;
bool gotB=false;
bool gotC=false;
bool gotD=false;
int i=0;
resip::Message* msg;
for( i=0; i<4 ;i++)
{
assert(msg = mFifo.getNext(1000));
DummyWorkMessage* dwm = dynamic_cast<DummyWorkMessage*>(msg);
assert(dwm);
if(dwm->result()==" I got that thing you sent me.")
{
if(dwm->query()=="A") gotA=true;
if(dwm->query()=="B") gotB=true;
if(dwm->query()=="C") gotC=true;
if(dwm->query()=="D") gotD=true;
}
delete dwm;
}
assert(i==4);
assert(gotA && gotB && gotC && gotD);
mDispatcher->stop();
lost = new DummyWorkMessage(this,"");
//We stopped the thread bank, it should not be accepting work.
assert(!mDispatcher->post(std::auto_ptr<resip::ApplicationMessage>(lost)));
mDispatcher->resume();
DummyWorkMessage* wasteTime1 = new DummyWorkMessage(this,"Take your time.");
DummyWorkMessage* wasteTime2 = new DummyWorkMessage(this,"Take your time.");
DummyWorkMessage* wasteTime3 = new DummyWorkMessage(this,"Take your time.");
DummyWorkMessage* wasteTime4 = new DummyWorkMessage(this,"Take your time.");
wasteTime1->wait=true;
wasteTime2->wait=true;
wasteTime3->wait=true;
wasteTime4->wait=true;
assert(mDispatcher->fifoCountDepth()==0);
mDispatcher->post(std::auto_ptr<resip::ApplicationMessage>(wasteTime1));
mDispatcher->post(std::auto_ptr<resip::ApplicationMessage>(wasteTime2));
mDispatcher->post(std::auto_ptr<resip::ApplicationMessage>(wasteTime3));
mDispatcher->post(std::auto_ptr<resip::ApplicationMessage>(wasteTime4));
mDispatcher->stop();
usleep(1000);
//Three in the thread bank, one in the queue.
assert(mDispatcher->fifoCountDepth()==1);
for( i=0; i<4 ;i++)
{
assert(msg = mFifo.getNext(2000));
DummyWorkMessage* dwm = dynamic_cast<DummyWorkMessage*>(msg);
assert(dwm);
assert(dwm->result()==" I got that thing you sent me.");
delete dwm;
}
assert(!(msg=mFifo.getNext(1000)));
mDispatcher->resume();
DummyWorkMessage* clog1 = new DummyWorkMessage(this);
DummyWorkMessage* clog2 = new DummyWorkMessage(this);
DummyWorkMessage* clog3 = new DummyWorkMessage(this);
clog1->wait=true;
clog2->wait=true;
clog3->wait=true;
//Three threads in the bank, each waiting for 1 sec
mDispatcher->post(std::auto_ptr<resip::ApplicationMessage>(clog1));
mDispatcher->post(std::auto_ptr<resip::ApplicationMessage>(clog2));
mDispatcher->post(std::auto_ptr<resip::ApplicationMessage>(clog3));
usleep(100);
for(i=0;i<1000;i++)
{
DummyWorkMessage* pummel = new DummyWorkMessage(this);
std::auto_ptr<resip::ApplicationMessage>batter(pummel);
assert(mDispatcher->post(batter));
}
usleep(100000);
assert(msg=mFifo.getNext(1000));
delete msg;
for(i=0;i<1002;i++)
{
msg=mFifo.getNext(10);
assert(msg);
delete msg;
}
mDispatcher->shutdownAll();
lost = new DummyWorkMessage(this);
assert(!(mDispatcher->post(std::auto_ptr<resip::ApplicationMessage>(lost))));
delete mDispatcher;
DummyWorker* dw = new DummyWorker;
std::auto_ptr<repro::Worker> worker(dw);
//Stack ptr set to null.
mDispatcher = new repro::Dispatcher(worker,0,3,true);
std::cout << "The following error message is intentional." << std::endl;
lost = new DummyWorkMessage(this);
assert(mDispatcher->post(std::auto_ptr<resip::ApplicationMessage>(lost)));
assert(!(msg=mFifo.getNext(100)));
}
| virtual const resip::Data& test::DummyTU::name | ( | ) | const [inline, virtual] |
Implements resip::TransactionUser.
Definition at line 278 of file testDispatcher.cxx.
{
return mName;
}
repro::Dispatcher* test::DummyTU::mDispatcher [private] |
Definition at line 285 of file testDispatcher.cxx.
resip::Data test::DummyTU::mName [private] |
Definition at line 287 of file testDispatcher.cxx.
resip::SipStack* test::DummyTU::mStack [private] |
Definition at line 286 of file testDispatcher.cxx.
1.7.5.1