TSG-6704 增加mock

This commit is contained in:
彭宣正
2021-05-26 11:10:59 +08:00
parent 4c9a8f89c4
commit 678bb1c6f9
20 changed files with 1949 additions and 642 deletions

View File

@@ -6,9 +6,14 @@ include_directories("/opt/MESA/include")
link_directories("/opt/MESA/lib")
#link_libraries(hos-client-cpp gtest gtest_main pthread)
# coverage
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
add_definitions(-g -W -Wall -std=c++11)
#add_executable(gtest_hos_client gtest_hos_init_instance.cpp gtest_hos_get_instance.cpp)
#add_executable(gtest_hos_client gtest_hos_write.cpp)
#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 ${SRCS})
target_link_libraries(gtest_hos_client hos-client-cpp gtest gtest_main pthread)

77
gtest/CheckHosClient.cpp Normal file
View File

@@ -0,0 +1,77 @@
#include "CheckHosClient.h"
void CheckStructHosConfigT(hos_config_t *actual, hos_config_t *expect)
{
EXPECT_STREQ(actual->accesskeyid, expect->accesskeyid);
EXPECT_STREQ(actual->secretkey, expect->secretkey);
EXPECT_STREQ(actual->log_path, expect->log_path);
EXPECT_EQ(actual->log_level, expect->log_level);
EXPECT_EQ(actual->pool_thread_size, expect->pool_thread_size);
EXPECT_EQ(actual->cache_count, expect->cache_count);
EXPECT_EQ(actual->cache_size, expect->cache_size);
EXPECT_EQ(actual->fs2_fmt, expect->fs2_fmt);
EXPECT_STREQ(actual->fs2_ip, expect->fs2_ip);
EXPECT_STREQ(actual->fs2_path, expect->fs2_path);
EXPECT_EQ(actual->fs2_port, expect->fs2_port);
EXPECT_STREQ(actual->ip, expect->ip);
EXPECT_EQ(actual->port, expect->port);
EXPECT_EQ(actual->thread_num, expect->thread_num);
EXPECT_EQ(actual->timeout, expect->timeout);
}
void CheckStructHosFunc(hos_func_thread_t *actual, hos_func_thread_t *expect)
{
//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);
EXPECT_EQ(actual->fs2_status, expect->fs2_status);
//EXPECT_EQ(actual->fs2_thread, expect->fs2_thread);
}
void CheckStructGHosHandle(hos_client_handle_t *actual, hos_client_handle_t *expect)
{
//EXPECT_STREQ(actual->buckets.c_str(), expect->buckets.c_str());
int bucketNum = actual->buckets.size() > expect->buckets.size() ? expect->buckets.size() : actual->buckets.size();
for (int i = 0; i < bucketNum; i++)
{
EXPECT_STREQ(actual->buckets.at(i).GetName().c_str(), expect->buckets.at(i).GetName().c_str());
}
EXPECT_EQ(actual->count, expect->count);
//EXPECT_TRUE(actual->log != NULL);
//EXPECT_TRUE(actual->S3Client != NULL);
CheckStructHosConfigT(&actual->hos_config, &expect->hos_config);
CheckStructHosFunc(&actual->hos_func, &expect->hos_func);
}
void CheckStructGHosFdContext(hos_fd_context_t *actual, hos_fd_context_t *expect)
{
if (actual == NULL || expect == NULL)
{
EXPECT_TRUE(actual == expect);
}
else
{
EXPECT_STREQ(actual->bucket, expect->bucket);
//EXPECT_TRUE(actual->cache == NULL);
EXPECT_EQ(actual->cache_count, expect->cache_count);
EXPECT_EQ(actual->cache_rest, expect->cache_rest);
EXPECT_EQ(actual->callback, expect->callback);
EXPECT_EQ(actual->fd, expect->fd);
EXPECT_EQ(actual->fd_status, expect->fd_status);
EXPECT_EQ(actual->mode, expect->mode);
EXPECT_STREQ(actual->object, expect->object);
EXPECT_EQ(actual->overtime, expect->overtime);
EXPECT_EQ(actual->position, expect->position);
EXPECT_EQ(actual->recive_cnt, expect->recive_cnt);
EXPECT_EQ(actual->timeout, expect->timeout);
EXPECT_EQ(actual->userdata, expect->userdata);
}
}
void CheckHosInstance(hos_instance actual, hos_instance expect)
{
EXPECT_EQ(actual->result, expect->result);
EXPECT_EQ(actual->error_code, expect->error_code);
EXPECT_STREQ(actual->error_message, expect->error_message);
EXPECT_STREQ(actual->hos_url_prefix, expect->hos_url_prefix);
}

