diff options
Diffstat (limited to 'gtest/gtest_hos_write.cpp')
| -rw-r--r-- | gtest/gtest_hos_write.cpp | 280 |
1 files changed, 225 insertions, 55 deletions
diff --git a/gtest/gtest_hos_write.cpp b/gtest/gtest_hos_write.cpp index 19419f9b..456055f1 100644 --- a/gtest/gtest_hos_write.cpp +++ b/gtest/gtest_hos_write.cpp @@ -6,7 +6,7 @@ #define HOS_BUFF "This a googleTest" #define HOS_FILE "../conf/default.conf" -static void gtest_hos_handle_init(hos_client_handle_t *hos_handle) +static void gtest_hos_handle_init(hos_client_handle_t *hos_handle, int thread_num) { memset(hos_handle, 0, sizeof(hos_client_handle_t)); hos_handle->buckets.push_back(Aws::S3::Model::Bucket().WithName("session_record_hos_bucket")); @@ -25,10 +25,20 @@ static void gtest_hos_handle_init(hos_client_handle_t *hos_handle) memcpy(hos_handle->hos_config.log_path, "./hoslog", strlen("./hoslog")+1); hos_handle->hos_config.pool_thread_size = 10; hos_handle->hos_config.port = 9098; - hos_handle->hos_config.thread_num = 1; + hos_handle->hos_config.thread_num = thread_num; hos_handle->hos_config.timeout = 1000; hos_handle->hos_func.fd_thread_status = 0; hos_handle->hos_func.fs2_status = 1; + + data_info_t *data_info = (data_info_t *)calloc(1, sizeof(data_info_t)); + hos_handle->hos_func.fs2_info[0].reserved = (void *)data_info; + data_info->tx_pkts = (size_t *)calloc(thread_num, sizeof(size_t)); + data_info->tx_bytes = (size_t *)calloc(thread_num, sizeof(size_t)); + data_info->rx_pkts = (size_t *)calloc(thread_num, sizeof(size_t)); + data_info->rx_bytes = (size_t *)calloc(thread_num, sizeof(size_t)); + data_info->tx_failed_pkts = (size_t *)calloc(thread_num, sizeof(size_t)); + data_info->tx_failed_bytes = (size_t *)calloc(thread_num, sizeof(size_t)); + data_info->cache = (size_t *)calloc(thread_num, sizeof(size_t)); } static void gtest_hos_instance_init(hos_instance instance) @@ -105,15 +115,17 @@ static void hos_bucket_not_exits_cb(bool result, const char *bucket, const char TEST(hos_write, normal) { + int thread_num = 3; hos_instance_s expect_hos_instance; hos_client_handle_t expect_hos_handle; hos_fd_context_t expect_fd_info[3]; + data_info_t *data_info = NULL; - hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 3, HOS_BUCKET); + hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET); gtest_hos_instance_init(&expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance); - gtest_hos_handle_init(&expect_hos_handle); - expect_hos_handle.hos_config.thread_num=3; + gtest_hos_handle_init(&expect_hos_handle, thread_num); + data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved; CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); size_t fd = hos_open_fd(HOS_BUCKET, "object_buff", hos_write_buff_cb, (void *)"object_buff", 0, BUFF_MODE); @@ -129,10 +141,15 @@ TEST(hos_write, normal) int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF), 0); EXPECT_EQ(ret, HOS_CLIENT_OK); expect_fd_info[0].fd_status = 2; + data_info->rx_bytes[0] += strlen(HOS_BUFF); + data_info->rx_pkts[0] +=1; + data_info->tx_bytes[0] += strlen(HOS_BUFF); + data_info->tx_pkts[0] += 1; + CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); //CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]); - EXPECT_TRUE(g_fd_context[0][0].cache == NULL); + //EXPECT_TRUE(g_fd_context[0][0].cache == NULL); size_t fd1 = hos_open_fd(HOS_BUCKET, "object_append", hos_write_append_cb, (void *)"object_append", 1, BUFF_MODE | APPEND_MODE); EXPECT_EQ(fd1, 3); @@ -147,6 +164,9 @@ TEST(hos_write, normal) ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1); EXPECT_EQ(ret, HOS_CLIENT_OK); + data_info->rx_bytes[1] += strlen(HOS_BUFF); + data_info->rx_pkts[1] +=1; + data_info->cache[1] += strlen(HOS_BUFF); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); expect_fd_info[1].cache_rest -= strlen(HOS_BUFF); @@ -156,6 +176,9 @@ TEST(hos_write, normal) ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1); EXPECT_EQ(ret, HOS_CLIENT_OK); + data_info->rx_bytes[1] += strlen(HOS_BUFF); + data_info->rx_pkts[1] +=1; + data_info->cache[1] += strlen(HOS_BUFF); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); expect_fd_info[1].cache_rest -= strlen(HOS_BUFF); @@ -174,23 +197,32 @@ TEST(hos_write, normal) expect_fd_info[2].mode = FILE_MODE; CheckStructGHosFdContext(g_fd_context[2], &expect_fd_info[2]); - ret = hos_write(fd2, HOS_FILE, strlen(HOS_CONF), 0); + ret = hos_write(fd2, HOS_FILE, strlen(HOS_CONF), 2); EXPECT_EQ(ret, HOS_CLIENT_OK); + struct stat buffer; + stat(HOS_CONF, &buffer); + data_info->rx_bytes[2] += buffer.st_size; + data_info->rx_pkts[2] +=1; + data_info->tx_bytes[2] += buffer.st_size; + data_info->tx_pkts[2] += 1; CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); expect_fd_info[2].fd_status = 2; //CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]); - EXPECT_TRUE(g_fd_context[1][0].cache != NULL); + //EXPECT_TRUE(g_fd_context[2][0].cache != NULL); ret = hos_close_fd(fd, 0); EXPECT_EQ(ret, HOS_CLIENT_OK); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - ret = hos_close_fd(fd1, 0); + ret = hos_close_fd(fd1, 1); EXPECT_EQ(ret, HOS_CLIENT_OK); + data_info->tx_bytes[1] += data_info->cache[1]; + data_info->tx_pkts[1] += 1; + data_info->cache[1] = 0; CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - ret = hos_close_fd(fd2, 0); + ret = hos_close_fd(fd2, 2); EXPECT_EQ(ret, HOS_CLIENT_OK); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); @@ -202,6 +234,13 @@ TEST(hos_write, normal) CheckHosInstance(hos_instance, &expect_hos_instance); Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets); + free(data_info->cache); + free(data_info->rx_bytes); + free(data_info->rx_pkts); + free(data_info->tx_bytes); + free(data_info->tx_pkts); + free(data_info->tx_failed_bytes); + free(data_info->tx_failed_pkts); memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s)); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); EXPECT_EQ((void *)g_fd_context, (void *)NULL); @@ -212,12 +251,14 @@ TEST(hos_write, bucket_not_exits) hos_instance_s expect_hos_instance; hos_client_handle_t expect_hos_handle; hos_fd_context_t expect_fd_info[3]; + int thread_num = 3; + data_info_t *data_info = NULL; - hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 3, HOS_BUCKET); + hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET); gtest_hos_instance_init(&expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance); - gtest_hos_handle_init(&expect_hos_handle); - expect_hos_handle.hos_config.thread_num=3; + gtest_hos_handle_init(&expect_hos_handle, thread_num); + data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved; CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); size_t fd = hos_open_fd("bucket_not_exits", "object_buff", hos_bucket_not_exits_cb, (void *)"object_buff", 0, BUFF_MODE); @@ -233,12 +274,12 @@ TEST(hos_write, bucket_not_exits) int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF), 0); EXPECT_EQ(ret, HOS_CLIENT_OK); + data_info->rx_bytes[0] = strlen(HOS_BUFF); + data_info->rx_pkts[0] += 1; + data_info->tx_failed_bytes[0] = strlen(HOS_BUFF); + data_info->tx_failed_pkts[0] += 1; CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - //expect_fd_info[0].cache_rest -= strlen(HOS_BUFF); - //expect_fd_info[0].cache_count--; - expect_fd_info[0].fd_status = 2; - //CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]); EXPECT_TRUE(g_fd_context[0][0].cache == NULL); size_t fd1 = hos_open_fd("bucket_not_exits", "object_append", hos_bucket_not_exits_cb, (void *)"object_append", 1, BUFF_MODE | APPEND_MODE); @@ -255,6 +296,9 @@ TEST(hos_write, bucket_not_exits) ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1); EXPECT_EQ(ret, HOS_CLIENT_OK); + data_info->cache[1] += strlen(HOS_BUFF); + data_info->rx_bytes[1] += strlen(HOS_BUFF); + data_info->rx_pkts[1] += 1; CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); expect_fd_info[1].cache_rest -= strlen(HOS_BUFF); @@ -264,6 +308,9 @@ TEST(hos_write, bucket_not_exits) ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1); EXPECT_EQ(ret, HOS_CLIENT_OK); + data_info->cache[1] += strlen(HOS_BUFF); + data_info->rx_bytes[1] += strlen(HOS_BUFF); + data_info->rx_pkts[1] += 1; CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); expect_fd_info[1].cache_rest -= strlen(HOS_BUFF); @@ -286,6 +333,12 @@ TEST(hos_write, bucket_not_exits) ret = hos_write(fd2, HOS_FILE, strlen(HOS_CONF), 2); EXPECT_EQ(ret, HOS_CLIENT_OK); expect_fd_info[2].fd_status = 2; + struct stat buffer; + stat(HOS_CONF, &buffer); + data_info->rx_bytes[2] += buffer.st_size; + data_info->rx_pkts[2] += 1; + data_info->tx_failed_bytes[2] += buffer.st_size; + data_info->tx_failed_pkts[2] += 1; CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); //CheckStructGHosFdContext(g_fd_context[2], &expect_fd_info[2]); @@ -295,11 +348,14 @@ TEST(hos_write, bucket_not_exits) EXPECT_EQ(ret, HOS_CLIENT_OK); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - ret = hos_close_fd(fd1, 0); + ret = hos_close_fd(fd1, 1); EXPECT_EQ(ret, HOS_CLIENT_OK); + data_info->tx_failed_bytes[1] += data_info->cache[1]; + data_info->tx_failed_pkts[1] += 1; + data_info->cache[1] = 0; CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - ret = hos_close_fd(fd2, 0); + ret = hos_close_fd(fd2, 2); EXPECT_EQ(ret, HOS_CLIENT_OK); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); @@ -311,6 +367,13 @@ TEST(hos_write, bucket_not_exits) CheckHosInstance(hos_instance, &expect_hos_instance); Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets); + free(data_info->cache); + free(data_info->rx_bytes); + free(data_info->rx_pkts); + free(data_info->tx_bytes); + free(data_info->tx_pkts); + free(data_info->tx_failed_bytes); + free(data_info->tx_failed_pkts); memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s)); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); EXPECT_EQ((void *)g_fd_context, (void *)NULL); @@ -321,12 +384,14 @@ TEST(hos_write, sync_mode) hos_instance_s expect_hos_instance; hos_client_handle_t expect_hos_handle; hos_fd_context_t expect_fd_info[3]; + int thread_num = 3; + data_info_t * data_info = NULL; - hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_sync_conf", 3, HOS_BUCKET); + hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_sync_conf", thread_num, HOS_BUCKET); gtest_hos_instance_init(&expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance); - gtest_hos_handle_init(&expect_hos_handle); - expect_hos_handle.hos_config.thread_num=3; + gtest_hos_handle_init(&expect_hos_handle, thread_num); + data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved; expect_hos_handle.hos_config.pool_thread_size = 0; CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); @@ -340,6 +405,10 @@ TEST(hos_write, sync_mode) int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF), 0); EXPECT_EQ(ret, HOS_CLIENT_OK); + data_info->rx_bytes[0] += strlen(HOS_BUFF); + data_info->rx_pkts[0] += 1; + data_info->tx_bytes[0] += strlen(HOS_BUFF); + data_info->tx_pkts[0] += 1; CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); //CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]); @@ -356,6 +425,9 @@ TEST(hos_write, sync_mode) ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1); EXPECT_EQ(ret, HOS_CLIENT_OK); + data_info->rx_bytes[1] += strlen(HOS_BUFF); + data_info->rx_pkts[1] += 1; + data_info->cache[1] += strlen(HOS_BUFF); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); expect_fd_info[1].cache_count--; @@ -365,6 +437,9 @@ TEST(hos_write, sync_mode) ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1); EXPECT_EQ(ret, HOS_CLIENT_OK); + data_info->rx_bytes[1] += strlen(HOS_BUFF); + data_info->rx_pkts[1] += 1; + data_info->cache[1] += strlen(HOS_BUFF); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); expect_fd_info[1].cache_count--; @@ -382,6 +457,12 @@ TEST(hos_write, sync_mode) CheckStructGHosFdContext(g_fd_context[2], &expect_fd_info[2]); ret = hos_write(fd2, HOS_FILE, strlen(HOS_BUFF), 2); EXPECT_EQ(ret, HOS_CLIENT_OK); + struct stat buffer; + stat(HOS_CONF, &buffer); + data_info->rx_bytes[2] += buffer.st_size; + data_info->rx_pkts[2] += 1; + data_info->tx_bytes[2] += buffer.st_size; + data_info->tx_pkts[2] += 1; CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); expect_fd_info[2].fd_status = 2; @@ -392,11 +473,14 @@ TEST(hos_write, sync_mode) EXPECT_EQ(ret, HOS_CLIENT_OK); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - ret = hos_close_fd(fd1, 0); + ret = hos_close_fd(fd1, 1); EXPECT_EQ(ret, HOS_CLIENT_OK); + data_info->tx_bytes[1] += data_info->cache[1]; + data_info->tx_pkts[1] += 1; + data_info->cache[1] = 0; CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - ret = hos_close_fd(fd2, 0); + ret = hos_close_fd(fd2, 2); EXPECT_EQ(ret, HOS_CLIENT_OK); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); @@ -408,6 +492,13 @@ TEST(hos_write, sync_mode) CheckHosInstance(hos_instance, &expect_hos_instance); Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets); + free(data_info->cache); + free(data_info->rx_bytes); + free(data_info->rx_pkts); + free(data_info->tx_bytes); + free(data_info->tx_pkts); + free(data_info->tx_failed_bytes); + free(data_info->tx_failed_pkts); memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s)); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); EXPECT_EQ((void *)g_fd_context, (void *)NULL); @@ -418,43 +509,54 @@ TEST(hos_write, sync_mode_bucket_not_exits) hos_instance_s expect_hos_instance; hos_client_handle_t expect_hos_handle; hos_fd_context_t expect_fd_info[3]; + int thread_num = 3; + data_info_t *data_info = NULL; - hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_sync_conf", 3, HOS_BUCKET); + hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_sync_conf", thread_num, HOS_BUCKET); gtest_hos_instance_init(&expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance); - gtest_hos_handle_init(&expect_hos_handle); - expect_hos_handle.hos_config.thread_num=3; + gtest_hos_handle_init(&expect_hos_handle, thread_num); + data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved; expect_hos_handle.hos_config.pool_thread_size = 0; CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - size_t fd = hos_open_fd(HOS_BUCKET, "object_buff", NULL, NULL, 0, BUFF_MODE); + size_t fd = hos_open_fd(HOS_CONF, "object_buff", NULL, NULL, 0, BUFF_MODE); EXPECT_EQ(fd, 3); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info[0]); expect_fd_info[0].object = (char *)"object_buff"; expect_fd_info[0].mode = BUFF_MODE; + expect_fd_info[0].bucket = (char *)HOS_CONF; CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]); - int ret = hos_write(fd, HOS_BUFF, strlen(HOS_CONF), 0); - EXPECT_EQ(ret, HOS_CLIENT_OK); + int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF), 0); + EXPECT_EQ(ret, NO_SUCH_BUCKET); expect_fd_info[0].fd_status = 2; + data_info->rx_bytes[0] += strlen(HOS_BUFF); + data_info->rx_pkts[0] += 1; + data_info->tx_failed_bytes[0] += strlen(HOS_BUFF); + data_info->tx_failed_pkts[0] += 1; CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); //CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]); EXPECT_TRUE(g_fd_context[0][0].cache == NULL); - size_t fd1 = hos_open_fd(HOS_BUCKET, "object_append", NULL, NULL, 1, BUFF_MODE | APPEND_MODE); + size_t fd1 = hos_open_fd(HOS_CONF, "object_append", NULL, NULL, 1, BUFF_MODE | APPEND_MODE); EXPECT_EQ(fd1, 3); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info[1]); expect_fd_info[1].object = (char *)"object_append"; expect_fd_info[1].mode = BUFF_MODE | APPEND_MODE; + expect_fd_info[1].bucket = (char *)HOS_CONF; CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]); ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1); EXPECT_EQ(ret, HOS_CLIENT_OK); + data_info->rx_bytes[1] += strlen(HOS_BUFF); + data_info->rx_pkts[1] += 1; + data_info->cache[1] += strlen(HOS_BUFF); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); expect_fd_info[1].cache_count--; @@ -463,6 +565,10 @@ TEST(hos_write, sync_mode_bucket_not_exits) EXPECT_TRUE(g_fd_context[1][0].cache != NULL); ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1); + EXPECT_EQ(ret, HOS_CLIENT_OK); + data_info->rx_bytes[1] += strlen(HOS_BUFF); + data_info->rx_pkts[1] += 1; + data_info->cache[1] += strlen(HOS_BUFF); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); expect_fd_info[1].cache_count--; @@ -470,32 +576,41 @@ TEST(hos_write, sync_mode_bucket_not_exits) CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]); EXPECT_TRUE(g_fd_context[1][0].cache != NULL); - size_t fd2 = hos_open_fd(HOS_BUCKET, "object_file", NULL, NULL, 2, FILE_MODE); + size_t fd2 = hos_open_fd(HOS_CONF, "object_file", NULL, NULL, 2, FILE_MODE); EXPECT_EQ(fd2, 3); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info[2]); expect_fd_info[2].object = (char *)"object_file"; expect_fd_info[2].mode = FILE_MODE; + expect_fd_info[2].bucket = (char *)HOS_CONF; CheckStructGHosFdContext(g_fd_context[2], &expect_fd_info[2]); ret = hos_write(fd2, HOS_FILE, strlen(HOS_FILE), 2); - EXPECT_EQ(ret, HOS_CLIENT_OK); + EXPECT_EQ(ret, NO_SUCH_BUCKET); + struct stat buffer; + stat(HOS_CONF, &buffer); + data_info->rx_bytes[2] += buffer.st_size; + data_info->rx_pkts[2] += 1; + data_info->tx_failed_bytes[2] += buffer.st_size; + data_info->tx_failed_pkts[2] += 1; expect_fd_info[2].fd_status = 2; CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); //CheckStructGHosFdContext(g_fd_context[2], &expect_fd_info[2]); EXPECT_TRUE(g_fd_context[2][0].cache == NULL); - ret = hos_close_fd(fd, 0); EXPECT_EQ(ret, HOS_CLIENT_OK); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - ret = hos_close_fd(fd1, 0); + ret = hos_close_fd(fd1, 1); EXPECT_EQ(ret, HOS_CLIENT_OK); + data_info->tx_failed_bytes[1] += data_info->cache[1]; + data_info->tx_failed_pkts[1] += 1; + data_info->cache[1] = 0; CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - ret = hos_close_fd(fd2, 0); + ret = hos_close_fd(fd2, 2); EXPECT_EQ(ret, HOS_CLIENT_OK); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); @@ -507,6 +622,13 @@ TEST(hos_write, sync_mode_bucket_not_exits) CheckHosInstance(hos_instance, &expect_hos_instance); Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets); + free(data_info->cache); + free(data_info->rx_bytes); + free(data_info->rx_pkts); + free(data_info->tx_bytes); + free(data_info->tx_pkts); + free(data_info->tx_failed_bytes); + free(data_info->tx_failed_pkts); memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s)); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); EXPECT_EQ((void *)g_fd_context, (void *)NULL); @@ -517,12 +639,12 @@ TEST(hos_write, paramer_error) hos_instance_s expect_hos_instance; hos_client_handle_t expect_hos_handle; hos_fd_context_t expect_fd_info; + int thread_num = 2; - hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET); + hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET); gtest_hos_instance_init(&expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance); - gtest_hos_handle_init(&expect_hos_handle); - expect_hos_handle.hos_config.thread_num=2; + gtest_hos_handle_init(&expect_hos_handle, thread_num); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); int fd = hos_open_fd(HOS_BUCKET, "object_buff", hos_callback, NULL, 0, BUFF_MODE); @@ -535,7 +657,7 @@ TEST(hos_write, paramer_error) expect_fd_info.mode = BUFF_MODE; CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info); - int ret = hos_write(0, HOS_BUFF, strlen(HOS_CONF), 0); + int ret = hos_write(0, HOS_BUFF, strlen(HOS_BUFF), 0); EXPECT_EQ(ret, HOS_PARAMETER_ERROR); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); @@ -548,6 +670,14 @@ TEST(hos_write, paramer_error) CheckHosInstance(hos_instance, &expect_hos_instance); Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets); + data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved; + free(data_info->cache); + free(data_info->rx_bytes); + free(data_info->rx_pkts); + free(data_info->tx_bytes); + free(data_info->tx_pkts); + free(data_info->tx_failed_bytes); + free(data_info->tx_failed_pkts); memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s)); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); EXPECT_EQ((void *)g_fd_context, (void *)NULL); @@ -558,12 +688,12 @@ TEST(hos_write, fd_not_find) hos_instance_s expect_hos_instance; hos_client_handle_t expect_hos_handle; hos_fd_context_t expect_fd_info; + int thread_num = 2; - hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET); + hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET); gtest_hos_instance_init(&expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance); - gtest_hos_handle_init(&expect_hos_handle); - expect_hos_handle.hos_config.thread_num=2; + gtest_hos_handle_init(&expect_hos_handle, thread_num); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); int ret = hos_write(3, HOS_BUFF, strlen(HOS_CONF), 0); @@ -579,6 +709,14 @@ TEST(hos_write, fd_not_find) CheckHosInstance(hos_instance, &expect_hos_instance); Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets); + data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved; + free(data_info->cache); + free(data_info->rx_bytes); + free(data_info->rx_pkts); + free(data_info->tx_bytes); + free(data_info->tx_pkts); + free(data_info->tx_failed_bytes); + free(data_info->tx_failed_pkts); memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s)); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); EXPECT_EQ((void *)g_fd_context, (void *)NULL); @@ -589,12 +727,12 @@ TEST(hos_write, file_not_exit) hos_instance_s expect_hos_instance; hos_client_handle_t expect_hos_handle; hos_fd_context_t expect_fd_info; + int thread_num = 2; - hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET); + hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET); gtest_hos_instance_init(&expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance); - gtest_hos_handle_init(&expect_hos_handle); - expect_hos_handle.hos_config.thread_num=2; + gtest_hos_handle_init(&expect_hos_handle, thread_num); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); int fd = hos_open_fd(HOS_CONF, "object_file", NULL, NULL, 0, FILE_MODE); @@ -619,6 +757,14 @@ TEST(hos_write, file_not_exit) CheckHosInstance(hos_instance, &expect_hos_instance); Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets); + data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved; + free(data_info->cache); + free(data_info->rx_bytes); + free(data_info->rx_pkts); + free(data_info->tx_bytes); + free(data_info->tx_pkts); + free(data_info->tx_failed_bytes); + free(data_info->tx_failed_pkts); memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s)); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); EXPECT_EQ((void *)g_fd_context, (void *)NULL); @@ -629,12 +775,12 @@ TEST(hos_write, over_threadnums) hos_instance_s expect_hos_instance; hos_client_handle_t expect_hos_handle; hos_fd_context_t expect_fd_info; + int thread_num = 2; - hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET); + hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET); gtest_hos_instance_init(&expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance); - gtest_hos_handle_init(&expect_hos_handle); - expect_hos_handle.hos_config.thread_num=2; + gtest_hos_handle_init(&expect_hos_handle, thread_num); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); int fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, BUFF_MODE); @@ -658,6 +804,14 @@ TEST(hos_write, over_threadnums) CheckHosInstance(hos_instance, &expect_hos_instance); Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets); + data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved; + free(data_info->cache); + free(data_info->rx_bytes); + free(data_info->rx_pkts); + free(data_info->tx_bytes); + free(data_info->tx_pkts); + free(data_info->tx_failed_bytes); + free(data_info->tx_failed_pkts); memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s)); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); EXPECT_EQ((void *)g_fd_context, (void *)NULL); @@ -668,6 +822,7 @@ TEST(hos_write, not_init_instance) int ret = hos_write(3, HOS_BUFF, strlen(HOS_CONF), 0); EXPECT_EQ(ret, HOS_INSTANCE_NOT_INIT); } + static void *hos_function(void *ptr) { #define HOS_FD_NUMS_LOCAL 20 @@ -681,22 +836,24 @@ static void *hos_function(void *ptr) hos_instance_s expect_hos_instance; hos_client_handle_t expect_hos_handle; hos_fd_context_t expect_fd_info[32][20]; + int thread_num = 32; + data_info_t *data_info = NULL; { hos_instance = hos_get_instance(); if (hos_instance->result == false) { - hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 32, HOS_BUCKET); + hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET); } } gtest_hos_instance_init(&expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance); - gtest_hos_handle_init(&expect_hos_handle); - expect_hos_handle.hos_config.thread_num=32; + gtest_hos_handle_init(&expect_hos_handle, thread_num); + data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved; expect_hos_handle.count = thread_id + 1; CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - for (i = 0; i < 20; i++) + for (i = 0; i < HOS_FD_NUMS_LOCAL; i++) { snprintf(object[i], 1024, "object_%lu_%d", thread_id, i); fd[i] = hos_open_fd(HOS_BUCKET, object[i], hos_callback, object[i], 0, BUFF_MODE | APPEND_MODE); @@ -710,10 +867,13 @@ static void *hos_function(void *ptr) CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[thread_id][i]); } - for (i = 0; i < 20; i++) + for (i = 0; i < HOS_FD_NUMS_LOCAL; i++) { ret = hos_write(fd[i], HOS_BUFF, strlen(HOS_BUFF), i); EXPECT_EQ(ret, HOS_CLIENT_OK); + data_info->cache[i] = strlen(HOS_BUFF); + data_info->rx_bytes[i] = strlen(HOS_BUFF); + data_info->rx_pkts[i] += 1; CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); expect_fd_info[thread_id][i].cache_rest -= strlen(HOS_BUFF); @@ -722,10 +882,13 @@ static void *hos_function(void *ptr) EXPECT_TRUE(g_fd_context[1][0].cache != NULL); } - for (i = 0; i < 20; i++) + for (i = 0; i < HOS_FD_NUMS_LOCAL; i++) { ret = hos_close_fd(fd[i], i); EXPECT_EQ(ret, 0); + data_info->rx_bytes[i] = data_info->cache[i]; + data_info->rx_pkts[i] += 1; + data_info->cache[i] = 0; CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); } @@ -737,6 +900,13 @@ static void *hos_function(void *ptr) CheckHosInstance(hos_instance, &expect_hos_instance); Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets); + free(data_info->cache); + free(data_info->rx_bytes); + free(data_info->rx_pkts); + free(data_info->tx_bytes); + free(data_info->tx_pkts); + free(data_info->tx_failed_bytes); + free(data_info->tx_failed_pkts); memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s)); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); EXPECT_EQ((void *)g_fd_context, (void *)NULL); |
