void KumonosuManagerTest::pingTest() { pthread_t serverThread; RequestQueue* iqueue = new RequestQueue(); RequestQueue* oqueue = new RequestQueue(); RequestQueue* imqueue = new RequestQueue(); shared_ptr<LocalRequestManagerHandler> handler (new LocalRequestManagerHandler(iqueue, oqueue, imqueue)); shared_ptr<TProcessor> serverProcessor (new LocalRequestManagerProcessor(handler)); shared_ptr<TServerTransport> transport(new TServerSocket(9393)); shared_ptr<TTransportFactory> transportFactory (new TBufferedTransportFactory()); shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory()); TSimpleServer *testServer = new TSimpleServer(serverProcessor, transport, transportFactory, protocolFactory); pthread_create(&serverThread, NULL, runServer, (void*) testServer); sleep(2); queueItem* item = new queueItem(); item->methodId = ManagerMethodMap::Ping; ping_arguments pingItem("a.badhostname.com", 8989, 24, 0, 1); item->argList = (arguments) pingItem; iqueue->addItem(0, item); KumonosuManager* manager = new KumonosuManager("localhost", 9393); // Add the server that would correspond with the Ping response // above Server newServer; newServer.setServerAddress("a.badhostname.com"); newServer.setServerPort(8989); newServer.setServerId(24); manager->addServer(newServer); pthread_t managerThread; pthread_create(&managerThread, NULL, runManager, (void*) manager); sleep(4); manager->stop(); testServer->stop(); CPPUNIT_ASSERT_MESSAGE("Incoming queue is not 0", iqueue->getItemQueue(0).size() == 0); CPPUNIT_ASSERT_MESSAGE("Outgoing queue is not 1", oqueue->getItemQueue(0).size() != 0); }
void KumonosuManagerTest::getServiceListTest() { pthread_t serverThread; RequestQueue* iqueue = new RequestQueue(); RequestQueue* oqueue = new RequestQueue(); RequestQueue* imqueue = new RequestQueue(); shared_ptr<LocalRequestManagerHandler> handler (new LocalRequestManagerHandler(iqueue, oqueue, imqueue)); shared_ptr<TProcessor> serverProcessor (new LocalRequestManagerProcessor(handler)); shared_ptr<TServerTransport> transport(new TServerSocket(9797)); shared_ptr<TTransportFactory> transportFactory (new TBufferedTransportFactory()); shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory()); TSimpleServer *testServer = new TSimpleServer(serverProcessor, transport, transportFactory, protocolFactory); pthread_create(&serverThread, NULL, runServer, (void*) testServer); sleep(2); queueItem* item = new queueItem(); item->methodId = ManagerMethodMap::GetServiceList; i32Arg serverId; serverId.name = "serverid"; serverId.value = 34; item->argList.i32Args.push_back(serverId); i32Arg serviceId; serviceId.name = "serviceid"; serviceId.value = 0; item->argList.i32Args.push_back(serviceId); iqueue->addItem(0, item); KumonosuManager* manager = new KumonosuManager("localhost", 9797); pthread_t managerThread; pthread_create(&managerThread, NULL, runManager, (void*) manager); sleep(4); manager->stop(); // getServerList should generate an outgoing message CPPUNIT_ASSERT_MESSAGE("Incoming queue is not 0", iqueue->getItemQueue(0).size() == 0); CPPUNIT_ASSERT_MESSAGE("Outgoing queue is not 1", oqueue->getItemQueue(0).size() == 1); testServer->stop(); }
void KumonosuManagerTest::methodNotFoundTest() { // Set up the server pthread_t serverThread; RequestQueue* iqueue = new RequestQueue(); RequestQueue* oqueue = new RequestQueue(); RequestQueue* imqueue = new RequestQueue(); shared_ptr<LocalRequestManagerHandler> handler (new LocalRequestManagerHandler(iqueue, oqueue, imqueue)); shared_ptr<TProcessor> serverProcessor (new LocalRequestManagerProcessor(handler)); shared_ptr<TServerTransport> transport(new TServerSocket(9292)); shared_ptr<TTransportFactory> transportFactory (new TBufferedTransportFactory()); shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory()); TSimpleServer *testServer = new TSimpleServer(serverProcessor, transport, transportFactory, protocolFactory); pthread_create(&serverThread, NULL, runServer, (void*) testServer); sleep(2); // Set up the invalid method call queueItem* item = new queueItem(); item->methodId = 800; iqueue->addItem(0, item); // Create the manager KumonosuManager* manager = new KumonosuManager("localhost", 9292); // Set the manager to run, invoking the methodNotFound call pthread_t managerThread; pthread_create(&managerThread, NULL, runManager, (void*) manager); // Pause to let it run some sleep(4); manager->stop(); CPPUNIT_ASSERT_MESSAGE("item queue size is not 0", iqueue->getItemQueue(0).size() == 0); testServer->stop(); }
void KumonosuManagerTest::getServiceListResponseTest() { pthread_t serverThread; RequestQueue* iqueue = new RequestQueue(); RequestQueue* oqueue = new RequestQueue(); RequestQueue* imqueue = new RequestQueue(); shared_ptr<LocalRequestManagerHandler> handler (new LocalRequestManagerHandler(iqueue, oqueue, imqueue)); shared_ptr<TProcessor> serverProcessor (new LocalRequestManagerProcessor(handler)); shared_ptr<TServerTransport> transport(new TServerSocket(9898)); shared_ptr<TTransportFactory> transportFactory (new TBufferedTransportFactory()); shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory()); TSimpleServer *testServer = new TSimpleServer(serverProcessor, transport, transportFactory, protocolFactory); pthread_create(&serverThread, NULL, runServer, (void*) testServer); sleep(2); queueItem* item = new queueItem(); item->methodId = ManagerMethodMap::GetServiceListResponse; iqueue->addItem(0, item); KumonosuManager* manager = new KumonosuManager("localhost", 9898); pthread_t managerThread; pthread_create(&managerThread, NULL, runManager, (void*) manager); sleep(4); manager->stop(); CPPUNIT_ASSERT_MESSAGE("Incoming queue is not 0", iqueue->getItemQueue(0).size() == 0); testServer->stop(); }
void RequestQueueTest::getItemQueueByCountTest() { RequestQueue* queue = new RequestQueue(); int32_t serviceId = 1; queueItem first_item; queueItem second_item; queueItem third_item; first_item.methodId = 0; second_item.methodId = 1; third_item.methodId = 2; queue->addItem(serviceId, &first_item); queue->addItem(serviceId, &second_item); queue->addItem(2, &third_item); std::queue<queueItem*> itemList = queue->getItemQueue(serviceId, 1); CPPUNIT_ASSERT(itemList.size() == 1); }