8 #include <gtest/gtest.h>
10 #include <Poco/Thread.h>
25 Poco::Thread::sleep( milliseconds );
37 taskTTLManager.addTaskTTL(
taskId, 10 );
39 EXPECT_EQ( taskTTLManager.getTaskTTL(
taskId ), 10U);
43 EXPECT_EQ( taskTTLManager.getTaskTTL(
taskId ), 0U);
47 taskTTLManager.addTaskTTL(
taskId, 10 );
48 taskTTLManager.addTaskTTL(
taskId, 20 );
50 EXPECT_EQ( taskTTLManager.getTaskTTL(
taskId ), 20U);
54 taskTTLManager.addTaskTTL(
taskId, 20 );
55 EXPECT_EQ( taskTTLManager.getTaskTTL(
taskId ), 20U);
56 taskTTLManager.removeTaskTTL(
taskId );
57 EXPECT_FALSE( taskTTLManager.isTaskTerminatedByTTL(
taskId ) );
62 taskTTLManager.addTaskTTL(
taskId, 10 );
63 sleep_milliseconds(20);
64 EXPECT_TRUE( taskTTLManager.isTaskExpired(
taskId ) );
65 taskTTLManager.removeTaskTTL(
taskId );
66 EXPECT_TRUE( taskTTLManager.isTaskTerminatedByTTL(
taskId ) );
70 taskTTLManager.addTaskTTL(
taskId, 100 );
72 EXPECT_FALSE( taskTTLManager.isTaskExpired(
taskId ) );
73 sleep_milliseconds( 10 );
74 EXPECT_FALSE( taskTTLManager.isTaskExpired(
taskId ) );
78 taskTTLManager.addTaskTTL(
taskId, 100 );
80 sleep_milliseconds( 10 );
81 EXPECT_FALSE( taskTTLManager.isTaskExpired(
taskId, 20 ) );
85 taskTTLManager.addTaskTTL(
taskId, 10 );
87 EXPECT_FALSE( taskTTLManager.isTaskExpired(
taskId ) );
88 sleep_milliseconds( 10 );
89 EXPECT_TRUE( taskTTLManager.isTaskExpired(
taskId ) );
93 taskTTLManager.addTaskTTL(
taskId, 100 );
95 sleep_milliseconds( 10 );
96 EXPECT_TRUE( taskTTLManager.isTaskExpired(
taskId, 10 ) );
101 taskTTLManager.addTaskTTL(
taskId, 10 );
102 taskTTLManager.addTaskTTL(
taskId + 1, 20 );
103 taskTTLManager.addTaskTTL(
taskId + 2, 30 );
104 taskTTLManager.addTaskTTL(
taskId + 4, 40 );
105 taskTTLManager.addTaskTTL(
taskId + 5, 50 );
107 sleep_milliseconds( 11 );
108 taskTTLManager.removeTaskTTL(
taskId );
109 taskTTLManager.removeTaskTTL(
taskId + 1);
110 EXPECT_TRUE( taskTTLManager.isTaskTerminatedByTTL(
taskId ) );
111 EXPECT_FALSE( taskTTLManager.isTaskTerminatedByTTL(
taskId + 1 ) );
112 sleep_milliseconds( 11 );
113 EXPECT_EQ( taskTTLManager.cleanupExpiredTasksByTTLQueue( 10, 10 ), 1U);
114 EXPECT_FALSE( taskTTLManager.isTaskTerminatedByTTL(
taskId ) );
115 EXPECT_FALSE( taskTTLManager.isTaskTerminatedByTTL(
taskId + 1 ) );
119 std::vector<unsigned long long> exceededTTLTasks;
120 taskTTLManager.addTaskTTL(
taskId, 10 );
121 taskTTLManager.addTaskTTL(
taskId + 1, 20 );
122 taskTTLManager.addTaskTTL(
taskId + 2, 30 );
123 taskTTLManager.addTaskTTL(
taskId + 4, 40 );
124 taskTTLManager.addTaskTTL(
taskId + 5, 50 );
125 sleep_milliseconds( 21 );
126 taskTTLManager.getExceededTTLTasks( 10, exceededTTLTasks );
128 EXPECT_EQ( exceededTTLTasks.size(), 2U);
132 std::vector<unsigned long long> exceededTTLTasks;
133 taskTTLManager.addTaskTTL(
taskId, 10 );
134 taskTTLManager.addTaskTTL(
taskId + 1, 20 );
135 taskTTLManager.addTaskTTL(
taskId + 2, 30 );
136 taskTTLManager.addTaskTTL(
taskId + 4, 40 );
137 taskTTLManager.addTaskTTL(
taskId + 5, 50 );
138 sleep_milliseconds( 20 );
139 taskTTLManager.getExceededTTLTasks( 10, exceededTTLTasks, 10 );
141 EXPECT_EQ( exceededTTLTasks.size(), 5U);
145 taskTTLManager.addTaskTTL(
taskId, 10 );
146 sleep_milliseconds( 20 );
147 EXPECT_FALSE( taskTTLManager.isTaskTerminatedByTTL(
taskId ) );
151 taskTTLManager.addTaskTTL(
taskId, 10 );
152 sleep_milliseconds( 11 );
153 taskTTLManager.removeTaskTTL(
taskId );
154 EXPECT_TRUE( taskTTLManager.isTaskTerminatedByTTL(
taskId ) );