| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include "aws/s3/private/s3_client_impl.h" |
| 7 |
#include "aws/s3/private/s3_request.h" |
| 8 |
#include "aws/s3/private/s3_util.h" |
| 9 |
#include "s3_tester.h" |
| 10 |
|
| 11 |
#include <aws/common/clock.h> |
| 12 |
#include <aws/testing/aws_test_harness.h> |
| 13 |
|
| 14 |
#define TEST_CASE(NAME) \ |
| 15 |
AWS_TEST_CASE(NAME, s_test_##NAME); \ |
| 16 |
static int s_test_##NAME(struct aws_allocator *allocator, void *ctx) |
| 17 |
|
| 18 |
#define DEFINE_HEADER(NAME, VALUE) \ |
| 19 |
{ \ |
| 20 |
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), \ |
| 21 |
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), \ |
| 22 |
} |
| 23 |
|
| 24 |
static void s_init_mock_s3_request_upload_part_timeout( |
| 25 |
struct aws_s3_request *mock_request, |
| 26 |
uint64_t original_upload_timeout_ms, |
| 27 |
uint64_t request_time_ns, |
| 28 |
uint64_t response_to_first_byte_time_ns) { |
| 29 |
mock_request->upload_timeout_ms = (size_t)original_upload_timeout_ms; |
| 30 |
struct aws_s3_request_metrics *metrics = mock_request->send_data.metrics; |
| 31 |
|
| 32 |
metrics->time_metrics.send_start_timestamp_ns = 0; |
| 33 |
metrics->time_metrics.send_end_timestamp_ns = 0; |
| 34 |
metrics->time_metrics.receive_end_timestamp_ns = request_time_ns; |
| 35 |
metrics->time_metrics.receive_start_timestamp_ns = response_to_first_byte_time_ns; |
| 36 |
} |
| 37 |
|
| 38 |
static int s_starts_upload_retry(struct aws_s3_client *client, struct aws_s3_request *mock_request) { |
| 39 |
uint64_t average_time_ns = aws_timestamp_convert( |
| 40 |
300, AWS_TIMESTAMP_MILLIS, AWS_TIMESTAMP_NANOS, NULL); |
| 41 |
AWS_ZERO_STRUCT(client->synced_data.upload_part_stats); |
| 42 |
|
| 43 |
s_init_mock_s3_request_upload_part_timeout(mock_request, 0, average_time_ns, average_time_ns); |
| 44 |
size_t init_count = client->ideal_connection_count; |
| 45 |
size_t p90_count = init_count / 10 + 1; |
| 46 |
for (size_t i = 0; i < init_count - p90_count; i++) { |
| 47 |
|
| 48 |
aws_s3_client_update_upload_part_timeout(client, mock_request, AWS_ERROR_SUCCESS); |
| 49 |
} |
| 50 |
|
| 51 |
uint64_t one_sec_time_ns = aws_timestamp_convert(1, AWS_TIMESTAMP_SECS, AWS_TIMESTAMP_NANOS, NULL); |
| 52 |
s_init_mock_s3_request_upload_part_timeout(mock_request, 0, one_sec_time_ns, one_sec_time_ns); |
| 53 |
for (size_t i = 0; i < p90_count; i++) { |
| 54 |
|
| 55 |
aws_s3_client_update_upload_part_timeout(client, mock_request, AWS_ERROR_SUCCESS); |
| 56 |
} |
| 57 |
|
| 58 |
ASSERT_FALSE(client->synced_data.upload_part_stats.stop_timeout); |
| 59 |
size_t current_timeout_ms = aws_atomic_load_int(&client->upload_timeout_ms); |
| 60 |
|
| 61 |
ASSERT_UINT_EQUALS(1000, current_timeout_ms); |
| 62 |
return AWS_OP_SUCCESS; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
TEST_CASE(client_update_upload_part_timeout) { |
| 67 |
(void)ctx; |
| 68 |
struct aws_s3_tester tester; |
| 69 |
AWS_ZERO_STRUCT(tester); |
| 70 |
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester)); |
| 71 |
struct aws_s3_client *client = NULL; |
| 72 |
struct aws_s3_tester_client_options client_options = { |
| 73 |
.part_size = MB_TO_BYTES(8), |
| 74 |
.tls_usage = AWS_S3_TLS_DISABLED, |
| 75 |
}; |
| 76 |
ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client)); |
| 77 |
struct aws_s3_request mock_request; |
| 78 |
struct aws_s3_request_metrics metrics; |
| 79 |
AWS_ZERO_STRUCT(mock_request); |
| 80 |
AWS_ZERO_STRUCT(metrics); |
| 81 |
mock_request.send_data.metrics = &metrics; |
| 82 |
|
| 83 |
uint64_t large_time_ns = |
| 84 |
aws_timestamp_convert(5500, AWS_TIMESTAMP_MILLIS, AWS_TIMESTAMP_NANOS, NULL); |
| 85 |
|
| 86 |
uint64_t average_time_ns = aws_timestamp_convert( |
| 87 |
250, AWS_TIMESTAMP_MILLIS, AWS_TIMESTAMP_NANOS, NULL); |
| 88 |
|
| 89 |
size_t init_count = client->ideal_connection_count; |
| 90 |
{ |
| 91 |
|
| 92 |
AWS_ZERO_STRUCT(client->synced_data.upload_part_stats); |
| 93 |
s_init_mock_s3_request_upload_part_timeout(&mock_request, 0, large_time_ns, average_time_ns); |
| 94 |
|
| 95 |
|
| 96 |
aws_s3_client_update_upload_part_timeout(client, &mock_request, AWS_ERROR_HTTP_RESPONSE_FIRST_BYTE_TIMEOUT); |
| 97 |
for (size_t i = 0; i < init_count; i++) { |
| 98 |
|
| 99 |
aws_s3_client_update_upload_part_timeout(client, &mock_request, AWS_ERROR_SUCCESS); |
| 100 |
} |
| 101 |
|
| 102 |
ASSERT_TRUE(client->synced_data.upload_part_stats.stop_timeout); |
| 103 |
size_t current_timeout_ms = aws_atomic_load_int(&client->upload_timeout_ms); |
| 104 |
ASSERT_UINT_EQUALS(0, current_timeout_ms); |
| 105 |
|
| 106 |
if (client->synced_data.upload_part_stats.initial_request_time.collecting_p90) { |
| 107 |
aws_priority_queue_clean_up(&client->synced_data.upload_part_stats.initial_request_time.p90_samples); |
| 108 |
client->synced_data.upload_part_stats.initial_request_time.collecting_p90 = false; |
| 109 |
} |
| 110 |
} |
| 111 |
{ |
| 112 |
|
| 113 |
AWS_ZERO_STRUCT(client->synced_data.upload_part_stats); |
| 114 |
|
| 115 |
size_t test_init_connection = 1000; |
| 116 |
*(uint32_t *)(void *)&client->ideal_connection_count = (uint32_t)test_init_connection; |
| 117 |
for (size_t i = 0; i < test_init_connection; i++) { |
| 118 |
|
| 119 |
uint64_t time_ns = aws_timestamp_convert(i, AWS_TIMESTAMP_MILLIS, AWS_TIMESTAMP_NANOS, NULL); |
| 120 |
s_init_mock_s3_request_upload_part_timeout(&mock_request, 0, time_ns, time_ns); |
| 121 |
aws_s3_client_update_upload_part_timeout(client, &mock_request, AWS_ERROR_SUCCESS); |
| 122 |
} |
| 123 |
|
| 124 |
size_t current_timeout_ms = aws_atomic_load_int(&client->upload_timeout_ms); |
| 125 |
|
| 126 |
ASSERT_UINT_EQUALS(1000, current_timeout_ms); |
| 127 |
|
| 128 |
if (client->synced_data.upload_part_stats.initial_request_time.collecting_p90) { |
| 129 |
aws_priority_queue_clean_up(&client->synced_data.upload_part_stats.initial_request_time.p90_samples); |
| 130 |
client->synced_data.upload_part_stats.initial_request_time.collecting_p90 = false; |
| 131 |
} |
| 132 |
|
| 133 |
*(uint32_t *)(void *)&client->ideal_connection_count = (uint32_t)init_count; |
| 134 |
} |
| 135 |
{ |
| 136 |
|
| 137 |
AWS_ZERO_STRUCT(client->synced_data.upload_part_stats); |
| 138 |
|
| 139 |
size_t test_init_connection = 10000; |
| 140 |
*(uint32_t *)(void *)&client->ideal_connection_count = (uint32_t)test_init_connection; |
| 141 |
for (size_t i = 0; i < test_init_connection; i++) { |
| 142 |
|
| 143 |
uint64_t time_ns = aws_timestamp_convert(i, AWS_TIMESTAMP_MILLIS, AWS_TIMESTAMP_NANOS, NULL); |
| 144 |
s_init_mock_s3_request_upload_part_timeout(&mock_request, 0, time_ns, time_ns); |
| 145 |
aws_s3_client_update_upload_part_timeout(client, &mock_request, AWS_ERROR_SUCCESS); |
| 146 |
} |
| 147 |
|
| 148 |
size_t current_timeout_ms = aws_atomic_load_int(&client->upload_timeout_ms); |
| 149 |
|
| 150 |
ASSERT_UINT_EQUALS(9000, current_timeout_ms); |
| 151 |
|
| 152 |
if (client->synced_data.upload_part_stats.initial_request_time.collecting_p90) { |
| 153 |
aws_priority_queue_clean_up(&client->synced_data.upload_part_stats.initial_request_time.p90_samples); |
| 154 |
client->synced_data.upload_part_stats.initial_request_time.collecting_p90 = false; |
| 155 |
} |
| 156 |
|
| 157 |
*(uint32_t *)(void *)&client->ideal_connection_count = (uint32_t)init_count; |
| 158 |
} |
| 159 |
|
| 160 |
{ |
| 161 |
ASSERT_SUCCESS(s_starts_upload_retry(client, &mock_request)); |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
s_init_mock_s3_request_upload_part_timeout( |
| 170 |
&mock_request, |
| 171 |
aws_timestamp_convert(1, AWS_TIMESTAMP_SECS, AWS_TIMESTAMP_MILLIS, NULL), |
| 172 |
average_time_ns, |
| 173 |
average_time_ns); |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
for (size_t i = 0; i < 1000; i++) { |
| 178 |
|
| 179 |
aws_s3_client_update_upload_part_timeout(client, &mock_request, AWS_ERROR_SUCCESS); |
| 180 |
} |
| 181 |
size_t current_timeout_ms = aws_atomic_load_int(&client->upload_timeout_ms); |
| 182 |
ASSERT_UINT_EQUALS( |
| 183 |
aws_timestamp_convert(average_time_ns, AWS_TIMESTAMP_NANOS, AWS_TIMESTAMP_MILLIS, NULL) + |
| 184 |
g_expect_timeout_offset_ms, |
| 185 |
current_timeout_ms); |
| 186 |
|
| 187 |
|
| 188 |
for (size_t i = 0; i < 1000; i++) { |
| 189 |
|
| 190 |
aws_s3_client_update_upload_part_timeout(client, &mock_request, AWS_ERROR_SUCCESS); |
| 191 |
} |
| 192 |
ASSERT_FALSE(client->synced_data.upload_part_stats.stop_timeout); |
| 193 |
current_timeout_ms = aws_atomic_load_int(&client->upload_timeout_ms); |
| 194 |
|
| 195 |
|
| 196 |
ASSERT_UINT_EQUALS( |
| 197 |
aws_timestamp_convert(average_time_ns, AWS_TIMESTAMP_NANOS, AWS_TIMESTAMP_MILLIS, NULL) + |
| 198 |
g_expect_timeout_offset_ms, |
| 199 |
current_timeout_ms); |
| 200 |
|
| 201 |
if (client->synced_data.upload_part_stats.initial_request_time.collecting_p90) { |
| 202 |
aws_priority_queue_clean_up(&client->synced_data.upload_part_stats.initial_request_time.p90_samples); |
| 203 |
client->synced_data.upload_part_stats.initial_request_time.collecting_p90 = false; |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
{ |
| 208 |
ASSERT_SUCCESS(s_starts_upload_retry(client, &mock_request)); |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
client->synced_data.upload_part_stats.timeout_rate_tracking.num_completed = 800; |
| 215 |
client->synced_data.upload_part_stats.timeout_rate_tracking.num_failed = 1; |
| 216 |
|
| 217 |
|
| 218 |
s_init_mock_s3_request_upload_part_timeout(&mock_request, 1000 , 0, 0); |
| 219 |
aws_s3_client_update_upload_part_timeout(client, &mock_request, AWS_ERROR_HTTP_RESPONSE_FIRST_BYTE_TIMEOUT); |
| 220 |
size_t current_timeout_ms = aws_atomic_load_int(&client->upload_timeout_ms); |
| 221 |
|
| 222 |
ASSERT_UINT_EQUALS(1100, current_timeout_ms); |
| 223 |
|
| 224 |
|
| 225 |
aws_s3_client_update_upload_part_timeout(client, &mock_request, AWS_ERROR_HTTP_RESPONSE_FIRST_BYTE_TIMEOUT); |
| 226 |
ASSERT_FALSE(client->synced_data.upload_part_stats.stop_timeout); |
| 227 |
current_timeout_ms = aws_atomic_load_int(&client->upload_timeout_ms); |
| 228 |
|
| 229 |
ASSERT_UINT_EQUALS(1100, current_timeout_ms); |
| 230 |
|
| 231 |
if (client->synced_data.upload_part_stats.initial_request_time.collecting_p90) { |
| 232 |
aws_priority_queue_clean_up(&client->synced_data.upload_part_stats.initial_request_time.p90_samples); |
| 233 |
client->synced_data.upload_part_stats.initial_request_time.collecting_p90 = false; |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
{ |
| 238 |
ASSERT_SUCCESS(s_starts_upload_retry(client, &mock_request)); |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
uint64_t real_response_time_ns = |
| 248 |
aws_timestamp_convert(3000 - g_expect_timeout_offset_ms, AWS_TIMESTAMP_MILLIS, AWS_TIMESTAMP_NANOS, NULL); |
| 249 |
s_init_mock_s3_request_upload_part_timeout( |
| 250 |
&mock_request, 1000 , real_response_time_ns, real_response_time_ns); |
| 251 |
|
| 252 |
|
| 253 |
aws_s3_client_update_upload_part_timeout(client, &mock_request, AWS_ERROR_HTTP_RESPONSE_FIRST_BYTE_TIMEOUT); |
| 254 |
size_t current_timeout_ms = aws_atomic_load_int(&client->upload_timeout_ms); |
| 255 |
ASSERT_UINT_EQUALS(1000, current_timeout_ms); |
| 256 |
|
| 257 |
|
| 258 |
aws_s3_client_update_upload_part_timeout(client, &mock_request, AWS_ERROR_HTTP_RESPONSE_FIRST_BYTE_TIMEOUT); |
| 259 |
current_timeout_ms = aws_atomic_load_int(&client->upload_timeout_ms); |
| 260 |
ASSERT_UINT_EQUALS(2000, current_timeout_ms); |
| 261 |
|
| 262 |
for (size_t i = 0; i < 10; i++) { |
| 263 |
aws_s3_client_update_upload_part_timeout(client, &mock_request, AWS_ERROR_HTTP_RESPONSE_FIRST_BYTE_TIMEOUT); |
| 264 |
} |
| 265 |
current_timeout_ms = aws_atomic_load_int(&client->upload_timeout_ms); |
| 266 |
|
| 267 |
ASSERT_UINT_EQUALS(2000, current_timeout_ms); |
| 268 |
|
| 269 |
|
| 270 |
s_init_mock_s3_request_upload_part_timeout( |
| 271 |
&mock_request, |
| 272 |
current_timeout_ms , |
| 273 |
real_response_time_ns, |
| 274 |
real_response_time_ns); |
| 275 |
for (size_t i = 0; i < 10; i++) { |
| 276 |
aws_s3_client_update_upload_part_timeout(client, &mock_request, AWS_ERROR_HTTP_RESPONSE_FIRST_BYTE_TIMEOUT); |
| 277 |
} |
| 278 |
current_timeout_ms = aws_atomic_load_int(&client->upload_timeout_ms); |
| 279 |
|
| 280 |
ASSERT_UINT_EQUALS(3000, current_timeout_ms); |
| 281 |
|
| 282 |
|
| 283 |
s_init_mock_s3_request_upload_part_timeout( |
| 284 |
&mock_request, |
| 285 |
current_timeout_ms , |
| 286 |
real_response_time_ns, |
| 287 |
real_response_time_ns); |
| 288 |
|
| 289 |
aws_s3_client_update_upload_part_timeout(client, &mock_request, AWS_ERROR_HTTP_RESPONSE_FIRST_BYTE_TIMEOUT); |
| 290 |
for (size_t i = 0; i < 10; i++) { |
| 291 |
aws_s3_client_update_upload_part_timeout(client, &mock_request, AWS_ERROR_SUCCESS); |
| 292 |
} |
| 293 |
|
| 294 |
current_timeout_ms = aws_atomic_load_int(&client->upload_timeout_ms); |
| 295 |
ASSERT_UINT_EQUALS(3000, current_timeout_ms); |
| 296 |
ASSERT_FALSE(client->synced_data.upload_part_stats.stop_timeout); |
| 297 |
|
| 298 |
if (client->synced_data.upload_part_stats.initial_request_time.collecting_p90) { |
| 299 |
aws_priority_queue_clean_up(&client->synced_data.upload_part_stats.initial_request_time.p90_samples); |
| 300 |
client->synced_data.upload_part_stats.initial_request_time.collecting_p90 = false; |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
{ |
| 305 |
ASSERT_SUCCESS(s_starts_upload_retry(client, &mock_request)); |
| 306 |
|
| 307 |
s_init_mock_s3_request_upload_part_timeout(&mock_request, 1000 , 0, 0); |
| 308 |
|
| 309 |
for (size_t i = 0; i < 10; i++) { |
| 310 |
|
| 311 |
aws_s3_client_update_upload_part_timeout(client, &mock_request, AWS_ERROR_HTTP_RESPONSE_FIRST_BYTE_TIMEOUT); |
| 312 |
aws_s3_client_update_upload_part_timeout(client, &mock_request, AWS_ERROR_HTTP_RESPONSE_FIRST_BYTE_TIMEOUT); |
| 313 |
size_t current_timeout_ms = aws_atomic_load_int(&client->upload_timeout_ms); |
| 314 |
s_init_mock_s3_request_upload_part_timeout( |
| 315 |
&mock_request, current_timeout_ms , 0, 0); |
| 316 |
} |
| 317 |
|
| 318 |
size_t current_timeout_ms = aws_atomic_load_int(&client->upload_timeout_ms); |
| 319 |
ASSERT_UINT_EQUALS(0, current_timeout_ms); |
| 320 |
ASSERT_TRUE(client->synced_data.upload_part_stats.stop_timeout); |
| 321 |
} |
| 322 |
|
| 323 |
aws_s3_client_release(client); |
| 324 |
aws_s3_tester_clean_up(&tester); |
| 325 |
return AWS_OP_SUCCESS; |
| 326 |
} |
| 327 |
|
| 328 |
|
| 329 |
TEST_CASE(client_meta_request_override_part_size) { |
| 330 |
(void)ctx; |
| 331 |
struct aws_s3_tester tester; |
| 332 |
AWS_ZERO_STRUCT(tester); |
| 333 |
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester)); |
| 334 |
struct aws_s3_client *client = NULL; |
| 335 |
struct aws_s3_tester_client_options client_options = { |
| 336 |
.part_size = MB_TO_BYTES(8), |
| 337 |
.tls_usage = AWS_S3_TLS_DISABLED, |
| 338 |
}; |
| 339 |
ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client)); |
| 340 |
|
| 341 |
struct aws_string *host_name = |
| 342 |
aws_s3_tester_build_endpoint_string(allocator, &g_test_bucket_name, &g_test_s3_region); |
| 343 |
struct aws_byte_cursor host_cur = aws_byte_cursor_from_string(host_name); |
| 344 |
struct aws_byte_cursor test_object_path = aws_byte_cursor_from_c_str("/mytest"); |
| 345 |
|
| 346 |
size_t override_part_size = MB_TO_BYTES(10); |
| 347 |
size_t content_length = |
| 348 |
MB_TO_BYTES(20); |
| 349 |
|
| 350 |
|
| 351 |
struct aws_input_stream_tester_options stream_options = { |
| 352 |
.autogen_length = content_length, |
| 353 |
}; |
| 354 |
struct aws_input_stream *input_stream = aws_input_stream_new_tester(allocator, &stream_options); |
| 355 |
|
| 356 |
struct aws_http_message *put_messages = aws_s3_test_put_object_request_new( |
| 357 |
allocator, &host_cur, g_test_body_content_type, test_object_path, input_stream, 0 ); |
| 358 |
|
| 359 |
struct aws_s3_meta_request_options meta_request_options = { |
| 360 |
.message = put_messages, |
| 361 |
.type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT, |
| 362 |
.part_size = override_part_size, |
| 363 |
}; |
| 364 |
struct aws_s3_meta_request *put_meta_request = client->vtable->meta_request_factory(client, &meta_request_options); |
| 365 |
ASSERT_UINT_EQUALS(put_meta_request->part_size, override_part_size); |
| 366 |
|
| 367 |
|
| 368 |
struct aws_http_message *get_message = aws_s3_test_get_object_request_new( |
| 369 |
allocator, aws_byte_cursor_from_string(host_name), g_pre_existing_object_1MB); |
| 370 |
|
| 371 |
struct aws_s3_meta_request_options get_meta_request_options = { |
| 372 |
.message = get_message, |
| 373 |
.type = AWS_S3_META_REQUEST_TYPE_GET_OBJECT, |
| 374 |
.part_size = override_part_size, |
| 375 |
}; |
| 376 |
|
| 377 |
struct aws_s3_meta_request *get_meta_request = |
| 378 |
client->vtable->meta_request_factory(client, &get_meta_request_options); |
| 379 |
ASSERT_UINT_EQUALS(get_meta_request->part_size, override_part_size); |
| 380 |
|
| 381 |
aws_http_message_release(put_messages); |
| 382 |
aws_s3_meta_request_release(put_meta_request); |
| 383 |
aws_http_message_release(get_message); |
| 384 |
aws_s3_meta_request_release(get_meta_request); |
| 385 |
aws_string_destroy(host_name); |
| 386 |
aws_s3_client_release(client); |
| 387 |
aws_input_stream_release(input_stream); |
| 388 |
aws_s3_tester_clean_up(&tester); |
| 389 |
|
| 390 |
return AWS_OP_SUCCESS; |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
TEST_CASE(client_meta_request_override_multipart_upload_threshold) { |
| 395 |
(void)ctx; |
| 396 |
struct aws_s3_tester tester; |
| 397 |
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester)); |
| 398 |
|
| 399 |
struct aws_s3_client_config client_config = { |
| 400 |
.part_size = MB_TO_BYTES(8), |
| 401 |
.multipart_upload_threshold = MB_TO_BYTES(15), |
| 402 |
}; |
| 403 |
|
| 404 |
ASSERT_SUCCESS(aws_s3_tester_bind_client( |
| 405 |
&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_REGION | AWS_S3_TESTER_BIND_CLIENT_SIGNING)); |
| 406 |
|
| 407 |
struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config); |
| 408 |
|
| 409 |
ASSERT_TRUE(client != NULL); |
| 410 |
|
| 411 |
struct aws_string *host_name = |
| 412 |
aws_s3_tester_build_endpoint_string(allocator, &g_test_bucket_name, &g_test_s3_region); |
| 413 |
struct aws_byte_cursor host_cur = aws_byte_cursor_from_string(host_name); |
| 414 |
struct aws_byte_cursor test_object_path = aws_byte_cursor_from_c_str("/mytest"); |
| 415 |
|
| 416 |
size_t override_multipart_upload_threshold = MB_TO_BYTES(20); |
| 417 |
size_t content_length = |
| 418 |
MB_TO_BYTES(20); |
| 419 |
|
| 420 |
|
| 421 |
struct aws_input_stream_tester_options stream_options = { |
| 422 |
.autogen_length = content_length, |
| 423 |
}; |
| 424 |
struct aws_input_stream *input_stream = aws_input_stream_new_tester(allocator, &stream_options); |
| 425 |
|
| 426 |
struct aws_http_message *put_messages = aws_s3_test_put_object_request_new( |
| 427 |
allocator, &host_cur, g_test_body_content_type, test_object_path, input_stream, 0 ); |
| 428 |
|
| 429 |
{ |
| 430 |
|
| 431 |
struct aws_s3_meta_request_options meta_request_options = { |
| 432 |
.message = put_messages, |
| 433 |
.type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT, |
| 434 |
.multipart_upload_threshold = override_multipart_upload_threshold, |
| 435 |
}; |
| 436 |
struct aws_s3_meta_request *put_meta_request = |
| 437 |
client->vtable->meta_request_factory(client, &meta_request_options); |
| 438 |
|
| 439 |
|
| 440 |
ASSERT_UINT_EQUALS(put_meta_request->part_size, 0); |
| 441 |
aws_s3_meta_request_release(put_meta_request); |
| 442 |
} |
| 443 |
|
| 444 |
{ |
| 445 |
|
| 446 |
|
| 447 |
struct aws_s3_meta_request_options meta_request_options = { |
| 448 |
.message = put_messages, |
| 449 |
.type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT, |
| 450 |
.part_size = override_multipart_upload_threshold, |
| 451 |
}; |
| 452 |
struct aws_s3_meta_request *put_meta_request = |
| 453 |
client->vtable->meta_request_factory(client, &meta_request_options); |
| 454 |
|
| 455 |
|
| 456 |
ASSERT_UINT_EQUALS(put_meta_request->part_size, 0); |
| 457 |
aws_s3_meta_request_release(put_meta_request); |
| 458 |
} |
| 459 |
|
| 460 |
aws_http_message_release(put_messages); |
| 461 |
aws_string_destroy(host_name); |
| 462 |
aws_s3_client_release(client); |
| 463 |
aws_input_stream_release(input_stream); |
| 464 |
aws_s3_tester_clean_up(&tester); |
| 465 |
|
| 466 |
return AWS_OP_SUCCESS; |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
TEST_CASE(s3_calculate_client_optimal_range_size) { |
| 471 |
(void)ctx; |
| 472 |
struct aws_s3_tester tester; |
| 473 |
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester)); |
| 474 |
|
| 475 |
|
| 476 |
{ |
| 477 |
struct aws_s3_client_config client_config = { |
| 478 |
.part_size = MB_TO_BYTES(8), |
| 479 |
.throughput_target_gbps = 10.0, |
| 480 |
.memory_limit_in_bytes = GB_TO_BYTES(2), |
| 481 |
}; |
| 482 |
|
| 483 |
ASSERT_SUCCESS(aws_s3_tester_bind_client( |
| 484 |
&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_REGION | AWS_S3_TESTER_BIND_CLIENT_SIGNING)); |
| 485 |
|
| 486 |
struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config); |
| 487 |
ASSERT_TRUE(client != NULL); |
| 488 |
|
| 489 |
|
| 490 |
ASSERT_TRUE(client->optimal_range_size >= MB_TO_BYTES(8)); |
| 491 |
ASSERT_TRUE(client->optimal_range_size <= GB_TO_BYTES(1)); |
| 492 |
|
| 493 |
|
| 494 |
ASSERT_TRUE(client->optimal_range_size > 0); |
| 495 |
|
| 496 |
aws_s3_client_release(client); |
| 497 |
} |
| 498 |
|
| 499 |
|
| 500 |
{ |
| 501 |
struct aws_s3_client_config client_config = { |
| 502 |
.part_size = MB_TO_BYTES(8), |
| 503 |
.throughput_target_gbps = 10.0, |
| 504 |
.memory_limit_in_bytes = GB_TO_BYTES(16), |
| 505 |
}; |
| 506 |
|
| 507 |
ASSERT_SUCCESS(aws_s3_tester_bind_client( |
| 508 |
&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_REGION | AWS_S3_TESTER_BIND_CLIENT_SIGNING)); |
| 509 |
|
| 510 |
struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config); |
| 511 |
ASSERT_TRUE(client != NULL); |
| 512 |
|
| 513 |
|
| 514 |
ASSERT_TRUE(client->optimal_range_size >= MB_TO_BYTES(8)); |
| 515 |
ASSERT_TRUE(client->optimal_range_size <= GB_TO_BYTES(1)); |
| 516 |
|
| 517 |
aws_s3_client_release(client); |
| 518 |
} |
| 519 |
|
| 520 |
|
| 521 |
{ |
| 522 |
struct aws_s3_client_config client_config = { |
| 523 |
.part_size = MB_TO_BYTES(8), |
| 524 |
.throughput_target_gbps = 100.0, |
| 525 |
.memory_limit_in_bytes = MB_TO_BYTES(512), |
| 526 |
}; |
| 527 |
|
| 528 |
ASSERT_SUCCESS(aws_s3_tester_bind_client( |
| 529 |
&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_REGION | AWS_S3_TESTER_BIND_CLIENT_SIGNING)); |
| 530 |
|
| 531 |
struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config); |
| 532 |
ASSERT_TRUE(client != NULL); |
| 533 |
|
| 534 |
|
| 535 |
ASSERT_TRUE(client->optimal_range_size >= MB_TO_BYTES(8)); |
| 536 |
|
| 537 |
aws_s3_client_release(client); |
| 538 |
} |
| 539 |
|
| 540 |
aws_s3_tester_clean_up(&tester); |
| 541 |
return AWS_OP_SUCCESS; |
| 542 |
} |