14
gtest/CheckHosClient.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef __CHECKHOS_CLIENT_H__
#define __CHECKHOS_CLIENT_H__
#include <aws/external/gtest.h>
#include "../src/hos_client.h"
#include "../src/hos_common.h"
void CheckStructHosConfigT(hos_config_t *actual, hos_config_t *expect);
void CheckStructHosFunc(hos_func_thread_t *actual, hos_func_thread_t *expect);
void CheckStructGHosHandle(hos_client_handle_t *actual, hos_client_handle_t *expect);
void CheckStructGHosFdContext(hos_fd_context_t *actual, hos_fd_context_t *expect);
void CheckHosInstance(hos_instance actual, hos_instance expect);
#endif

View File

@@ -0,0 +1,67 @@
#ifndef __GTEST_HOS_COMMON_H__
#define __GTEST_HOS_COMMON_H__
#include<stdint.h>
#include <netinet/in.h>
#ifndef MAX_HOS_STRING_LEN
#define MAX_HOS_STRING_LEN 1024
#endif
typedef struct data_info_s
{
size_t *tx_pkts;
size_t *tx_bytes;
size_t *rx_pkts;
size_t *rx_bytes;
size_t *tx_failed_pkts;
size_t *tx_failed_bytes;
size_t *cache;
}data_info_t;
enum
{
FS2_DATA_FLOW_STATE = 0,
FS2_POOL_THREAD_STATE,
FS2_RECORD_EVENTS,
};
typedef struct hos_config_s
{
char ip[INET6_ADDRSTRLEN];
char fs2_ip[INET6_ADDRSTRLEN];
char accesskeyid[MAX_HOS_STRING_LEN];
char secretkey[MAX_HOS_STRING_LEN];
char log_path[MAX_HOS_STRING_LEN];
char fs2_path[MAX_HOS_STRING_LEN];
uint32_t port;
uint32_t fs2_port;
uint32_t fs2_fmt;
uint32_t log_level;
uint32_t pool_thread_size;
uint32_t thread_num;
uint32_t cache_size;
uint32_t cache_count;
uint32_t timeout;
}hos_config_t;
typedef struct hos_client_handle_s
{
void *S3Client;
void *buckets;
void *executor;
size_t count; /* 记录了有多少个对象在使用hos */
hos_config_t hos_config;
}hos_client_handle_t;
typedef unsigned long size_t;
typedef struct hos_client_handle_s hos_client_handle_t;
typedef struct hos_fd_context_s hos_fd_context_t;
extern struct hos_instance_s g_hos_instance;
extern hos_client_handle_t g_hos_handle;//一个进程只允许有一个g_hos_handle
extern hos_fd_context_t **g_fd_context;
extern size_t (*g_fd_info)[65536]; //fd 实际从3开始 fd[thread_id][0]记录register的fdfd[thread_id][1]记录inject的fd
#endif

View File

@@ -1,5 +1,5 @@
[hos_default_conf]
hos_serverip=192.168.44.12
hos_serverip=127.0.0.1
hos_serverport=9098
hos_accesskeyid="default"
hos_secretkey="default"
@@ -9,8 +9,6 @@ hos_log_level=30
#default
hos_poolsize=10
#default
hos_thread_sum=32
#default
hos_cache_size=102400
#default
hos_cache_count=10
@@ -25,18 +23,16 @@ hos_fs2_format=0
#defaul
[hos_sync_conf]
hos_serverip=192.168.44.12
hos_serverip=127.0.0.1
hos_serverport=9098
hos_accesskeyid="default"
hos_secretkey="default"
hos_log_path="./log/hoslog"
hos_log_path="./hoslog"
#default
hos_log_level=30
#default
hos_poolsize=0
#default
hos_thread_sum=32
#default
hos_cache_size=102400
#default
hos_cache_count=10
@@ -51,18 +47,16 @@ hos_fs2_format=0
#default
[hos_no_fs2_conf]
hos_serverip=192.168.44.12
hos_serverip=127.0.0.1
hos_serverport=9098
hos_accesskeyid="default"
hos_secretkey="default"
hos_log_path="./log/hoslog"
hos_log_path="./hoslog"
#default
hos_log_level=30
#default
hos_poolsize=10
#default
hos_thread_sum=32
#default
hos_cache_size=102400
#default
hos_cache_count=10
@@ -75,14 +69,12 @@ hos_fs2_format=0
#default
[hos_default_conf]
hos_log_path="./log/hoslog"
hos_log_path="./hoslog"
#default
hos_log_level=30
#default
hos_poolsize=10
#default
hos_thread_sum=32
#default
hos_cache_size=102400
#default
hos_cache_count=10
@@ -101,14 +93,12 @@ hos_serverip=192.168.40.146
hos_serverport=9098
hos_accesskeyid="default"
hos_secretkey="default"
hos_log_path="./log/hoslog"
hos_log_path="./hoslog"
#default
hos_log_level=30
#default
hos_poolsize=0
#default
hos_thread_sum=32
#default
hos_cache_size=102400
#default
hos_cache_count=10

