✨ feat(src): 重构
This commit is contained in:
@@ -1,16 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
project(hos_write_demo)
|
||||
#project(hos_upload_complete)
|
||||
|
||||
SET(CMAKE_BUILD_TYPE Debug)
|
||||
#link_directories(/usr/local/lib64/)
|
||||
link_directories(/opt/MESA/lib/)
|
||||
#link_libraries(hos-client-cpp)
|
||||
include_directories(/opt/MESA/include)
|
||||
|
||||
add_executable(hos_write_demo hos_write_demo.cpp)
|
||||
#add_executable(hos_upload_complete hos_upload_complete.cpp)
|
||||
target_link_libraries(hos_write_demo hos-client-cpp)
|
||||
#target_link_libraries(hos_upload_complete hos-client-cpp)
|
||||
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
/*************************************************************************
|
||||
> File Name: single_thread.cpp
|
||||
> Author: pxz
|
||||
> Created Time: Fri 11 Sep 2020 09:52:05 AM CST
|
||||
************************************************************************/
|
||||
extern "C"
|
||||
{
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<unistd.h>
|
||||
#include<string.h>
|
||||
#include<time.h>
|
||||
}
|
||||
#include"hos_client.h"
|
||||
|
||||
//#define test_times 10000
|
||||
|
||||
#define debuginfo (void)
|
||||
|
||||
typedef struct userdata_s
|
||||
{
|
||||
struct timespec *finished;
|
||||
}userdata_t;
|
||||
|
||||
static size_t calc_time(struct timespec start, struct timespec end)
|
||||
{
|
||||
return (end.tv_sec * 1000 * 1000 * 1000 + end.tv_nsec -
|
||||
(start.tv_sec * 1000 * 1000 * 1000 + start.tv_nsec));
|
||||
}
|
||||
|
||||
int file_to_buffer(const char *file, char *buffer, size_t *len)
|
||||
{
|
||||
FILE *fp = fopen(file, "r");
|
||||
int num = 0;
|
||||
*len = 0;
|
||||
if (fp == NULL)
|
||||
{
|
||||
debuginfo("fopen file failed:%s\n", file);
|
||||
return -1;
|
||||
}
|
||||
do{
|
||||
num = fread(&buffer[*len], 1, 4096, fp);
|
||||
if (num < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
*len += num;
|
||||
}while(num == 4096);
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void callback(bool result, const char *error, const char *bucket, const char *object, void *userdata)
|
||||
{
|
||||
userdata_t *data = (userdata_t *)userdata;
|
||||
clock_gettime(CLOCK_MONOTONIC, data->finished);
|
||||
return ;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 4)
|
||||
{
|
||||
debuginfo("usege: singThread [bucket name] [object name]\n");
|
||||
return -1;
|
||||
}
|
||||
struct timespec start, end, finished;
|
||||
size_t time;
|
||||
int i = 0;
|
||||
char *bucket = argv[1];
|
||||
char *object = argv[2];
|
||||
int test_times = atoi(argv[3]);
|
||||
//int test_times = 10000;
|
||||
//char *buf = (char *)malloc(1024 * 1024 * 4);
|
||||
char buf[1024 * 1024 * 4];
|
||||
//char buf[1024 * 4];
|
||||
size_t buf_size;
|
||||
int mode = FILE_MODE;
|
||||
size_t fd[10000] = {0};
|
||||
userdata_t data = {&finished};
|
||||
|
||||
file_to_buffer(object, buf, &buf_size);
|
||||
|
||||
debuginfo("hos_client_init start ...\n");
|
||||
hos_client_handle handle = hos_client_create("192.168.44.12", 9098, "default", "default", 3000);
|
||||
if (handle == NULL)
|
||||
{
|
||||
debuginfo("error:hos_client_handle\n");
|
||||
return -1;
|
||||
}
|
||||
debuginfo("hos_client_init success ... \n");
|
||||
|
||||
debuginfo("hos_create_bucket start ... \n");
|
||||
if(hos_create_bucket(handle, bucket))
|
||||
{
|
||||
debuginfo("hos_create_bucket failed ... \n");
|
||||
return -1;
|
||||
}
|
||||
debuginfo("hos_create_bucket success ... \n");
|
||||
|
||||
debuginfo("hos_verify_bucket start ... \n");
|
||||
if(!hos_verify_bucket(handle, bucket))
|
||||
{
|
||||
debuginfo("hos_verify_bucket failed ... \n");
|
||||
return -1;
|
||||
}
|
||||
debuginfo("hos_verify_bucket success ... \n");
|
||||
|
||||
#if 1
|
||||
debuginfo("hos_upload_file start ...\n");
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
for (i = 0; i < test_times; i++)
|
||||
{
|
||||
hos_upload_file(handle, bucket, object, callback, (void *)&data, 0);
|
||||
}
|
||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||
time = calc_time(start, end);
|
||||
time /= test_times;
|
||||
printf("hos_upload_file spent %llu ns\n", time);
|
||||
debuginfo("hos_upload_file end ...\n");
|
||||
#else
|
||||
|
||||
debuginfo("hos_upload_buf start ...\n");
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
for (i = 0; i < test_times; i++)
|
||||
{
|
||||
hos_upload_buf(handle, bucket, object, buf, buf_len, callback, (void *)&data, 0);
|
||||
}
|
||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||
time = calc_time(start, end);
|
||||
time /= test_times;
|
||||
printf("hos_upload_buf spent %llu ns\n", time);
|
||||
debuginfo("hos_upload_buf end ...\n");
|
||||
|
||||
#endif
|
||||
debuginfo("hos_client_close start ...\n");
|
||||
if (hos_client_destory(handle) == 0)
|
||||
{
|
||||
time = calc_time(start, finished);
|
||||
time /= test_times;
|
||||
printf("hos upload finished spent %llu ns\n", time);
|
||||
}
|
||||
|
||||
debuginfo("hos_client_close end ...\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
/*************************************************************************
|
||||
> File Name: single_thread.cpp
|
||||
> Author: pxz
|
||||
> Created Time: Fri 11 Sep 2020 09:52:05 AM CST
|
||||
************************************************************************/
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<unistd.h>
|
||||
#include<string.h>
|
||||
#include<time.h>
|
||||
#include"hos_client.h"
|
||||
|
||||
//#define test_times 10000
|
||||
|
||||
#define debuginfo (void)
|
||||
|
||||
typedef struct userdata_s
|
||||
{
|
||||
struct timespec *finished;
|
||||
}userdata_t;
|
||||
|
||||
static size_t calc_time(struct timespec start, struct timespec end)
|
||||
{
|
||||
return (end.tv_sec * 1000 * 1000 * 1000 + end.tv_nsec -
|
||||
(start.tv_sec * 1000 * 1000 * 1000 + start.tv_nsec));
|
||||
}
|
||||
|
||||
int file_to_buffer(const char *file, char *buffer, size_t *len)
|
||||
{
|
||||
FILE *fp = fopen(file, "r");
|
||||
int num = 0;
|
||||
*len = 0;
|
||||
if (fp == NULL)
|
||||
{
|
||||
debuginfo("fopen file failed:%s\n", file);
|
||||
return -1;
|
||||
}
|
||||
do{
|
||||
num = fread(&buffer[*len], 1, 4096, fp);
|
||||
if (num < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
*len += num;
|
||||
}while(num == 4096);
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void callback(bool result, const char *error, const char *bucket, const char *object, void *userdata)
|
||||
{
|
||||
userdata_t *data = (userdata_t *)userdata;
|
||||
clock_gettime(CLOCK_MONOTONIC, data->finished);
|
||||
return ;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 4)
|
||||
{
|
||||
debuginfo("usege: singThread [bucket name] [object name]\n");
|
||||
return -1;
|
||||
}
|
||||
struct timespec start, end, finished;
|
||||
size_t time;
|
||||
int i = 0;
|
||||
char *bucket = argv[1];
|
||||
char *object = argv[2];
|
||||
int test_times = atoi(argv[3]);
|
||||
char *buf = (char *)malloc(1024 * 1024 * 40);
|
||||
size_t buf_size;
|
||||
int mode = FILE_MODE;
|
||||
size_t fd[10001] = {0};
|
||||
userdata_t data = {&finished};
|
||||
|
||||
file_to_buffer(object, buf, &buf_size);
|
||||
|
||||
debuginfo("hos_client_init start ...\n");
|
||||
hos_client_handle handle = hos_client_create("192.168.40.223", 9098, "default", "default", 400);
|
||||
//hos_client_handle handle = hos_client_create("http://192.168.32.10:9098/hos/", "default", "default", 4);
|
||||
if (handle == NULL)
|
||||
{
|
||||
printf("error:hos_client_handle\n");
|
||||
return -1;
|
||||
}
|
||||
debuginfo("hos_client_init success ... \n");
|
||||
|
||||
debuginfo("hos_create_bucket start ... \n");
|
||||
if(hos_create_bucket(handle, bucket))
|
||||
{
|
||||
printf("hos_create_bucket failed ... \n");
|
||||
return -1;
|
||||
}
|
||||
debuginfo("hos_create_bucket success ... \n");
|
||||
|
||||
debuginfo("hos_verify_bucket start ... \n");
|
||||
if(!hos_verify_bucket(handle, bucket))
|
||||
{
|
||||
printf("hos_verify_bucket failed ... \n");
|
||||
return -1;
|
||||
}
|
||||
debuginfo("hos_verify_bucket success ... \n");
|
||||
|
||||
#if 1
|
||||
mode = FILE_MODE;
|
||||
debuginfo("hos_upload_file start ...\n");
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
for (i = 0; i < test_times; i++)
|
||||
{
|
||||
fd[i] = hos_open_fd(handle, bucket, object, callback, (void *)&data, 0, mode);
|
||||
hos_write(fd[i], object, 0, 0);
|
||||
}
|
||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||
time = calc_time(start, end);
|
||||
time /= test_times;
|
||||
printf("hos_upload_file spent %llu ns\n", time);
|
||||
debuginfo("hos_upload_file end ...\n");
|
||||
#else
|
||||
|
||||
mode = BUFF_MODE | APPEND_MODE;
|
||||
#if 0
|
||||
for (i = 0; i < test_times; i++)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
debuginfo("hos_upload_buf start ...\n");
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
for (i = 0; i < test_times; i++)
|
||||
{
|
||||
fd[i] = hos_open_fd(handle, bucket, object, callback, (void *)&data, 0, mode);
|
||||
//printf("hos_write start...\n");
|
||||
if(hos_write(fd[i], buf, buf_size, 0, i + 1) != HOS_CLIENT_OK)
|
||||
{
|
||||
printf("error: hos_write!\n");
|
||||
}
|
||||
//printf("hos_write success...\n");
|
||||
}
|
||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||
time = calc_time(start, end);
|
||||
time /= test_times;
|
||||
printf("hos_upload_buf spent %llu ns\n", time);
|
||||
debuginfo("hos_upload_buf end ...\n");
|
||||
|
||||
#endif
|
||||
debuginfo("hos_client_close start ...\n");
|
||||
if (hos_client_destory(handle) == 0)
|
||||
{
|
||||
//printf("start:%lu\n", start.tv_sec * 1000 * 1000 * 1000 + start.tv_nsec);
|
||||
//printf("finished:%lu\n", finished.tv_sec * 1000 * 1000 * 1000 + finished.tv_nsec);
|
||||
time = calc_time(start, finished);
|
||||
time /= test_times;
|
||||
printf("hos upload finished spent %llu ns\n", time);
|
||||
}
|
||||
|
||||
debuginfo("hos_client_close end ...\n");
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#########################################################################
|
||||
# File Name: test_times.sh
|
||||
# Author: pxz
|
||||
# Created Time: Mon 21 Sep 2020 04:43:35 PM CST
|
||||
#########################################################################
|
||||
#!/bin/bash
|
||||
test_size=("1k" "10k" "100k" "1M" "2M" "3M" "4M")
|
||||
num=0
|
||||
echo ${test_size[${num}]}
|
||||
|
||||
while((${num} < 7))
|
||||
do
|
||||
./hos_write_complete mybucket ./data/${test_size[$num]}.data 1000
|
||||
let "num++"
|
||||
done
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#########################################################################
|
||||
# File Name: test_times.sh
|
||||
# Author: pxz
|
||||
# Created Time: Mon 21 Sep 2020 04:43:35 PM CST
|
||||
#########################################################################
|
||||
#!/bin/bash
|
||||
test_times=(1, 10, 100, 1000, 10000)
|
||||
num=0
|
||||
|
||||
while((${num} < 5))
|
||||
do
|
||||
./hos_write_complete mybucket my-file.txt ${test_times[$num]}
|
||||
let "num++"
|
||||
done
|
||||
|
||||
@@ -27,5 +27,5 @@ endif()
|
||||
# end of for ASAN
|
||||
|
||||
add_executable(HosClientPerformance HosClientPerformance.cpp)
|
||||
target_link_libraries(HosClientPerformance hos-client-cpp)
|
||||
target_link_libraries(HosClientPerformance hos-client-cpp MESA_handle_logger)
|
||||
|
||||
|
||||
@@ -15,64 +15,39 @@ extern "C"
|
||||
#include<sys/stat.h>
|
||||
#include<math.h>
|
||||
#include<netinet/in.h>
|
||||
#include<zlog.h>
|
||||
}
|
||||
#include"../../src/hos_client.h"
|
||||
#include "MESA_handle_logger.h"
|
||||
|
||||
#define MAX_THREAD_NUM 32
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a) > (b)) ? (b) : (a)
|
||||
#endif
|
||||
|
||||
typedef struct conf_s
|
||||
{
|
||||
#define STRING_SIZE 128
|
||||
char serverip[INET_ADDRSTRLEN];
|
||||
char bucket[STRING_SIZE];
|
||||
char object[STRING_SIZE];
|
||||
char file[STRING_SIZE];
|
||||
size_t port;
|
||||
size_t pool_size;
|
||||
size_t thread_sum;
|
||||
size_t size;
|
||||
float append_size;
|
||||
size_t slice;
|
||||
int mode;
|
||||
}conf_t;
|
||||
#define STRING_SIZE 1024
|
||||
|
||||
typedef struct thread_info_s
|
||||
{
|
||||
conf_t conf;
|
||||
hos_client_handle handle;
|
||||
char object[STRING_SIZE];
|
||||
char bucket[STRING_SIZE];
|
||||
char file[100][STRING_SIZE];
|
||||
int mode;
|
||||
size_t thread_num;
|
||||
}thread_info_t;
|
||||
|
||||
static void configuration_init(conf_t *conf)
|
||||
{
|
||||
strcpy(conf->serverip, "192.168.40.223");
|
||||
strcpy(conf->bucket, "mybucket");
|
||||
strcpy(conf->object, "myobject");
|
||||
strcpy(conf->file, "./file/test.txt");
|
||||
conf->port = 9098;
|
||||
conf->pool_size = 4000;
|
||||
conf->append_size = 1024;
|
||||
conf->thread_sum = 1;
|
||||
conf->mode = BUFF_MODE;
|
||||
conf->slice = 0;
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
typedef struct userdata_s
|
||||
{
|
||||
struct timespec *finished;
|
||||
}userdata_t;
|
||||
struct timespec *g_finished;
|
||||
char g_file_name[100][STRING_SIZE];
|
||||
size_t g_mode;
|
||||
size_t g_test_count;
|
||||
size_t g_append_size;
|
||||
|
||||
static size_t calc_time(struct timespec start, struct timespec end)
|
||||
{
|
||||
return (end.tv_sec - start.tv_sec) * 1000 * 1000 * 1000 + end.tv_nsec - start.tv_nsec;
|
||||
}
|
||||
|
||||
int read_file_list(const char *path, char file_name[][256])
|
||||
int read_file_list(const char *path, char file_name[][STRING_SIZE])
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *ptr;
|
||||
@@ -89,12 +64,12 @@ int read_file_list(const char *path, char file_name[][256])
|
||||
{
|
||||
if(strcmp(ptr->d_name,".")==0 || strcmp(ptr->d_name,"..")==0) ///current dir OR parrent dir
|
||||
continue;
|
||||
else if((ptr->d_type == 8) || (ptr->d_type == 10))
|
||||
else if((ptr->d_type == DT_REG) || (ptr->d_type == DT_LNK))
|
||||
{
|
||||
memcpy(file_name[file_num], path, path_len);
|
||||
strcat(file_name[file_num], ptr->d_name);
|
||||
}
|
||||
else if(ptr->d_type == 4) ///dir
|
||||
else if(ptr->d_type == DT_DIR) ///dir
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -135,12 +110,11 @@ static int file_to_buffer(const char *file, char *buffer, size_t *len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int upload_file(char *file, char *buff, int buff_len, int test_times, thread_info_t *thread_info, char *performance_info)
|
||||
static int upload_file(char *file, char *buff, int buff_len, thread_info_t *thread_info, char *performance_info)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
FILE *fp = NULL;
|
||||
size_t fd[3000];
|
||||
conf_t *conf = &thread_info->conf;
|
||||
struct timespec tstart, tend, twrite;
|
||||
long time_write = 0, time_upload = 0;
|
||||
size_t len = strlen(performance_info);
|
||||
@@ -149,11 +123,10 @@ static int upload_file(char *file, char *buff, int buff_len, int test_times, thr
|
||||
double variance = 0.00;
|
||||
double average = 0.00;
|
||||
long time = 0;
|
||||
int success_cnt;
|
||||
//写文件
|
||||
|
||||
//clock_gettime(CLOCK_MONOTONIC, &tstart);
|
||||
for (i = 0; i < test_times; i++)
|
||||
for (i = 0; i < g_test_count; i++)
|
||||
{
|
||||
clock_gettime(CLOCK_MONOTONIC, &tstart);
|
||||
fp = fopen(file, "w+");
|
||||
@@ -175,14 +148,14 @@ static int upload_file(char *file, char *buff, int buff_len, int test_times, thr
|
||||
}
|
||||
//clock_gettime(CLOCK_MONOTONIC, &twrite);
|
||||
//time_write = calc_time(tstart, twrite);
|
||||
time_write /= test_times;
|
||||
time_write /= g_test_count;
|
||||
|
||||
//上传文件
|
||||
//clock_gettime(CLOCK_MONOTONIC, &tstart);
|
||||
for (i = 0; i < test_times; i++)
|
||||
for (i = 0; i < g_test_count; i++)
|
||||
{
|
||||
clock_gettime(CLOCK_MONOTONIC, &tstart);
|
||||
fd[i] = hos_open_fd(thread_info->handle, conf->bucket, conf->object, callback, NULL, thread_info->thread_num, conf->mode);
|
||||
fd[i] = hos_open_fd(thread_info->bucket, thread_info->object, callback, NULL, thread_info->thread_num, g_mode);
|
||||
if (hos_write(fd[i], file, 0, thread_info->thread_num) != HOS_CLIENT_OK)
|
||||
{
|
||||
printf("error:hos_write file:%s\n", file);
|
||||
@@ -195,14 +168,14 @@ static int upload_file(char *file, char *buff, int buff_len, int test_times, thr
|
||||
}
|
||||
//clock_gettime(CLOCK_MONOTONIC, &tend);
|
||||
//time_upload = calc_time(tstart, tend);
|
||||
time_upload /= test_times;
|
||||
time_upload /= g_test_count;
|
||||
|
||||
average = time_write + time_upload;
|
||||
for (i = 0; i < test_times; i++)
|
||||
for (i = 0; i < g_test_count; i++)
|
||||
{
|
||||
variance += pow((record[i] - average), 2);
|
||||
}
|
||||
variance /= test_times;
|
||||
variance /= g_test_count;
|
||||
|
||||
sprintf(file_size, "%dk", buff_len / 1024);
|
||||
sprintf(&performance_info[len], "%-20lu%-20s%-20ld%-20ld%-20lf%-20lf\n",
|
||||
@@ -211,115 +184,84 @@ static int upload_file(char *file, char *buff, int buff_len, int test_times, thr
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int upload_buff(char * buff, int buff_len, int test_times, thread_info_t *thread_info, char *performance_info)
|
||||
static int upload_buff(char * buff, int buff_len, thread_info_t *thread_info, char *performance_info)
|
||||
{
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
int j = 0;
|
||||
size_t fd[1000] = {0};
|
||||
size_t tmp = 0;
|
||||
size_t rest = 0;
|
||||
struct timespec tstart, ttmp;
|
||||
size_t time = 0;
|
||||
size_t len;
|
||||
conf_t *conf = &thread_info->conf;
|
||||
char file_size[128];
|
||||
char append_size[128];
|
||||
size_t success_cnt = 0;
|
||||
int ret = 0;
|
||||
int drop = 0;
|
||||
double variance = 0.00;
|
||||
double average = 0.00;
|
||||
long record[30000] = {0};
|
||||
|
||||
if (conf->slice)
|
||||
if (g_mode & APPEND_MODE)
|
||||
{
|
||||
fd[0] = hos_open_fd(thread_info->handle, conf->bucket, conf->object, callback, NULL, thread_info->thread_num, conf->mode);
|
||||
for (i = 0; i < test_times; i++)
|
||||
fd[0] = hos_open_fd(thread_info->bucket, thread_info->object, callback, NULL, thread_info->thread_num, g_mode);
|
||||
|
||||
for (i = 0; i < g_test_count; i++)
|
||||
{
|
||||
j = 0;
|
||||
clock_gettime(CLOCK_MONOTONIC, &tstart);
|
||||
j = 0;
|
||||
while (1)
|
||||
{
|
||||
tmp = j * conf->slice;
|
||||
tmp = j * g_append_size;
|
||||
rest = buff_len - tmp;
|
||||
if (rest < conf->slice)
|
||||
if (rest < g_append_size)
|
||||
{
|
||||
hos_write(fd[0], &buff[tmp], rest, thread_info->thread_num);
|
||||
break;
|
||||
}
|
||||
hos_write(fd[0], &buff[tmp], conf->slice, thread_info->thread_num);
|
||||
hos_write(fd[0], &buff[tmp], g_append_size, thread_info->thread_num);
|
||||
j++;
|
||||
}
|
||||
clock_gettime(CLOCK_MONOTONIC, &ttmp);
|
||||
record[i] = calc_time(tstart, ttmp);
|
||||
average += record[i];
|
||||
}
|
||||
average /= test_times;
|
||||
average /= g_test_count;
|
||||
|
||||
for (i = 0; i < test_times; i++)
|
||||
for (i = 0; i < g_test_count; i++)
|
||||
{
|
||||
variance += pow((record[i] - average), 2);
|
||||
}
|
||||
variance /= test_times;
|
||||
variance /= g_test_count;
|
||||
|
||||
sprintf(file_size, "%dk", buff_len / 1024);
|
||||
sprintf(append_size, "%gk", conf->append_size / 1024);
|
||||
len = strlen(performance_info);
|
||||
sprintf(&performance_info[len], "%-20lu%-20s%-20s%-20d%-20lf%-20lf\n",
|
||||
thread_info->thread_num, file_size, append_size, 0, average, sqrt(variance));
|
||||
}else{
|
||||
|
||||
if (conf->mode & APPEND_MODE)
|
||||
if (buff_len > 1024 * 1024)
|
||||
{
|
||||
fd[0] = hos_open_fd(thread_info->handle, conf->bucket, conf->object, callback, NULL, thread_info->thread_num, conf->mode);
|
||||
#if 1
|
||||
for (i = 0; i < test_times; i++)
|
||||
sprintf(file_size, "%gM", (double)buff_len / 1024 / 1024);
|
||||
}
|
||||
else if (buff_len > 1024)
|
||||
{
|
||||
sprintf(file_size, "%gK", (double)buff_len / 1024);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(file_size, "%dB", buff_len);
|
||||
}
|
||||
sprintf(append_size, "%gK", (double)g_append_size / 1024);
|
||||
len = strlen(performance_info);
|
||||
sprintf(&performance_info[len], "%-20lu%-20s%-20s%-20lu%-20lf%-20lf\n",
|
||||
thread_info->thread_num, file_size, append_size, g_test_count, average, sqrt(variance));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < g_test_count; i++)
|
||||
{
|
||||
clock_gettime(CLOCK_MONOTONIC, &tstart);
|
||||
#endif
|
||||
j = 0;
|
||||
while(1)
|
||||
{
|
||||
tmp = j * conf->append_size;
|
||||
rest = buff_len - tmp;
|
||||
if (rest < conf->append_size)
|
||||
{
|
||||
hos_write(fd[0], &buff[tmp], rest, thread_info->thread_num);
|
||||
break;
|
||||
}
|
||||
hos_write(fd[0], &buff[tmp], conf->append_size, thread_info->thread_num);
|
||||
j++;
|
||||
}
|
||||
#if 1
|
||||
clock_gettime(CLOCK_MONOTONIC, &ttmp);
|
||||
record[i] = calc_time(tstart, ttmp);
|
||||
average += record[i];
|
||||
}
|
||||
average /= test_times;
|
||||
#endif
|
||||
|
||||
for (i = 0; i < test_times; i++)
|
||||
{
|
||||
variance += pow((record[i] - average), 2);
|
||||
}
|
||||
variance /= test_times;
|
||||
|
||||
sprintf(file_size, "%dk", buff_len / 1024);
|
||||
sprintf(append_size, "%gk", conf->append_size / 1024);
|
||||
len = strlen(performance_info);
|
||||
sprintf(&performance_info[len], "%-20lu%-20s%-20s%-20d%-20lf%-20lf\n",
|
||||
thread_info->thread_num, file_size, append_size, 0, average,sqrt(variance));
|
||||
}else
|
||||
{
|
||||
for (i = 0; i < test_times; i++)
|
||||
{
|
||||
clock_gettime(CLOCK_MONOTONIC, &tstart);
|
||||
fd[i] = hos_open_fd(thread_info->handle, conf->bucket, conf->object, callback, NULL, thread_info->thread_num, conf->mode);
|
||||
fd[i] = hos_open_fd(thread_info->bucket, thread_info->object, callback, NULL, thread_info->thread_num, g_mode);
|
||||
ret = hos_write(fd[i], buff, buff_len, thread_info->thread_num);
|
||||
if (ret == HOS_CLIENT_OK)
|
||||
{
|
||||
success_cnt++;
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
//printf("error code:%d, thread_id:%d\n", ret, thread_info->thread_num);
|
||||
//break;
|
||||
@@ -331,23 +273,33 @@ static int upload_buff(char * buff, int buff_len, int test_times, thread_info_t
|
||||
if (success_cnt)
|
||||
average /= success_cnt;
|
||||
else
|
||||
average /= test_times;
|
||||
average /= g_test_count;
|
||||
|
||||
for (i = 0; i < test_times; i++)
|
||||
for (i = 0; i < g_test_count; i++)
|
||||
{
|
||||
variance += pow((record[i] - average), 2);
|
||||
}
|
||||
variance /= test_times;
|
||||
variance /= g_test_count;
|
||||
|
||||
sprintf(file_size, "%dk", buff_len / 1024);
|
||||
sprintf(append_size, "%luk", conf->append_size / 1024);
|
||||
if (buff_len > 1024 * 1024)
|
||||
{
|
||||
sprintf(file_size, "%gM", (double)buff_len / 1024 / 1024);
|
||||
}
|
||||
else if (buff_len > 1024)
|
||||
{
|
||||
sprintf(file_size, "%gK", (double)buff_len / 1024);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(file_size, "%dB", buff_len);
|
||||
}
|
||||
sprintf(append_size, "%gK", (double)g_append_size / 1024);
|
||||
len = strlen(performance_info);
|
||||
sprintf(&performance_info[len], "%-20lu%-20s%-20d%-20d%-20lf%-20lf\n",
|
||||
thread_info->thread_num, file_size, 0, 0, average, sqrt(variance));
|
||||
}
|
||||
sprintf(&performance_info[len], "%-20lu%-20s%-20d%-20lu%-20lf%-20lf\n",
|
||||
thread_info->thread_num, file_size, 0, g_test_count, average, sqrt(variance));
|
||||
}
|
||||
|
||||
for (i = 0; i < test_times; i++)
|
||||
for (i = 0; i < g_test_count; i++)
|
||||
{
|
||||
if (fd[i] > 2)
|
||||
{
|
||||
@@ -362,15 +314,11 @@ static void *put_object_thread(void *ptr)
|
||||
{
|
||||
char *performance_info = NULL;
|
||||
thread_info_t *thread_info = (thread_info_t *)ptr;
|
||||
conf_t *conf = &thread_info->conf;
|
||||
char file[128];
|
||||
size_t buff_len;
|
||||
int ret;
|
||||
int i;
|
||||
char *buff = NULL;
|
||||
char file_name[100][256];
|
||||
struct stat s_buf;
|
||||
int test_times = 1000;
|
||||
|
||||
buff = (char *)malloc(30 * 1024 * 1024);
|
||||
if (buff == NULL)
|
||||
@@ -387,49 +335,26 @@ static void *put_object_thread(void *ptr)
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
memset(performance_info, 0, 10240);
|
||||
memset(file_name, 0, 100 *256);
|
||||
|
||||
stat(conf->file, &s_buf);
|
||||
if (S_ISDIR(s_buf.st_mode))
|
||||
{
|
||||
read_file_list(conf->file, file_name);
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
if (file_name[i][0] == '\0')
|
||||
if (g_file_name[i][0] == '\0')
|
||||
break;
|
||||
ret = file_to_buffer(file_name[i], buff, &buff_len);
|
||||
ret = file_to_buffer(g_file_name[i], buff, &buff_len);
|
||||
if (ret == -1)
|
||||
{
|
||||
free(buff);
|
||||
free(performance_info);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
if (conf->mode & BUFF_MODE)
|
||||
if (g_mode & BUFF_MODE)
|
||||
{
|
||||
upload_buff(buff, buff_len, test_times, thread_info, performance_info);
|
||||
}else
|
||||
upload_buff(buff, buff_len, thread_info, performance_info);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(file, "./file/file_%lu_%d", thread_info->thread_num, i);
|
||||
upload_file(file, buff, buff_len, test_times, thread_info, performance_info);
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
ret = file_to_buffer(conf->file, buff, &buff_len);
|
||||
if (ret == -1)
|
||||
{
|
||||
free(buff);
|
||||
free(performance_info);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
if (conf->mode & BUFF_MODE)
|
||||
{
|
||||
upload_buff(buff, buff_len, test_times, thread_info, performance_info);
|
||||
}else
|
||||
{
|
||||
sprintf(file, "./file/file_%lu", thread_info->thread_num);
|
||||
upload_file(file, buff, buff_len, test_times, thread_info, performance_info);
|
||||
upload_file(file, buff, buff_len, thread_info, performance_info);
|
||||
}
|
||||
}
|
||||
free(buff);
|
||||
@@ -440,92 +365,87 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
int buf_size;
|
||||
conf_t conf;
|
||||
char *object;
|
||||
char *retval;
|
||||
size_t thread_num;
|
||||
size_t thread[MAX_THREAD_NUM];
|
||||
thread_info_t thread_info[MAX_THREAD_NUM];
|
||||
cpu_set_t mask;
|
||||
FILE *log = NULL;
|
||||
char log_name[256];
|
||||
const char *log_prefix = "./log/";
|
||||
char log_name[STRING_SIZE];
|
||||
const char *log_prefix = "./";
|
||||
char conf_path[STRING_SIZE] = {0};
|
||||
char bucket[STRING_SIZE] = {0};
|
||||
char object[STRING_SIZE] = {0};
|
||||
char module[STRING_SIZE] = {0};
|
||||
char upload_file_path[STRING_SIZE] = {0};
|
||||
size_t thread_sum = 0;
|
||||
time_t timep;
|
||||
#if 0
|
||||
if (argc <= 1)
|
||||
{
|
||||
printf("usage: HosClientPerformance \n[-e set endpoint] \n[-b set bucket] \n"
|
||||
"[-o set object] \n[-f set file] \n[-p set pool size] \n"
|
||||
"[-t set thread sum] \n[-B set BUFF_MODE] \n"
|
||||
"[-F set FILE_MODE] \n[-A set APPEND_MODE] \n"
|
||||
"[-h show help info] \n");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
configuration_init(&conf);
|
||||
struct stat s_buf;
|
||||
|
||||
/*init*/
|
||||
g_append_size = 102400;
|
||||
memcpy(bucket, "hos_test_bucket", strlen("hos_test_bucket"));
|
||||
memcpy(object, "object", strlen("object"));
|
||||
memcpy(conf_path, "../conf/default.conf", strlen("../conf/default.conf"));
|
||||
memcpy(module, "module", strlen("module"));
|
||||
memcpy(upload_file_path, "../CMakeLists.txt", strlen("../CMakeLists.txt"));
|
||||
thread_sum = 1;
|
||||
g_mode = BUFF_MODE;
|
||||
g_test_count = 100;
|
||||
|
||||
//读取命令行配置
|
||||
while((ch = getopt(argc, argv, "a:b:o:f:p:t:k:s:i:P:S:BFAh")) != -1)
|
||||
while((ch = getopt(argc, argv, "a:b:c:o:m:f:t:M:n:h")) != -1)
|
||||
{
|
||||
switch(ch)
|
||||
{
|
||||
case 'a':
|
||||
conf.append_size = 1024 * atof(optarg);
|
||||
g_append_size = atoi(optarg);
|
||||
break;
|
||||
case 'i':
|
||||
//endpoint
|
||||
case 'b': /*bucket*/
|
||||
buf_size = MIN(STRING_SIZE, strlen(optarg));
|
||||
strncpy((char *)conf.serverip, optarg, buf_size);
|
||||
strncpy(bucket, optarg, buf_size);
|
||||
bucket[buf_size] = '\0';
|
||||
break;
|
||||
case 'b':
|
||||
case 'c': /*configuration file*/
|
||||
buf_size = MIN(STRING_SIZE, strlen(optarg));
|
||||
strncpy((char *)conf.bucket, optarg, buf_size);
|
||||
conf.bucket[buf_size] = '\0';
|
||||
strncpy(conf_path, optarg, buf_size);
|
||||
conf_path[buf_size] = '\0';
|
||||
break;
|
||||
case 'o':
|
||||
case 'o': /*object*/
|
||||
buf_size = MIN(STRING_SIZE, strlen(optarg));
|
||||
strncpy(conf.object, optarg, buf_size);
|
||||
conf.object[buf_size] = '\0';
|
||||
strncpy(object, optarg, buf_size);
|
||||
object[buf_size] = '\0';
|
||||
break;
|
||||
case 'f':
|
||||
case 'm': /*module*/
|
||||
buf_size = MIN(STRING_SIZE, strlen(optarg));
|
||||
strncpy(conf.file, optarg, buf_size);
|
||||
conf.file[buf_size] = '\0';
|
||||
strncpy(module, optarg, buf_size);
|
||||
module[buf_size] = '\0';
|
||||
break;
|
||||
case 'P':
|
||||
conf.pool_size = atoi(optarg);
|
||||
conf.pool_size = MIN(4000, conf.pool_size);
|
||||
case 'f': /*module*/
|
||||
buf_size = MIN(STRING_SIZE, strlen(optarg));
|
||||
strncpy(upload_file_path, optarg, buf_size);
|
||||
upload_file_path[buf_size] = '\0';
|
||||
break;
|
||||
case 't':
|
||||
conf.thread_sum = atoi(optarg);
|
||||
thread_sum = atoi(optarg);
|
||||
break;
|
||||
case 'B':
|
||||
conf.mode &= BUFF_MODE;
|
||||
case 'M':
|
||||
g_mode = atoi(optarg);
|
||||
break;
|
||||
case 'F':
|
||||
conf.mode &= FILE_MODE;
|
||||
break;
|
||||
case 'A':
|
||||
conf.mode |= APPEND_MODE;
|
||||
break;
|
||||
case 'k':
|
||||
conf.append_size = 1024 * atoi(optarg);
|
||||
break;
|
||||
case 's':
|
||||
conf.size = atoi(optarg);
|
||||
break;
|
||||
case 'S':
|
||||
conf.slice = atoi(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
conf.port = atoi(optarg);
|
||||
case 'n':
|
||||
g_test_count = atoi(optarg);
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
printf("usage: HosClientPerformance \n[-e set endpoint] \n[-b set bucket] \n"
|
||||
"[-o set object] \n[-f set file] \n[-p set pool size] \n"
|
||||
"[-t set thread sum] \n[-B set BUFF_MODE] \n"
|
||||
"[-F set FILE_MODE] \n[-A set APPEND_MODE] \n"
|
||||
"[-h show help info] \n[-a set append size(K)]\n");
|
||||
printf("usage: HosClientPerformance \n"
|
||||
"[-b set bucket] \n"
|
||||
"[-c set conf file path] \n"
|
||||
"[-o set object] \n"
|
||||
"[-t set thread sum] \n"
|
||||
"[-m set module] \n"
|
||||
"[-f set upload file path] \n"
|
||||
"[-M set mode] \n"
|
||||
"[-h show help info] \n");
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
@@ -540,50 +460,52 @@ int main(int argc, char *argv[])
|
||||
perror(log_name);
|
||||
return -1;
|
||||
}
|
||||
//创建client
|
||||
hos_client_handle handle = hos_client_create(conf.serverip, conf.port, "default", "default", conf.pool_size);
|
||||
if (handle == NULL)
|
||||
//初始化hos instance
|
||||
hos_instance hos_instance = hos_init_instance(conf_path, module, thread_sum, bucket);
|
||||
if (hos_instance == NULL)
|
||||
{
|
||||
printf("error:hos_client_handle\n");
|
||||
printf("error:hos_client_handle\n %s\n", hos_instance->error_message);
|
||||
fclose(log);
|
||||
return -1;
|
||||
}
|
||||
|
||||
hos_set_thread_sum(handle, conf.thread_sum);
|
||||
hos_set_cache_size(handle, conf.append_size);
|
||||
hos_set_cache_count(handle, 0);
|
||||
|
||||
//创建bucket
|
||||
if (hos_create_bucket(handle, conf.bucket))
|
||||
{
|
||||
printf("error:hos_create_bucket\n");
|
||||
fclose(log);
|
||||
hos_client_destory(handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//zlog_init("../conf/zlog.conf");
|
||||
MESA_handle_runtime_log_creation(NULL);
|
||||
printf("\n==============================================================================================================================\n");
|
||||
if (conf.mode & BUFF_MODE)
|
||||
if (g_mode & BUFF_MODE)
|
||||
{
|
||||
printf("%-20s%-20s%-20s%-20s%-20s\n", "thread_id", "file_size", "append_size", "upload_time", "total_time");
|
||||
printf("%-20s%-20s%-20s%-20s%-20s%-20s\n", "thread_id", "file_size", "append_size", "upload_time", "total_time", "std-dev");
|
||||
}else
|
||||
{
|
||||
printf("%-20s%-20s%-20s%-20s%-20s\n", "thread_id", "file_size", "write_time", "upload_time", "total_time");
|
||||
printf("%-20s%-20s%-20s%-20s%-20s%-20s\n", "thread_id", "file_size", "write_time", "upload_time", "total_time", "std-dev");
|
||||
}
|
||||
hos_expand_fs2(handle, "./log/fs2.log", 0, "127.0.0.1", 8001);
|
||||
//hos_expand_fs2(handle, NULL, 0, "127.0.0.1", 8001);
|
||||
for ( thread_num = 0; thread_num < conf.thread_sum; thread_num++ )
|
||||
|
||||
memset(g_file_name, 0, 100 * 256);
|
||||
stat(upload_file_path, &s_buf);
|
||||
if (S_ISDIR(s_buf.st_mode))
|
||||
{
|
||||
read_file_list(upload_file_path, g_file_name);
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
if (g_file_name[i][0] == '\0')
|
||||
break;
|
||||
}
|
||||
}else
|
||||
{
|
||||
memcpy(g_file_name[0], upload_file_path, MIN(strlen(upload_file_path), STRING_SIZE - 1));
|
||||
}
|
||||
|
||||
for ( thread_num = 0; thread_num < thread_sum; thread_num++ )
|
||||
{
|
||||
thread_info[thread_num].conf = conf;
|
||||
object = thread_info[thread_num].conf.object;
|
||||
sprintf(&object[strlen(object)], "-%lu", thread_num);
|
||||
thread_info[thread_num].thread_num = thread_num;
|
||||
thread_info[thread_num].handle = handle;
|
||||
sprintf(thread_info[thread_num].object, "%s-%lu", object, thread_num);
|
||||
sprintf(thread_info[thread_num].bucket, "%s", bucket);
|
||||
|
||||
if(pthread_create(&thread[thread_num], NULL, put_object_thread, (void *)&thread_info[thread_num]))
|
||||
{
|
||||
perror(" ");
|
||||
fclose(log);
|
||||
hos_client_destory(handle);
|
||||
hos_shutdown_instance();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -595,7 +517,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
for (thread_num = 0; thread_num < conf.thread_sum; thread_num++)
|
||||
for (thread_num = 0; thread_num < thread_sum; thread_num++)
|
||||
{
|
||||
pthread_join(thread[thread_num], (void **)&retval);
|
||||
if (retval)
|
||||
@@ -606,7 +528,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (hos_client_destory(handle) == 0)
|
||||
if (hos_shutdown_instance() == 0)
|
||||
{
|
||||
//time = calc_time(start, finished);
|
||||
//time /= test_times;
|
||||
|
||||
16
example/performance/conf/default.conf
Normal file
16
example/performance/conf/default.conf
Normal file
@@ -0,0 +1,16 @@
|
||||
[module]
|
||||
hos_serverip=192.168.44.12
|
||||
hos_serverport=9098
|
||||
hos_accesskeyid="default"
|
||||
hos_secretkey="default"
|
||||
hos_log_path="./hoslog" #default
|
||||
hos_log_level=30 #default
|
||||
hos_poolsize=100 #default
|
||||
hos_thread_sum=32 #default
|
||||
hos_cache_size=102400 #default
|
||||
hos_cache_count=10 #default
|
||||
hos_fd_live_time_ms=1000 #default
|
||||
hos_fs2_serverip=127.0.0.1
|
||||
hos_fs2_serverport=10086
|
||||
hos_fs2_path="./hos_fs2_log" #default
|
||||
hos_fs2_format=0 #default
|
||||
@@ -1,15 +0,0 @@
|
||||
#########################################################################
|
||||
# File Name: c.sh
|
||||
# Author: pxz
|
||||
# Created Time: Tue 13 Oct 2020 06:28:57 PM CST
|
||||
#########################################################################
|
||||
#!/bin/bash
|
||||
size=("100" "200" "300" "400" "500" "600" "700" "800" "900" "1k" "1500" "10k" "100k" "1M" "2M" "3M" "4M" "5M" "10M" "20M" "30M")
|
||||
|
||||
num=0
|
||||
|
||||
while((${num} < 11))
|
||||
do
|
||||
truncate -s ${size[$num]} ${size[$num]}.data
|
||||
let "num++"
|
||||
done
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,23 +0,0 @@
|
||||
Content-Type: multipart/mixed; boundary="===============1952501954711757490=="
|
||||
MIME-Version: 1.0
|
||||
From: z1343921421z@163.com
|
||||
To: z1789327568z@163.com
|
||||
Cc: z1789327568z@163.com
|
||||
Subject: =?utf-8?b?5pyx5piO5piOc3ViamVjdA==?=
|
||||
|
||||
--===============1952501954711757490==
|
||||
Content-Type: text/plain; charset="utf-8"
|
||||
MIME-Version: 1.0
|
||||
Content-Transfer-Encoding: base64
|
||||
|
||||
5pyx5piO5piOY29udGVudA==
|
||||
|
||||
--===============1952501954711757490==
|
||||
Content-Type: text/plain; charset="utf-8"
|
||||
MIME-Version: 1.0
|
||||
Content-Transfer-Encoding: base64
|
||||
Content-Disposition: attachment; filename="mail_attachment_name.txt"
|
||||
|
||||
Y2VzaGk=
|
||||
|
||||
--===============1952501954711757490==--
|
||||
Binary file not shown.
@@ -13,7 +13,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-cove
|
||||
|
||||
add_definitions(-g -W -Wall -std=c++11)
|
||||
#add_executable(gtest_hos_client gtest_hos_init_instance.cpp gtest_hos_get_instance.cpp gtest_hos_close_fd.cpp gtest_hos_open_fd.cpp)
|
||||
#add_executable(gtest_hos_client CheckHosClient.cpp gtest_hos_upload_buff.cpp)
|
||||
#add_executable(gtest_hos_client CheckHosClient.cpp gtest_hos_write.cpp)
|
||||
add_executable(gtest_hos_client ${SRCS})
|
||||
target_link_libraries(gtest_hos_client hos-client-cpp gtest gtest_main pthread)
|
||||
|
||||
|
||||
@@ -19,11 +19,52 @@ void CheckStructHosConfigT(hos_config_t *actual, hos_config_t *expect)
|
||||
EXPECT_EQ(actual->timeout, expect->timeout);
|
||||
}
|
||||
|
||||
void CheckStructHosFunc(hos_func_thread_t *actual, hos_func_thread_t *expect)
|
||||
void CheckStructFs2DataInfo(data_info_t *actual, data_info_t *expect, int thread_num)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < thread_num; i++)
|
||||
{
|
||||
if (actual->cache)
|
||||
{
|
||||
EXPECT_EQ(actual->cache[i], expect->cache[i]);
|
||||
}
|
||||
if (actual->rx_bytes)
|
||||
{
|
||||
EXPECT_EQ(actual->rx_bytes[i], expect->rx_bytes[i]);
|
||||
}
|
||||
if (actual->rx_pkts)
|
||||
{
|
||||
EXPECT_EQ(actual->rx_pkts[i], expect->rx_pkts[i]);
|
||||
}
|
||||
if (actual->tx_bytes)
|
||||
{
|
||||
EXPECT_EQ(actual->tx_bytes[i], expect->tx_bytes[i]);
|
||||
}
|
||||
if (actual->tx_pkts)
|
||||
{
|
||||
EXPECT_EQ(actual->tx_pkts[i], expect->tx_pkts[i]);
|
||||
}
|
||||
if (actual->tx_failed_bytes)
|
||||
{
|
||||
EXPECT_EQ(actual->tx_failed_bytes[i], expect->tx_failed_bytes[i]);
|
||||
}
|
||||
if (actual->tx_failed_pkts)
|
||||
{
|
||||
EXPECT_EQ(actual->tx_failed_pkts[i], expect->tx_failed_pkts[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckStructHosFunc(hos_func_thread_t *actual, hos_func_thread_t *expect, int thread_num)
|
||||
{
|
||||
//EXPECT_EQ(actual->fd_thread, expect->fd_thread);
|
||||
EXPECT_EQ(actual->fd_thread_status, expect->fd_thread_status);
|
||||
//CheckStructFs2Info(actual->fs2_info, expect->fs2_info);
|
||||
if (actual->fs2_info[0].reserved != NULL)
|
||||
{
|
||||
CheckStructFs2DataInfo((data_info_t *)actual->fs2_info[0].reserved,
|
||||
(data_info_t *)expect->fs2_info[0].reserved, thread_num);
|
||||
}
|
||||
EXPECT_EQ(actual->fs2_status, expect->fs2_status);
|
||||
//EXPECT_EQ(actual->fs2_thread, expect->fs2_thread);
|
||||
}
|
||||
@@ -40,7 +81,7 @@ void CheckStructGHosHandle(hos_client_handle_t *actual, hos_client_handle_t *exp
|
||||
//EXPECT_TRUE(actual->log != NULL);
|
||||
//EXPECT_TRUE(actual->S3Client != NULL);
|
||||
CheckStructHosConfigT(&actual->hos_config, &expect->hos_config);
|
||||
CheckStructHosFunc(&actual->hos_func, &expect->hos_func);
|
||||
CheckStructHosFunc(&actual->hos_func, &expect->hos_func, actual->hos_config.thread_num);
|
||||
}
|
||||
|
||||
void CheckStructGHosFdContext(hos_fd_context_t *actual, hos_fd_context_t *expect)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define HOS_CONF "../conf/default.conf"
|
||||
#define HOS_BUCKET "firewall_hos_bucket"
|
||||
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle, int thread_num)
|
||||
{
|
||||
memset(hos_handle, 0, sizeof(hos_client_handle_t));
|
||||
hos_handle->buckets.push_back(Aws::S3::Model::Bucket().WithName("session_record_hos_bucket"));
|
||||
@@ -23,10 +23,20 @@ static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
|
||||
memcpy(hos_handle->hos_config.log_path, "./hoslog", strlen("./hoslog")+1);
|
||||
hos_handle->hos_config.pool_thread_size = 10;
|
||||
hos_handle->hos_config.port = 9098;
|
||||
hos_handle->hos_config.thread_num = 1;
|
||||
hos_handle->hos_config.thread_num = thread_num;
|
||||
hos_handle->hos_config.timeout = 1000;
|
||||
hos_handle->hos_func.fd_thread_status = 0;
|
||||
hos_handle->hos_func.fs2_status = 1;
|
||||
|
||||
data_info_t *data_info = (data_info_t *)calloc(1, sizeof(data_info_t));
|
||||
hos_handle->hos_func.fs2_info[0].reserved = (void *)data_info;
|
||||
data_info->tx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->cache = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
}
|
||||
|
||||
static void gtest_hos_instance_init(hos_instance instance)
|
||||
@@ -61,12 +71,12 @@ TEST(hos_close_fd, normal)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
int thread_num = 2;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, thread_num);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
size_t fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, BUFF_MODE);
|
||||
@@ -88,6 +98,14 @@ TEST(hos_close_fd, normal)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -98,11 +116,12 @@ TEST(hos_close_fd, paramer_error)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
int thread_num = 2;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
gtest_hos_handle_init(&expect_hos_handle, thread_num);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
@@ -124,6 +143,14 @@ TEST(hos_close_fd, paramer_error)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -140,12 +167,12 @@ TEST(hos_close_fd, fd_not_exits)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
int thread_num = 2;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, thread_num);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_close_fd(7, 0);
|
||||
@@ -160,6 +187,14 @@ TEST(hos_close_fd, fd_not_exits)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define HOS_CONF "../conf/default.conf"
|
||||
#define HOS_BUCKET "firewall_hos_bucket"
|
||||
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle, int thread_num)
|
||||
{
|
||||
memset(hos_handle, 0, sizeof(hos_client_handle_t));
|
||||
hos_handle->buckets.push_back(Aws::S3::Model::Bucket().WithName("session_record_hos_bucket"));
|
||||
@@ -23,10 +23,20 @@ static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
|
||||
memcpy(hos_handle->hos_config.log_path, "./hoslog", strlen("./hoslog")+1);
|
||||
hos_handle->hos_config.pool_thread_size = 10;
|
||||
hos_handle->hos_config.port = 9098;
|
||||
hos_handle->hos_config.thread_num = 1;
|
||||
hos_handle->hos_config.thread_num = thread_num;
|
||||
hos_handle->hos_config.timeout = 1000;
|
||||
hos_handle->hos_func.fd_thread_status = 0;
|
||||
hos_handle->hos_func.fs2_status = 1;
|
||||
|
||||
data_info_t *data_info = (data_info_t *)calloc(1, sizeof(data_info_t));
|
||||
hos_handle->hos_func.fs2_info[0].reserved = (void *)data_info;
|
||||
data_info->tx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->cache = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
}
|
||||
|
||||
static void gtest_hos_instance_init(hos_instance instance)
|
||||
@@ -51,7 +61,7 @@ TEST(hos_get_instance, normal)
|
||||
hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
gtest_hos_handle_init(&expect_hos_handle, 1);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
hos_instance = hos_get_instance();
|
||||
@@ -71,6 +81,14 @@ TEST(hos_get_instance, normal)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
}
|
||||
|
||||
@@ -9,58 +9,84 @@
|
||||
#define HOS_CONF "../conf/default.conf"
|
||||
#define HOS_BUCKET "firewall_hos_bucket"
|
||||
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle, int thread_num)
|
||||
{
|
||||
memset(hos_handle, 0, sizeof(hos_client_handle_t));
|
||||
hos_handle->buckets.push_back(Aws::S3::Model::Bucket().WithName("session_record_hos_bucket"));
|
||||
hos_handle->buckets.push_back(Aws::S3::Model::Bucket().WithName("firewall_hos_bucket"));
|
||||
hos_handle->count = 1;
|
||||
memcpy(hos_handle->hos_config.accesskeyid, "default", strlen("default")+1);
|
||||
memcpy(hos_handle->hos_config.secretkey, "default", strlen("default")+1);
|
||||
hos_handle->hos_config.cache_count = 10;
|
||||
hos_handle->hos_config.cache_size = 102400;
|
||||
hos_handle->hos_config.fs2_fmt = 0;
|
||||
memcpy(hos_handle->hos_config.fs2_ip, "127.0.0.1", strlen("127.0.0.1")+1);
|
||||
memcpy(hos_handle->hos_config.fs2_path, "./log/hos_fs2_log", strlen("./log/hos_fs2_log")+1);
|
||||
hos_handle->hos_config.fs2_port = 10086;
|
||||
memcpy(hos_handle->hos_config.ip, "127.0.0.1", strlen("127.0.0.1")+1);
|
||||
hos_handle->hos_config.log_level = 30;
|
||||
memcpy(hos_handle->hos_config.log_path, "./hoslog", strlen("./hoslog")+1);
|
||||
hos_handle->hos_config.pool_thread_size = 10;
|
||||
hos_handle->hos_config.port = 9098;
|
||||
hos_handle->hos_config.thread_num = thread_num;
|
||||
hos_handle->hos_config.timeout = 1000;
|
||||
hos_handle->hos_func.fd_thread_status = 0;
|
||||
hos_handle->hos_func.fs2_status = 1;
|
||||
|
||||
data_info_t *data_info = (data_info_t *)calloc(1, sizeof(data_info_t));
|
||||
hos_handle->hos_func.fs2_info[0].reserved = (void *)data_info;
|
||||
data_info->tx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->cache = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
}
|
||||
|
||||
static void gtest_hos_instance_init(hos_instance instance)
|
||||
{
|
||||
memset(instance, 0, sizeof(hos_instance_s));
|
||||
instance->result = true;
|
||||
instance->error_code = 0;
|
||||
instance->error_message[0] ='\0';
|
||||
instance->hos_url_prefix = "http://127.0.0.1:9098/hos/";
|
||||
}
|
||||
|
||||
TEST(hos_init_instance, normal)
|
||||
{
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
|
||||
hos_instance_s expect_hos_instance;
|
||||
expect_hos_instance.result = true;
|
||||
expect_hos_instance.error_code = 0;
|
||||
expect_hos_instance.error_message[0] ='\0';
|
||||
expect_hos_instance.hos_url_prefix = "http://127.0.0.1:9098/hos/";
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
memset(&expect_hos_handle, 0, sizeof(expect_hos_handle));
|
||||
expect_hos_handle.buckets.push_back(Aws::S3::Model::Bucket().WithName("session_record_hos_bucket"));
|
||||
expect_hos_handle.buckets.push_back(Aws::S3::Model::Bucket().WithName("firewall_hos_bucket"));
|
||||
expect_hos_handle.count = 1;
|
||||
memcpy(expect_hos_handle.hos_config.accesskeyid, "default", strlen("default")+1);
|
||||
memcpy(expect_hos_handle.hos_config.secretkey, "default", strlen("default")+1);
|
||||
expect_hos_handle.hos_config.cache_count = 10;
|
||||
expect_hos_handle.hos_config.cache_size = 102400;
|
||||
expect_hos_handle.hos_config.fs2_fmt = 0;
|
||||
memcpy(expect_hos_handle.hos_config.fs2_ip, "127.0.0.1", strlen("127.0.0.1")+1);
|
||||
memcpy(expect_hos_handle.hos_config.fs2_path, "./log/hos_fs2_log", strlen("./log/hos_fs2_log")+1);
|
||||
expect_hos_handle.hos_config.fs2_port = 10086;
|
||||
memcpy(expect_hos_handle.hos_config.ip, "127.0.0.1", strlen("127.0.0.1")+1);
|
||||
expect_hos_handle.hos_config.log_level = 30;
|
||||
memcpy(expect_hos_handle.hos_config.log_path, "./hoslog", strlen("./hoslog")+1);
|
||||
expect_hos_handle.hos_config.pool_thread_size = 10;
|
||||
expect_hos_handle.hos_config.port = 9098;
|
||||
expect_hos_handle.hos_config.thread_num = 1;
|
||||
expect_hos_handle.hos_config.timeout = 1000;
|
||||
expect_hos_handle.hos_func.fd_thread_status = 0;
|
||||
expect_hos_handle.hos_func.fs2_status = 1;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle, 1);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_shutdown_instance();
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
expect_hos_instance.result = 0;
|
||||
expect_hos_instance.error_code = 0;
|
||||
expect_hos_instance.error_message[0] ='\0';
|
||||
expect_hos_instance.hos_url_prefix = NULL;
|
||||
memset(&expect_hos_instance, 0, sizeof(expect_hos_instance));
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
}
|
||||
|
||||
TEST(hos_init_instance, param_error)
|
||||
{
|
||||
hos_instance hos_instance = hos_init_instance(NULL, "hos_default_conf", 1, HOS_BUCKET);
|
||||
|
||||
hos_instance_s expect_hos_instance;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(NULL, "hos_default_conf", 1, HOS_BUCKET);
|
||||
expect_hos_instance.result = false;
|
||||
expect_hos_instance.error_code = HOS_PARAMETER_ERROR;
|
||||
const char *err_msg = "param error:conf_path:(null), module:hos_default_conf, thread_num:1, bucket:firewall_hos_bucket";
|
||||
@@ -71,50 +97,32 @@ TEST(hos_init_instance, param_error)
|
||||
|
||||
TEST(hos_init_instance, no_fs2)
|
||||
{
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_no_fs2_conf", 1, HOS_BUCKET);
|
||||
hos_instance_s expect_hos_instance;
|
||||
expect_hos_instance.result = true;
|
||||
expect_hos_instance.error_code = 0;
|
||||
expect_hos_instance.error_message[0] ='\0';
|
||||
expect_hos_instance.hos_url_prefix = "http://127.0.0.1:9098/hos/";
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
memset(&expect_hos_handle, 0, sizeof(expect_hos_handle));
|
||||
expect_hos_handle.buckets.push_back(Aws::S3::Model::Bucket().WithName("session_record_hos_bucket"));
|
||||
expect_hos_handle.buckets.push_back(Aws::S3::Model::Bucket().WithName("firewall_hos_bucket"));
|
||||
expect_hos_handle.count = 1;
|
||||
memcpy(expect_hos_handle.hos_config.accesskeyid, "default", strlen("default")+1);
|
||||
memcpy(expect_hos_handle.hos_config.secretkey, "default", strlen("default")+1);
|
||||
expect_hos_handle.hos_config.cache_count = 10;
|
||||
expect_hos_handle.hos_config.cache_size = 102400;
|
||||
expect_hos_handle.hos_config.fs2_fmt = 0;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_no_fs2_conf", 1, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle, 1);
|
||||
expect_hos_handle.hos_config.fs2_ip[0] = '\0';
|
||||
expect_hos_handle.hos_config.fs2_path[0] = '\0';
|
||||
//memcpy(expect_hos_handle.hos_config.fs2_ip, "127.0.0.1", strlen("127.0.0.1")+1);
|
||||
memcpy(expect_hos_handle.hos_config.fs2_path, "./log/hos_fs2_log", strlen("./log/hos_fs2_log")+1);
|
||||
//expect_hos_handle.hos_config.fs2_port = 10086;
|
||||
expect_hos_handle.hos_config.fs2_port = 0;
|
||||
memcpy(expect_hos_handle.hos_config.ip, "127.0.0.1", strlen("127.0.0.1")+1);
|
||||
expect_hos_handle.hos_config.log_level = 30;
|
||||
memcpy(expect_hos_handle.hos_config.log_path, "./hoslog", strlen("./hoslog")+1);
|
||||
expect_hos_handle.hos_config.pool_thread_size = 10;
|
||||
expect_hos_handle.hos_config.port = 9098;
|
||||
expect_hos_handle.hos_config.thread_num = 1;
|
||||
expect_hos_handle.hos_config.timeout = 1000;
|
||||
expect_hos_handle.hos_func.fd_thread_status = 0;
|
||||
expect_hos_handle.hos_func.fs2_status = 0;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_shutdown_instance();
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
expect_hos_instance.result = 0;
|
||||
expect_hos_instance.error_code = 0;
|
||||
expect_hos_instance.error_message[0] ='\0';
|
||||
expect_hos_instance.hos_url_prefix = NULL;
|
||||
memset(&expect_hos_instance, 0, sizeof(expect_hos_instance));
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define HOS_CONF "../conf/default.conf"
|
||||
#define HOS_BUCKET "firewall_hos_bucket"
|
||||
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle, int thread_num)
|
||||
{
|
||||
memset(hos_handle, 0, sizeof(hos_client_handle_t));
|
||||
hos_handle->buckets.push_back(Aws::S3::Model::Bucket().WithName("session_record_hos_bucket"));
|
||||
@@ -23,10 +23,20 @@ static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
|
||||
memcpy(hos_handle->hos_config.log_path, "./hoslog", strlen("./hoslog")+1);
|
||||
hos_handle->hos_config.pool_thread_size = 10;
|
||||
hos_handle->hos_config.port = 9098;
|
||||
hos_handle->hos_config.thread_num = 1;
|
||||
hos_handle->hos_config.thread_num = thread_num;
|
||||
hos_handle->hos_config.timeout = 1000;
|
||||
hos_handle->hos_func.fd_thread_status = 0;
|
||||
hos_handle->hos_func.fs2_status = 1;
|
||||
|
||||
data_info_t *data_info = (data_info_t *)calloc(1, sizeof(data_info_t));
|
||||
hos_handle->hos_func.fs2_info[0].reserved = (void *)data_info;
|
||||
data_info->tx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->cache = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
}
|
||||
|
||||
static void gtest_hos_instance_init(hos_instance instance)
|
||||
@@ -65,8 +75,7 @@ TEST(hos_open_fd, normal)
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, 2);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
size_t fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, BUFF_MODE);
|
||||
@@ -102,6 +111,14 @@ TEST(hos_open_fd, normal)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -115,8 +132,7 @@ TEST(hos_open_fd, paramer_error)
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, 2);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int fd = hos_open_fd(NULL, "object", NULL, NULL, 0, BUFF_MODE);
|
||||
@@ -132,6 +148,14 @@ TEST(hos_open_fd, paramer_error)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -145,8 +169,7 @@ TEST(hos_open_fd, over_threadnums)
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, 2);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int fd = hos_open_fd(HOS_CONF, "object", NULL, NULL, 3, BUFF_MODE);
|
||||
@@ -162,6 +185,14 @@ TEST(hos_open_fd, over_threadnums)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -177,8 +208,7 @@ TEST(hos_open_fd, fd_not_enough)
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, 2);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
gtest_hos_fd_init(&expect_fd_info);
|
||||
@@ -215,6 +245,14 @@ TEST(hos_open_fd, fd_not_enough)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#define HOS_CONF "../conf/default.conf"
|
||||
#define HOS_BUCKET "firewall_hos_bucket"
|
||||
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle, int thread_num)
|
||||
{
|
||||
memset(hos_handle, 0, sizeof(hos_client_handle_t));
|
||||
hos_handle->buckets.push_back(Aws::S3::Model::Bucket().WithName("session_record_hos_bucket"));
|
||||
@@ -28,10 +28,20 @@ static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
|
||||
memcpy(hos_handle->hos_config.log_path, "./hoslog", strlen("./hoslog")+1);
|
||||
hos_handle->hos_config.pool_thread_size = 10;
|
||||
hos_handle->hos_config.port = 9098;
|
||||
hos_handle->hos_config.thread_num = 1;
|
||||
hos_handle->hos_config.thread_num = thread_num;
|
||||
hos_handle->hos_config.timeout = 1000;
|
||||
hos_handle->hos_func.fd_thread_status = 0;
|
||||
hos_handle->hos_func.fs2_status = 1;
|
||||
|
||||
data_info_t *data_info = (data_info_t *)calloc(1, sizeof(data_info_t));
|
||||
hos_handle->hos_func.fs2_info[0].reserved = (void *)data_info;
|
||||
data_info->tx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->cache = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
}
|
||||
|
||||
static void gtest_hos_instance_init(hos_instance instance)
|
||||
@@ -53,7 +63,7 @@ TEST(hos_shutdown_instance, normal)
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
gtest_hos_handle_init(&expect_hos_handle, 1);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_shutdown_instance();
|
||||
@@ -63,6 +73,14 @@ TEST(hos_shutdown_instance, normal)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -83,7 +101,7 @@ TEST(hos_shutdown_instance, shutdown_more)
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
gtest_hos_handle_init(&expect_hos_handle, 1);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_shutdown_instance();
|
||||
@@ -93,6 +111,14 @@ TEST(hos_shutdown_instance, shutdown_more)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#define HOS_BUCKET "firewall_hos_bucket"
|
||||
#define HOS_BUFF "This is a googletest"
|
||||
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle, int thread_num)
|
||||
{
|
||||
memset(hos_handle, 0, sizeof(hos_client_handle_t));
|
||||
hos_handle->buckets.push_back(Aws::S3::Model::Bucket().WithName("session_record_hos_bucket"));
|
||||
@@ -24,10 +24,20 @@ static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
|
||||
memcpy(hos_handle->hos_config.log_path, "./hoslog", strlen("./hoslog")+1);
|
||||
hos_handle->hos_config.pool_thread_size = 10;
|
||||
hos_handle->hos_config.port = 9098;
|
||||
hos_handle->hos_config.thread_num = 1;
|
||||
hos_handle->hos_config.thread_num = thread_num;
|
||||
hos_handle->hos_config.timeout = 1000;
|
||||
hos_handle->hos_func.fd_thread_status = 0;
|
||||
hos_handle->hos_func.fs2_status = 1;
|
||||
|
||||
data_info_t *data_info = (data_info_t *)calloc(1, sizeof(data_info_t));
|
||||
hos_handle->hos_func.fs2_info[0].reserved = (void *)data_info;
|
||||
data_info->tx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->cache = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
}
|
||||
|
||||
static void gtest_hos_instance_init(hos_instance instance)
|
||||
@@ -62,16 +72,21 @@ TEST(hos_upload_buff, normal)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, 2);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_upload_buf(HOS_BUCKET, "object", HOS_BUFF, strlen(HOS_BUFF), hos_callback, (void *)"object", 0);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->rx_bytes[0] += strlen(HOS_BUFF);
|
||||
data_info->rx_pkts[0] += 1;
|
||||
data_info->tx_bytes[0] += strlen(HOS_BUFF);
|
||||
data_info->tx_pkts[0] += 1;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
@@ -82,6 +97,13 @@ TEST(hos_upload_buff, normal)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -92,16 +114,21 @@ TEST(hos_upload_buff, bucket_not_exits)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, 2);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_upload_buf("bucket_not_exits", "object", HOS_BUFF, strlen(HOS_BUFF), hos_bucket_not_exits_cb, (void *)"object", 0);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->rx_bytes[0] += strlen(HOS_BUFF);
|
||||
data_info->rx_pkts[0] += 1;
|
||||
data_info->tx_failed_bytes[0] += strlen(HOS_BUFF);
|
||||
data_info->tx_failed_pkts[0] += 1;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
@@ -112,6 +139,13 @@ TEST(hos_upload_buff, bucket_not_exits)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -122,12 +156,13 @@ TEST(hos_upload_buff, param_error)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, 2);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_upload_buf(NULL, "object", HOS_BUFF, strlen(HOS_BUFF), hos_callback, (void *)"object", 0);
|
||||
@@ -142,6 +177,13 @@ TEST(hos_upload_buff, param_error)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#define HOS_BUCKET "firewall_hos_bucket"
|
||||
#define HOS_BUFF "Makefile"
|
||||
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle, int thread_num)
|
||||
{
|
||||
memset(hos_handle, 0, sizeof(hos_client_handle_t));
|
||||
hos_handle->buckets.push_back(Aws::S3::Model::Bucket().WithName("session_record_hos_bucket"));
|
||||
@@ -24,10 +24,20 @@ static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
|
||||
memcpy(hos_handle->hos_config.log_path, "./hoslog", strlen("./hoslog")+1);
|
||||
hos_handle->hos_config.pool_thread_size = 10;
|
||||
hos_handle->hos_config.port = 9098;
|
||||
hos_handle->hos_config.thread_num = 1;
|
||||
hos_handle->hos_config.thread_num = thread_num;
|
||||
hos_handle->hos_config.timeout = 1000;
|
||||
hos_handle->hos_func.fd_thread_status = 0;
|
||||
hos_handle->hos_func.fs2_status = 1;
|
||||
|
||||
data_info_t *data_info = (data_info_t *)calloc(1, sizeof(data_info_t));
|
||||
hos_handle->hos_func.fs2_info[0].reserved = (void *)data_info;
|
||||
data_info->tx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->cache = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
}
|
||||
|
||||
static void gtest_hos_instance_init(hos_instance instance)
|
||||
@@ -62,16 +72,23 @@ TEST(hos_upload_file, normal)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, 2);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_upload_file(HOS_BUCKET, HOS_BUFF, hos_callback, (void *)HOS_BUFF, 0);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
struct stat buffer;
|
||||
stat(HOS_BUFF, &buffer);
|
||||
data_info->rx_bytes[0] += buffer.st_size;
|
||||
data_info->rx_pkts[0] += 1;
|
||||
data_info->tx_bytes[0] += buffer.st_size;
|
||||
data_info->tx_pkts[0] += 1;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
@@ -82,6 +99,13 @@ TEST(hos_upload_file, normal)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -92,12 +116,13 @@ TEST(hos_upload_file, param_error)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, 2);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_upload_file(NULL, "object", hos_callback, (void *)"object", 0);
|
||||
@@ -112,6 +137,13 @@ TEST(hos_upload_file, param_error)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -122,12 +154,13 @@ TEST(hos_upload_file, file_not_exits)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, 2);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_upload_file(HOS_BUCKET, "file_not_exits", hos_callback, (void *)"object", 0);
|
||||
@@ -142,6 +175,13 @@ TEST(hos_upload_file, file_not_exits)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -158,16 +198,23 @@ TEST(hos_upload_file, bucket_not_exits)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, 2);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_upload_file(HOS_CONF, HOS_CONF, hos_bucket_not_exits_cb, (void *)HOS_CONF, 0);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
struct stat buffer;
|
||||
stat(HOS_CONF, &buffer);
|
||||
data_info->rx_bytes[0] += buffer.st_size;
|
||||
data_info->rx_pkts[0] += 1;
|
||||
data_info->tx_failed_bytes[0] += buffer.st_size;
|
||||
data_info->tx_failed_pkts[0] += 1;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
@@ -178,6 +225,13 @@ TEST(hos_upload_file, bucket_not_exits)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#define HOS_CONF "../conf/default.conf"
|
||||
#define HOS_BUCKET "firewall_hos_bucket"
|
||||
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle, int thread_num)
|
||||
{
|
||||
memset(hos_handle, 0, sizeof(hos_client_handle_t));
|
||||
hos_handle->buckets.push_back(Aws::S3::Model::Bucket().WithName("session_record_hos_bucket"));
|
||||
@@ -28,10 +28,20 @@ static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
|
||||
memcpy(hos_handle->hos_config.log_path, "./hoslog", strlen("./hoslog")+1);
|
||||
hos_handle->hos_config.pool_thread_size = 10;
|
||||
hos_handle->hos_config.port = 9098;
|
||||
hos_handle->hos_config.thread_num = 1;
|
||||
hos_handle->hos_config.thread_num = thread_num;
|
||||
hos_handle->hos_config.timeout = 1000;
|
||||
hos_handle->hos_func.fd_thread_status = 0;
|
||||
hos_handle->hos_func.fs2_status = 1;
|
||||
|
||||
data_info_t *data_info = (data_info_t *)calloc(1, sizeof(data_info_t));
|
||||
hos_handle->hos_func.fs2_info[0].reserved = (void *)data_info;
|
||||
data_info->tx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->cache = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
}
|
||||
|
||||
static void gtest_hos_instance_init(hos_instance instance)
|
||||
@@ -52,8 +62,7 @@ TEST(hos_verify_bucket, normal)
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=1;
|
||||
gtest_hos_handle_init(&expect_hos_handle, 1);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
bool result = hos_verify_bucket(HOS_BUCKET);
|
||||
@@ -68,6 +77,14 @@ TEST(hos_verify_bucket, normal)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -82,8 +99,7 @@ TEST(hos_verify_bucket, not_exits)
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=1;
|
||||
gtest_hos_handle_init(&expect_hos_handle, 1);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
bool result = hos_verify_bucket("hos_not_exits_bucket");
|
||||
@@ -98,6 +114,14 @@ TEST(hos_verify_bucket, not_exits)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define HOS_BUFF "This a googleTest"
|
||||
#define HOS_FILE "../conf/default.conf"
|
||||
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
|
||||
static void gtest_hos_handle_init(hos_client_handle_t *hos_handle, int thread_num)
|
||||
{
|
||||
memset(hos_handle, 0, sizeof(hos_client_handle_t));
|
||||
hos_handle->buckets.push_back(Aws::S3::Model::Bucket().WithName("session_record_hos_bucket"));
|
||||
@@ -25,10 +25,20 @@ static void gtest_hos_handle_init(hos_client_handle_t *hos_handle)
|
||||
memcpy(hos_handle->hos_config.log_path, "./hoslog", strlen("./hoslog")+1);
|
||||
hos_handle->hos_config.pool_thread_size = 10;
|
||||
hos_handle->hos_config.port = 9098;
|
||||
hos_handle->hos_config.thread_num = 1;
|
||||
hos_handle->hos_config.thread_num = thread_num;
|
||||
hos_handle->hos_config.timeout = 1000;
|
||||
hos_handle->hos_func.fd_thread_status = 0;
|
||||
hos_handle->hos_func.fs2_status = 1;
|
||||
|
||||
data_info_t *data_info = (data_info_t *)calloc(1, sizeof(data_info_t));
|
||||
hos_handle->hos_func.fs2_info[0].reserved = (void *)data_info;
|
||||
data_info->tx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->rx_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_pkts = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->tx_failed_bytes = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
data_info->cache = (size_t *)calloc(thread_num, sizeof(size_t));
|
||||
}
|
||||
|
||||
static void gtest_hos_instance_init(hos_instance instance)
|
||||
@@ -105,15 +115,17 @@ static void hos_bucket_not_exits_cb(bool result, const char *bucket, const char
|
||||
|
||||
TEST(hos_write, normal)
|
||||
{
|
||||
int thread_num = 3;
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info[3];
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 3, HOS_BUCKET);
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=3;
|
||||
gtest_hos_handle_init(&expect_hos_handle, thread_num);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
size_t fd = hos_open_fd(HOS_BUCKET, "object_buff", hos_write_buff_cb, (void *)"object_buff", 0, BUFF_MODE);
|
||||
@@ -129,10 +141,15 @@ TEST(hos_write, normal)
|
||||
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF), 0);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
expect_fd_info[0].fd_status = 2;
|
||||
data_info->rx_bytes[0] += strlen(HOS_BUFF);
|
||||
data_info->rx_pkts[0] +=1;
|
||||
data_info->tx_bytes[0] += strlen(HOS_BUFF);
|
||||
data_info->tx_pkts[0] += 1;
|
||||
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
//CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
|
||||
EXPECT_TRUE(g_fd_context[0][0].cache == NULL);
|
||||
//EXPECT_TRUE(g_fd_context[0][0].cache == NULL);
|
||||
|
||||
size_t fd1 = hos_open_fd(HOS_BUCKET, "object_append", hos_write_append_cb, (void *)"object_append", 1, BUFF_MODE | APPEND_MODE);
|
||||
EXPECT_EQ(fd1, 3);
|
||||
@@ -147,6 +164,9 @@ TEST(hos_write, normal)
|
||||
|
||||
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->rx_bytes[1] += strlen(HOS_BUFF);
|
||||
data_info->rx_pkts[1] +=1;
|
||||
data_info->cache[1] += strlen(HOS_BUFF);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
|
||||
@@ -156,6 +176,9 @@ TEST(hos_write, normal)
|
||||
|
||||
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->rx_bytes[1] += strlen(HOS_BUFF);
|
||||
data_info->rx_pkts[1] +=1;
|
||||
data_info->cache[1] += strlen(HOS_BUFF);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
|
||||
@@ -174,23 +197,32 @@ TEST(hos_write, normal)
|
||||
expect_fd_info[2].mode = FILE_MODE;
|
||||
CheckStructGHosFdContext(g_fd_context[2], &expect_fd_info[2]);
|
||||
|
||||
ret = hos_write(fd2, HOS_FILE, strlen(HOS_CONF), 0);
|
||||
ret = hos_write(fd2, HOS_FILE, strlen(HOS_CONF), 2);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
struct stat buffer;
|
||||
stat(HOS_CONF, &buffer);
|
||||
data_info->rx_bytes[2] += buffer.st_size;
|
||||
data_info->rx_pkts[2] +=1;
|
||||
data_info->tx_bytes[2] += buffer.st_size;
|
||||
data_info->tx_pkts[2] += 1;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
expect_fd_info[2].fd_status = 2;
|
||||
//CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
|
||||
EXPECT_TRUE(g_fd_context[1][0].cache != NULL);
|
||||
//EXPECT_TRUE(g_fd_context[2][0].cache != NULL);
|
||||
|
||||
ret = hos_close_fd(fd, 0);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
ret = hos_close_fd(fd1, 0);
|
||||
ret = hos_close_fd(fd1, 1);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->tx_bytes[1] += data_info->cache[1];
|
||||
data_info->tx_pkts[1] += 1;
|
||||
data_info->cache[1] = 0;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
ret = hos_close_fd(fd2, 0);
|
||||
ret = hos_close_fd(fd2, 2);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
@@ -202,6 +234,13 @@ TEST(hos_write, normal)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -212,12 +251,14 @@ TEST(hos_write, bucket_not_exits)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info[3];
|
||||
int thread_num = 3;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 3, HOS_BUCKET);
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=3;
|
||||
gtest_hos_handle_init(&expect_hos_handle, thread_num);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
size_t fd = hos_open_fd("bucket_not_exits", "object_buff", hos_bucket_not_exits_cb, (void *)"object_buff", 0, BUFF_MODE);
|
||||
@@ -233,12 +274,12 @@ TEST(hos_write, bucket_not_exits)
|
||||
|
||||
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF), 0);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->rx_bytes[0] = strlen(HOS_BUFF);
|
||||
data_info->rx_pkts[0] += 1;
|
||||
data_info->tx_failed_bytes[0] = strlen(HOS_BUFF);
|
||||
data_info->tx_failed_pkts[0] += 1;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
//expect_fd_info[0].cache_rest -= strlen(HOS_BUFF);
|
||||
//expect_fd_info[0].cache_count--;
|
||||
expect_fd_info[0].fd_status = 2;
|
||||
//CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
|
||||
EXPECT_TRUE(g_fd_context[0][0].cache == NULL);
|
||||
|
||||
size_t fd1 = hos_open_fd("bucket_not_exits", "object_append", hos_bucket_not_exits_cb, (void *)"object_append", 1, BUFF_MODE | APPEND_MODE);
|
||||
@@ -255,6 +296,9 @@ TEST(hos_write, bucket_not_exits)
|
||||
|
||||
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->cache[1] += strlen(HOS_BUFF);
|
||||
data_info->rx_bytes[1] += strlen(HOS_BUFF);
|
||||
data_info->rx_pkts[1] += 1;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
|
||||
@@ -264,6 +308,9 @@ TEST(hos_write, bucket_not_exits)
|
||||
|
||||
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->cache[1] += strlen(HOS_BUFF);
|
||||
data_info->rx_bytes[1] += strlen(HOS_BUFF);
|
||||
data_info->rx_pkts[1] += 1;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
|
||||
@@ -286,6 +333,12 @@ TEST(hos_write, bucket_not_exits)
|
||||
ret = hos_write(fd2, HOS_FILE, strlen(HOS_CONF), 2);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
expect_fd_info[2].fd_status = 2;
|
||||
struct stat buffer;
|
||||
stat(HOS_CONF, &buffer);
|
||||
data_info->rx_bytes[2] += buffer.st_size;
|
||||
data_info->rx_pkts[2] += 1;
|
||||
data_info->tx_failed_bytes[2] += buffer.st_size;
|
||||
data_info->tx_failed_pkts[2] += 1;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
//CheckStructGHosFdContext(g_fd_context[2], &expect_fd_info[2]);
|
||||
@@ -295,11 +348,14 @@ TEST(hos_write, bucket_not_exits)
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
ret = hos_close_fd(fd1, 0);
|
||||
ret = hos_close_fd(fd1, 1);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->tx_failed_bytes[1] += data_info->cache[1];
|
||||
data_info->tx_failed_pkts[1] += 1;
|
||||
data_info->cache[1] = 0;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
ret = hos_close_fd(fd2, 0);
|
||||
ret = hos_close_fd(fd2, 2);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
@@ -311,6 +367,13 @@ TEST(hos_write, bucket_not_exits)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -321,12 +384,14 @@ TEST(hos_write, sync_mode)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info[3];
|
||||
int thread_num = 3;
|
||||
data_info_t * data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_sync_conf", 3, HOS_BUCKET);
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_sync_conf", thread_num, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=3;
|
||||
gtest_hos_handle_init(&expect_hos_handle, thread_num);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
expect_hos_handle.hos_config.pool_thread_size = 0;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
@@ -340,6 +405,10 @@ TEST(hos_write, sync_mode)
|
||||
|
||||
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF), 0);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->rx_bytes[0] += strlen(HOS_BUFF);
|
||||
data_info->rx_pkts[0] += 1;
|
||||
data_info->tx_bytes[0] += strlen(HOS_BUFF);
|
||||
data_info->tx_pkts[0] += 1;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
//CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
|
||||
@@ -356,6 +425,9 @@ TEST(hos_write, sync_mode)
|
||||
|
||||
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->rx_bytes[1] += strlen(HOS_BUFF);
|
||||
data_info->rx_pkts[1] += 1;
|
||||
data_info->cache[1] += strlen(HOS_BUFF);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
expect_fd_info[1].cache_count--;
|
||||
@@ -365,6 +437,9 @@ TEST(hos_write, sync_mode)
|
||||
|
||||
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->rx_bytes[1] += strlen(HOS_BUFF);
|
||||
data_info->rx_pkts[1] += 1;
|
||||
data_info->cache[1] += strlen(HOS_BUFF);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
expect_fd_info[1].cache_count--;
|
||||
@@ -382,6 +457,12 @@ TEST(hos_write, sync_mode)
|
||||
CheckStructGHosFdContext(g_fd_context[2], &expect_fd_info[2]);
|
||||
ret = hos_write(fd2, HOS_FILE, strlen(HOS_BUFF), 2);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
struct stat buffer;
|
||||
stat(HOS_CONF, &buffer);
|
||||
data_info->rx_bytes[2] += buffer.st_size;
|
||||
data_info->rx_pkts[2] += 1;
|
||||
data_info->tx_bytes[2] += buffer.st_size;
|
||||
data_info->tx_pkts[2] += 1;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
expect_fd_info[2].fd_status = 2;
|
||||
@@ -392,11 +473,14 @@ TEST(hos_write, sync_mode)
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
ret = hos_close_fd(fd1, 0);
|
||||
ret = hos_close_fd(fd1, 1);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->tx_bytes[1] += data_info->cache[1];
|
||||
data_info->tx_pkts[1] += 1;
|
||||
data_info->cache[1] = 0;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
ret = hos_close_fd(fd2, 0);
|
||||
ret = hos_close_fd(fd2, 2);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
@@ -408,6 +492,13 @@ TEST(hos_write, sync_mode)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -418,43 +509,54 @@ TEST(hos_write, sync_mode_bucket_not_exits)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info[3];
|
||||
int thread_num = 3;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_sync_conf", 3, HOS_BUCKET);
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_sync_conf", thread_num, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=3;
|
||||
gtest_hos_handle_init(&expect_hos_handle, thread_num);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
expect_hos_handle.hos_config.pool_thread_size = 0;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
size_t fd = hos_open_fd(HOS_BUCKET, "object_buff", NULL, NULL, 0, BUFF_MODE);
|
||||
size_t fd = hos_open_fd(HOS_CONF, "object_buff", NULL, NULL, 0, BUFF_MODE);
|
||||
EXPECT_EQ(fd, 3);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
gtest_hos_fd_init(&expect_fd_info[0]);
|
||||
expect_fd_info[0].object = (char *)"object_buff";
|
||||
expect_fd_info[0].mode = BUFF_MODE;
|
||||
expect_fd_info[0].bucket = (char *)HOS_CONF;
|
||||
CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
|
||||
|
||||
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_CONF), 0);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF), 0);
|
||||
EXPECT_EQ(ret, NO_SUCH_BUCKET);
|
||||
expect_fd_info[0].fd_status = 2;
|
||||
data_info->rx_bytes[0] += strlen(HOS_BUFF);
|
||||
data_info->rx_pkts[0] += 1;
|
||||
data_info->tx_failed_bytes[0] += strlen(HOS_BUFF);
|
||||
data_info->tx_failed_pkts[0] += 1;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
//CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[0]);
|
||||
EXPECT_TRUE(g_fd_context[0][0].cache == NULL);
|
||||
|
||||
size_t fd1 = hos_open_fd(HOS_BUCKET, "object_append", NULL, NULL, 1, BUFF_MODE | APPEND_MODE);
|
||||
size_t fd1 = hos_open_fd(HOS_CONF, "object_append", NULL, NULL, 1, BUFF_MODE | APPEND_MODE);
|
||||
EXPECT_EQ(fd1, 3);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
gtest_hos_fd_init(&expect_fd_info[1]);
|
||||
expect_fd_info[1].object = (char *)"object_append";
|
||||
expect_fd_info[1].mode = BUFF_MODE | APPEND_MODE;
|
||||
expect_fd_info[1].bucket = (char *)HOS_CONF;
|
||||
CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
|
||||
|
||||
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->rx_bytes[1] += strlen(HOS_BUFF);
|
||||
data_info->rx_pkts[1] += 1;
|
||||
data_info->cache[1] += strlen(HOS_BUFF);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
expect_fd_info[1].cache_count--;
|
||||
@@ -463,6 +565,10 @@ TEST(hos_write, sync_mode_bucket_not_exits)
|
||||
EXPECT_TRUE(g_fd_context[1][0].cache != NULL);
|
||||
|
||||
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF), 1);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->rx_bytes[1] += strlen(HOS_BUFF);
|
||||
data_info->rx_pkts[1] += 1;
|
||||
data_info->cache[1] += strlen(HOS_BUFF);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
expect_fd_info[1].cache_count--;
|
||||
@@ -470,32 +576,41 @@ TEST(hos_write, sync_mode_bucket_not_exits)
|
||||
CheckStructGHosFdContext(g_fd_context[1], &expect_fd_info[1]);
|
||||
EXPECT_TRUE(g_fd_context[1][0].cache != NULL);
|
||||
|
||||
size_t fd2 = hos_open_fd(HOS_BUCKET, "object_file", NULL, NULL, 2, FILE_MODE);
|
||||
size_t fd2 = hos_open_fd(HOS_CONF, "object_file", NULL, NULL, 2, FILE_MODE);
|
||||
EXPECT_EQ(fd2, 3);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
gtest_hos_fd_init(&expect_fd_info[2]);
|
||||
expect_fd_info[2].object = (char *)"object_file";
|
||||
expect_fd_info[2].mode = FILE_MODE;
|
||||
expect_fd_info[2].bucket = (char *)HOS_CONF;
|
||||
CheckStructGHosFdContext(g_fd_context[2], &expect_fd_info[2]);
|
||||
ret = hos_write(fd2, HOS_FILE, strlen(HOS_FILE), 2);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
EXPECT_EQ(ret, NO_SUCH_BUCKET);
|
||||
struct stat buffer;
|
||||
stat(HOS_CONF, &buffer);
|
||||
data_info->rx_bytes[2] += buffer.st_size;
|
||||
data_info->rx_pkts[2] += 1;
|
||||
data_info->tx_failed_bytes[2] += buffer.st_size;
|
||||
data_info->tx_failed_pkts[2] += 1;
|
||||
expect_fd_info[2].fd_status = 2;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
//CheckStructGHosFdContext(g_fd_context[2], &expect_fd_info[2]);
|
||||
EXPECT_TRUE(g_fd_context[2][0].cache == NULL);
|
||||
|
||||
|
||||
ret = hos_close_fd(fd, 0);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
ret = hos_close_fd(fd1, 0);
|
||||
ret = hos_close_fd(fd1, 1);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->tx_failed_bytes[1] += data_info->cache[1];
|
||||
data_info->tx_failed_pkts[1] += 1;
|
||||
data_info->cache[1] = 0;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
ret = hos_close_fd(fd2, 0);
|
||||
ret = hos_close_fd(fd2, 2);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
@@ -507,6 +622,13 @@ TEST(hos_write, sync_mode_bucket_not_exits)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -517,12 +639,12 @@ TEST(hos_write, paramer_error)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
int thread_num = 2;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, thread_num);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int fd = hos_open_fd(HOS_BUCKET, "object_buff", hos_callback, NULL, 0, BUFF_MODE);
|
||||
@@ -535,7 +657,7 @@ TEST(hos_write, paramer_error)
|
||||
expect_fd_info.mode = BUFF_MODE;
|
||||
CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info);
|
||||
|
||||
int ret = hos_write(0, HOS_BUFF, strlen(HOS_CONF), 0);
|
||||
int ret = hos_write(0, HOS_BUFF, strlen(HOS_BUFF), 0);
|
||||
EXPECT_EQ(ret, HOS_PARAMETER_ERROR);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
@@ -548,6 +670,14 @@ TEST(hos_write, paramer_error)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -558,12 +688,12 @@ TEST(hos_write, fd_not_find)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
int thread_num = 2;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, thread_num);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int ret = hos_write(3, HOS_BUFF, strlen(HOS_CONF), 0);
|
||||
@@ -579,6 +709,14 @@ TEST(hos_write, fd_not_find)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -589,12 +727,12 @@ TEST(hos_write, file_not_exit)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
int thread_num = 2;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, thread_num);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int fd = hos_open_fd(HOS_CONF, "object_file", NULL, NULL, 0, FILE_MODE);
|
||||
@@ -619,6 +757,14 @@ TEST(hos_write, file_not_exit)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -629,12 +775,12 @@ TEST(hos_write, over_threadnums)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info;
|
||||
int thread_num = 2;
|
||||
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2, HOS_BUCKET);
|
||||
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET);
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=2;
|
||||
gtest_hos_handle_init(&expect_hos_handle, thread_num);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
int fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, BUFF_MODE);
|
||||
@@ -658,6 +804,14 @@ TEST(hos_write, over_threadnums)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
@@ -668,6 +822,7 @@ TEST(hos_write, not_init_instance)
|
||||
int ret = hos_write(3, HOS_BUFF, strlen(HOS_CONF), 0);
|
||||
EXPECT_EQ(ret, HOS_INSTANCE_NOT_INIT);
|
||||
}
|
||||
|
||||
static void *hos_function(void *ptr)
|
||||
{
|
||||
#define HOS_FD_NUMS_LOCAL 20
|
||||
@@ -681,22 +836,24 @@ static void *hos_function(void *ptr)
|
||||
hos_instance_s expect_hos_instance;
|
||||
hos_client_handle_t expect_hos_handle;
|
||||
hos_fd_context_t expect_fd_info[32][20];
|
||||
int thread_num = 32;
|
||||
data_info_t *data_info = NULL;
|
||||
|
||||
{
|
||||
hos_instance = hos_get_instance();
|
||||
if (hos_instance->result == false)
|
||||
{
|
||||
hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 32, HOS_BUCKET);
|
||||
hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num, HOS_BUCKET);
|
||||
}
|
||||
}
|
||||
gtest_hos_instance_init(&expect_hos_instance);
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
gtest_hos_handle_init(&expect_hos_handle);
|
||||
expect_hos_handle.hos_config.thread_num=32;
|
||||
gtest_hos_handle_init(&expect_hos_handle, thread_num);
|
||||
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info[0].reserved;
|
||||
expect_hos_handle.count = thread_id + 1;
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
|
||||
for (i = 0; i < 20; i++)
|
||||
for (i = 0; i < HOS_FD_NUMS_LOCAL; i++)
|
||||
{
|
||||
snprintf(object[i], 1024, "object_%lu_%d", thread_id, i);
|
||||
fd[i] = hos_open_fd(HOS_BUCKET, object[i], hos_callback, object[i], 0, BUFF_MODE | APPEND_MODE);
|
||||
@@ -710,10 +867,13 @@ static void *hos_function(void *ptr)
|
||||
CheckStructGHosFdContext(g_fd_context[0], &expect_fd_info[thread_id][i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 20; i++)
|
||||
for (i = 0; i < HOS_FD_NUMS_LOCAL; i++)
|
||||
{
|
||||
ret = hos_write(fd[i], HOS_BUFF, strlen(HOS_BUFF), i);
|
||||
EXPECT_EQ(ret, HOS_CLIENT_OK);
|
||||
data_info->cache[i] = strlen(HOS_BUFF);
|
||||
data_info->rx_bytes[i] = strlen(HOS_BUFF);
|
||||
data_info->rx_pkts[i] += 1;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
expect_fd_info[thread_id][i].cache_rest -= strlen(HOS_BUFF);
|
||||
@@ -722,10 +882,13 @@ static void *hos_function(void *ptr)
|
||||
EXPECT_TRUE(g_fd_context[1][0].cache != NULL);
|
||||
}
|
||||
|
||||
for (i = 0; i < 20; i++)
|
||||
for (i = 0; i < HOS_FD_NUMS_LOCAL; i++)
|
||||
{
|
||||
ret = hos_close_fd(fd[i], i);
|
||||
EXPECT_EQ(ret, 0);
|
||||
data_info->rx_bytes[i] = data_info->cache[i];
|
||||
data_info->rx_pkts[i] += 1;
|
||||
data_info->cache[i] = 0;
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
}
|
||||
@@ -737,6 +900,13 @@ static void *hos_function(void *ptr)
|
||||
CheckHosInstance(hos_instance, &expect_hos_instance);
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
free(data_info->cache);
|
||||
free(data_info->rx_bytes);
|
||||
free(data_info->rx_pkts);
|
||||
free(data_info->tx_bytes);
|
||||
free(data_info->tx_pkts);
|
||||
free(data_info->tx_failed_bytes);
|
||||
free(data_info->tx_failed_pkts);
|
||||
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
|
||||
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
|
||||
EXPECT_EQ((void *)g_fd_context, (void *)NULL);
|
||||
|
||||
@@ -6,6 +6,7 @@ include_directories(${CMAKE_INSTALL_PREFIX}/include/MESA)
|
||||
link_directories(${CMAKE_INSTALL_PREFIX}/lib)
|
||||
|
||||
option(HOS_MOCK "If enabled, the SDK will be built using a MOCK .cpp file for S3." OFF)
|
||||
option(HOS_MESA_LOG "If enabled, the SDK will be built using a MOCK .cpp file for S3." ON)
|
||||
|
||||
file(GLOB HOS_HEADERS "*.h")
|
||||
file(GLOB HOS_SOURCE "*.cpp")
|
||||
@@ -15,6 +16,10 @@ if (HOS_MOCK)
|
||||
file(GLOB HOS_MOCK_SOURCE "mock/hos_mock.cpp")
|
||||
endif()
|
||||
|
||||
if (HOS_MESA_LOG)
|
||||
add_definitions(-DHOS_MESA_LOG)
|
||||
endif()
|
||||
|
||||
file(GLOB HOS_SRC
|
||||
${HOS_SOURCE}
|
||||
${HOS_HEADERS}
|
||||
|
||||
@@ -8,6 +8,7 @@ extern "C"
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
}
|
||||
#include <aws/s3/model/PutObjectRequest.h>
|
||||
#include <aws/s3/model/CreateBucketRequest.h>
|
||||
@@ -21,9 +22,26 @@ extern "C"
|
||||
#include "mock/hos_mock.h"
|
||||
#endif
|
||||
#include "hos_client.h"
|
||||
#include "MESA_handle_logger.h"
|
||||
#include "MESA_prof_load.h"
|
||||
#include "hos_common.h"
|
||||
#ifdef HOS_MESA_LOG
|
||||
#include "MESA_handle_logger.h"
|
||||
#else
|
||||
#define RLOG_LV_DEBUG 10
|
||||
#define RLOG_LV_INFO 20
|
||||
#define RLOG_LV_FATAL 30
|
||||
|
||||
#define MESA_create_runtime_log_handle(path, lv) \
|
||||
(void *)fopen((path), "a+")
|
||||
#define MESA_destroy_runtime_log_handle(handle) \
|
||||
fclose((FILE *)handle)
|
||||
#define MESA_HANDLE_RUNTIME_LOG(handle, lv, mod, fmt, args...) \
|
||||
do{ \
|
||||
fprintf(((FILE *) handle), "line:%d, level:%d, module:%s, ", __LINE__, lv, mod); \
|
||||
fprintf(((FILE *) handle), fmt, ##args);\
|
||||
fprintf(((FILE *) handle), "\n");\
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
struct hos_instance_s g_hos_instance;
|
||||
hos_client_handle_t g_hos_handle;//一个进程只允许有一个g_hos_handle
|
||||
@@ -58,13 +76,30 @@ static size_t hash_get_min_free_fd(size_t thread_id)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int hos_delete_fd(size_t fd, size_t thread_id)
|
||||
static int hos_delete_fd(size_t thread_id, hos_fd_context_t *context)
|
||||
{
|
||||
if (fd == 0)
|
||||
if (context == NULL)
|
||||
{
|
||||
return HOS_PARAMETER_ERROR;
|
||||
}
|
||||
delete_context_by_fd(&g_fd_context[thread_id], fd);
|
||||
size_t fd = context->fd;
|
||||
|
||||
if (context)
|
||||
{
|
||||
if (context->bucket)
|
||||
{
|
||||
free(context->bucket);
|
||||
context->bucket = NULL;
|
||||
}
|
||||
if (context->object)
|
||||
{
|
||||
free(context->object);
|
||||
context->object = NULL;
|
||||
}
|
||||
HASH_DEL(g_fd_context[thread_id], context);
|
||||
free(context);
|
||||
}
|
||||
|
||||
g_fd_info[thread_id][fd] = 0;
|
||||
g_fd_info[thread_id][HOS_FD_FREE]++;
|
||||
g_fd_info[thread_id][HOS_FD_INJECT]--;
|
||||
@@ -90,8 +125,8 @@ static void PutObjectAsyncFinished(const Aws::S3::S3Client* S3Client,
|
||||
}
|
||||
if (a_fd_context == NULL)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
|
||||
"Not find the info of [thread_id:%d fd:%d]", thread_id, fd);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
|
||||
"error: Not find the info of [thread_id:%lu fd:%lu]", thread_id, fd);
|
||||
|
||||
if (hos_func->fs2_info[FS2_DATA_FLOW_STATE].fs2_handle && hos_func->fs2_info[FS2_DATA_FLOW_STATE].reserved)
|
||||
{
|
||||
@@ -99,15 +134,15 @@ static void PutObjectAsyncFinished(const Aws::S3::S3Client* S3Client,
|
||||
data_info->tx_failed_pkts[thread_id]++;
|
||||
data_info->tx_failed_bytes[thread_id] += stream_len;
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
bool result = outcome.IsSuccess();
|
||||
if (!result)
|
||||
{
|
||||
error = outcome.GetError().GetMessage().c_str();
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
|
||||
"[%s:%s] upload failed. error:%s",a_fd_context->bucket, a_fd_context->object, error);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
|
||||
"error: [%s:%s] upload failed. error:%s", a_fd_context->bucket, a_fd_context->object, error);
|
||||
|
||||
if (hos_func->fs2_info[FS2_DATA_FLOW_STATE].fs2_handle && hos_func->fs2_info[FS2_DATA_FLOW_STATE].reserved)
|
||||
{
|
||||
@@ -123,15 +158,15 @@ static void PutObjectAsyncFinished(const Aws::S3::S3Client* S3Client,
|
||||
data_info = (data_info_t *)hos_func->fs2_info[FS2_DATA_FLOW_STATE].reserved;
|
||||
data_info->tx_pkts[thread_id]++;
|
||||
data_info->tx_bytes[thread_id] += stream_len;
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"[%s:%s] upload success. tx_pkts:%d, tx_bytes:%d",
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"debug: [%s:%s] upload success. tx_pkts:%lu, tx_bytes:%lu",
|
||||
a_fd_context->bucket, a_fd_context->object,
|
||||
data_info->tx_pkts[thread_id], data_info->tx_bytes[thread_id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"[%s:%s] upload success. stream size:%d", a_fd_context->bucket, a_fd_context->object, stream_len);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"debug: [%s:%s] upload success. stream size:%lu", a_fd_context->bucket, a_fd_context->object, stream_len);
|
||||
}
|
||||
}
|
||||
put_finished_callback callback = (put_finished_callback)a_fd_context->callback;
|
||||
@@ -147,6 +182,8 @@ static void PutObjectAsyncFinished(const Aws::S3::S3Client* S3Client,
|
||||
hos_close_fd(fd, thread_id);
|
||||
}
|
||||
}
|
||||
g_hos_handle.task_num[thread_id]--;
|
||||
}
|
||||
|
||||
static void hos_client_create()
|
||||
{
|
||||
@@ -174,7 +211,8 @@ static void hos_client_create()
|
||||
if (hos_conf->pool_thread_size > 0)
|
||||
{
|
||||
//异步模式
|
||||
config.executor = std::shared_ptr<Aws::Utils::Threading::PooledThreadExecutor>(std::make_shared<Aws::Utils::Threading::PooledThreadExecutor>(hos_conf->pool_thread_size, Aws::Utils::Threading::OverflowPolicy::REJECT_IMMEDIATELY)); //支持线程池
|
||||
//config.executor = std::shared_ptr<Aws::Utils::Threading::PooledThreadExecutor>(std::make_shared<Aws::Utils::Threading::PooledThreadExecutor>(hos_conf->pool_thread_size, Aws::Utils::Threading::OverflowPolicy::REJECT_IMMEDIATELY)); //支持线程池
|
||||
config.executor = std::shared_ptr<Aws::Utils::Threading::PooledThreadExecutor>(std::make_shared<Aws::Utils::Threading::PooledThreadExecutor>(hos_conf->pool_thread_size, Aws::Utils::Threading::OverflowPolicy::QUEUE_TASKS_EVENLY_ACCROSS_THREADS)); //支持线程池
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -197,13 +235,14 @@ static void hos_client_create()
|
||||
g_hos_instance.error_code = (size_t)outcome.GetError().GetErrorType() + 1;
|
||||
snprintf(g_hos_instance.error_message, HOS_ERROR_MESSAGE_SIZE, outcome.GetError().GetMessage().c_str());
|
||||
g_hos_instance.result = false;
|
||||
MESA_handle_runtime_log(log, RLOG_LV_FATAL, "hos_client_create", g_hos_instance.error_message);
|
||||
MESA_HANDLE_RUNTIME_LOG(log, RLOG_LV_FATAL, "hos_client_create", "error: %s", g_hos_instance.error_message);
|
||||
return;
|
||||
}
|
||||
|
||||
g_hos_handle.buckets = outcome.GetResult().GetBuckets();
|
||||
g_hos_handle.count++;
|
||||
g_hos_handle.executor = std::dynamic_pointer_cast<Aws::Utils::Threading::PooledThreadExecutor>(config.executor);
|
||||
g_hos_handle.task_num = (size_t *)calloc(hos_conf->thread_num, sizeof(size_t));
|
||||
|
||||
g_fd_context = (hos_fd_context_t **)calloc(hos_conf->thread_num, sizeof(hos_fd_context_t *));
|
||||
g_fd_info = (size_t (*)[MAX_HOS_CLIENT_FD_NUM + 1])calloc(hos_conf->thread_num, sizeof(size_t [MAX_HOS_CLIENT_FD_NUM + 1]));
|
||||
@@ -213,7 +252,13 @@ static void hos_client_create()
|
||||
g_fd_info[i][0] = 65533;
|
||||
}
|
||||
|
||||
MESA_handle_runtime_log(log, RLOG_LV_DEBUG, "hos_client_create", "hos s3client create success, url:%s.",endpoint);
|
||||
if (g_hos_handle.hos_func.fd_thread == 0)
|
||||
{
|
||||
g_hos_handle.hos_func.fd_thread_status = 0;
|
||||
pthread_create(&g_hos_handle.hos_func.fd_thread, NULL, hos_fd_manage, NULL);
|
||||
}
|
||||
|
||||
MESA_HANDLE_RUNTIME_LOG(log, RLOG_LV_DEBUG, "hos_client_create", "debug: hos s3client create success, url:%s.",endpoint);
|
||||
g_hos_instance.result = true;
|
||||
}
|
||||
|
||||
@@ -221,15 +266,15 @@ bool hos_verify_bucket(const char *bucket)
|
||||
{
|
||||
if (bucket == NULL)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"bucket is null");
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"debug: bucket is null");
|
||||
return false;
|
||||
}
|
||||
if (g_hos_instance.result != true || g_hos_handle.S3Client == NULL)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"g_hos_instance.result:%s, g_hos_handle.S3Client:%s",
|
||||
g_hos_instance.result, (g_hos_handle.S3Client==NULL)?(NULL):("not null"));
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"debug: g_hos_instance.result:%d, g_hos_handle.S3Client:%s",
|
||||
g_hos_instance.result, (g_hos_handle.S3Client==NULL)?("null"):("not null"));
|
||||
return false;
|
||||
}
|
||||
Aws::S3::Model::ListBucketsOutcome outcome = g_hos_handle.S3Client->ListBuckets();
|
||||
@@ -242,14 +287,14 @@ bool hos_verify_bucket(const char *bucket)
|
||||
{
|
||||
if (strcmp(new_bucket.GetName().c_str(), bucket) == 0)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, "hos_verify_bucket","bucket:%s exits", bucket);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, "hos_verify_bucket","debug: bucket:%s exits", bucket);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_verify_bucket","error:%s", outcome.GetError().GetMessage().c_str());
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, "hos_verify_bucket","error:%s", outcome.GetError().GetMessage().c_str());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -336,8 +381,8 @@ static void *fs2_statistics(void *ptr)
|
||||
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[0], fs2_info->column_ids[1], FS_OP_SET, rx_bytes_interval);
|
||||
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[0], fs2_info->column_ids[2], FS_OP_SET, tx_pkts_interval);
|
||||
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[0], fs2_info->column_ids[3], FS_OP_SET, tx_bytes_interval);
|
||||
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[0], fs2_info->column_ids[5], FS_OP_SET, tx_failed_pkts_interval);
|
||||
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[0], fs2_info->column_ids[4], FS_OP_SET, tx_failed_bytes_interval);
|
||||
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[0], fs2_info->column_ids[4], FS_OP_SET, tx_failed_pkts_interval);
|
||||
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[0], fs2_info->column_ids[5], FS_OP_SET, tx_failed_bytes_interval);
|
||||
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[0], fs2_info->column_ids[6], FS_OP_SET, cache_interval);
|
||||
|
||||
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[1], fs2_info->column_ids[0], FS_OP_SET, rx_pkts_sum);
|
||||
@@ -492,16 +537,17 @@ static int hos_putobject_async(Aws::S3::Model::PutObjectRequest& request, size_t
|
||||
ret = S3Client.PutObjectAsync(request, PutObjectAsyncFinished, context);
|
||||
if (ret)
|
||||
{
|
||||
g_hos_handle.task_num[thread_id]++;
|
||||
//不算真正成功,需要等到PutObjectAsyncFinished的结果
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"PutObjectAsync success. [%s:%s]", bucket, object);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"debug: PutObjectAsync success. [%s:%s]", bucket, object);
|
||||
|
||||
return HOS_CLIENT_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"PutObjectAsync failed. [%s:%s]", bucket, object);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"debug: PutObjectAsync failed. [%s:%s]", bucket, object);
|
||||
|
||||
if (hos_func->fs2_info[0].fs2_handle)
|
||||
{
|
||||
@@ -531,22 +577,22 @@ static int hos_putobject_sync(Aws::S3::Model::PutObjectRequest& request, size_t
|
||||
data_info = (data_info_t *)hos_func->fs2_info[FS2_DATA_FLOW_STATE].reserved;
|
||||
data_info->tx_pkts[thread_id]++;
|
||||
data_info->tx_bytes[thread_id] += stream_len;
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"PutObject success. [%s:%s] tx_pkts:%d, tx_bytes:%d",
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"debug: PutObject success. [%s:%s] tx_pkts:%lu, tx_bytes:%lu",
|
||||
bucket, object, data_info->tx_pkts[thread_id], data_info->tx_bytes[thread_id]);
|
||||
}
|
||||
else
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"PutObject success. [%s:%s]", bucket, object);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"debug: PutObject success. [%s:%s]", bucket, object);
|
||||
}
|
||||
|
||||
return HOS_CLIENT_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"PutObject failed. [%s:%s] cause:%s", bucket, object, Outcome.GetError().GetMessage().c_str());
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"debug: PutObject failed. [%s:%s] cause:%s", bucket, object, Outcome.GetError().GetMessage().c_str());
|
||||
|
||||
if (hos_func->fs2_info[FS2_DATA_FLOW_STATE].fs2_handle && hos_func->fs2_info[FS2_DATA_FLOW_STATE].reserved)
|
||||
{
|
||||
@@ -618,21 +664,21 @@ hos_instance hos_init_instance(const char *conf_path, const char *module, size_t
|
||||
{
|
||||
if(hos_verify_bucket(bucket) == false)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__, "bucket:%s not exist.", bucket);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__, "error: bucket:%s not exist.", bucket);
|
||||
hos_shutdown_instance();
|
||||
g_hos_instance.result = false;
|
||||
g_hos_instance.error_code = HOS_BUCKET_NOT_EXIST;
|
||||
snprintf(g_hos_instance.error_message, HOS_ERROR_MESSAGE_SIZE, "bucket:%s not exits.", bucket);
|
||||
return &g_hos_instance;
|
||||
}
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__, "Instance init completed");
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__, "debug:%s","Instance init completed");
|
||||
if (hos_conf->fs2_ip && hos_conf->fs2_port)
|
||||
{
|
||||
hos_expand_fs2();
|
||||
}
|
||||
else
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__, "hos fs2 function not starup");
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,"error: hos fs2 function not starup");
|
||||
}
|
||||
g_hos_instance.error_code = 0;
|
||||
g_hos_instance.error_message[0]='\0';
|
||||
@@ -656,7 +702,7 @@ int hos_create_bucket(const char *bucket)
|
||||
{
|
||||
if ((bucket == NULL) || (g_hos_handle.S3Client == NULL))
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_create_bucket",
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, "hos_create_bucket",
|
||||
"error:bucket:%s, s3client:%s", bucket, g_hos_handle.S3Client?"not null":"null");
|
||||
return HOS_PARAMETER_ERROR;
|
||||
}
|
||||
@@ -667,7 +713,7 @@ int hos_create_bucket(const char *bucket)
|
||||
{
|
||||
if (strcmp(new_bucket.GetName().c_str(), bucket) == 0)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__, "%s was exits", bucket);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__, "debug: %s was exits", bucket);
|
||||
return HOS_CLIENT_OK;
|
||||
}
|
||||
}
|
||||
@@ -682,12 +728,12 @@ int hos_create_bucket(const char *bucket)
|
||||
Aws::S3::S3Errors errorcode = createBucketOutcome.GetError().GetErrorType();
|
||||
if (errorcode != Aws::S3::S3Errors::BUCKET_ALREADY_OWNED_BY_YOU)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,"error: %s create failed. %s",
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,"error: %s create failed. %s",
|
||||
bucket, createBucketOutcome.GetError().GetMessage().c_str());
|
||||
return (int)errorcode + 1;
|
||||
}
|
||||
}
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__, "%s create successful", bucket);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__, "error: %s create successful", bucket);
|
||||
|
||||
return HOS_CLIENT_OK;
|
||||
}
|
||||
@@ -703,13 +749,13 @@ static int hos_upload_stream(const char *bucket, const char *object, const char
|
||||
|
||||
if ((g_hos_handle.S3Client == NULL) || (bucket == NULL) || (object == NULL) || (thread_id > hos_conf->thread_num))
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_upload_stream",
|
||||
"s3client:%s, bucket:%s, object:%s, thread_id:%d, thread_num:%d",
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, "hos_upload_stream",
|
||||
"error: s3client:%s, bucket:%s, object:%s, thread_id:%lu, thread_num:%u",
|
||||
g_hos_handle.S3Client?"not null":"null", bucket, object, thread_id, hos_conf->thread_num);
|
||||
return HOS_PARAMETER_ERROR;
|
||||
}
|
||||
|
||||
mode = data?1:0; // 1, file mode; 0 buf mode
|
||||
mode = data?1:0; // 0, file mode; 1 buf mode
|
||||
|
||||
// Create and configure the asynchronous put object request.
|
||||
Aws::S3::Model::PutObjectRequest request;
|
||||
@@ -776,7 +822,7 @@ int hos_upload_file(const char *bucket, const char *file_path, put_finished_call
|
||||
struct stat buffer;
|
||||
if (g_hos_instance.result == false || g_hos_handle.S3Client == NULL)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
|
||||
"error:g_hos_instance.result:%d, g_hos_handle.S3CLient:%s",
|
||||
g_hos_instance.result, (g_hos_handle.S3Client == NULL)?(NULL):("not null"));
|
||||
return HOS_INSTANCE_NOT_INIT;
|
||||
@@ -784,15 +830,15 @@ int hos_upload_file(const char *bucket, const char *file_path, put_finished_call
|
||||
|
||||
if ((bucket == NULL) || (file_path == NULL) || (thread_id > g_hos_handle.hos_config.thread_num))
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_upload_file",
|
||||
"s3client:%s, bucket:%s, file_path:%s, thread_id:%d, thread_num:%d",
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, "hos_upload_file",
|
||||
"error: bucket:%s, file_path:%s, thread_id:%lu, thread_num:%u",
|
||||
bucket, file_path, thread_id, g_hos_handle.hos_config.thread_num);
|
||||
return HOS_PARAMETER_ERROR;
|
||||
}
|
||||
|
||||
if (stat(file_path, &buffer) == -1)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_upload_file", "The file:%s not exist", file_path);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, "hos_upload_file", "error: The file:%s not exist", file_path);
|
||||
return HOS_FILE_NOT_EXIST;
|
||||
}
|
||||
return hos_upload_stream(bucket, file_path, NULL, buffer.st_size, callback, userdata, thread_id);
|
||||
@@ -802,7 +848,7 @@ int hos_upload_buf(const char *bucket, const char *object, const char *buf, size
|
||||
{
|
||||
if (g_hos_instance.result == false || g_hos_handle.S3Client == NULL)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
|
||||
"error:g_hos_instance.result:%d, g_hos_handle.S3CLient:%s",
|
||||
g_hos_instance.result, (g_hos_handle.S3Client == NULL)?(NULL):("not null"));
|
||||
return HOS_INSTANCE_NOT_INIT;
|
||||
@@ -811,8 +857,8 @@ int hos_upload_buf(const char *bucket, const char *object, const char *buf, size
|
||||
if ((bucket == NULL) || (object == NULL) || (buf == NULL) || (buf_len == 0)
|
||||
|| (thread_id > g_hos_handle.hos_config.thread_num))
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_upload_buf",
|
||||
"bucket:%s, object:%s, buf:%s, buf_len:%d, thread_id:%d, thread_num:%d",
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, "hos_upload_buf",
|
||||
"bucket:%s, object:%s, buf:%s, buf_len:%lu, thread_id:%lu, thread_num:%u",
|
||||
bucket, object, buf?"not null":"null", buf_len, thread_id, g_hos_handle.hos_config.thread_num);
|
||||
return HOS_PARAMETER_ERROR;
|
||||
}
|
||||
@@ -824,35 +870,39 @@ static void *hos_fd_manage(void *ptr)
|
||||
hos_fd_context_t *a_fd_context;
|
||||
size_t thread_sum = g_hos_handle.hos_config.thread_num;
|
||||
size_t thread_num;
|
||||
size_t fd;
|
||||
//size_t fd;
|
||||
while(1)
|
||||
{
|
||||
if (g_hos_handle.hos_func.fd_thread_status)
|
||||
break;
|
||||
for (thread_num = 0; thread_num < thread_sum; thread_num++)
|
||||
{
|
||||
for(fd = 3; fd < MAX_HOS_CLIENT_FD_NUM + 1; fd++)
|
||||
{
|
||||
if (!g_fd_info[thread_num][fd])
|
||||
continue;
|
||||
#if 0
|
||||
a_fd_context = find_context_by_fd(g_fd_context[thread_num], fd);
|
||||
if (!a_fd_context)
|
||||
continue;
|
||||
#endif
|
||||
hos_fd_context_t *tmp = NULL;
|
||||
HASH_ITER(hh, g_fd_context[thread_num], a_fd_context, tmp)
|
||||
{
|
||||
if (!a_fd_context)
|
||||
break;
|
||||
|
||||
if (a_fd_context->fd_status == HOS_FD_INJECT)
|
||||
{
|
||||
if (a_fd_context->position == a_fd_context->recive_cnt)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"[%s:%s] upload completed. [thread:%d fd:%d] delete",
|
||||
a_fd_context->bucket, a_fd_context->object, thread_num, fd);
|
||||
hos_delete_fd(fd, thread_num);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
|
||||
"debug: [%s:%s] upload completed. [thread:%lu fd:%lu] delete",
|
||||
a_fd_context->bucket, a_fd_context->object, thread_num, a_fd_context->fd);
|
||||
hos_delete_fd(thread_num, a_fd_context);
|
||||
}
|
||||
else if (a_fd_context->overtime <= get_current_ms())
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
|
||||
"[%s:%s] upload not completed, but the live-time of [thread_id:%d fd:%d] is over.",
|
||||
a_fd_context->bucket, a_fd_context->object, thread_num, fd);
|
||||
hos_delete_fd(fd, thread_num);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
|
||||
"error: [%s:%s] upload not completed, but the live-time of [thread_id:%lu fd:%lu] is over.",
|
||||
a_fd_context->bucket, a_fd_context->object, thread_num, a_fd_context->fd);
|
||||
hos_delete_fd(thread_num, a_fd_context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -866,15 +916,15 @@ int hos_open_fd(const char *bucket, const char *object, put_finished_callback ca
|
||||
{
|
||||
if (g_hos_instance.result == false || g_hos_handle.S3Client == NULL)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
|
||||
"error:g_hos_instance.result:%d, g_hos_handle.S3CLient:%s",
|
||||
g_hos_instance.result, (g_hos_handle.S3Client == NULL)?("null"):("not null"));
|
||||
return HOS_INSTANCE_NOT_INIT;
|
||||
}
|
||||
if ((bucket == NULL) || (object == NULL) || (thread_id > g_hos_handle.hos_config.thread_num) || strlen(bucket) == 0 || strlen(object) == 0)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_open_fd",
|
||||
"bucket:%s, obejct:%s, thread_id:%d",
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, "hos_open_fd",
|
||||
"error: bucket:%s, obejct:%s, thread_id:%lu",
|
||||
//(bucket == NULL)?"null":bucket, (object == NULL)?"null":object, thread_id);
|
||||
bucket, object, thread_id);
|
||||
return HOS_PARAMETER_ERROR;
|
||||
@@ -883,16 +933,16 @@ int hos_open_fd(const char *bucket, const char *object, put_finished_callback ca
|
||||
size_t fd = hash_get_min_free_fd(thread_id);
|
||||
if (fd == 0)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_open_fd",
|
||||
"error:fd not enough, thread_id:%d, fd free: %d, fd register:%d, fd inject:%d",
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, "hos_open_fd",
|
||||
"error:fd not enough, thread_id:%lu, fd free: %lu, fd register:%lu, fd inject:%lu",
|
||||
thread_id,
|
||||
g_fd_info[thread_id][HOS_FD_FREE],
|
||||
g_fd_info[thread_id][HOS_FD_REGISTER],
|
||||
g_fd_info[thread_id][HOS_FD_INJECT]);
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, "hos_open_fd", "thread_id:%d, fd:%d", thread_id, fd);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, "hos_open_fd", "debug: thread_id:%lu, fd:%lu", thread_id, fd);
|
||||
return HOS_FD_NOT_ENOUGH;
|
||||
}
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, "hos_open_fd", "thread_id:%d, fd:%d", thread_id, fd);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, "hos_open_fd", "debug: thread_id:%lu, fd:%lu", thread_id, fd);
|
||||
|
||||
hos_fd_context_t info = {fd, mode, (char *)bucket, (char *)object, (void *)callback, userdata,
|
||||
NULL,/*cache*/ g_hos_handle.hos_config.cache_count, 0,/*position*/ 0,/*recive_cnt*/
|
||||
@@ -900,6 +950,7 @@ int hos_open_fd(const char *bucket, const char *object, put_finished_callback ca
|
||||
0,/*overtime*/ g_hos_handle.hos_config.timeout,};
|
||||
add_fd_context(&g_fd_context[thread_id], &info);
|
||||
|
||||
#if 0
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(m_client_lock);
|
||||
if (g_hos_handle.hos_func.fd_thread == 0)
|
||||
@@ -908,6 +959,7 @@ int hos_open_fd(const char *bucket, const char *object, put_finished_callback ca
|
||||
pthread_create(&g_hos_handle.hos_func.fd_thread, NULL, hos_fd_manage, NULL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return fd;
|
||||
}
|
||||
@@ -925,7 +977,7 @@ int hos_write(size_t fd, const char *stream, size_t stream_len, size_t thread_id
|
||||
|
||||
if (g_hos_instance.result == false || g_hos_handle.S3Client == NULL)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
|
||||
"error:g_hos_instance.result:%d, g_hos_handle.S3CLient:%s",
|
||||
g_hos_instance.result, (g_hos_handle.S3Client == NULL)?(NULL):("not null"));
|
||||
return HOS_INSTANCE_NOT_INIT;
|
||||
@@ -933,8 +985,8 @@ int hos_write(size_t fd, const char *stream, size_t stream_len, size_t thread_id
|
||||
|
||||
if ((fd < 3) || fd > MAX_HOS_CLIENT_FD_NUM || (stream == NULL) || (thread_id > hos_conf->thread_num))
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL,
|
||||
"hos_write", "error: fd:%d, stream:%s, stream_len:%d, thread_id:%d.",
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL,
|
||||
"hos_write", "error: fd:%lu, stream:%s, stream_len:%lu, thread_id:%lu.",
|
||||
fd, stream?"not null":"null", stream_len, thread_id);
|
||||
return HOS_PARAMETER_ERROR;
|
||||
}
|
||||
@@ -945,10 +997,18 @@ int hos_write(size_t fd, const char *stream, size_t stream_len, size_t thread_id
|
||||
}
|
||||
if (a_fd_context == NULL)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__, "fd info not find. thread_id:%d, fd:%d", thread_id, fd);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__, "error: fd info not find. thread_id:%lu, fd:%lu", thread_id, fd);
|
||||
return HOS_HASH_NOT_FIND;
|
||||
}
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__, "Get fd_context, thread_id:%d, fd:%d", thread_id, fd);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__, "debug: Get fd_context, thread_id:%lu, fd:%lu", thread_id, fd);
|
||||
|
||||
// create and configure the asynchronous put object request.
|
||||
Aws::S3::Model::PutObjectRequest request;
|
||||
|
||||
//设置上传数据类型
|
||||
if (a_fd_context->mode & BUFF_MODE)
|
||||
{
|
||||
//BUFF_MODE
|
||||
|
||||
//field_stat2 record
|
||||
if (hos_func->fs2_info[0].fs2_handle)
|
||||
@@ -960,14 +1020,6 @@ int hos_write(size_t fd, const char *stream, size_t stream_len, size_t thread_id
|
||||
data_info->rx_bytes[thread_id] += stream_len;
|
||||
}
|
||||
}
|
||||
|
||||
// create and configure the asynchronous put object request.
|
||||
Aws::S3::Model::PutObjectRequest request;
|
||||
|
||||
//设置上传数据类型
|
||||
if (a_fd_context->mode & BUFF_MODE)
|
||||
{
|
||||
//BUFF_MODE
|
||||
if (a_fd_context->mode & APPEND_MODE)
|
||||
{
|
||||
//APPEND_MODE
|
||||
@@ -1002,7 +1054,7 @@ int hos_write(size_t fd, const char *stream, size_t stream_len, size_t thread_id
|
||||
a_fd_context->cache->seekg(0, std::ios_base::end);
|
||||
upload_len = a_fd_context->cache->tellg();
|
||||
a_fd_context->cache->seekg(0, std::ios_base::beg);
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__, "x-hos-posotion:%s", num);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__, "debug: x-hos-posotion:%s", num);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1018,14 +1070,24 @@ int hos_write(size_t fd, const char *stream, size_t stream_len, size_t thread_id
|
||||
{
|
||||
if (stat(stream, &buffer) == -1)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__, "The file:%s not exist", stream);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__, "error: The file:%s not exist", stream);
|
||||
return HOS_FILE_NOT_EXIST;
|
||||
}
|
||||
//文件类型
|
||||
const std::shared_ptr<Aws::IOStream> input_data =
|
||||
Aws::MakeShared<Aws::FStream>("hos_write file mode", a_fd_context->object, std::ios_base::in | std::ios_base::binary);
|
||||
Aws::MakeShared<Aws::FStream>("hos_write file mode", stream, std::ios_base::in | std::ios_base::binary);
|
||||
request.SetBody(input_data);
|
||||
upload_len = buffer.st_size;
|
||||
//field_stat2 record
|
||||
if (hos_func->fs2_info[0].fs2_handle)
|
||||
{
|
||||
if (hos_func->fs2_info[0].reserved)
|
||||
{
|
||||
data_info = (data_info_t *)hos_func->fs2_info[0].reserved;
|
||||
data_info->rx_pkts[thread_id]++;
|
||||
data_info->rx_bytes[thread_id] += upload_len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
request.SetBucket(a_fd_context->bucket);
|
||||
@@ -1062,16 +1124,16 @@ int hos_close_fd(size_t fd, size_t thread_id)
|
||||
|
||||
if (g_hos_instance.result == false || g_hos_handle.S3Client == NULL)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
|
||||
"error:g_hos_instance.result:%d, g_hos_handle.S3CLient:%s",
|
||||
g_hos_instance.result, (g_hos_handle.S3Client == NULL)?(NULL):("not null"));
|
||||
g_hos_instance.result, (g_hos_handle.S3Client == NULL)?("null"):("not null"));
|
||||
return HOS_INSTANCE_NOT_INIT;
|
||||
}
|
||||
|
||||
if (fd < 3 || fd > 65533 || thread_id > hos_conf->thread_num)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_close_fd",
|
||||
"error:fd:%d, thread_id:%d, thread_sum:%d.",
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, "hos_close_fd",
|
||||
"error:fd:%lu, thread_id:%lu, thread_sum:%u.",
|
||||
fd, thread_id, hos_conf->thread_num);
|
||||
return HOS_PARAMETER_ERROR;
|
||||
}
|
||||
@@ -1081,8 +1143,8 @@ int hos_close_fd(size_t fd, size_t thread_id)
|
||||
}
|
||||
if (a_fd_context == NULL)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG,
|
||||
"hos_close_fd", "not find the a_fd_context of [fd:%d thread:%d]",
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG,
|
||||
"hos_close_fd", "debug: not find the a_fd_context of [fd:%lu thread:%lu]",
|
||||
fd, thread_id);
|
||||
return HOS_CLIENT_OK;
|
||||
}
|
||||
@@ -1117,6 +1179,7 @@ int hos_close_fd(size_t fd, size_t thread_id)
|
||||
{
|
||||
hos_putobject_sync(request, upload_len, thread_id, fd, a_fd_context->bucket, a_fd_context->object);
|
||||
}
|
||||
((data_info_t *)(g_hos_handle.hos_func.fs2_info->reserved))->cache[thread_id] = 0;
|
||||
}
|
||||
}
|
||||
a_fd_context->fd_status = HOS_FD_INJECT;
|
||||
@@ -1138,19 +1201,33 @@ int hos_shutdown_instance()
|
||||
size_t i = 0;
|
||||
hos_config_t *hos_conf = &g_hos_handle.hos_config;
|
||||
hos_func_thread_t *hos_func = &g_hos_handle.hos_func;
|
||||
size_t task_num = 0;
|
||||
|
||||
if (g_hos_handle.S3Client == NULL)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, "hos_shutdown_instance", "There is no hos client.");
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, "hos_shutdown_instance", "debug: There is no hos client.");
|
||||
return HOS_CLIENT_OK;
|
||||
}
|
||||
|
||||
if (g_hos_handle.count > 0 && --g_hos_handle.count)
|
||||
{
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, "hos_shutdown_instance", "hos client count:%d.", g_hos_handle.count);
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, "hos_shutdown_instance", "debug: hos client count:%lu.", g_hos_handle.count);
|
||||
return HOS_CLIENT_OK;
|
||||
}
|
||||
|
||||
//先等待所有的task完成
|
||||
while(1)
|
||||
{
|
||||
task_num = 0;
|
||||
for (uint32_t i = 0; i < g_hos_handle.hos_config.thread_num; i++)
|
||||
{
|
||||
task_num += g_hos_handle.task_num[i];
|
||||
}
|
||||
if (task_num == 0)
|
||||
break;
|
||||
usleep(500 * 1000);
|
||||
}
|
||||
|
||||
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
|
||||
|
||||
if (hos_func->fd_thread)
|
||||
@@ -1208,7 +1285,12 @@ int hos_shutdown_instance()
|
||||
|
||||
delete g_hos_handle.S3Client;
|
||||
g_hos_handle.S3Client = NULL;
|
||||
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__, "delete s3client.");
|
||||
if (g_hos_handle.task_num != NULL)
|
||||
{
|
||||
free(g_hos_handle.task_num);
|
||||
g_hos_handle.task_num = NULL;
|
||||
}
|
||||
MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__, "debug: delete s3client.");
|
||||
|
||||
if (g_fd_info)
|
||||
{
|
||||
|
||||
@@ -97,6 +97,7 @@ typedef struct hos_client_handle_s
|
||||
hos_config_t hos_config;
|
||||
hos_func_thread_t hos_func;
|
||||
void *log;
|
||||
size_t *task_num;
|
||||
}hos_client_handle_t;
|
||||
|
||||
extern struct hos_instance_s g_hos_instance;
|
||||
|
||||
Reference in New Issue
Block a user