Skip to content

Commit 76871ec

Browse files
author
DenverM80
committed
WIP: Add file for an optional put_directory test
1 parent 1c10a5c commit 76871ec

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ add_executable(ds3_c_tests
7777
search_tests.cpp
7878
service_tests.cpp
7979
connection_tests.cpp
80+
put_directory.cpp
8081
test.cpp)
8182

8283
add_test(regression_tests ds3_c_tests)

test/put_directory.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* ******************************************************************************
3+
* Copyright 2014-2016 Spectra Logic Corporation. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the "license" file accompanying this file.
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* ****************************************************************************
14+
*/
15+
16+
#include <stdio.h>
17+
#include <string.h>
18+
#include <unistd.h>
19+
#include <glib.h>
20+
#include <sys/stat.h>
21+
#include <boost/test/unit_test.hpp>
22+
#include <inttypes.h>
23+
#include "ds3.h"
24+
#include "ds3_net.h"
25+
#include "test.h"
26+
27+
struct check_ds3_test_directory_given {
28+
return getenv(DS3_TEST_DIRECTORY) != NULL;
29+
};
30+
31+
BOOST_AUTO_TEST_CASE( put_directory,
32+
* boost::unit_test::precondition(check_ds3_test_directory_given)) {
33+
printf("-----Testing PUT all objects in a directory-------\n");
34+
35+
const char* dir_path = getenv("DS3_TEST_DIRECTORY");
36+
BOOST_CHECK(dir_path != NULL);
37+
38+
const char* bucket_name = "test_bulk_put_directory";
39+
40+
ds3_request* request = NULL;
41+
ds3_master_object_list_response* bulk_response = NULL;
42+
43+
ds3_client* client = get_client();
44+
int client_thread=1;
45+
ds3_client_register_logging(client, DS3_DEBUG, test_log, (void*)&client_thread); // Use DEBUG level logging
46+
47+
ds3_error* error = create_bucket_with_data_policy(client, bucket_name, ids.data_policy_id->value);
48+
49+
char** objects_list;
50+
uint64_t num_objs = 0;
51+
GDir* dir_info = g_dir_open(dir_path, 0, NULL);
52+
for (char* current_obj = (char*)g_dir_read_name(dir_info); current_obj != NULL; current_obj = (char*)g_dir_read_name(dir_info)) {
53+
objects_list[num_objs++] = current_obj;
54+
}
55+
56+
ds3_bulk_object_list_response* bulk_object_list = ds3_convert_object_list_from_strings((const char**)objects_list, num_objs);
57+
58+
request = ds3_init_put_bulk_job_spectra_s3_request(bucket_name, bulk_object_list);
59+
ds3_master_object_list_response* mol;
60+
error = ds3_put_bulk_job_spectra_s3_request(client, request, &mol);
61+
ds3_request_free(request);
62+
ds3_bulk_object_list_response_free(bulk_object_list);
63+
handle_error(error);
64+
65+
ds3_master_object_list_response* chunks_list = ensure_available_chunks(client, mol->job_id);
66+
67+
// Use helper functions from test.cpp
68+
GPtrArray* put_dir_args = new_put_chunks_threads_args(client, NULL, bucket_name, mol, chunks_list, 1, True); // Last param indicates verbose logging in the spawned thread
69+
70+
// capture test start time
71+
struct timespec start_time_t, end_time_t;
72+
double elapsed_t;
73+
clock_gettime(CLOCK_MONOTONIC, &start_time_t);
74+
75+
GThread* put_dir_xfer_thread = g_thread_new("put_dir_xfer_thread", (GThreadFunc)put_chunks_from_file, g_ptr_array_index(put_dir_args, 0));
76+
77+
// Block and cleanup GThread(s)
78+
g_thread_join(put_dir_xfer_thread);
79+
80+
// find elapsed CPU and real time
81+
clock_gettime(CLOCK_MONOTONIC, &end_time_t);
82+
elapsed_t = timespec_to_seconds(&end_time_t) - timespec_to_seconds(&start_time_t);
83+
ds3_log_message(client1->log, DS3_INFO, " Elapsed time[%f]", elapsed_t);
84+
85+
ds3_master_object_list_response_free(chunks_list);
86+
ds3_master_object_list_response_free(mol);
87+
put_chunks_threads_args_free(put_dir_args);
88+
clear_bucket(client, bucket_name);
89+
free_client(client);
90+
}
91+

test/test.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,11 @@ void put_chunks_from_file(void* args) {
525525
if (_args->verbose) {
526526
ds3_log_message(_args->client->log, DS3_INFO, " GlibThread[%d] BEGIN xfer File[%s] Chunk[%lu]", _args->thread_num, object->name->value, _args->chunks_list->num_objects);
527527
}
528-
file = fopen(_args->src_object_name, "r");
528+
if (_args->src_object_name) {
529+
file = fopen(_args->src_object_name, "r");
530+
} else {
531+
file = fopen(object->name->value, "r");
532+
}
529533
if (object->offset != 0) {
530534
fseek(file, object->offset, SEEK_SET);
531535
}

0 commit comments

Comments
 (0)