View File

@@ -1,55 +1,132 @@
#include <aws/external/gtest.h>
#include "hos_client.h"
#include <aws/s3/model/Bucket.h>
#include "CheckHosClient.h"
#define HOS_CONF "../conf/default.conf"
#define HOS_BUCKET "hos_test_bucket"
#define HOS_BUCKET "firewall_hos_bucket"
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
{
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 = 1;
hos_handle->hos_config.timeout = 1000;
hos_handle->hos_func.fd_thread_status = 0;
hos_handle->hos_func.fs2_status = 1;
}
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/";
}
static void gtest_hos_fd_init(hos_fd_context_t *fd_info)
{
memset(fd_info, 0, sizeof(hos_fd_context_t));
fd_info->bucket = (char *)HOS_BUCKET;
fd_info->object = (char *)"object";
fd_info->cache_count = 10;
fd_info->cache_rest = g_hos_handle.hos_config.cache_size;
fd_info->callback = NULL;
fd_info->fd = 3;
fd_info->fd_status = HOS_FD_REGISTER;
fd_info->mode = BUFF_MODE;
fd_info->overtime = 0;
fd_info->position = 0;
fd_info->recive_cnt = 0;
fd_info->timeout = g_hos_handle.hos_config.timeout;
fd_info->userdata = NULL;
}
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;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, BUFF_MODE);
EXPECT_EQ(fd, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info);
CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info);
int ret = hos_close_fd(fd, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
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;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int fd = hos_open_fd(NULL, "object", NULL, NULL, 0, BUFF_MODE);
EXPECT_EQ(fd, HOS_PARAMETER_ERROR);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
CheckStructGHosFdContext(g_fd_context[0], NULL);
int ret = hos_close_fd(fd, 0);
EXPECT_EQ(ret, HOS_PARAMETER_ERROR);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
TEST(hos_close_fd, not_init_instance)
@@ -60,19 +137,30 @@ TEST(hos_close_fd, not_init_instance)
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;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_close_fd(7, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}

View File

@@ -1,32 +1,77 @@
#include <aws/external/gtest.h>
#include "hos_client.h"
#include <aws/s3/model/Bucket.h>
#include "CheckHosClient.h"
#define HOS_CONF "../conf/default.conf"
#define HOS_BUCKET "hos_test_bucket"
#define HOS_BUCKET "firewall_hos_bucket"
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
{
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 = 1;
hos_handle->hos_config.timeout = 1000;
hos_handle->hos_func.fd_thread_status = 0;
hos_handle->hos_func.fs2_status = 1;
}
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_get_instance, normal)
{
hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle;
hos_instance hos_instance = hos_get_instance();
EXPECT_EQ(hos_instance->result, false);
memset(&expect_hos_instance, 0, sizeof(hos_instance_s));
expect_hos_instance.result = false;
CheckHosInstance(hos_instance, &expect_hos_instance);
hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
gtest_hos_instance_init(&expect_hos_instance);
CheckHosInstance(hos_instance, &expect_hos_instance);
gtest_hos_handle_init(&expect_hos_handle);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
hos_instance = hos_get_instance();
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
expect_hos_handle.count++;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
hos_shutdown_instance();
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
hos_shutdown_instance();
EXPECT_EQ(hos_instance->result, false);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
CheckHosInstance(hos_instance, &expect_hos_instance);
expect_hos_handle.count--;
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.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
}

View File

