--- /dev/null
+/*\r
+ * sslid_replication_data_processor_test.cpp\r
+ *\r
+ * Created on: Jan 20, 2009\r
+ * Author: root\r
+ */\r
+#include "sslid_to_be_test_file.h"\r
+\r
+using namespace boost::unit_test;\r
+using namespace l7vs;\r
+\r
+#define SECTION_NUMBER 200\r
+#define STRUCT_NUMBER 256\r
+\r
+int test_value = 0;\r
+// function for testing register_replication_area_lock\r
+void lock_function(){\r
+ test_value = 1;\r
+}\r
+\r
+// function for testing register_replication_area_unlock\r
+void unlock_function(){\r
+ test_value = 2;\r
+}\r
+\r
+// function sslid_replication_data_processor test\r
+void sslid_replication_data_processor_test(){\r
+\r
+ int data_area_size = 128*sizeof(struct l7vs::sslid_replication_data_header) + STRUCT_NUMBER*sizeof(struct l7vs::sslid_replication_data);\r
+ char replication_data_area[128*sizeof(struct l7vs::sslid_replication_data_header) + STRUCT_NUMBER*sizeof(struct l7vs::sslid_replication_data)] = { 0 };\r
+ int maxlist_test = 5;\r
+ char *header_start_address = replication_data_area;\r
+ char *real_data_start_address = header_start_address + 128*sizeof(struct l7vs::sslid_replication_data_header);\r
+ l7vs::sslid_replication_data_header* first_header = (sslid_replication_data_header*)header_start_address;\r
+\r
+ l7vs::sslid_replication_data_processor test_object(maxlist_test, replication_data_area, SECTION_NUMBER);\r
+\r
+ // test_case[1] maxlist value chek\r
+ BOOST_CHECK_EQUAL(maxlist_test, test_object.maxlist);\r
+ // max_temp_list value check\r
+ BOOST_CHECK_EQUAL(maxlist_test * 2, test_object.max_temp_list);\r
+ // replication_area value check\r
+ BOOST_CHECK_EQUAL(replication_data_area, real_data_start_address);\r
+\r
+ // test_case[2] NULL pointer test\r
+ try {\r
+ l7vs::sslid_replication_data_processor test_object1(maxlist_test, NULL, 0);\r
+ BOOST_CHECK(test_object1.replication_area == NULL);\r
+ } catch (...) {\r
+ BOOST_ERROR("exception: sslid_replication_data_processor");\r
+ }\r
+\r
+ // test_case[3] if over replication area, nothing to do, test it\r
+ try {\r
+ memset(replication_data_area, 0, 128*sizeof(struct l7vs::sslid_replication_data_header));\r
+ for(int i = 0; i < 128; i++){\r
+ l7vs::sslid_replication_data_header* temp= ((l7vs::sslid_replication_data_header*)replication_data_area) + i;\r
+ temp->size = sizeof(l7vs::sslid_replication_data);\r
+ }\r
+ l7vs::sslid_replication_data_processor replication_data_processor2(2, replication_data_area, 1);\r
+ } catch (...) {\r
+ BOOST_ERROR("exception: sslid_session_data_processor");\r
+ }\r
+\r
+ // test_case[4] when virtual service data has exist and the virtual service's data area is samller than needed,\r
+ // need to resize the virtual service session information, test\r
+ int max_list_size = 2;\r
+ memset(replication_data_area, 0, data_area_size);\r
+ // TODO zhangzg 2008/01/22 how to set the heder's ip and port need a reference(ip && port is the virtual service' key)\r
+ first_header->virtualserver_addr.s_addr = inet_addr("192.168.120.102");\r
+ first_header->virtualserver_port = 80;\r
+ first_header->size = (max_list_size - 1) * sizeof(l7vs::sslid_replication_data);\r
+ first_header->offset = real_data_start_address - header_start_address;\r
+ l7vs::sslid_replication_data_processor replication_data_processor3(max_list_size, replication_data_area, SECTION_NUMBER);\r
+ // the virtual service's size is resized, check it\r
+ int expecting_size = (int)(max_list_size * sizeof(l7vs::sslid_replication_data));\r
+ BOOST_CHECK_EQUAL(first_header->size, expecting_size);\r
+\r
+ // test_case[5] when resize the virtual service session information, if header area is full, nothing to do, test it\r
+ try {\r
+ memset(replication_data_area, 0, 128*sizeof(struct l7vs::sslid_replication_data_header));\r
+ for(int i = 0; i < 128; i++){\r
+ l7vs::sslid_replication_data_header* temp= ((l7vs::sslid_replication_data_header*)replication_data_area) + i;\r
+ temp->size = sizeof(l7vs::sslid_replication_data);\r
+ }\r
+ // TODO zhangzg 2008/01/22 how to set the heder's ip and port need a reference(ip && port is the virtual service' key)\r
+ first_header->virtualserver_addr.s_addr = inet_addr("192.168.120.102");\r
+ first_header->virtualserver_port = 80;\r
+ first_header->size = (max_list_size - 1) * sizeof(l7vs::sslid_replication_data);\r
+ first_header->offset = real_data_start_address - header_start_address;\r
+ l7vs::sslid_replication_data_processor replication_data_processor4(max_list_size, replication_data_area, SECTION_NUMBER);\r
+ } catch (...) {\r
+ BOOST_ERROR("exception: sslid_session_data_processor");\r
+ }\r
+\r
+ // test_case[6] when resize the virtual service session information, if header area is not full,\r
+ // virtual service session information is changed, test it\r
+ memset(replication_data_area, 0, data_area_size);\r
+ // TODO zhangzg 2008/01/22 how to set the heder's ip and port need a reference(ip && port is the virtual service' key)\r
+ first_header->virtualserver_addr.s_addr = inet_addr("192.168.120.102");\r
+ first_header->virtualserver_port = 80;\r
+ first_header->size = (max_list_size - 1) * sizeof(l7vs::sslid_replication_data);\r
+ first_header->offset = real_data_start_address - header_start_address;\r
+ l7vs::sslid_replication_data_processor replication_data_processor5(max_list_size, replication_data_area, SECTION_NUMBER);\r
+ // the virtual service information's size is resized, get it\r
+ expecting_size = (int)(max_list_size * sizeof(l7vs::sslid_replication_data));\r
+ // the virtual service information's offset is resized, get it\r
+ int expecting_offset = real_data_start_address - header_start_address + expecting_size;\r
+ // size check\r
+ BOOST_CHECK_EQUAL(first_header->size, expecting_size);\r
+ // offset check\r
+ BOOST_CHECK_EQUAL(first_header->offset, expecting_offset);\r
+\r
+ // test_case[6] when virtual service data is not exist and the sslip replication area there is\r
+ // not enough sapce to add data, nothing to do, test it\r
+ try {\r
+ memset(replication_data_area, 0, 128*sizeof(struct l7vs::sslid_replication_data_header));\r
+ for(int i = 0; i < 128; i++){\r
+ l7vs::sslid_replication_data_header* temp= ((l7vs::sslid_replication_data_header*)replication_data_area) + i;\r
+ temp->size = max_list_size * sizeof(l7vs::sslid_replication_data);\r
+ temp->virtualserver_addr.s_addr = inet_addr("255.255.255.255");\r
+ if(i == 127) {\r
+ temp->size = 0;\r
+ }\r
+ }\r
+ l7vs::sslid_replication_data_processor replication_data_processor6(max_list_size, replication_data_area, SECTION_NUMBER);\r
+ l7vs::sslid_session_data_processor test_object6(max_list_size, 0, &replication_data_processor6);\r
+ } catch (...) {\r
+ BOOST_ERROR("exception: sslid_session_data_processor");\r
+ }\r
+\r
+ // test_case[7] when virtual service data is not exist and the sslip replication area there is\r
+ // enough sapce to add data, add the data to the replication area, test it\r
+ memset(replication_data_area, 0, 128*sizeof(struct l7vs::sslid_replication_data_header));\r
+ l7vs::sslid_replication_data_processor replication_data_processor7(max_list_size, replication_data_area, SECTION_NUMBER);\r
+ expecting_size = (int)(max_list_size * sizeof(l7vs::sslid_replication_data));\r
+ expecting_offset = real_data_start_address - header_start_address;\r
+ // session information's size check\r
+ BOOST_CHECK_EQUAL(first_header->size, expecting_size);\r
+ // session information's offset check\r
+ BOOST_CHECK_EQUAL(first_header->offset, expecting_size);\r
+\r
+ // test_case[8] when virtual service data is not exist and the sslip replication header area\r
+ // is full, nothing to do, test it\r
+ try {\r
+ memset(replication_data_area, 0, 128*sizeof(struct l7vs::sslid_replication_data_header));\r
+ for(int i = 0; i < 128; i++){\r
+ l7vs::sslid_replication_data_header* temp= ((l7vs::sslid_replication_data_header*)replication_data_area) + i;\r
+ temp->size = sizeof(l7vs::sslid_replication_data);\r
+ temp->virtualserver_addr.s_addr = inet_addr("255.255.255.255");\r
+ }\r
+ l7vs::sslid_replication_data_processor replication_data_processor8(max_list_size, replication_data_area, SECTION_NUMBER);\r
+ l7vs::sslid_session_data_processor test_object8(max_list_size, 0, &replication_data_processor8);\r
+ } catch (...) {\r
+ BOOST_ERROR("exception: sslid_session_data_processor");\r
+ }\r
+}\r
+\r
+// function put_into_temp_list test\r
+void put_into_temp_list_test(){\r
+\r
+ char replication_data_area[128*sizeof(struct l7vs::sslid_replication_data_header) + STRUCT_NUMBER*sizeof(struct l7vs::sslid_replication_data)] = { 0 };\r
+ time_t last_time = time(0);\r
+ boost::asio::ip::tcp::endpoint endpoint;\r
+\r
+ l7vs::sslid_replication_temp_data test_data1;\r
+ test_data1.session_id = "test_id1";\r
+ test_data1.last_time = last_time;\r
+ test_data1.op_code = 'A';\r
+ test_data1.realserver_addr = endpoint;\r
+\r
+ l7vs::sslid_replication_temp_data test_data2;\r
+ test_data2.session_id = "test_id2";\r
+ test_data2.last_time = last_time;\r
+ test_data2.op_code = 'U';\r
+ test_data2.realserver_addr = endpoint;\r
+\r
+ l7vs::sslid_replication_temp_data test_data3;\r
+ test_data3.session_id = "test_id3";\r
+ test_data3.last_time = last_time;\r
+ test_data3.op_code = 'D';\r
+ test_data3.realserver_addr = endpoint;\r
+\r
+ // test_case[8] element put into list test(list is not full and put inot 1 item)\r
+ l7vs::sslid_replication_data_processor test_object(2, replication_data_area, SECTION_NUMBER);\r
+ test_object.put_into_temp_list(test_data1);\r
+ l7vs::sslid_replication_temp_data& temp_data = test_object.temp_list.back();\r
+ std::string expecting_session_id = "test_id1";\r
+ // the item which put into the temp_list check\r
+ // session_id check\r
+ BOOST_CHECK_EQUAL(temp_data.session_id, expecting_session_id);\r
+ // last_time check\r
+ BOOST_CHECK_EQUAL(temp_data.last_time, last_time);\r
+ // op_code check\r
+ BOOST_CHECK_EQUAL(temp_data.op_code, 'A');\r
+ // realserver_addr check\r
+ BOOST_CHECK_EQUAL(temp_data.realserver_addr, endpoint);\r
+\r
+ // test_case[9] element put into list test(put into 2 items)\r
+ test_object.temp_list.clear();\r
+ test_object.put_into_temp_list(test_data2);\r
+ test_object.put_into_temp_list(test_data3);\r
+ l7vs::sslid_replication_temp_data& expecting_data1 = test_object.temp_list.front();\r
+ l7vs::sslid_replication_temp_data& expecting_data2 = test_object.temp_list.back();\r
+ // the items which put into the temp_list check\r
+ // session_id check\r
+ BOOST_CHECK_EQUAL(expecting_data1.session_id, test_data2.session_id);\r
+ BOOST_CHECK_EQUAL(expecting_data2.session_id, test_data3.session_id);\r
+ // last_time check\r
+ BOOST_CHECK_EQUAL(expecting_data1.last_time, test_data2.last_time);\r
+ BOOST_CHECK_EQUAL(expecting_data2.last_time, test_data3.last_time);\r
+ // op_code check\r
+ BOOST_CHECK_EQUAL(expecting_data1.op_code, 'U');\r
+ BOOST_CHECK_EQUAL(expecting_data2.op_code, 'D');\r
+ // realserver_addr check\r
+ BOOST_CHECK_EQUAL(expecting_data1.realserver_addr, test_data2.realserver_addr);\r
+ BOOST_CHECK_EQUAL(expecting_data2.realserver_addr, test_data3.realserver_addr);\r
+\r
+ // TODO zhangzg 2008/01/20 when list is full, how to test?(multi-ply thread)\r
+}\r
+\r
+// function write_replicaion_area test\r
+void write_replicaion_area_test(){\r
+\r
+ char replication_data_area[128*sizeof(struct l7vs::sslid_replication_data_header) + STRUCT_NUMBER*sizeof(struct l7vs::sslid_replication_data)] = { 0 };\r
+ time_t test_time = time(0);\r
+ l7vs::sslid_replication_data_processor test_object(1, replication_data_area, SECTION_NUMBER);\r
+ l7vs::sslid_replication_temp_data test_data1;\r
+ boost::function<void(void)> function_pointer;\r
+ boost::asio::ip::tcp::endpoint realserver_addr;\r
+\r
+ // test_case[10] when temp_list is empty, test it\r
+ try {\r
+ test_object.temp_list.clear();\r
+ boost::thread test_thread1(boost::bind(&l7vs::sslid_replication_data_processor::write_replicaion_area, &test_object));\r
+ test_thread1.timed_join(boost::posix_time::milliseconds(100));\r
+ } catch(...) {\r
+ BOOST_ERROR("exception: write_replicaion_area");\r
+ }\r
+\r
+ // test_case[11] data add test(when data area has one sslip_replication_data)\r
+ l7vs::sslid_replication_data temp_data;\r
+ std::string temp_session_id = "temp_id1";\r
+ memset(test_object.replication_area, 0, 3*sizeof(struct l7vs::sslid_replication_data));\r
+ temp_data.last_time = time(0);\r
+ memcpy(temp_data.session_id, temp_session_id.c_str(), temp_session_id.length());\r
+ temp_data.valid = 1;\r
+ memcpy(test_object.replication_area, &temp_data, sizeof(struct l7vs::sslid_replication_data));\r
+ // set the added data\r
+ realserver_addr.address(boost::asio::ip::address::from_string("192.168.120.102"));\r
+ realserver_addr.port(80);\r
+ test_data1.session_id = "test_id1";\r
+ test_data1.last_time = test_time;\r
+ test_data1.op_code = 'A';\r
+ test_data1.realserver_addr = realserver_addr;\r
+ test_object.temp_list.clear();\r
+ test_object.put_into_temp_list(test_data1);\r
+ // get the existing data\r
+ l7vs::sslid_replication_data old_data;\r
+ memset(&old_data, 0, sizeof(sslid_replication_data));\r
+ memcpy(&old_data, test_object.replication_area, sizeof(sslid_replication_data));\r
+ boost::thread test_thread2(boost::bind(&sslid_replication_data_processor::write_replicaion_area, &test_object));\r
+ test_thread2.timed_join(boost::posix_time::milliseconds(100));\r
+ // data add position: after the old existing data, check it\r
+ // get the added data information\r
+ std::string added_session_id((test_object.replication_area + 1)->session_id);\r
+ std::string added_address_ip(inet_ntoa((test_object.replication_area + 1)->realserver_addr.sin_addr));\r
+ unsigned short added_address_port = ntohs((test_object.replication_area + 1)->realserver_addr.sin_port);\r
+ // the old existing data not changed, check it\r
+ int compare_result = memcmp(&old_data, test_object.replication_area, sizeof(sslid_replication_data));\r
+ BOOST_CHECK_EQUAL(compare_result, 0);\r
+ // added session_id check\r
+ BOOST_CHECK_EQUAL(added_session_id, test_data1.session_id);\r
+ // added last_time check\r
+ BOOST_CHECK_EQUAL((test_object.replication_area + 1)->last_time, test_data1.last_time);\r
+ // added valid flag check\r
+ BOOST_CHECK_EQUAL((test_object.replication_area + 1)->valid, 1);\r
+ // added realserver_addr ip check\r
+ BOOST_CHECK_EQUAL(added_address_ip, test_data1.realserver_addr.address().to_string());\r
+ // added realserver_addr port check\r
+ BOOST_CHECK_EQUAL(added_address_port, test_data1.realserver_addr.port());\r
+\r
+ // test_case[12] data add test(when data area has two sslip_replication_data,and the first sslip_replication_data's valid flag is unused)\r
+ memset(test_object.replication_area, 0, 3*sizeof(struct l7vs::sslid_replication_data));\r
+ temp_session_id = "temp_id2";\r
+ temp_data.last_time = time(0);\r
+ memcpy(temp_data.session_id, temp_session_id.c_str(), temp_session_id.length());\r
+ temp_data.valid = 0;\r
+ memcpy(test_object.replication_area, &temp_data, sizeof(struct l7vs::sslid_replication_data));\r
+ temp_session_id = "temp_id3";\r
+ temp_data.last_time = time(0);\r
+ memcpy(temp_data.session_id, temp_session_id.c_str(), temp_session_id.length());\r
+ temp_data.valid = 1;\r
+ memcpy(test_object.replication_area + 1, &temp_data, sizeof(struct l7vs::sslid_replication_data));\r
+ // set the added data\r
+ realserver_addr.address(boost::asio::ip::address::from_string("192.168.120.102"));\r
+ realserver_addr.port(80);\r
+ test_data1.session_id = "test_id1";\r
+ test_data1.last_time = test_time;\r
+ test_data1.op_code = 'A';\r
+ test_data1.realserver_addr = realserver_addr;\r
+ test_object.temp_list.clear();\r
+ test_object.put_into_temp_list(test_data1);\r
+ // get the second existing data\r
+ memset(&old_data, 0, sizeof(sslid_replication_data));\r
+ memcpy(&old_data, test_object.replication_area + 1, sizeof(sslid_replication_data));\r
+ boost::thread test_thread3(boost::bind(&sslid_replication_data_processor::write_replicaion_area, &test_object));\r
+ test_thread3.timed_join(boost::posix_time::milliseconds(100));\r
+ // data add position: the first existing data position, check it\r
+ // get the added data information\r
+ added_session_id = std::string(test_object.replication_area->session_id);\r
+ added_address_ip = std::string(inet_ntoa(test_object.replication_area->realserver_addr.sin_addr));\r
+ added_address_port = ntohs(test_object.replication_area->realserver_addr.sin_port);\r
+ // the second existing data not changed, check it\r
+ compare_result = memcmp(&old_data, test_object.replication_area + 1, sizeof(sslid_replication_data));\r
+ BOOST_CHECK_EQUAL(compare_result, 0);\r
+ // added session_id check\r
+ BOOST_CHECK_EQUAL(added_session_id, test_data1.session_id);\r
+ // added last_time check\r
+ BOOST_CHECK_EQUAL((test_object.replication_area)->last_time, test_data1.last_time);\r
+ // added valid flag check\r
+ BOOST_CHECK_EQUAL((test_object.replication_area)->valid, 1);\r
+ // added realserver_addr ip check\r
+ BOOST_CHECK_EQUAL(added_address_ip, test_data1.realserver_addr.address().to_string());\r
+ // added realserver_addr port check\r
+ BOOST_CHECK_EQUAL(added_address_port, test_data1.realserver_addr.port());\r
+\r
+ // test_case[13] data add test(when data area has no sslip_replication_data)\r
+ memset(test_object.replication_area, 0, 3*sizeof(struct l7vs::sslid_replication_data));\r
+ realserver_addr.address(boost::asio::ip::address::from_string("192.168.120.102"));\r
+ realserver_addr.port(80);\r
+ test_data1.session_id = "test_id1";\r
+ test_data1.last_time = test_time;\r
+ test_data1.op_code = 'A';\r
+ test_data1.realserver_addr = realserver_addr;\r
+ test_object.temp_list.clear();\r
+ test_object.put_into_temp_list(test_data1);\r
+ boost::thread test_thread4(boost::bind(&sslid_replication_data_processor::write_replicaion_area, &test_object));\r
+ test_thread4.timed_join(boost::posix_time::milliseconds(100));\r
+ std::string saved_session_id(test_object.replication_area->session_id);\r
+ std::string saved_address_ip(inet_ntoa(test_object.replication_area->realserver_addr.sin_addr));\r
+ unsigned short saved_address_port = ntohs(test_object.replication_area->realserver_addr.sin_port);\r
+ // session_id is saved, check it\r
+ BOOST_CHECK_EQUAL(saved_session_id, std::string("test_id1"));\r
+ // last_time is saved, check it\r
+ BOOST_CHECK_EQUAL(test_object.replication_area->last_time, test_time);\r
+ // valid flag check\r
+ BOOST_CHECK_EQUAL(test_object.replication_area->valid, 1);\r
+ // realserver_addr ip check\r
+ BOOST_CHECK_EQUAL(saved_address_ip, std::string("192.168.120.102"));\r
+ // realserver_addr port check\r
+ BOOST_CHECK_EQUAL(saved_address_port, 80);\r
+\r
+ // test_case[14] data update test\r
+ time_t update_time = test_time - 10;\r
+ realserver_addr.address(boost::asio::ip::address::from_string("255.255.255.255"));\r
+ realserver_addr.port(999);\r
+ test_data1.op_code = 'U';\r
+ test_data1.last_time = update_time;\r
+ test_data1.realserver_addr = realserver_addr;\r
+ test_object.temp_list.clear();\r
+ test_object.put_into_temp_list(test_data1);\r
+ boost::thread test_thread11(boost::bind(&sslid_replication_data_processor::write_replicaion_area, &test_object));\r
+ test_thread11.timed_join(boost::posix_time::milliseconds(100));\r
+ // get saved information\r
+ saved_session_id = std::string(test_object.replication_area->session_id);\r
+ saved_address_ip = std::string(inet_ntoa(test_object.replication_area->realserver_addr.sin_addr));\r
+ saved_address_port = ntohs(test_object.replication_area->realserver_addr.sin_port);\r
+ // session_id is not changed, check it\r
+ BOOST_CHECK_EQUAL(saved_session_id, std::string("test_id1"));\r
+ // last_time is updated , check it\r
+ BOOST_CHECK_EQUAL(test_object.replication_area->last_time, update_time);\r
+ // valid flag is not changed ,check it\r
+ BOOST_CHECK_EQUAL(test_object.replication_area->valid, 1);\r
+ // realserver_addr ip is changed, check it\r
+ BOOST_CHECK_EQUAL(saved_address_ip, std::string("255.255.255.255"));\r
+ // realserver_addr port is changed, check it\r
+ BOOST_CHECK_EQUAL(saved_address_port, 999);\r
+\r
+ // test_case[15] data delete test(using above test_case saved data)\r
+ realserver_addr.address(boost::asio::ip::address::from_string("192.168.120.102"));\r
+ realserver_addr.port(80);\r
+ test_data1.op_code = 'D';\r
+ test_data1.realserver_addr = realserver_addr;\r
+ test_data1.last_time = test_time;\r
+ test_object.temp_list.clear();\r
+ test_object.put_into_temp_list(test_data1);\r
+ boost::thread test_thread5(boost::bind(&sslid_replication_data_processor::write_replicaion_area, &test_object));\r
+ test_thread5.timed_join(boost::posix_time::milliseconds(100));\r
+ // get saved information\r
+ saved_session_id = std::string(test_object.replication_area->session_id);\r
+ saved_address_ip = std::string(inet_ntoa(test_object.replication_area->realserver_addr.sin_addr));\r
+ saved_address_port = ntohs(test_object.replication_area->realserver_addr.sin_port);\r
+ // sslid_replication_data is deleted logically, valid flag is setted to 0, check it\r
+ BOOST_CHECK_EQUAL(test_object.replication_area->valid, 0);\r
+ // last_time is not updated , check it\r
+ BOOST_CHECK_EQUAL(test_object.replication_area->last_time, update_time);\r
+ // realserver_addr ip is not changed, check it\r
+ BOOST_CHECK_EQUAL(saved_address_ip, std::string("255.255.255.255"));\r
+ // realserver_addr port is not changed, check it\r
+ BOOST_CHECK_EQUAL(saved_address_port, 999);\r
+\r
+ // test_case[16] when op_code is out of 'A','U','D', not add test\r
+ l7vs::sslid_replication_temp_data test_data2;\r
+ memset(test_object.replication_area, 0, 3*sizeof(struct l7vs::sslid_replication_data));\r
+ realserver_addr.address(boost::asio::ip::address::from_string("192.168.120.102"));\r
+ realserver_addr.port(80);\r
+ test_data2.session_id = "test_id2";\r
+ test_data2.op_code = 'T';\r
+ test_data2.last_time = test_time;\r
+ test_data2.realserver_addr = realserver_addr;\r
+ test_object.temp_list.clear();\r
+ test_object.put_into_temp_list(test_data2);\r
+ // get old session data\r
+ l7vs::sslid_replication_data old_session_data[3];\r
+ memcpy(&old_session_data, test_object.replication_area, 3*sizeof(sslid_replication_data));\r
+ boost::thread test_thread6(boost::bind(&sslid_replication_data_processor::write_replicaion_area, &test_object));\r
+ test_thread6.timed_join(boost::posix_time::milliseconds(100));\r
+ // test_data2 is not saved, so old data is not changed, check it\r
+ // old data not changed check\r
+ compare_result = memcmp(&old_session_data, test_object.replication_area, 3*sizeof(sslid_replication_data));\r
+ BOOST_CHECK_EQUAL(compare_result, 0);\r
+\r
+ // test_case[17] when op_code is out of 'A','U','D', not update, not delete test\r
+ // add one data to the sslid replication data area, if the data not changed proving not update, not delete\r
+ temp_session_id = "test_id3";\r
+ memset(test_object.replication_area, 0, 3*sizeof(struct l7vs::sslid_replication_data));\r
+ test_object.replication_area->last_time = test_time;\r
+ memcpy(test_object.replication_area->session_id, temp_session_id.c_str(), temp_session_id.length());\r
+ // set testing data\r
+ l7vs::sslid_replication_temp_data test_data3;\r
+ realserver_addr.address(boost::asio::ip::address::from_string("255.255.255.255"));\r
+ realserver_addr.port(80);\r
+ test_data3.session_id = temp_session_id;\r
+ test_data3.op_code = 'T';\r
+ test_data3.last_time = test_time;\r
+ test_data3.realserver_addr = realserver_addr;\r
+ test_object.temp_list.clear();\r
+ test_object.put_into_temp_list(test_data3);\r
+ // get old session data\r
+ memcpy(&old_session_data, test_object.replication_area, 3*sizeof(sslid_replication_data));\r
+ boost::thread test_thread7(boost::bind(&sslid_replication_data_processor::write_replicaion_area, &test_object));\r
+ test_thread7.timed_join(boost::posix_time::milliseconds(100));\r
+ // old data not changed check\r
+ compare_result = memcmp(&old_session_data, test_object.replication_area, 3*sizeof(sslid_replication_data));\r
+ BOOST_CHECK_EQUAL(compare_result, 0);\r
+\r
+ // test_case[18] when replication_area_lock and replication_area_unlock function is NULL test\r
+ test_data1.session_id = "test_id3";\r
+ test_data1.op_code = 'A';\r
+ test_value = 0;\r
+ test_object.replication_area_lock = NULL;\r
+ test_object.replication_area_unlock = NULL;\r
+ test_object.temp_list.clear();\r
+ test_object.put_into_temp_list(test_data1);\r
+ try{\r
+ boost::thread test_thread8(boost::bind(&sslid_replication_data_processor::write_replicaion_area, &test_object));\r
+ test_thread8.timed_join(boost::posix_time::milliseconds(100));\r
+ } catch(...) {\r
+ BOOST_ERROR("exception: write_replicaion_area_test");\r
+ }\r
+\r
+ // test_case[19] when replication_area_lock function is not NULL test\r
+ test_value = 0;\r
+ function_pointer = &lock_function;\r
+ test_object.replication_area_lock = function_pointer;\r
+ test_object.replication_area_unlock = NULL;\r
+ test_object.temp_list.clear();\r
+ test_object.put_into_temp_list(test_data1);\r
+ try{\r
+ boost::thread test_thread9(boost::bind(&sslid_replication_data_processor::write_replicaion_area, &test_object));\r
+ test_thread9.timed_join(boost::posix_time::milliseconds(100));\r
+ } catch(...) {\r
+ BOOST_ERROR("exception: write_replicaion_area_test");\r
+ }\r
+ // replication_area_lock function called check\r
+ BOOST_CHECK_EQUAL(test_value, 1);\r
+\r
+ // test_case[20] when replication_area_unlock function is not NULL test\r
+ test_value = 0;\r
+ function_pointer = &unlock_function;\r
+ test_object.replication_area_lock = NULL;\r
+ test_object.replication_area_unlock = unlock_function;\r
+ test_object.temp_list.clear();\r
+ test_object.put_into_temp_list(test_data1);\r
+ try{\r
+ boost::thread test_thread10(boost::bind(&sslid_replication_data_processor::write_replicaion_area, &test_object));\r
+ test_thread10.timed_join(boost::posix_time::milliseconds(100));\r
+ } catch(...) {\r
+ BOOST_ERROR("exception: write_replicaion_area_test");\r
+ }\r
+ // replication_area_unlock function called check\r
+ BOOST_CHECK_EQUAL(test_value, 2);\r
+\r
+}\r
+\r
+// function register_replication_area_lock test\r
+void register_replication_area_lock_test(){\r
+\r
+ char replication_data_area[128*sizeof(struct l7vs::sslid_replication_data_header) + STRUCT_NUMBER*sizeof(struct l7vs::sslid_replication_data)] = { 0 };\r
+ l7vs::sslid_replication_data_processor test_object(1, replication_data_area, SECTION_NUMBER);\r
+ boost::function<void(void)> register_function;\r
+\r
+ // test_case[21] registered function is NULL test\r
+ register_function = NULL;\r
+ test_object.register_replication_area_lock(register_function);\r
+ // function registered correctly check;\r
+ BOOST_CHECK(test_object.replication_area_lock == NULL);\r
+\r
+ // test_case[22] registered replication_area_lock function test\r
+ test_value = 0;\r
+ register_function = &lock_function;\r
+ test_object.register_replication_area_lock(register_function);\r
+ // function registered correctly check;\r
+ test_object.replication_area_lock();\r
+ BOOST_CHECK_EQUAL(test_value, 1);\r
+}\r
+\r
+// function register_replication_area_unlock test\r
+void register_replication_area_unlock_test(){\r
+\r
+ char replication_data_area[128*sizeof(struct l7vs::sslid_replication_data_header) + STRUCT_NUMBER*sizeof(struct l7vs::sslid_replication_data)] = { 0 };\r
+ l7vs::sslid_replication_data_processor test_object(1, replication_data_area, SECTION_NUMBER);\r
+ boost::function<void(void)> register_function;\r
+\r
+ // test_case[23] registered function is NULL test\r
+ register_function = NULL;\r
+ test_object.register_replication_area_unlock(register_function);\r
+ // function registered correctly check;\r
+ BOOST_CHECK(test_object.replication_area_lock == NULL);\r
+\r
+ // test_case[24] registered replication_area_unlock function test\r
+ test_value = 0;\r
+ register_function = &unlock_function;\r
+ test_object.register_replication_area_unlock(register_function);\r
+ // function registered correctly check;\r
+ test_object.replication_area_unlock();\r
+ BOOST_CHECK_EQUAL(test_value, 2);\r
+}\r
+\r
+void get_from_temp_list_thread1(l7vs::sslid_replication_data_processor* test_object){\r
+\r
+ l7vs::sslid_replication_temp_data test_data1;\r
+ boost::asio::ip::tcp::endpoint endpoint;\r
+\r
+ test_data1.session_id = "test_id1";\r
+ test_data1.op_code = 'A';\r
+ test_data1.realserver_addr = endpoint;\r
+ test_data1.last_time = time(0);\r
+ test_object->temp_list.push_back(test_data1);\r
+}\r
+\r
+void get_from_temp_list_thread2(\r
+ l7vs::sslid_replication_data_processor* test_object,\r
+ l7vs::sslid_replication_temp_data& get_data) {\r
+\r
+ test_object->get_from_temp_list(get_data);\r
+}\r
+\r
+// function get_from_temp_list test\r
+void get_from_temp_list_test(){\r
+\r
+ char replication_data_area[128*sizeof(struct l7vs::sslid_replication_data_header) + STRUCT_NUMBER*sizeof(struct l7vs::sslid_replication_data)] = { 0 };\r
+ l7vs::sslid_replication_data_processor test_object(2, replication_data_area, SECTION_NUMBER);\r
+ l7vs::sslid_replication_temp_data test_data1;\r
+ l7vs::sslid_replication_temp_data test_data2;\r
+ l7vs::sslid_replication_temp_data get_data;\r
+ boost::asio::ip::tcp::endpoint endpoint;\r
+\r
+ // test_case[25] when temp_list size is empty, test\r
+ try {\r
+ test_object.temp_list.clear();\r
+ boost::thread_group thread_group1;\r
+ thread_group1.create_thread(boost::bind(&get_from_temp_list_thread1, &test_object));\r
+ thread_group1.create_thread(boost::bind(&get_from_temp_list_thread2, &test_object, get_data));\r
+ thread_group1.join_all();\r
+ } catch(...) {\r
+ BOOST_ERROR("exception: get_from_temp_list");\r
+ }\r
+\r
+ // test_case[26] first element of temp_list is removed test\r
+ test_data1.session_id = "test_id1";\r
+ test_data1.op_code = 'T';\r
+ test_data1.realserver_addr = endpoint;\r
+ test_data1.last_time = time(0);\r
+ test_data2.session_id = "test_id2";\r
+ test_data2.op_code = 'A';\r
+ test_data2.realserver_addr = endpoint;\r
+ test_data2.last_time = time(0);\r
+ test_object.temp_list.push_back(test_data1);\r
+ test_object.temp_list.push_back(test_data2);\r
+ memset(&get_data, 0, sizeof(l7vs::sslid_replication_temp_data));\r
+ test_object.get_from_temp_list(get_data);\r
+ // first item removed check,so only one item leave, check it\r
+ BOOST_CHECK_EQUAL((int)test_object.temp_list.size(), 1);\r
+ // leaved item check(the leaved item should be test_data2)\r
+ // session_id check\r
+ BOOST_CHECK_EQUAL(get_data.session_id, test_data2.session_id);\r
+ // op_code check\r
+ BOOST_CHECK_EQUAL(get_data.op_code, test_data2.op_code);\r
+ // realserver_addr check\r
+ BOOST_CHECK_EQUAL(get_data.realserver_addr, test_data2.realserver_addr);\r
+ // last_time check\r
+ BOOST_CHECK_EQUAL(get_data.last_time, test_data2.last_time);\r
+\r
+ // test_case[27] get data test(list has one item)\r
+ test_data1.session_id = "test_id1";\r
+ test_data1.op_code = 'A';\r
+ test_data1.realserver_addr = endpoint;\r
+ test_data1.last_time = time(0);\r
+ memset(&get_data, 0, sizeof(l7vs::sslid_replication_temp_data));\r
+ test_object.temp_list.clear();\r
+ test_object.put_into_temp_list(test_data1);\r
+ test_object.get_from_temp_list(get_data);\r
+ // got data check\r
+ // session_id check\r
+ BOOST_CHECK_EQUAL(get_data.session_id, test_data1.session_id);\r
+ // op_code check\r
+ BOOST_CHECK_EQUAL(get_data.op_code, test_data1.op_code);\r
+ // realserver_addr check\r
+ BOOST_CHECK_EQUAL(get_data.realserver_addr, test_data1.realserver_addr);\r
+ // last_time check\r
+ BOOST_CHECK_EQUAL(get_data.last_time, test_data1.last_time);\r
+\r
+ // test_case[28] get data test(list has two items, get the item which first put into)\r
+ test_data1.session_id = "test_id1";\r
+ test_data1.op_code = 'U';\r
+ test_data1.realserver_addr = endpoint;\r
+ test_data1.last_time = time(0);\r
+ test_data2.session_id = "test_id2";\r
+ test_data2.op_code = 'D';\r
+ test_data2.realserver_addr = endpoint;\r
+ test_data2.last_time = time(0);\r
+ test_object.put_into_temp_list(test_data2);\r
+ test_object.put_into_temp_list(test_data1);\r
+ memset(&get_data, 0, sizeof(l7vs::sslid_replication_temp_data));\r
+ test_object.get_from_temp_list(get_data);\r
+ // got data check\r
+ // session_id check\r
+ BOOST_CHECK_EQUAL(get_data.session_id, test_data2.session_id);\r
+ // op_code check\r
+ BOOST_CHECK_EQUAL(get_data.op_code, test_data2.op_code);\r
+ // realserver_addr check\r
+ BOOST_CHECK_EQUAL(get_data.realserver_addr, test_data2.realserver_addr);\r
+ // last_time check\r
+ BOOST_CHECK_EQUAL(get_data.last_time, test_data2.last_time);\r
+}\r
+\r
+void sslid_replication_data_processor_test_main()\r
+{\r
+ // create unit test suite\r
+ test_suite* ts = BOOST_TEST_SUITE( "sslid_replication_data_processor" );\r
+\r
+ // add test case to test suite\r
+ ts->add( BOOST_TEST_CASE( &sslid_replication_data_processor_test ) );\r
+ ts->add( BOOST_TEST_CASE( &put_into_temp_list_test ) );\r
+ ts->add( BOOST_TEST_CASE( &write_replicaion_area_test ) );\r
+ ts->add( BOOST_TEST_CASE( ®ister_replication_area_lock_test ) );\r
+ ts->add( BOOST_TEST_CASE( ®ister_replication_area_unlock_test ) );\r
+ ts->add( BOOST_TEST_CASE( &get_from_temp_list_test ) );\r
+\r
+ framework::master_test_suite().add( ts );\r
+}\r
--- /dev/null
+/*\r
+ * sslid_session_data_processor_test.cpp\r
+ *\r
+ * Created on: Jan 20, 2009\r
+ * Author: root\r
+ */\r
+#include "sslid_to_be_test_file.h"\r
+\r
+using namespace boost::unit_test;\r
+using namespace l7vs;\r
+\r
+#define SECTION_NUMBER 200\r
+#define STRUCT_NUMBER 256\r
+\r
+// function sslid_session_data_processor test\r
+void sslid_session_data_processor_test(){\r
+\r
+ char replication_data_area[128*sizeof(struct l7vs::sslid_replication_data_header) + STRUCT_NUMBER*sizeof(struct l7vs::sslid_replication_data)] = { 0 };\r
+ l7vs::sslid_replication_data_processor replication_data_processor(2, replication_data_area, SECTION_NUMBER);\r
+ l7vs::sslid_session_data_processor test_object(2, 5, &replication_data_processor);\r
+\r
+ // test_case[1] maxlist check\r
+ BOOST_CHECK_EQUAL(test_object.maxlist, 2);\r
+ // timeout check\r
+ BOOST_CHECK_EQUAL(test_object.timeout, 5);\r
+ // replication_data_processor check\r
+ BOOST_CHECK_EQUAL(test_object.replication_data_processor, &replication_data_processor);\r
+}\r
+\r
+// function get_endpoint_from_session_data test\r
+void get_endpoint_from_session_data_test(){\r
+\r
+ int result = 10;\r
+ char replication_data_area[128*sizeof(struct l7vs::sslid_replication_data_header) + STRUCT_NUMBER*sizeof(struct l7vs::sslid_replication_data)] = { 0 };\r
+ time_t lasttime = time(0);\r
+ std::string session_id;\r
+ boost::asio::ip::address endpoint_address;\r
+ boost::asio::ip::tcp::endpoint saved_endpoint;\r
+ boost::asio::ip::tcp::endpoint get_endpoint;\r
+ l7vs::sslid_replication_data_processor replication_data_processor(2, replication_data_area, SECTION_NUMBER);\r
+ l7vs::sslid_session_data_processor test_object(2, 0, &replication_data_processor);\r
+\r
+ // test_case[2] session_endpoint_map and session_lasttime_map are all empty test\r
+ session_id = "test_id1";\r
+ result = test_object.get_endpoint_from_session_data(session_id, get_endpoint);\r
+ // function result check\r
+ BOOST_CHECK_EQUAL(result, -1);\r
+\r
+ // test_case[3] when session_endpoint_map is empty, but session_lasttime_map is not empty test\r
+ result = 10;\r
+ test_object.session_endpoint_map.clear();\r
+ test_object.session_lasttime_map[session_id] = lasttime;\r
+ result = test_object.get_endpoint_from_session_data(session_id, get_endpoint);\r
+ // function result check\r
+ BOOST_CHECK_EQUAL(result, -1);\r
+\r
+ // test_case[4] when session_endpoint_map is not empty, but session_lasttime_map is empty test\r
+ result = 10;\r
+ test_object.session_lasttime_map.clear();\r
+ test_object.session_endpoint_map[session_id] = saved_endpoint;\r
+ result = test_object.get_endpoint_from_session_data(session_id, get_endpoint);\r
+ // function result check\r
+ BOOST_CHECK_EQUAL(result, -1);\r
+\r
+ // test_case[5] not time out test\r
+ result = 10;\r
+ endpoint_address = boost::asio::ip::address::from_string("192.168.120.102");\r
+ saved_endpoint.address(endpoint_address);\r
+ saved_endpoint.port(80);\r
+ get_endpoint.address(boost::asio::ip::address::from_string("0.0.0.0"));\r
+ test_object.session_endpoint_map[session_id] = saved_endpoint;\r
+ test_object.session_lasttime_map[session_id] = lasttime;\r
+ test_object.timeout = 10000;\r
+ result = test_object.get_endpoint_from_session_data(session_id, get_endpoint);\r
+ // got endpoint check\r
+ BOOST_CHECK_EQUAL(get_endpoint, saved_endpoint);\r
+ // function result check\r
+ BOOST_CHECK_EQUAL(result, 0);\r
+\r
+ // test_case[6] time out test\r
+ std::map<std::string, boost::asio::ip::tcp::endpoint>::iterator it1;\r
+ std::map<std::string, time_t>::iterator it2;\r
+ std::multimap<time_t, std::string>::iterator it3;\r
+ boost::asio::ip::tcp::endpoint temp_endpoint;\r
+ result = 10;\r
+ get_endpoint = temp_endpoint;\r
+ test_object.session_endpoint_map.clear();\r
+ test_object.session_lasttime_map.clear();\r
+ test_object.lasttime_session_map.clear();\r
+ test_object.replication_data_processor->temp_list.clear();\r
+ test_object.session_endpoint_map[session_id] = saved_endpoint;\r
+ test_object.session_lasttime_map[session_id] = lasttime;\r
+ test_object.lasttime_session_map.insert(std::make_pair(lasttime, session_id));\r
+ test_object.lasttime_session_map.insert(std::make_pair(lasttime, std::string("test_id2")));\r
+ test_object.timeout = 0;\r
+ result = test_object.get_endpoint_from_session_data(session_id, get_endpoint);\r
+ it1 = test_object.session_endpoint_map.find(session_id);\r
+ it2 = test_object.session_lasttime_map.find(session_id);\r
+ it3 = test_object.lasttime_session_map.find(lasttime);\r
+ sslid_replication_temp_data get_temp_data;\r
+ test_object.replication_data_processor->get_from_temp_list(get_temp_data);\r
+ // session_endpoint_map item removed check\r
+ BOOST_CHECK(it1 == test_object.session_endpoint_map.end());\r
+ // session_lasttime_map item removed check\r
+ BOOST_CHECK(it2 == test_object.session_lasttime_map.end());\r
+ // lasttime_session_map item removed check\r
+ BOOST_CHECK_EQUAL(it3->second, std::string("test_id2"));\r
+ // function result check\r
+ BOOST_CHECK_EQUAL(result, -1);\r
+ // get_endpoint not be changed check\r
+ BOOST_CHECK_EQUAL(get_endpoint, temp_endpoint);\r
+ // item which put into the temp_list check\r
+ char char_d = 'D';\r
+ BOOST_CHECK_EQUAL(get_temp_data.op_code, char_d);\r
+ BOOST_CHECK_EQUAL(get_temp_data.session_id, session_id);\r
+}\r
+\r
+// function write_session_data test\r
+void write_session_data_test(){\r
+\r
+ int result = 10;\r
+ char replication_data_area[128*sizeof(struct l7vs::sslid_replication_data_header) + STRUCT_NUMBER*sizeof(struct l7vs::sslid_replication_data)] = { 0 };\r
+ time_t write_time = time(0);\r
+ std::string session_id;\r
+ boost::asio::ip::tcp::endpoint old_saved_endpoint;\r
+ boost::asio::ip::tcp::endpoint new_saved_endpoint;\r
+ boost::asio::ip::tcp::endpoint get_endpoint;\r
+ l7vs::sslid_replication_data_processor replication_data_processor(2, replication_data_area, SECTION_NUMBER);\r
+ l7vs::sslid_session_data_processor test_object(2, 0, &replication_data_processor);\r
+\r
+ // test_case[7] session_id exist test\r
+ test_object.session_endpoint_map.clear();\r
+ test_object.session_lasttime_map.clear();\r
+ test_object.lasttime_session_map.clear();\r
+ test_object.replication_data_processor->temp_list.clear();\r
+ old_saved_endpoint.address(boost::asio::ip::address::from_string("0.0.0.0"));\r
+ new_saved_endpoint.address(boost::asio::ip::address::from_string("192.168.120.102"));\r
+ session_id = "test_id1";\r
+ test_object.session_endpoint_map[session_id] = old_saved_endpoint;\r
+ result = test_object.write_session_data(session_id, new_saved_endpoint, write_time);\r
+ std::multimap<time_t, std::string>::iterator lasttime_session_map_iterator =\r
+ test_object.lasttime_session_map.find(write_time);\r
+ l7vs::sslid_replication_temp_data& get_temp_data = test_object.replication_data_processor->temp_list.front();\r
+ // session_endpoint_map is setted check\r
+ BOOST_CHECK_EQUAL(test_object.session_endpoint_map[session_id], new_saved_endpoint);\r
+ // session_lasttime_map is setted check\r
+ BOOST_CHECK_EQUAL(test_object.session_lasttime_map[session_id], write_time);\r
+ // lasttime_session_map is setted check\r
+ BOOST_CHECK_EQUAL(lasttime_session_map_iterator->second, session_id);\r
+ // function result check\r
+ BOOST_CHECK_EQUAL(result, 0);\r
+ // item which put into temp_list check\r
+ // op_code check\r
+ BOOST_CHECK_EQUAL(get_temp_data.op_code, 'U');\r
+ // session_id check\r
+ BOOST_CHECK_EQUAL(get_temp_data.session_id, session_id);\r
+ // realserver_addr check\r
+ BOOST_CHECK_EQUAL(get_temp_data.realserver_addr, new_saved_endpoint);\r
+ // last_time check\r
+ BOOST_CHECK_EQUAL(get_temp_data.last_time, write_time);\r
+\r
+ // test_case[8] session_id not exist test(session_endpoint_map size = maxlist - 1)\r
+ test_object.session_endpoint_map.clear();\r
+ test_object.session_lasttime_map.clear();\r
+ test_object.lasttime_session_map.clear();\r
+ test_object.replication_data_processor->temp_list.clear();\r
+ test_object.session_endpoint_map.insert(std::make_pair(std::string("test_id2"), new_saved_endpoint));\r
+ result = test_object.write_session_data(session_id, new_saved_endpoint, write_time);\r
+ lasttime_session_map_iterator =test_object.lasttime_session_map.find(write_time);\r
+ get_temp_data = test_object.replication_data_processor->temp_list.front();\r
+ // session_endpoint_map is setted check\r
+ BOOST_CHECK_EQUAL(test_object.session_endpoint_map[session_id], new_saved_endpoint);\r
+ // session_lasttime_map is setted check\r
+ BOOST_CHECK_EQUAL(test_object.session_lasttime_map[session_id], write_time);\r
+ // lasttime_session_map is setted check\r
+ BOOST_CHECK_EQUAL(lasttime_session_map_iterator->second, session_id);\r
+ // function result check\r
+ BOOST_CHECK_EQUAL(result, 0);\r
+ // item which put into temp_list check\r
+ // op_code check\r
+ BOOST_CHECK_EQUAL(get_temp_data.op_code, 'A');\r
+ // session_id check\r
+ BOOST_CHECK_EQUAL(get_temp_data.session_id, session_id);\r
+ // realserver_addr check\r
+ BOOST_CHECK_EQUAL(get_temp_data.realserver_addr, new_saved_endpoint);\r
+ // last_time check\r
+ BOOST_CHECK_EQUAL(get_temp_data.last_time, write_time);\r
+\r
+ // test_case[9] session_id not exist test(session_endpoint_map size = maxlist)\r
+ test_object.session_endpoint_map.clear();\r
+ test_object.session_lasttime_map.clear();\r
+ test_object.lasttime_session_map.clear();\r
+ test_object.replication_data_processor->temp_list.clear();\r
+ test_object.session_endpoint_map.insert(std::make_pair(std::string("test_id2"), new_saved_endpoint));\r
+ test_object.session_endpoint_map.insert(std::make_pair(std::string("test_id3"), new_saved_endpoint));\r
+ result = test_object.write_session_data(session_id, new_saved_endpoint, write_time);\r
+ l7vs::sslid_replication_temp_data& first_item = test_object.replication_data_processor->temp_list.front();\r
+ l7vs::sslid_replication_temp_data& last_item = test_object.replication_data_processor->temp_list.back();\r
+ // clear_expired_session_data function is called check(the first item in the temp_list is put by clear_expired_session_data function)\r
+ BOOST_CHECK_EQUAL(first_item.op_code, 'D');\r
+ BOOST_CHECK_EQUAL(first_item.session_id, session_id);\r
+ // session_endpoint_map is setted check\r
+ BOOST_CHECK_EQUAL(test_object.session_endpoint_map[session_id], new_saved_endpoint);\r
+ // session_lasttime_map is setted check\r
+ BOOST_CHECK_EQUAL(test_object.session_lasttime_map[session_id], write_time);\r
+ // lasttime_session_map is setted check\r
+ BOOST_CHECK_EQUAL(lasttime_session_map_iterator->second, session_id);\r
+ // function result check\r
+ BOOST_CHECK_EQUAL(result, 0);\r
+ // the add operation check(the second item in the temp_list is to be added item)\r
+ // op_code check\r
+ BOOST_CHECK_EQUAL(last_item.op_code, 'A');\r
+ // session_id check\r
+ BOOST_CHECK_EQUAL(get_temp_data.session_id, session_id);\r
+ // realserver_addr check\r
+ BOOST_CHECK_EQUAL(get_temp_data.realserver_addr, new_saved_endpoint);\r
+ // last_time check\r
+ BOOST_CHECK_EQUAL(get_temp_data.last_time, write_time);\r
+}\r
+\r
+// function clear_expired_session_data test\r
+void clear_expired_session_data_test(){\r
+\r
+ int result = 10;\r
+ char replication_data_area[128*sizeof(struct l7vs::sslid_replication_data_header) + STRUCT_NUMBER*sizeof(struct l7vs::sslid_replication_data)] = { 0 };\r
+ time_t test_time;\r
+ boost::asio::ip::tcp::endpoint saved_endpoint1;\r
+ boost::asio::ip::tcp::endpoint saved_endpoint2;\r
+ l7vs::sslid_replication_data_processor replication_data_processor(2, replication_data_area, SECTION_NUMBER);\r
+ l7vs::sslid_session_data_processor test_object(2, 0, &replication_data_processor);\r
+\r
+ // test_case[10] map empty test\r
+ test_object.timeout = 0;\r
+ test_object.session_endpoint_map.clear();\r
+ test_object.session_lasttime_map.clear();\r
+ test_object.lasttime_session_map.clear();\r
+ try{\r
+ result = test_object.clear_expired_session_data();\r
+ } catch(...) {\r
+ BOOST_ERROR("exception: clear_expired_session_data");\r
+ }\r
+ // function result check\r
+ BOOST_CHECK_EQUAL(result, 0);\r
+\r
+ // test_case[11] when time out items exist(all items is time out), items remove test\r
+ test_time = time(0);\r
+ test_time = test_time - 5;\r
+ test_object.timeout = 0;\r
+ test_object.session_endpoint_map.clear();\r
+ test_object.session_lasttime_map.clear();\r
+ test_object.lasttime_session_map.clear();\r
+ test_object.replication_data_processor->temp_list.clear();\r
+ test_object.session_endpoint_map.insert(std::make_pair(std::string("test_id1"), saved_endpoint1));\r
+ test_object.session_endpoint_map.insert(std::make_pair(std::string("test_id2"), saved_endpoint2));\r
+ test_object.session_lasttime_map.insert(std::make_pair(std::string("test_id1"), test_time));\r
+ test_object.session_lasttime_map.insert(std::make_pair(std::string("test_id2"), test_time));\r
+ test_object.lasttime_session_map.insert(std::make_pair(test_time, std::string("test_id1")));\r
+ test_object.lasttime_session_map.insert(std::make_pair(test_time, std::string("test_id2")));\r
+ result = test_object.clear_expired_session_data();\r
+ l7vs::sslid_replication_temp_data& first_data = test_object.replication_data_processor->temp_list.front();\r
+ l7vs::sslid_replication_temp_data& last_data = test_object.replication_data_processor->temp_list.back();\r
+ // remove result check(all items is removed)\r
+ // function result check\r
+ BOOST_CHECK_EQUAL(result, 0);\r
+ // session_endpoint_map items remove check\r
+ BOOST_CHECK_EQUAL((int)test_object.session_endpoint_map.size(), 0);\r
+ // session_lasttime_map items remove check\r
+ BOOST_CHECK_EQUAL((int)test_object.session_lasttime_map.size(), 0);\r
+ // lasttime_session_map items remove check\r
+ BOOST_CHECK_EQUAL((int)test_object.lasttime_session_map.size(), 0);\r
+ // removed items check\r
+ BOOST_CHECK_EQUAL(first_data.op_code, 'D');\r
+ BOOST_CHECK_EQUAL(first_data.session_id, std::string("test_id1"));\r
+ BOOST_CHECK_EQUAL(last_data.op_code, 'D');\r
+ BOOST_CHECK_EQUAL(last_data.session_id, std::string("test_id2"));\r
+\r
+ // test_case[12] when time out item exists(one item is time out, but another item is not), item remove test\r
+ saved_endpoint2.port(88);\r
+ test_object.timeout = 100;\r
+ test_time = time(0);\r
+ time_t out_time = test_time - 1000;\r
+ time_t not_out_time = test_time;\r
+ test_object.session_endpoint_map.clear();\r
+ test_object.session_lasttime_map.clear();\r
+ test_object.lasttime_session_map.clear();\r
+ test_object.replication_data_processor->temp_list.clear();\r
+ test_object.session_endpoint_map.insert(std::make_pair(std::string("test_id1"), saved_endpoint1));\r
+ test_object.session_endpoint_map.insert(std::make_pair(std::string("test_id2"), saved_endpoint2));\r
+ test_object.session_lasttime_map.insert(std::make_pair(std::string("test_id1"), out_time));\r
+ test_object.session_lasttime_map.insert(std::make_pair(std::string("test_id2"), not_out_time));\r
+ test_object.lasttime_session_map.insert(std::make_pair(out_time, std::string("test_id1")));\r
+ test_object.lasttime_session_map.insert(std::make_pair(not_out_time, std::string("test_id2")));\r
+ result = test_object.clear_expired_session_data();\r
+ std::map<std::string, boost::asio::ip::tcp::endpoint>::iterator it1 = test_object.session_endpoint_map.begin();\r
+ std::map<std::string, time_t>::iterator it2 = test_object.session_lasttime_map.begin();\r
+ std::multimap<time_t, std::string>::iterator it3 = test_object.lasttime_session_map.begin();\r
+ l7vs::sslid_replication_temp_data& temp_data = test_object.replication_data_processor->temp_list.front();\r
+ // remove ruslt check(item 'test_id1' is removed, but item 'test_id2' is still existing)\r
+ // function result check\r
+ BOOST_CHECK_EQUAL(result, 0);\r
+ // session_endpoint_map item remove check\r
+ BOOST_CHECK_EQUAL((int)test_object.session_endpoint_map.size(), 1);\r
+ BOOST_CHECK_EQUAL(it1->first, std::string("test_id2"));\r
+ BOOST_CHECK_EQUAL(it1->second, saved_endpoint2);\r
+ // session_lasttime_map item remove check\r
+ BOOST_CHECK_EQUAL((int)test_object.session_lasttime_map.size(), 1);\r
+ BOOST_CHECK_EQUAL(it2->first, std::string("test_id2"));\r
+ BOOST_CHECK_EQUAL(it2->second, not_out_time);\r
+ // lasttime_session_map item remove check\r
+ BOOST_CHECK_EQUAL((int)test_object.lasttime_session_map.size(), 1);\r
+ BOOST_CHECK_EQUAL(it3->first, not_out_time);\r
+ BOOST_CHECK_EQUAL(it3->second, std::string("test_id2"));\r
+ // removed item check\r
+ BOOST_CHECK_EQUAL(temp_data.op_code, 'D');\r
+ BOOST_CHECK_EQUAL(temp_data.session_id, std::string("test_id1"));\r
+\r
+ // test_case[13] when time out items are not exist, item remove test\r
+ test_object.timeout = 10000;\r
+ time_t earlier_time = test_time -5;\r
+ time_t earliest_time = test_time -10;\r
+ test_object.session_endpoint_map.clear();\r
+ test_object.session_lasttime_map.clear();\r
+ test_object.lasttime_session_map.clear();\r
+ test_object.replication_data_processor->temp_list.clear();\r
+ test_object.session_endpoint_map.insert(std::make_pair(std::string("test_id1"), saved_endpoint1));\r
+ test_object.session_endpoint_map.insert(std::make_pair(std::string("test_id2"), saved_endpoint2));\r
+ test_object.session_lasttime_map.insert(std::make_pair(std::string("test_id1"), earlier_time));\r
+ test_object.session_lasttime_map.insert(std::make_pair(std::string("test_id2"), earliest_time));\r
+ test_object.lasttime_session_map.insert(std::make_pair(earlier_time, std::string("test_id1")));\r
+ test_object.lasttime_session_map.insert(std::make_pair(earliest_time, std::string("test_id2")));\r
+ result = test_object.clear_expired_session_data();\r
+ it1 = test_object.session_endpoint_map.begin();\r
+ it2 = test_object.session_lasttime_map.begin();\r
+ it3 = test_object.lasttime_session_map.begin();\r
+ temp_data = test_object.replication_data_processor->temp_list.front();\r
+ // remove ruslt check(item 'test_id2' which has the earliest lasttime is removed)\r
+ // function result check\r
+ BOOST_CHECK_EQUAL(result, 0);\r
+ // session_endpoint_map item remove check\r
+ BOOST_CHECK_EQUAL((int)test_object.session_endpoint_map.size(), 1);\r
+ BOOST_CHECK_EQUAL(it1->first, std::string("test_id1"));\r
+ BOOST_CHECK_EQUAL(it1->second, saved_endpoint1);\r
+ // session_lasttime_map item remove check\r
+ BOOST_CHECK_EQUAL((int)test_object.session_lasttime_map.size(), 1);\r
+ BOOST_CHECK_EQUAL(it2->first, std::string("test_id1"));\r
+ BOOST_CHECK_EQUAL(it2->second, earlier_time);\r
+ // lasttime_session_map item remove check\r
+ BOOST_CHECK_EQUAL((int)test_object.lasttime_session_map.size(), 1);\r
+ BOOST_CHECK_EQUAL(it3->first, earlier_time);\r
+ BOOST_CHECK_EQUAL(it3->second, std::string("test_id1"));\r
+ // removed item check\r
+ BOOST_CHECK_EQUAL(temp_data.op_code, 'D');\r
+ BOOST_CHECK_EQUAL(temp_data.session_id, std::string("test_id2"));\r
+}\r
+\r
+// function read_session_data_from_replication_area test\r
+void read_session_data_from_replication_area_test(){\r
+\r
+ int result = 10;\r
+ unsigned short port1 = 888;\r
+ unsigned short port2 = 999;\r
+ char replication_data_area[128*sizeof(struct l7vs::sslid_replication_data_header) + STRUCT_NUMBER*sizeof(struct l7vs::sslid_replication_data)] = { 0 };\r
+ char *header_start_address = replication_data_area;\r
+ char *real_data_start_address = header_start_address + 128*sizeof(struct l7vs::sslid_replication_data_header);\r
+ time_t last_time1 = time(0);\r
+ l7vs::sslid_replication_data_header* first_header = (sslid_replication_data_header*)header_start_address;\r
+ l7vs::sslid_replication_data* first_real_data = (sslid_replication_data*)real_data_start_address;\r
+ l7vs::sslid_replication_data_processor replication_data_processor(2, replication_data_area, SECTION_NUMBER);\r
+ l7vs::sslid_session_data_processor test_object(2, 0, &replication_data_processor);\r
+\r
+ // setting for the replication area\r
+ // set the header area\r
+ first_header->virtualserver_addr.s_addr = inet_addr("192.168.120.102");\r
+ first_header->virtualserver_port = 80;\r
+ first_header->offset = real_data_start_address - header_start_address;\r
+ first_header->size = 2*sizeof(struct l7vs::sslid_replication_data);\r
+ // set the real data area(the first data)\r
+ char session_id1[] = "test_id1";\r
+ memcpy(first_real_data->session_id, session_id1, sizeof(session_id1));\r
+ first_real_data->valid = 1;\r
+ first_real_data->realserver_addr.sin_family = AF_INET;\r
+ first_real_data->realserver_addr.sin_addr.s_addr = inet_addr("192.168.120.242");\r
+ first_real_data->realserver_addr.sin_port = port1;\r
+ first_real_data->last_time = last_time1;\r
+ // set the real data area(the second data)\r
+ char session_id2[] = "test_id2";\r
+ time_t last_time2 = last_time1 - 10;\r
+ memcpy((first_real_data + 1)->session_id, session_id2, sizeof(session_id2));\r
+ (first_real_data + 1)->valid = 1;\r
+ (first_real_data + 1)->realserver_addr.sin_family = AF_INET;\r
+ (first_real_data + 1)->realserver_addr.sin_addr.s_addr = inet_addr("255.255.255.255");\r
+ (first_real_data + 1)->realserver_addr.sin_port = port2;\r
+ (first_real_data + 1)->last_time = last_time2;\r
+\r
+ // test_case[14] NULL pointer test\r
+ try {\r
+ result = test_object.read_session_data_from_replication_area(NULL);\r
+ } catch (...){\r
+ BOOST_ERROR("exception: read_session_data_from_replication_area");\r
+ }\r
+ // function result check\r
+ BOOST_CHECK_EQUAL(result, -1);\r
+\r
+ std::map<std::string, boost::asio::ip::tcp::endpoint>::iterator it1;\r
+ std::map<std::string, time_t>::iterator it2;\r
+ std::multimap<time_t, std::string>::iterator it3;\r
+\r
+ // test_case[15] read data test(read the first data)\r
+ result = 10;\r
+ test_object.session_endpoint_map.clear();\r
+ test_object.session_lasttime_map.clear();\r
+ test_object.lasttime_session_map.clear();\r
+ result = test_object.read_session_data_from_replication_area(first_real_data);\r
+ it1 = test_object.session_endpoint_map.begin();\r
+ it2 = test_object.session_lasttime_map.begin();\r
+ it3 = test_object.lasttime_session_map.begin();\r
+ // function result check\r
+ BOOST_CHECK_EQUAL(result, 0);\r
+ // session_endpoint_map check\r
+ BOOST_CHECK_EQUAL((int)test_object.session_endpoint_map.size(), 1);\r
+ // session_endpoint_map's session_id check\r
+ BOOST_CHECK_EQUAL(it1->first, std::string("test_id1"));\r
+ // session_endpoint_map's endpoint (ip && port) check\r
+ BOOST_CHECK_EQUAL(it1->second.address().to_string(), std::string("192.168.120.242"));\r
+ BOOST_CHECK_EQUAL(it1->second.port(), port1);\r
+ // session_lasttime_map check\r
+ BOOST_CHECK_EQUAL((int)test_object.session_lasttime_map.size(), 1);\r
+ // session_lasttime_map's session_id check\r
+ BOOST_CHECK_EQUAL(it2->first, std::string("test_id1"));\r
+ // session_lasttime_map's lasttime check\r
+ BOOST_CHECK_EQUAL(it2->second, last_time1);\r
+ // lasttime_session_map check\r
+ BOOST_CHECK_EQUAL((int)test_object.lasttime_session_map.size(), 1);\r
+ // lasttime_session_map's lasttime check\r
+ BOOST_CHECK_EQUAL(it3->first, last_time1);\r
+ // lasttime_session_map's session_id check\r
+ BOOST_CHECK_EQUAL(it3->second, std::string("test_id1"));\r
+\r
+ // test_case[16] read data test(read the second data)\r
+ result = 10;\r
+ test_object.session_endpoint_map.clear();\r
+ test_object.session_lasttime_map.clear();\r
+ test_object.lasttime_session_map.clear();\r
+ result = test_object.read_session_data_from_replication_area(first_real_data + 1);\r
+ it1 = test_object.session_endpoint_map.begin();\r
+ it2 = test_object.session_lasttime_map.begin();\r
+ it3 = test_object.lasttime_session_map.begin();\r
+ // function result check\r
+ BOOST_CHECK_EQUAL(result, 0);\r
+ // session_endpoint_map check\r
+ BOOST_CHECK_EQUAL((int)test_object.session_endpoint_map.size(), 1);\r
+ // session_endpoint_map's session_id check\r
+ BOOST_CHECK_EQUAL(it1->first, std::string("test_id2"));\r
+ // session_endpoint_map's endpoint (ip && port) check\r
+ BOOST_CHECK_EQUAL(it1->second.address().to_string(), std::string("255.255.255.255"));\r
+ BOOST_CHECK_EQUAL(it1->second.port(), port2);\r
+ // session_lasttime_map check\r
+ BOOST_CHECK_EQUAL((int)test_object.session_lasttime_map.size(), 1);\r
+ // session_lasttime_map's session_id check\r
+ BOOST_CHECK_EQUAL(it2->first, std::string("test_id2"));\r
+ // session_lasttime_map's lasttime check\r
+ BOOST_CHECK_EQUAL(it2->second, last_time2);\r
+ // lasttime_session_map check\r
+ BOOST_CHECK_EQUAL((int)test_object.lasttime_session_map.size(), 1);\r
+ // lasttime_session_map's lasttime check\r
+ BOOST_CHECK_EQUAL(it3->first, last_time2);\r
+ // lasttime_session_map's session_id check\r
+ BOOST_CHECK_EQUAL(it3->second, std::string("test_id2"));\r
+}\r
+\r
+void sslid_session_data_processor_test_main()\r
+{\r
+\r
+ // create unit test suite\r
+ test_suite* ts = BOOST_TEST_SUITE( "sslid_session_data_processor" );\r
+\r
+ // add test case to test suite\r
+ ts->add( BOOST_TEST_CASE( &sslid_session_data_processor_test ) );\r
+ ts->add( BOOST_TEST_CASE( &get_endpoint_from_session_data_test ) );\r
+ ts->add( BOOST_TEST_CASE( &write_session_data_test ) );\r
+ ts->add( BOOST_TEST_CASE( &clear_expired_session_data_test ) );\r
+ ts->add( BOOST_TEST_CASE( &read_session_data_from_replication_area_test ) );\r
+\r
+ framework::master_test_suite().add( ts );\r
+}\r