✨ feat(src): 重构
This commit is contained in:
@@ -13,7 +13,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-cove
|
||||
|
||||
add_definitions(-g -W -Wall -std=c++11)
|
||||
#add_executable(gtest_hos_client gtest_hos_init_instance.cpp gtest_hos_get_instance.cpp gtest_hos_close_fd.cpp gtest_hos_open_fd.cpp)
|
||||
#add_executable(gtest_hos_client CheckHosClient.cpp gtest_hos_upload_buff.cpp)
|
||||
#add_executable(gtest_hos_client CheckHosClient.cpp gtest_hos_write.cpp)
|
||||
add_executable(gtest_hos_client ${SRCS})
|
||||
target_link_libraries(gtest_hos_client hos-client-cpp gtest gtest_main pthread)
|
||||
|
||||
|
||||
@@ -19,11 +19,52 @@ void CheckStructHosConfigT(hos_config_t *actual, hos_config_t *expect)
|
||||
EXPECT_EQ(actual->timeout, expect->timeout);
|
||||
}
|
||||
|
||||
void CheckStructHosFunc(hos_func_thread_t *actual, hos_func_thread_t *expect)
|
||||
void CheckStructFs2DataInfo(data_info_t *actual, data_info_t *expect, int thread_num)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < thread_num; i++)
|
||||
{
|
||||
if (actual->cache)
|
||||
{
|
||||
EXPECT_EQ(actual->cache[i], expect->cache[i]);
|
||||
}
|
||||
if (actual->rx_bytes)
|
||||
{
|
||||
EXPECT_EQ(actual->rx_bytes[i], expect->rx_bytes[i]);
|
||||
}
|
||||
if (actual->rx_pkts)
|
||||
{
|
||||
EXPECT_EQ(actual->rx_pkts[i], expect->rx_pkts[i]);
|
||||
}
|
||||
if (actual->tx_bytes)
|
||||
{
|
||||
EXPECT_EQ(actual->tx_bytes[i], expect->tx_bytes[i]);
|
||||
}
|
||||
if (actual->tx_pkts)
|
||||
{
|
||||
EXPECT_EQ(actual->tx_pkts[i], expect->tx_pkts[i]);
|
||||
}
|
||||
if (actual->tx_failed_bytes)
|
||||
{
|
||||
EXPECT_EQ(actual->tx_failed_bytes[i], expect->tx_failed_bytes[i]);
|
||||
}
|
||||
if (actual->tx_failed_pkts)
|
||||
{
|
||||
EXPECT_EQ(actual->tx_failed_pkts[i], expect->tx_failed_pkts[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckStructHosFunc(hos_func_thread_t *actual, hos_func_thread_t *expect, int thread_num)
|
||||
{
|
||||
//EXPECT_EQ(actual->fd_thread, expect->fd_thread);
|
||||
EXPECT_EQ(actual->fd_thread_status, expect->fd_thread_status);
|
||||
//CheckStructFs2Info(actual->fs2_info, expect->fs2_info);
|
||||
if (actual->fs2_info[0].reserved != NULL)
|
||||
{
|
||||
CheckStructFs2DataInfo((data_info_t *)actual->fs2_info[0].reserved,
|
||||
(data_info_t *)expect->fs2_info[0].reserved, thread_num);
|
||||
}
|
||||
EXPECT_EQ(actual->fs2_status, expect->fs2_status);
|
||||
//EXPECT_EQ(actual->fs2_thread, expect->fs2_thread);
|
||||
}
|
||||
@@ -40,7 +81,7 @@ void CheckStructGHosHandle(hos_client_handle_t *actual, hos_client_handle_t *exp
|
||||
//EXPECT_TRUE(actual->log != NULL);
|
||||
//EXPECT_TRUE(actual->S3Client != NULL);
|
||||
CheckStructHosConfigT(&actual->hos_config, &expect->hos_config);
|
||||
CheckStructHosFunc(&actual->hos_func, &expect->hos_func);
|
||||
CheckStructHosFunc(&actual->hos_func, &expect->hos_func, actual->hos_config.thread_num);
|
||||
}
|
||||
|
||||
void CheckStructGHosFdContext(hos_fd_context_t *actual, hos_fd_context_t *expect)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define HOS_CONF "../conf/default.conf"
|
||||
#define HOS_BUCKET "firewall_hos_bucket"
|
||||
|
||||
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"));
|
||||
@@ -23,10 +23,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)
|
||||
@@ -61,12 +71,12 @@ TEST(hos_close_fd, normal)
|
||||
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);
|
||||
|
||||
size_t fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, BUFF_MODE);
|
||||
@@ -88,6 +98,14 @@ TEST(hos_close_fd, normal)
|
||||
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);
|
||||
@@ -98,11 +116,12 @@ TEST(hos_close_fd, 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);
|
||||
gtest_hos_handle_init(&expect_hos_handle, thread_num);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
@@ -124,6 +143,14 @@ TEST(hos_close_fd, 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);
|
||||
@@ -140,12 +167,12 @@ TEST(hos_close_fd, fd_not_exits)
|
||||
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_close_fd(7, 0);
|
||||
@@ -160,6 +187,14 @@ TEST(hos_close_fd, fd_not_exits)
|
||||
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);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define HOS_CONF "../conf/default.conf"
|
||||
#define HOS_BUCKET "firewall_hos_bucket"
|
||||
|
||||
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"));
|
||||
@@ -23,10 +23,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)
|
||||
@@ -51,7 +61,7 @@ TEST(hos_get_instance, normal)
|
||||
hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
gtest_hos_handle_init(&expect_hos_handle, 1);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
hos_instance = hos_get_instance();
|
||||
@@ -71,6 +81,14 @@ TEST(hos_get_instance, normal)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -9,58 +9,84 @@
|
||||
#define HOS_CONF "../conf/default.conf"
|
||||
#define HOS_BUCKET "firewall_hos_bucket"
|
||||
|
||||
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"));
|
||||
hos_handle->buckets.push_back(Aws::S3::Model::Bucket().WithName("firewall_hos_bucket"));
|
||||
hos_handle->count = 1;
|
||||
memcpy(hos_handle->hos_config.accesskeyid, "default", strlen("default")+1);
|
||||
memcpy(hos_handle->hos_config.secretkey, "default", strlen("default")+1);
|
||||
hos_handle->hos_config.cache_count = 10;
|
||||
hos_handle->hos_config.cache_size = 102400;
|
||||
hos_handle->hos_config.fs2_fmt = 0;
|
||||
memcpy(hos_handle->hos_config.fs2_ip, "127.0.0.1", strlen("127.0.0.1")+1);
|
||||
memcpy(hos_handle->hos_config.fs2_path, "./log/hos_fs2_log", strlen("./log/hos_fs2_log")+1);
|
||||
hos_handle->hos_config.fs2_port = 10086;
|
||||
memcpy(hos_handle->hos_config.ip, "127.0.0.1", strlen("127.0.0.1")+1);
|
||||
hos_handle->hos_config.log_level = 30;
|
||||
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 = 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)
|
||||
{
|
||||
memset(instance, 0, sizeof(hos_instance_s));
|
||||
instance->result = true;
|
||||
instance->error_code = 0;
|
||||
instance->error_message[0] ='\0';
|
||||
instance->hos_url_prefix = "http://127.0.0.1:9098/hos/";
|
||||
}
|
||||
|
||||
TEST(hos_init_instance, normal)
|
||||
{
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
|
||||
hos_instance_s expect_hos_instance;
|
||||
expect_hos_instance.result = true;
|
||||
expect_hos_instance.error_code = 0;
|
||||
expect_hos_instance.error_message[0] ='\0';
|
||||
expect_hos_instance.hos_url_prefix = "http://127.0.0.1:9098/hos/";
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
memset(&expect_hos_handle, 0, sizeof(expect_hos_handle));
|
||||
expect_hos_handle.buckets.push_back(Aws::S3::Model::Bucket().WithName("session_record_hos_bucket"));
|
||||
expect_hos_handle.buckets.push_back(Aws::S3::Model::Bucket().WithName("firewall_hos_bucket"));
|
||||
expect_hos_handle.count = 1;
|
||||
memcpy(expect_hos_handle.hos_config.accesskeyid, "default", strlen("default")+1);
|
||||
memcpy(expect_hos_handle.hos_config.secretkey, "default", strlen("default")+1);
|
||||
expect_hos_handle.hos_config.cache_count = 10;
|
||||
expect_hos_handle.hos_config.cache_size = 102400;
|
||||
expect_hos_handle.hos_config.fs2_fmt = 0;
|
||||
memcpy(expect_hos_handle.hos_config.fs2_ip, "127.0.0.1", strlen("127.0.0.1")+1);
|
||||
memcpy(expect_hos_handle.hos_config.fs2_path, "./log/hos_fs2_log", strlen("./log/hos_fs2_log")+1);
|
||||
expect_hos_handle.hos_config.fs2_port = 10086;
|
||||
memcpy(expect_hos_handle.hos_config.ip, "127.0.0.1", strlen("127.0.0.1")+1);
|
||||
expect_hos_handle.hos_config.log_level = 30;
|
||||
memcpy(expect_hos_handle.hos_config.log_path, "./hoslog", strlen("./hoslog")+1);
|
||||
expect_hos_handle.hos_config.pool_thread_size = 10;
|
||||
expect_hos_handle.hos_config.port = 9098;
|
||||
expect_hos_handle.hos_config.thread_num = 1;
|
||||
expect_hos_handle.hos_config.timeout = 1000;
|
||||
expect_hos_handle.hos_func.fd_thread_status = 0;
|
||||
expect_hos_handle.hos_func.fs2_status = 1;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle, 1);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_shutdown_instance();
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
expect_hos_instance.result = 0;
|
||||
expect_hos_instance.error_code = 0;
|
||||
expect_hos_instance.error_message[0] ='\0';
|
||||
expect_hos_instance.hos_url_prefix = NULL;
|
||||
memset(&expect_hos_instance, 0, sizeof(expect_hos_instance));
|
||||
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);
|
||||
}
|
||||
|
||||
TEST(hos_init_instance, param_error)
|
||||
{
|
||||
hos_instance hos_instance = hos_init_instance(NULL, "hos_default_conf", 1, HOS_BUCKET);
|
||||
|
||||
hos_instance_s expect_hos_instance;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(NULL, "hos_default_conf", 1, HOS_BUCKET);
|
||||
expect_hos_instance.result = false;
|
||||
expect_hos_instance.error_code = HOS_PARAMETER_ERROR;
|
||||
const char *err_msg = "param error:conf_path:(null), module:hos_default_conf, thread_num:1, bucket:firewall_hos_bucket";
|
||||
@@ -71,50 +97,32 @@ TEST(hos_init_instance, param_error)
|
||||
|
||||
TEST(hos_init_instance, no_fs2)
|
||||
{
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_no_fs2_conf", 1, HOS_BUCKET);
|
||||
hos_instance_s expect_hos_instance;
|
||||
expect_hos_instance.result = true;
|
||||
expect_hos_instance.error_code = 0;
|
||||
expect_hos_instance.error_message[0] ='\0';
|
||||
expect_hos_instance.hos_url_prefix = "http://127.0.0.1:9098/hos/";
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
memset(&expect_hos_handle, 0, sizeof(expect_hos_handle));
|
||||
expect_hos_handle.buckets.push_back(Aws::S3::Model::Bucket().WithName("session_record_hos_bucket"));
|
||||
expect_hos_handle.buckets.push_back(Aws::S3::Model::Bucket().WithName("firewall_hos_bucket"));
|
||||
expect_hos_handle.count = 1;
|
||||
memcpy(expect_hos_handle.hos_config.accesskeyid, "default", strlen("default")+1);
|
||||
memcpy(expect_hos_handle.hos_config.secretkey, "default", strlen("default")+1);
|
||||
expect_hos_handle.hos_config.cache_count = 10;
|
||||
expect_hos_handle.hos_config.cache_size = 102400;
|
||||
expect_hos_handle.hos_config.fs2_fmt = 0;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_no_fs2_conf", 1, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle, 1);
|
||||
expect_hos_handle.hos_config.fs2_ip[0] = '\0';
|
||||
expect_hos_handle.hos_config.fs2_path[0] = '\0';
|
||||
//memcpy(expect_hos_handle.hos_config.fs2_ip, "127.0.0.1", strlen("127.0.0.1")+1);
|
||||
memcpy(expect_hos_handle.hos_config.fs2_path, "./log/hos_fs2_log", strlen("./log/hos_fs2_log")+1);
|
||||
//expect_hos_handle.hos_config.fs2_port = 10086;
|
||||
expect_hos_handle.hos_config.fs2_port = 0;
|
||||
memcpy(expect_hos_handle.hos_config.ip, "127.0.0.1", strlen("127.0.0.1")+1);
|
||||
expect_hos_handle.hos_config.log_level = 30;
|
||||
memcpy(expect_hos_handle.hos_config.log_path, "./hoslog", strlen("./hoslog")+1);
|
||||
expect_hos_handle.hos_config.pool_thread_size = 10;
|
||||
expect_hos_handle.hos_config.port = 9098;
|
||||
expect_hos_handle.hos_config.thread_num = 1;
|
||||
expect_hos_handle.hos_config.timeout = 1000;
|
||||
expect_hos_handle.hos_func.fd_thread_status = 0;
|
||||
expect_hos_handle.hos_func.fs2_status = 0;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_shutdown_instance();
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
expect_hos_instance.result = 0;
|
||||
expect_hos_instance.error_code = 0;
|
||||
expect_hos_instance.error_message[0] ='\0';
|
||||
expect_hos_instance.hos_url_prefix = NULL;
|
||||
memset(&expect_hos_instance, 0, sizeof(expect_hos_instance));
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define HOS_CONF "../conf/default.conf"
|
||||
#define HOS_BUCKET "firewall_hos_bucket"
|
||||
|
||||
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"));
|
||||
@@ -23,10 +23,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)
|
||||
@@ -65,8 +75,7 @@ TEST(hos_open_fd, normal)
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, 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, 2);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
size_t fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, BUFF_MODE);
|
||||
@@ -102,6 +111,14 @@ TEST(hos_open_fd, normal)
|
||||
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);
|
||||
@@ -115,8 +132,7 @@ TEST(hos_open_fd, paramer_error)
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, 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, 2);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int fd = hos_open_fd(NULL, "object", NULL, NULL, 0, BUFF_MODE);
|
||||
@@ -132,6 +148,14 @@ TEST(hos_open_fd, 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);
|
||||
@@ -145,8 +169,7 @@ TEST(hos_open_fd, over_threadnums)
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, 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, 2);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int fd = hos_open_fd(HOS_CONF, "object", NULL, NULL, 3, BUFF_MODE);
|
||||
@@ -162,6 +185,14 @@ TEST(hos_open_fd, 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);
|
||||
@@ -177,8 +208,7 @@ TEST(hos_open_fd, fd_not_enough)
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, 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, 2);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
gtest_hos_fd_init(&expect_fd_info);
|
||||
@@ -215,6 +245,14 @@ TEST(hos_open_fd, fd_not_enough)
|
||||
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);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#define HOS_CONF "../conf/default.conf"
|
||||
#define HOS_BUCKET "firewall_hos_bucket"
|
||||
|
||||
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"));
|
||||
@@ -28,10 +28,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)
|
||||
@@ -53,7 +63,7 @@ TEST(hos_shutdown_instance, normal)
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
gtest_hos_handle_init(&expect_hos_handle, 1);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_shutdown_instance();
|
||||
@@ -63,6 +73,14 @@ TEST(hos_shutdown_instance, normal)
|
||||
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);
|
||||
@@ -83,7 +101,7 @@ TEST(hos_shutdown_instance, shutdown_more)
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
gtest_hos_handle_init(&expect_hos_handle, 1);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_shutdown_instance();
|
||||
@@ -93,6 +111,14 @@ TEST(hos_shutdown_instance, shutdown_more)
|
||||
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);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#define HOS_BUCKET "firewall_hos_bucket"
|
||||
#define HOS_BUFF "This is a googletest"
|
||||
|
||||
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"));
|
||||
@@ -24,10 +24,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)
|
||||
@@ -62,16 +72,21 @@ TEST(hos_upload_buff, normal)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, 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, 2);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_upload_buf(HOS_BUCKET, "object", HOS_BUFF, strlen(HOS_BUFF), hos_callback, (void *)"object", 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);
|
||||
|
||||
@@ -82,6 +97,13 @@ TEST(hos_upload_buff, 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);
|
||||
@@ -92,16 +114,21 @@ TEST(hos_upload_buff, bucket_not_exits)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, 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, 2);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_upload_buf("bucket_not_exits", "object", HOS_BUFF, strlen(HOS_BUFF), hos_bucket_not_exits_cb, (void *)"object", 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);
|
||||
|
||||
@@ -112,6 +139,13 @@ TEST(hos_upload_buff, 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);
|
||||
@@ -122,12 +156,13 @@ TEST(hos_upload_buff, param_error)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, 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, 2);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_upload_buf(NULL, "object", HOS_BUFF, strlen(HOS_BUFF), hos_callback, (void *)"object", 0);
|
||||
@@ -142,6 +177,13 @@ TEST(hos_upload_buff, param_error)
|
||||
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);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#define HOS_BUCKET "firewall_hos_bucket"
|
||||
#define HOS_BUFF "Makefile"
|
||||
|
||||
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"));
|
||||
@@ -24,10 +24,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)
|
||||
@@ -62,16 +72,23 @@ TEST(hos_upload_file, normal)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, 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, 2);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_upload_file(HOS_BUCKET, HOS_BUFF, hos_callback, (void *)HOS_BUFF, 0);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
struct stat buffer;
|
||||
stat(HOS_BUFF, &buffer);
|
||||
data_info->rx_bytes[0] += buffer.st_size;
|
||||
data_info->rx_pkts[0] += 1;
|
||||
data_info->tx_bytes[0] += buffer.st_size;
|
||||
data_info->tx_pkts[0] += 1;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
@@ -82,6 +99,13 @@ TEST(hos_upload_file, 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);
|
||||
@@ -92,12 +116,13 @@ TEST(hos_upload_file, param_error)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, 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, 2);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_upload_file(NULL, "object", hos_callback, (void *)"object", 0);
|
||||
@@ -112,6 +137,13 @@ TEST(hos_upload_file, param_error)
|
||||
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);
|
||||
@@ -122,12 +154,13 @@ TEST(hos_upload_file, file_not_exits)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, 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, 2);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_upload_file(HOS_BUCKET, "file_not_exits", hos_callback, (void *)"object", 0);
|
||||
@@ -142,6 +175,13 @@ TEST(hos_upload_file, file_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);
|
||||
@@ -158,16 +198,23 @@ TEST(hos_upload_file, bucket_not_exits)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, 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, 2);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_upload_file(HOS_CONF, HOS_CONF, hos_bucket_not_exits_cb, (void *)HOS_CONF, 0);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
struct stat buffer;
|
||||
stat(HOS_CONF, &buffer);
|
||||
data_info->rx_bytes[0] += buffer.st_size;
|
||||
data_info->rx_pkts[0] += 1;
|
||||
data_info->tx_failed_bytes[0] += buffer.st_size;
|
||||
data_info->tx_failed_pkts[0] += 1;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
@@ -178,6 +225,13 @@ TEST(hos_upload_file, 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);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#define HOS_CONF "../conf/default.conf"
|
||||
#define HOS_BUCKET "firewall_hos_bucket"
|
||||
|
||||
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"));
|
||||
@@ -28,10 +28,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)
|
||||
@@ -52,8 +62,7 @@ TEST(hos_verify_bucket, normal)
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, 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=1;
|
||||
gtest_hos_handle_init(&expect_hos_handle, 1);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
bool result = hos_verify_bucket(HOS_BUCKET);
|
||||
@@ -68,6 +77,14 @@ TEST(hos_verify_bucket, normal)
|
||||
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);
|
||||
@@ -82,8 +99,7 @@ TEST(hos_verify_bucket, not_exits)
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, 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=1;
|
||||
gtest_hos_handle_init(&expect_hos_handle, 1);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
bool result = hos_verify_bucket("hos_not_exits_bucket");
|
||||
@@ -98,6 +114,14 @@ TEST(hos_verify_bucket, not_exits)
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user