@@ -3,72 +3,159 @@
> Author: pxz
> Created Time: Tue 29 Sep 2020 10:20:49 AM CST
************************************************************************/
#include <aws/external/gtest.h>
#include "hos_client.h"
#include <aws/s3/model/Bucket.h>
#include "CheckHosClient.h"
#define HOS_CONF "../conf/default.conf"
#define HOS_BUCKET "hos_test_bucket"
#define HOS_BUCKET "firewall_hos_bucket"
TEST(hos_init_instance, normal)
{
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
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;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
EXPECT_EQ(hos_instance->result, false);
EXPECT_EQ(hos_instance->error_code, HOS_PARAMETER_ERROR);
EXPECT_STREQ(hos_instance->error_message, "param error:conf_path:(null), module:hos_default_conf, thread_num:1, bucket:hos_test_bucket");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
hos_instance_s expect_hos_instance;
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";
memcpy(expect_hos_instance.error_message, err_msg, strlen(err_msg)+1);
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
}
TEST(hos_init_instance, no_fs2)
{
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_no_fs2_conf", 1, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
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_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
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;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
}
TEST(hos_init_instance, bucket_not_exits)
{
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, "hos_bucket_not_exits");
EXPECT_EQ(hos_instance->result, false);
EXPECT_EQ(hos_instance->error_code, HOS_BUCKET_NOT_EXIST);
EXPECT_STREQ(hos_instance->error_message, "bucket:hos_bucket_not_exits not exits.");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
hos_instance_s expect_hos_instance;
expect_hos_instance.result = false;
expect_hos_instance.error_code = HOS_BUCKET_NOT_EXIST;
const char *err_msg = "bucket:hos_bucket_not_exits not exits.";
memcpy(expect_hos_instance.error_message, err_msg, strlen(err_msg)+1);
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
hos_client_handle_t expect_hos_handle;
memset(&expect_hos_handle, 0, sizeof(expect_hos_handle));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
}
TEST(hos_init_instance, conf_error)
{
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_error_conf", 1, "hos_bucket_not_exits");
EXPECT_EQ(hos_instance->result, false);
EXPECT_EQ(hos_instance->error_code, HOS_CONF_ERROR);
EXPECT_STREQ(hos_instance->error_message, "hos param error:hos ip:, hos port:0, accesskeyid:, secretkey:");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
hos_instance_s expect_hos_instance;
expect_hos_instance.result = false;
expect_hos_instance.error_code = HOS_CONF_ERROR;
const char *err_msg = "hos param error:hos ip:, hos port:0, accesskeyid:, secretkey:";
memcpy(expect_hos_instance.error_message, err_msg, strlen(err_msg)+1);
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
}
TEST(hos_init_instance, server_conn_failed)
{
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_error_server_conf", 1, "hos_bucket_not_exits");
EXPECT_EQ(hos_instance->result, false);
EXPECT_EQ(hos_instance->error_code, NETWORK_CONNECTION);
EXPECT_STREQ(hos_instance->error_message, "curlCode: 7, Couldn't connect to server");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
hos_instance_s expect_hos_instance;
expect_hos_instance.result = false;
expect_hos_instance.error_code = NETWORK_CONNECTION;
const char *err_msg = "curlCode: 7, Couldn't connect to server";
memcpy(expect_hos_instance.error_message, err_msg, strlen(err_msg)+1);
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
}

View File

