2 #include <boost/test/included/unit_test.hpp>
3 #include <boost/thread/condition.hpp>
4 #include "realserver.h"
5 #include "realserver_element.h"
9 //class l7vs::realserver;
11 using namespace boost::unit_test;
18 class realserver_fake : public realserver
21 boost::mutex starting_mutex;
22 boost::condition starting_condition;
29 void set_active(const int in_active) {
30 boost::mutex::scoped_lock lock(*active_mutex_ptr);
34 void set_inact(const int in_inact) {
35 boost::mutex::scoped_lock lock(*inact_mutex_ptr);
40 void increment_active2(const std::string &msg1, const std::string &msg2, const std::string &msg3, const std::string &msg4) {
42 boost::mutex::scoped_lock lock(starting_mutex);
43 starting_condition.wait(lock);
47 // increment_active();
49 boost::mutex::scoped_lock lock(*active_mutex_ptr);
53 if (nactive == INT_MAX) {
62 void decrement_active2(const std::string &msg1, const std::string &msg2, const std::string &msg3, const std::string &msg4) {
64 boost::mutex::scoped_lock lock(starting_mutex);
65 starting_condition.wait(lock);
69 // decrement_active();
71 boost::mutex::scoped_lock lock(*active_mutex_ptr);
83 void increment_inact2(const std::string &msg1, const std::string &msg2, const std::string &msg3, const std::string &msg4) {
85 boost::mutex::scoped_lock lock(starting_mutex);
86 starting_condition.wait(lock);
92 boost::mutex::scoped_lock lock(*inact_mutex_ptr);
96 if (ninact == INT_MAX) {
108 l7vs::realserver_fake rush_server;
110 void starting_thread(int id)
113 std::stringstream msg1, msg2, msg3, msg4;
115 msg1 << "start increment_active <Thread:" << id << ">";
116 msg2 << "complete increment_active <Thread:" << id << ">";
117 msg3 << "start inside <Thread:" << id << ">";
118 msg4 << "complete inside <Thread:" << id << ">";
119 rush_server.increment_active2(msg1.str(), msg2.str(), msg3.str(), msg4.str());
122 std::stringstream msg1, msg2, msg3, msg4;
124 msg1 << "start decrement_active <Thread:" << id << ">";
125 msg2 << "complete decrement_active <Thread:" << id << ">";
126 msg3 << "start inside <Thread:" << id << ">";
127 msg4 << "complete inside <Thread:" << id << ">";
128 rush_server.decrement_active2(msg1.str(), msg2.str(), msg3.str(), msg4.str());
131 std::stringstream msg1, msg2, msg3, msg4;
133 msg1 << "start increment_inact <Thread:" << id << ">";
134 msg2 << "complete increment_inact <Thread:" << id << ">";
135 msg3 << "start inside <Thread:" << id << ">";
136 msg4 << "complete inside <Thread:" << id << ">";
137 rush_server.increment_inact2(msg1.str(), msg2.str(), msg3.str(), msg4.str());
143 void realserver_test()
147 unsigned long long send_byte = 0ULL;
149 l7vs::realserver_element::REALSERVER_FWDMODE_TAG fwdmode = l7vs::realserver_element::FWD_NONE;
151 // unit_test[1] コンストラクタのテスト(全てが初期化済み)
152 l7vs::realserver server1;
154 BOOST_CHECK_EQUAL(nactive, server1.get_active());
155 BOOST_CHECK_EQUAL(ninact, server1.get_inact());
156 BOOST_CHECK_EQUAL(send_byte, server1.send_byte);
157 BOOST_CHECK_EQUAL(weight, server1.weight);
158 BOOST_CHECK_EQUAL(fwdmode, server1.fwdmode);
160 // unit_test[2] コピーコンストラクタのテスト(全てがコピー元と同じ)
161 server1.tcp_endpoint = boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string("11.11.11.11"), 11) ;
162 server1.udp_endpoint = boost::asio::ip::udp::endpoint(boost::asio::ip::address::from_string("22.22.22.22"), 22) ;
163 server1.send_byte = 10;
165 server1.fwdmode = l7vs::realserver_element::FWD_TPROXY;
166 server1.increment_active();
167 server1.increment_inact();
169 l7vs::realserver server2(server1);
171 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
172 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
173 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
174 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
175 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
176 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
177 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
180 // unit_test[3] 比較オペレータのテスト(TCPエンドポイントが異なるとエラー)
181 BOOST_CHECK_EQUAL((server1 == server2), true);
183 server1.tcp_endpoint = boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string("33.33.33.33"), 33) ;
184 BOOST_CHECK_EQUAL((server1 == server2), false);
185 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
186 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
187 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
188 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
189 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
190 BOOST_CHECK(server2.tcp_endpoint != server1.tcp_endpoint);
191 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
193 // unit_test[4] 比較オペレータのテスト2(UDPエンドポイントが異なるとエラー)
195 server1.udp_endpoint = boost::asio::ip::udp::endpoint(boost::asio::ip::address::from_string("44.44.44.44"), 44) ;
196 BOOST_CHECK_EQUAL((server1 == server2), false);
197 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
198 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
199 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
200 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
201 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
202 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
203 BOOST_CHECK(server2.udp_endpoint != server1.udp_endpoint);
205 // unit_test[5] 比較オペレータのテスト3(weightが異なるとエラー)
208 BOOST_CHECK_EQUAL((server1 == server2), false);
209 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
210 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
211 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
212 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
213 BOOST_CHECK(server2.weight != server1.weight);
214 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
215 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
217 // unit_test[5+] 比較オペレータのテスト3+(fwdmodeが異なるとエラー)
219 server1.fwdmode = l7vs::realserver_element::FWD_MASQ;
220 BOOST_CHECK_EQUAL((server1 == server2), false);
221 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
222 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
223 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
224 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
225 BOOST_CHECK(server2.fwdmode != server1.fwdmode);
226 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
227 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
229 // unit_test[6] 比較オペレータのテスト4(接続数が異なっても問題無し)
231 server1.increment_active();
232 BOOST_CHECK_EQUAL((server1 == server2), true);
233 BOOST_CHECK(server2.get_active() != server1.get_active());
234 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
235 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
236 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
237 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
238 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
239 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
241 // unit_test[7] 比較オペレータのテスト5(切断数が異なっても問題無し)
243 server1.increment_inact();
244 BOOST_CHECK_EQUAL((server1 == server2), true);
245 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
246 BOOST_CHECK(server2.get_inact() != server1.get_inact());
247 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
248 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
249 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
250 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
251 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
253 // unit_test[8] 比較オペレータのテスト6(送信バイト数が異なっても問題無し)
255 server1.send_byte = 100;
256 BOOST_CHECK_EQUAL((server1 == server2), true);
257 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
258 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
259 BOOST_CHECK(server2.send_byte != server1.send_byte);
260 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
261 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
262 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
263 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
265 // unit_test[9] 否定オペレータのテスト(TCPエンドポイントが異なると検出)
268 BOOST_CHECK_EQUAL((server1 != server2), false);
270 server1.tcp_endpoint = boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string("33.33.33.33"), 33) ;
271 BOOST_CHECK_EQUAL((server1 != server2), true);
272 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
273 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
274 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
275 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
276 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
277 BOOST_CHECK(server2.tcp_endpoint != server1.tcp_endpoint);
278 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
280 // unit_test[10] 否定オペレータのテスト2(UDPエンドポイントが異なると検出)
282 server1.udp_endpoint = boost::asio::ip::udp::endpoint(boost::asio::ip::address::from_string("44.44.44.44"), 44) ;
283 BOOST_CHECK_EQUAL((server1 != server2), true);
284 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
285 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
286 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
287 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
288 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
289 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
290 BOOST_CHECK(server2.udp_endpoint != server1.udp_endpoint);
292 // unit_test[11] 否定オペレータのテスト3(weightが異なると検出)
295 BOOST_CHECK_EQUAL((server1 != server2), true);
296 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
297 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
298 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
299 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
300 BOOST_CHECK(server2.weight != server1.weight);
301 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
302 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
304 // unit_test[11+] 否定オペレータのテスト3+(fwdmodeが異なると検出)
306 server1.fwdmode = l7vs::realserver_element::FWD_MASQ;
307 BOOST_CHECK_EQUAL((server1 != server2), true);
308 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
309 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
310 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
311 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
312 BOOST_CHECK(server2.fwdmode != server1.fwdmode);
313 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
314 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
316 // unit_test[12] 否定オペレータのテスト4(接続数が異なっても問題無し)
318 server1.increment_active();
319 BOOST_CHECK_EQUAL((server1 != server2), false);
320 BOOST_CHECK(server2.get_active() != server1.get_active());
321 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
322 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
323 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
324 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
325 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
326 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
328 // unit_test[13] 否定オペレータのテスト5(切断数が異なっても問題無し)
330 server1.increment_inact();
331 BOOST_CHECK_EQUAL((server1 != server2), false);
332 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
333 BOOST_CHECK(server2.get_inact() != server1.get_inact());
334 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
335 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
336 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
337 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
338 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
340 // unit_test[14] 否定オペレータのテスト6(送信バイト数が異なっても問題無し)
342 server1.send_byte = 100;
343 BOOST_CHECK_EQUAL((server1 != server2), false);
344 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
345 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
346 BOOST_CHECK(server2.send_byte != server1.send_byte);
347 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
348 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
349 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
350 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
352 // unit_test[15] コピーオペレータのテスト(全てがコピー元と同じ)
353 server1 = l7vs::realserver();
356 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
357 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
358 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
359 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
360 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
361 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
362 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
364 BOOST_CHECK(server1 == server2);
366 // unit_test[16] 大小比較オペレータのテスト(TCPエンドポイントが大きいと検出)
367 server1.tcp_endpoint = boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string("10.144.169.86"), 21) ;
369 BOOST_CHECK_EQUAL((server2 < server1), true);
370 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
371 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
372 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
373 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
374 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
375 BOOST_CHECK(server2.tcp_endpoint < server1.tcp_endpoint);
376 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
378 // unit_test[17] 大小比較オペレータのテスト2(UDPエンドポイントが異なっても問題無し)
380 server1.udp_endpoint = boost::asio::ip::udp::endpoint(boost::asio::ip::address::from_string("10.144.169.86"), 21) ;
382 BOOST_CHECK_EQUAL((server2 < server1), false);
383 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
384 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
385 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
386 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
387 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
388 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
389 BOOST_CHECK(server2.udp_endpoint < server1.udp_endpoint);
391 // unit_test[18] 大小比較オペレータのテスト3(TCPが等しくweightが大きいと検出)
395 BOOST_CHECK_EQUAL((server2 < server1), true);
396 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
397 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
398 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
399 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
400 BOOST_CHECK(server2.weight < server1.weight);
401 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
402 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
404 // unit_test[18+] 大小比較オペレータのテスト3+(TCP,weightが等しくfwdmodeが大きいと検出)
406 server1.fwdmode = l7vs::realserver_element::FWD_TPROXY;
407 server2.fwdmode = l7vs::realserver_element::FWD_MASQ;
409 BOOST_CHECK_EQUAL((server2 < server1), true);
410 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
411 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
412 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
413 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
414 BOOST_CHECK(server2.fwdmode < server1.fwdmode);
415 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
416 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
418 // unit_test[19] 大小比較オペレータのテスト4(接続数が異なっても問題無し)
420 server1.increment_active();
421 BOOST_CHECK_EQUAL((server2 < server1), false);
422 BOOST_CHECK(server2.get_active() != server1.get_active());
423 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
424 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
425 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
426 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
427 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
428 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
430 // unit_test[20] 大小比較オペレータのテスト5(切断数が異なっても問題無し)
432 server1.increment_inact();
433 BOOST_CHECK_EQUAL((server2 < server1), false);
434 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
435 BOOST_CHECK(server2.get_inact() != server1.get_inact());
436 BOOST_CHECK_EQUAL(server2.send_byte, server1.send_byte);
437 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
438 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
439 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
440 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
442 // unit_test[21] 大小比較オペレータのテスト6(送信バイト数が異なっても問題無し)
444 server1.send_byte = 100;
445 BOOST_CHECK_EQUAL((server2 < server1), false);
446 BOOST_CHECK_EQUAL(server2.get_active(), server1.get_active());
447 BOOST_CHECK_EQUAL(server2.get_inact(), server1.get_inact());
448 BOOST_CHECK(server2.send_byte != server1.send_byte);
449 BOOST_CHECK_EQUAL(server2.weight, server1.weight);
450 BOOST_CHECK_EQUAL(server2.fwdmode, server1.fwdmode);
451 BOOST_CHECK(server2.tcp_endpoint == server1.tcp_endpoint);
452 BOOST_CHECK(server2.udp_endpoint == server1.udp_endpoint);
454 // unit_test[22] 接続数取得メソッドのテスト
455 BOOST_CHECK_EQUAL(server1.get_active(), nactive);
457 // unit_test[23] 切断数取得メソッドのテスト
458 BOOST_CHECK_EQUAL(server1.get_inact(), ninact);
460 // unit_test[24] 接続数インクリメントメソッドのテスト
461 server1.increment_active();
462 BOOST_CHECK_EQUAL(server1.get_active(), 1);
464 // unit_test[25] 接続数デクリメントメソッドのテスト
465 server1.decrement_active();
466 BOOST_CHECK_EQUAL(server1.get_active(), 0);
468 // unit_test[26] 接続数インクリメントメソッドのテスト2(上限INT_MAXに達すると0にクリア)
469 // BOOST_MESSAGE( "wait a minute to INT_MAX" );
470 // for ( int loop = 0; loop < INT_MAX; loop++ ){
471 // server1.increment_active();
473 // BOOST_CHECK_EQUAL( server1.get_active(), 0 );
475 l7vs::realserver_fake server3;
477 nactive = INT_MAX - 1 ;
478 server3.set_active(nactive);
479 BOOST_CHECK_EQUAL(server3.get_active(), nactive);
481 server3.increment_active();
482 BOOST_CHECK_EQUAL(server3.get_active(), 0);
484 // unit_test[27] 接続数デクリメントメソッドのテスト2(0に対しては何も行わない)
485 server1.decrement_active();
486 BOOST_CHECK_EQUAL(server1.get_active(), 0);
488 // unit_test[28] 切断数インクリメントメソッドのテスト
489 server1.increment_inact();
490 BOOST_CHECK_EQUAL(server1.get_inact(), 1);
492 // unit_test[29] 切断数インクリメントメソッドのテスト2(上限INT_MAXに達すると0にクリア)
493 // BOOST_MESSAGE( "wait a minute to INT_MAX" );
494 // for ( int loop = server1.get_inact(); loop < INT_MAX; loop++ ){
495 // server1.increment_inact();
497 // BOOST_CHECK_EQUAL( server1.get_inact(), 0 );
499 ninact = INT_MAX - 1 ;
500 server3.set_inact(ninact);
501 BOOST_CHECK_EQUAL(server3.get_inact(), ninact);
503 server3.increment_inact();
504 BOOST_CHECK_EQUAL(server3.get_inact(), 0);
507 boost::thread thread_item1(boost::bind(&starting_thread, 1));
508 boost::thread thread_item2(boost::bind(&starting_thread, 2));
509 boost::thread thread_item3(boost::bind(&starting_thread, 3));
510 boost::thread thread_item4(boost::bind(&starting_thread, 4));
511 boost::thread thread_item5(boost::bind(&starting_thread, 5));
513 // unit_test[30] 接続数インクリメントメソッドのテスト3(複数スレッドから同時アクセス)
514 BOOST_MESSAGE("sleep in");
516 rush_server.starting_condition.notify_all();
518 BOOST_CHECK_EQUAL(rush_server.get_active(), 5);
520 // unit_test[31] 接続数デクリメントメソッドのテスト3(複数スレッドから同時アクセス)
521 BOOST_MESSAGE("sleep in");
523 rush_server.starting_condition.notify_all();
525 BOOST_CHECK_EQUAL(rush_server.get_active(), 0);
527 // unit_test[32] 切断数インクリメントメソッドのテスト3(複数スレッドから同時アクセス)
528 BOOST_MESSAGE("sleep in");
530 rush_server.starting_condition.notify_all();
539 BOOST_CHECK_EQUAL(rush_server.get_inact(), 5);
542 // nactive, ninactをelement時のみsettter有効にする評価
544 rs.increment_active();
545 // rs.set_active( 10 ); // protectedなので変更できない(コンパイルエラー)
546 BOOST_CHECK(rs.get_active() != 10);
547 rs.increment_inact();
548 // rs.set_inact( 10 ); // protectedなので変更できない(コンパイルエラー)
549 BOOST_CHECK(rs.get_inact() != 10);
551 // こんなことするとrealserver上からも変更できてしまうけどそれは不正なので無視とする
552 // l7vs::realserver_element& rs_elem2( rs );
553 // rs_elem2.set_active( 10 );
554 // BOOST_CHECK( rs.get_active() != 10 );
555 // rs_elem2.set_inact( 10 );
556 // BOOST_CHECK( rs.get_inact() != 10 );
559 l7vs::realserver_element rs_elem(rs);
560 BOOST_CHECK_EQUAL(rs_elem.get_active(), 1);
561 BOOST_CHECK_EQUAL(rs_elem.get_inact(), 1);
562 rs_elem.set_active(0); // publicなので設定可能
563 rs_elem.set_inact(0); // publicなので設定可能
564 BOOST_CHECK_EQUAL(rs_elem.get_active(), 0);
565 BOOST_CHECK_EQUAL(rs_elem.get_inact(), 0);
568 test_suite *init_unit_test_suite(int argc, char *argv[])
570 // l7vs::Logger logger;
571 // l7vs::Parameter parameter;
573 // logger.loadConf();
575 // create unit test suite
576 test_suite *ts = BOOST_TEST_SUITE("realserver_test");
578 // add test case to test suite
579 ts->add(BOOST_TEST_CASE(&realserver_test));
581 framework::master_test_suite().add(ts);