//on linux Mordor::IOManager user epoll
TEST(IOManager, event) {
//   Log::root()->level(Log::TRACE);
//   Log::root()->addSink( LogSink::ptr(new StdoutLogSink));
   //IOManager(size_t threads = 1, bool useCaller = true, bool autoStart = true);
   IOManager iomanager;
   const size_t conn_num = 5;
   std::vector<boost::shared_ptr<Conn> > conns; 
   conns.reserve(conn_num);

   //register event
   for(size_t i = 0 ; i < conn_num; i++){
       boost::shared_ptr<Conn> conn(new Conn);
       iomanager.registerEvent(conn->getReadFd(), IOManager::READ,  boost::bind(&Conn::read, conn));
       conns.push_back(conn);
   }

   //write 
   for(size_t i = 0; i < conns.size(); i++) {
      MORDOR_LOG_DEBUG(Log::root()) <<  " write on for  "  << conns[i]->getReadFd();
      conns[i]->write(100);
   }

    iomanager.dispatch();
    iomanager.stop();

   for(size_t i = 0; i < conns.size(); i++) {
      ASSERT_EQ(boost::this_thread::get_id() , conns[i]->tid);
      ASSERT_EQ(100, conns[i]->read_count);
   }
}
Beispiel #2
0
MORDOR_UNITTEST(IOManager, laterTimer)
{
    int sequence = 0;
    IOManager manager;
    manager.registerTimer(100000, boost::bind(&singleTimer, boost::ref(sequence), 1));
    MORDOR_TEST_ASSERT_EQUAL(sequence, 0);
    manager.dispatch();
    ++sequence;
    MORDOR_TEST_ASSERT_EQUAL(sequence, 2);
}