@@ -1,107 +1,223 @@
#include <aws/external/gtest.h>
#include "hos_client.h"
#include <aws/s3/model/Bucket.h>
#include "CheckHosClient.h"
#define HOS_CONF "../conf/default.conf"
#define HOS_BUCKET "hos_test_bucket"
#define HOS_BUCKET "firewall_hos_bucket"
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
{
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 = 1;
hos_handle->hos_config.timeout = 1000;
hos_handle->hos_func.fd_thread_status = 0;
hos_handle->hos_func.fs2_status = 1;
}
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/";
}
static void gtest_hos_fd_init(hos_fd_context_t *fd_info)
{
memset(fd_info, 0, sizeof(hos_fd_context_t));
fd_info->bucket = (char *)HOS_BUCKET;
fd_info->object = (char *)"object";
fd_info->cache_count = 10;
fd_info->cache_rest = g_hos_handle.hos_config.cache_size;
fd_info->callback = NULL;
fd_info->fd = 3;
fd_info->fd_status = HOS_FD_REGISTER;
fd_info->mode = BUFF_MODE;
fd_info->overtime = 0;
fd_info->position = 0;
fd_info->recive_cnt = 0;
fd_info->timeout = g_hos_handle.hos_config.timeout;
fd_info->userdata = NULL;
}
TEST(hos_open_fd, normal)
{
hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info[2];
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, BUFF_MODE);
EXPECT_EQ(fd, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[0]);
CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
size_t fd1 = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 1, BUFF_MODE);
EXPECT_EQ(fd1, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[1]);
CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
int ret = hos_close_fd(fd, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
//CheckStructGHosFdContext(g_fd_context[0], NULL);
ret = hos_close_fd(fd1, 1);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
//CheckStructGHosFdContext(g_fd_context[1], NULL);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
TEST(hos_open_fd, paramer_error)
{
hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int fd = hos_open_fd(NULL, "object", NULL, NULL, 0, BUFF_MODE);
EXPECT_EQ(fd, HOS_PARAMETER_ERROR);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
CheckStructGHosFdContext(g_fd_context[0], NULL);
int ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
TEST(hos_open_fd, over_threadnums)
{
hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int fd = hos_open_fd(HOS_CONF, "object", NULL, NULL, 3, BUFF_MODE);
EXPECT_EQ(fd, HOS_PARAMETER_ERROR);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
CheckStructGHosFdContext(g_fd_context[2], NULL);
int ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
TEST(hos_open_fd, fd_not_enough)
{
int i = 0, fd = 0;
hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info);
hos_fd_context_t * prev = NULL;
hos_fd_context_t * current = NULL;
for (i = 0; i < 65533; i++)
{
fd = hos_open_fd(HOS_CONF, "object", NULL, NULL, 0, BUFF_MODE);
fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, BUFF_MODE);
EXPECT_EQ(fd, i+3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
expect_fd_info.fd = i+3;
if (i == 0)
{
current = g_fd_context[0];
}
else
{
current = (hos_fd_context_t *)prev->hh.next;
}
CheckStructGHosFdContext(current, &expect_fd_info);
prev = current;
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
}
fd = hos_open_fd(HOS_CONF, "object", NULL, NULL, 0, BUFF_MODE);
EXPECT_EQ(fd, HOS_FD_NOT_ENOUGH);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
EXPECT_EQ(prev->hh.next, (void *)NULL);
int ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
TEST(hos_open_fd, not_init_instance)

View File

@@ -3,24 +3,69 @@
> Author: pxz
> Created Time: Tue 29 Sep 2020 10:20:49 AM CST
************************************************************************/
#include <aws/external/gtest.h>
#include "hos_client.h"
#include <aws/s3/model/Bucket.h>
#include "CheckHosClient.h"
#define HOS_CONF "../conf/default.conf"
#define HOS_BUCKET "hos_test_bucket"
#define HOS_BUCKET "firewall_hos_bucket"
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
{
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 = 1;
hos_handle->hos_config.timeout = 1000;
hos_handle->hos_func.fd_thread_status = 0;
hos_handle->hos_func.fs2_status = 1;
}
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_shutdown_instance, normal)
{
hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
gtest_hos_instance_init(&expect_hos_instance);
CheckHosInstance(hos_instance, &expect_hos_instance);
gtest_hos_handle_init(&expect_hos_handle);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
TEST(hos_shutdown_instance, no_init)
@@ -31,19 +76,30 @@ TEST(hos_shutdown_instance, no_init)
TEST(hos_shutdown_instance, shutdown_more)
{
hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
gtest_hos_instance_init(&expect_hos_instance);
CheckHosInstance(hos_instance, &expect_hos_instance);
gtest_hos_handle_init(&expect_hos_handle);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
}

View File

@@ -1,10 +1,44 @@
#include <aws/external/gtest.h>
#include "hos_client.h"
#include <aws/s3/model/Bucket.h>
#include "CheckHosClient.h"
#define HOS_CONF "../conf/default.conf"
#define HOS_BUCKET "hos_test_bucket"
#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)
{
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 = 1;
hos_handle->hos_config.timeout = 1000;
hos_handle->hos_func.fd_thread_status = 0;
hos_handle->hos_func.fs2_status = 1;
}
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/";
}
static void hos_callback(bool result, const char *bucket, const char *object, const char *error, void *userdata)
{
SUCCEED();
@@ -25,59 +59,92 @@ static void hos_bucket_not_exits_cb(bool result, const char *bucket, const char
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;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
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);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
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;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
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);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
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;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_upload_buf(NULL, "object", HOS_BUFF, strlen(HOS_BUFF), hos_callback, (void *)"object", 0);
EXPECT_EQ(ret, HOS_PARAMETER_ERROR);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
TEST(hos_upload_buff, not_init_instance)

View File

@@ -1,10 +1,44 @@
#include <aws/external/gtest.h>
#include "hos_client.h"
#include <aws/s3/model/Bucket.h>
#include "CheckHosClient.h"
#define HOS_CONF "../conf/default.conf"
#define HOS_BUCKET "hos_test_bucket"
#define HOS_BUCKET "firewall_hos_bucket"
#define HOS_BUFF "Makefile"
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
{
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 = 1;
hos_handle->hos_config.timeout = 1000;
hos_handle->hos_func.fd_thread_status = 0;
hos_handle->hos_func.fs2_status = 1;
}
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/";
}
static void hos_callback(bool result, const char *bucket, const char *object, const char *error, void *userdata)
{
SUCCEED();
@@ -18,66 +52,99 @@ static void hos_bucket_not_exits_cb(bool result, const char *bucket, const char
{
SUCCEED();
EXPECT_EQ(result, false);
EXPECT_STREQ(bucket, HOS_BUCKET);
EXPECT_STREQ(bucket, HOS_CONF);
EXPECT_STREQ(object, (char *)userdata);
EXPECT_STREQ(error, "The specified bucket does not exist.");
}
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;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
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);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
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;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_upload_file(NULL, "object", hos_callback, (void *)"object", 0);
EXPECT_EQ(ret, HOS_PARAMETER_ERROR);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
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;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_upload_file(HOS_BUCKET, "file_not_exits", hos_callback, (void *)"object", 0);
EXPECT_EQ(ret, HOS_FILE_NOT_EXIST);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
TEST(hos_upload_file, not_init_instance)
@@ -88,19 +155,30 @@ TEST(hos_upload_file, not_init_instance)
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;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
int ret = hos_upload_file(HOS_BUCKET, HOS_CONF, hos_bucket_not_exits_cb, (void *)HOS_CONF, 0);
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;
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);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}

