blob: 24f79643a94e494330487e2b0570bf458e1c8008 [file] [log] [blame]
Marc Slemko8a40a762006-07-19 17:46:50 +00001#include <TimerManager.h>
2#include <PosixThreadFactory.h>
3#include <Monitor.h>
4
5#include <assert.h>
6#include <iostream>
7
8namespace facebook { namespace thrift { namespace concurrency { namespace test {
9
10using namespace facebook::thrift::concurrency;
11
12/** ThreadManagerTests class
13
14 @author marc
15 @version $Id:$ */
16
17class TimerManagerTests {
18
19 class Task: public Runnable {
20
21 public:
22
23 Task(Monitor& monitor) :
24 _monitor(monitor),
25 _done(false) {}
26
27 void run() {
28
29 std::cout << "\t\t\tHello World" << std::endl;
30
31 _done = true;
32
33 {Synchronized s(_monitor);
34 _monitor.notifyAll();
35 }
36 }
37
38 Monitor& _monitor;
39 bool _done;
40 };
41
42public:
43
44 bool test00() {
45
46 TimerManager* timerManager = new TimerManager();
47
48 timerManager->threadFactory(new PosixThreadFactory());
49
50 timerManager->start();
51
52 assert(timerManager->state() == TimerManager::STARTED);
53
54 TimerManagerTests::Task* task = new TimerManagerTests::Task(_monitor);
55
56 {Synchronized s(_monitor);
57
58 timerManager->add(task, 1000LL);
59
60 _monitor.wait();
61 }
62
63 assert(task->_done);
64
65 delete task;
66
67 std::cout << "\t\t\tSuccess!" << std::endl;
68
69 return true;
70 }
71
72 friend class TestTask;
73
74 Monitor _monitor;
75};
76
77
78}}}} // facebook::thrift::concurrency
79
80using namespace facebook::thrift::concurrency::test;
81