View File

@@ -3,50 +3,104 @@
> Author: pxz
> Created Time: Tue 29 Sep 2020 10:32:14 AM CST
************************************************************************/
#include <aws/external/gtest.h>
#include "hos_client.h"
#include <aws/s3/model/Bucket.h>
#include "CheckHosClient.h"
#define HOS_CONF "../conf/default.conf"
#define HOS_BUCKET "hos_test_bucket"
#define HOS_BUCKET "firewall_hos_bucket"
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
{
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 = 1;
hos_handle->hos_config.timeout = 1000;
hos_handle->hos_func.fd_thread_status = 0;
hos_handle->hos_func.fs2_status = 1;
}
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_verify_bucket, normal)
{
hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
bool result = hos_verify_bucket(HOS_BUCKET);
EXPECT_EQ(result, true);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
TEST(hos_verify_bucket, not_exits)
{
hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
bool result = hos_verify_bucket("hos_not_exits_bucket");
EXPECT_EQ(result, false);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
TEST(hos_verify_bucket, no_instance)

View File

@@ -1,11 +1,63 @@
#include <aws/external/gtest.h>
#include "hos_client.h"
#include <aws/s3/model/Bucket.h>
#include "CheckHosClient.h"
#define HOS_CONF "../conf/default.conf"
#define HOS_BUCKET "hos_test_bucket"
#define HOS_BUCKET "firewall_hos_bucket"
#define HOS_BUFF "This a googleTest"
#define HOS_FILE "../conf/default.conf"
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
{
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 = 1;
hos_handle->hos_config.timeout = 1000;
hos_handle->hos_func.fd_thread_status = 0;
hos_handle->hos_func.fs2_status = 1;
}
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/";
}
static void gtest_hos_fd_init(hos_fd_context_t *fd_info)
{
memset(fd_info, 0, sizeof(hos_fd_context_t));
fd_info->bucket = (char *)HOS_BUCKET;
fd_info->object = (char *)"object";
fd_info->cache_count = 10;
fd_info->cache_rest = g_hos_handle.hos_config.cache_size;
fd_info->callback = NULL;
fd_info->fd = 3;
fd_info->fd_status = HOS_FD_REGISTER;
fd_info->mode = BUFF_MODE;
fd_info->overtime = 0;
fd_info->position = 0;
fd_info->recive_cnt = 0;
fd_info->timeout = g_hos_handle.hos_config.timeout;
fd_info->userdata = NULL;
}
static void hos_callback(bool result, const char *bucket, const char *object, const char *error, void *userdata)
{
SUCCEED();
@@ -14,6 +66,7 @@ static void hos_callback(bool result, const char *bucket, const char *object, co
EXPECT_STREQ(object, (char *)userdata);
EXPECT_STREQ(error, NULL);
}
static void hos_write_buff_cb(bool result, const char *bucket, const char *object, const char *error, void *userdata)
{
SUCCEED();
@@ -22,6 +75,7 @@ static void hos_write_buff_cb(bool result, const char *bucket, const char *objec
EXPECT_STREQ(object, (char *)userdata);
EXPECT_STREQ(error, NULL);
}
static void hos_write_append_cb(bool result, const char *bucket, const char *object, const char *error, void *userdata)
{
SUCCEED();
@@ -30,6 +84,7 @@ static void hos_write_append_cb(bool result, const char *bucket, const char *obj
EXPECT_STREQ(object, (char *)userdata);
EXPECT_STREQ(error, NULL);
}
static void hos_write_file_cb(bool result, const char *bucket, const char *object, const char *error, void *userdata)
{
SUCCEED();
@@ -38,6 +93,7 @@ static void hos_write_file_cb(bool result, const char *bucket, const char *objec
EXPECT_STREQ(object, (char *)userdata);
EXPECT_STREQ(error, NULL);
}
static void hos_bucket_not_exits_cb(bool result, const char *bucket, const char *object, const char *error, void *userdata)
{
SUCCEED();
@@ -49,369 +105,562 @@ static void hos_bucket_not_exits_cb(bool result, const char *bucket, const char
TEST(hos_write, normal)
{
hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info[3];
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 3, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
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);
EXPECT_EQ(fd, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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].callback = (void *)hos_write_buff_cb;
expect_fd_info[0].object = (char *)"object_buff";
expect_fd_info[0].userdata = (void *)"object_buff";
CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF), 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
expect_fd_info[0].fd_status = 2;
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", hos_write_append_cb, (void *)"object_append", 1, BUFF_MODE | APPEND_MODE);
EXPECT_EQ(fd1, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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].callback = (void *)hos_write_append_cb;
expect_fd_info[1].object = (char *)"object_append";
expect_fd_info[1].userdata = (void *)"object_append";
expect_fd_info[1].mode = BUFF_MODE | APPEND_MODE;
CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 0);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 0);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
expect_fd_info[1].cache_count--;
CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
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);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
expect_fd_info[1].cache_count--;
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", hos_write_file_cb, (void *)"object_file", 2, FILE_MODE);
EXPECT_EQ(fd2, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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].callback = (void *)hos_write_file_cb;
expect_fd_info[2].object = (char *)"object_file";
expect_fd_info[2].userdata = (void *)"object_file";
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);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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);
ret = hos_close_fd(fd, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_close_fd(fd1, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_close_fd(fd2, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
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];
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 3, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
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);
EXPECT_EQ(fd, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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].callback = (void *)hos_bucket_not_exits_cb;
expect_fd_info[0].userdata = (void *)"object_buff";
expect_fd_info[0].bucket = (char *)"bucket_not_exits";
expect_fd_info[0].object = (char *)"object_buff";
CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF), 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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);
EXPECT_EQ(fd1, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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].callback = (void *) hos_bucket_not_exits_cb;
expect_fd_info[1].userdata = (void *)"object_append";
expect_fd_info[1].bucket = (char *)"bucket_not_exits";
expect_fd_info[1].object = (char *)"object_append";
expect_fd_info[1].mode = BUFF_MODE | APPEND_MODE;
CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 0);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 0);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
expect_fd_info[1].cache_count--;
CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
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);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
expect_fd_info[1].cache_count--;
CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
EXPECT_TRUE(g_fd_context[1][0].cache != NULL);
size_t fd2 = hos_open_fd("bucket_not_exits", "object_file", hos_bucket_not_exits_cb, (void *)"object_file", 2, FILE_MODE);
EXPECT_EQ(fd2, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
ret = hos_write(fd2, HOS_FILE, strlen(HOS_CONF), 0);
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].callback = (void *) hos_bucket_not_exits_cb;
expect_fd_info[2].userdata = (void *)"object_file";
expect_fd_info[2].bucket = (char *)"bucket_not_exits";
expect_fd_info[2].object = (char *)"object_file";
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), 2);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_close_fd(fd1, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_close_fd(fd2, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
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];
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_sync_conf", 3, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
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);
EXPECT_EQ(fd, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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";
CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF), 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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);
EXPECT_EQ(fd1, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 0);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 0);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[1].cache_count--;
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
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);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[1].cache_count--;
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
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_buff", NULL, NULL, 2, FILE_MODE);
EXPECT_EQ(fd2, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
ret = hos_write(fd2, HOS_FILE, strlen(HOS_BUFF), 0);
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_buff";
expect_fd_info[2].mode = FILE_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);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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[2][0].cache == NULL);
ret = hos_close_fd(fd, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_close_fd(fd1, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_close_fd(fd2, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
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];
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_sync_conf", 3, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
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);
EXPECT_EQ(fd, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
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);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
expect_fd_info[0].fd_status = 2;
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);
EXPECT_EQ(fd1, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_CONF), 0);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_CONF), 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[1].cache_count--;
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
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_buff", NULL, NULL, 2, FILE_MODE);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[1].cache_count--;
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
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);
EXPECT_EQ(fd2, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
ret = hos_write(fd2, HOS_FILE, strlen(HOS_CONF), 0);
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;
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(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_close_fd(fd1, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_close_fd(fd2, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
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;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
int fd = hos_open_fd(NULL, "object", hos_callback, NULL, 0, BUFF_MODE);
EXPECT_EQ(fd, HOS_PARAMETER_ERROR);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int fd = hos_open_fd(HOS_BUCKET, "object_buff", hos_callback, 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);
expect_fd_info.object = (char *)"object_buff";
expect_fd_info.callback = (void *)hos_callback;
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);
EXPECT_EQ(ret, HOS_PARAMETER_ERROR);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
//CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
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;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_write(3, HOS_BUFF, strlen(HOS_CONF), 0);
EXPECT_EQ(ret, HOS_HASH_NOT_FIND);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
CheckStructGHosFdContext(g_fd_context[0], NULL);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
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;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
int fd = hos_open_fd(HOS_CONF, "object", NULL, NULL, 0, FILE_MODE);
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int fd = hos_open_fd(HOS_CONF, "object_file", NULL, NULL, 0, FILE_MODE);
EXPECT_EQ(fd, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
int ret = hos_write(3, "not_exit_file", strlen(HOS_CONF), 0);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info);
expect_fd_info.bucket = (char *)HOS_CONF;
expect_fd_info.object = (char *)"object_file";
expect_fd_info.mode = FILE_MODE;
CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info);
int ret = hos_write(fd, "not_exit_file", strlen(HOS_CONF), 0);
EXPECT_EQ(ret, HOS_FILE_NOT_EXIST);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
//CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
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;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
int fd = hos_open_fd(HOS_CONF, "object", NULL, NULL, 0, BUFF_MODE);
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;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, BUFF_MODE);
EXPECT_EQ(fd, 3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info);
expect_fd_info.object = (char *)"object";
CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info);
int ret = hos_write(3, HOS_BUFF, strlen(HOS_CONF), 6);
EXPECT_EQ(ret, HOS_PARAMETER_ERROR);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
//CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info);
ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
}
TEST(hos_write, not_init_instance)
@@ -429,6 +678,9 @@ static void *hos_function(void *ptr)
int fd[HOS_FD_NUMS_LOCAL] = {0};
char object[HOS_FD_NUMS_LOCAL][1024];
int ret = 0;
hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info[32][20];
{
hos_instance = hos_get_instance();
@@ -437,44 +689,57 @@ static void *hos_function(void *ptr)
hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 32, HOS_BUCKET);
}
}
EXPECT_EQ(hos_instance->result, true);
EXPECT_EQ(hos_instance->error_code, HOS_CLIENT_OK);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
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;
expect_hos_handle.count = thread_id + 1;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
for (i = 0; i < 20; i++)
{
snprintf(object[i], 1024, "object_%lu_%d", thread_id, i);
fd[i] = hos_open_fd(HOS_CONF, object[i], hos_callback, object[i], 0, BUFF_MODE | APPEND_MODE);
EXPECT_EQ(fd[i], i+3);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
fd[i] = hos_open_fd(HOS_BUCKET, object[i], hos_callback, object[i], 0, BUFF_MODE | APPEND_MODE);
EXPECT_EQ(fd[i], i + 3);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[thread_id][i]);
expect_fd_info[thread_id][i].object = object[i];
expect_fd_info[thread_id][i].mode = BUFF_MODE | APPEND_MODE;
expect_fd_info[thread_id][i].callback = (void *)hos_callback;
CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[thread_id][i]);
}
for (i = 0; i < 20; i++)
{
ret = hos_write(fd[i], HOS_BUFF, strlen(HOS_BUFF), i);
EXPECT_EQ(ret, HOS_CLIENT_OK);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
expect_fd_info[thread_id][i].cache_rest -= strlen(HOS_BUFF);
expect_fd_info[thread_id][i].cache_count--;
CheckStructGHosFdContext(&g_fd_context[thread_id][i], &expect_fd_info[thread_id][i]);
EXPECT_TRUE(g_fd_context[1][0].cache != NULL);
}
for (i = 0; i < 20; i++)
{
ret = hos_close_fd(fd[i], i);
EXPECT_EQ(ret, 0);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, "http://192.168.44.12:9098/hos/");
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
}
ret = hos_shutdown_instance();
EXPECT_EQ(ret, 0);
EXPECT_EQ(hos_instance->error_code, 0);
EXPECT_STREQ(hos_instance->error_message, "");
EXPECT_STREQ(hos_instance->hos_url_prefix, NULL);
expect_hos_instance.result = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
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);
pthread_exit(NULL);
#undef HOS_FD_NUMS_LOCAL