void test_upload_decision_by_timeout(void) { KAA_TRACE_IN(logger); kaa_error_t error_code = KAA_ERR_NONE; size_t DEFAULT_UPLOAD_TIMEOUT_THRESHOLD = 1;// in sec. error_code = ext_log_upload_strategy_change_strategy(strategy, KAA_LOG_UPLOAD_BY_TIMEOUT_STRATEGY); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = ext_log_upload_strategy_set_upload_timeout(strategy, DEFAULT_UPLOAD_TIMEOUT_THRESHOLD); ASSERT_EQUAL(error_code, KAA_ERR_NONE); test_log_storage_context_t log_storage_context; ext_log_upload_decision_t upload_decision = NOOP; log_storage_context.total_size = 0; log_storage_context.record_count = 0; log_storage_context.upload_timeout = DEFAULT_UPLOAD_TIMEOUT_THRESHOLD; upload_decision = ext_log_upload_strategy_decide(strategy, &log_storage_context); ASSERT_EQUAL(upload_decision, NOOP); log_storage_context.upload_timeout = DEFAULT_UPLOAD_TIMEOUT_THRESHOLD + 1; usleep(1000 * 1000); upload_decision = ext_log_upload_strategy_decide(strategy, &log_storage_context); ASSERT_EQUAL(upload_decision, UPLOAD); KAA_TRACE_OUT(logger); }
void test_upload_decision_by_count(void) { KAA_TRACE_IN(logger); kaa_error_t error_code = KAA_ERR_NONE; size_t DEFAULT_UPLOAD_COUNT_THRESHOLD = 64; error_code = ext_log_upload_strategy_change_strategy(strategy, KAA_LOG_UPLOAD_BY_RECORD_COUNT); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = ext_log_upload_strategy_set_threshold_count(strategy, DEFAULT_UPLOAD_COUNT_THRESHOLD); ASSERT_EQUAL(error_code, KAA_ERR_NONE); test_log_storage_context_t log_storage_context; ext_log_upload_decision_t upload_decision = NOOP; log_storage_context.total_size = 0; log_storage_context.record_count = DEFAULT_UPLOAD_COUNT_THRESHOLD - 1; upload_decision = ext_log_upload_strategy_decide(strategy, &log_storage_context); ASSERT_EQUAL(upload_decision, NOOP); log_storage_context.total_size = 0; log_storage_context.record_count = DEFAULT_UPLOAD_COUNT_THRESHOLD; upload_decision = ext_log_upload_strategy_decide(strategy, &log_storage_context); ASSERT_EQUAL(upload_decision, UPLOAD); log_storage_context.total_size = 0; log_storage_context.record_count = DEFAULT_UPLOAD_COUNT_THRESHOLD + 1; upload_decision = ext_log_upload_strategy_decide(strategy, &log_storage_context); ASSERT_EQUAL(upload_decision, UPLOAD); KAA_TRACE_OUT(logger); }
void test_noop_decision_on_failure(void **state) { (void)state; size_t DEFAULT_UPLOAD_VOLUME_THRESHOLD = 8 * 1024; size_t DEFAULT_UPLOAD_COUNT_THRESHOLD = 64; kaa_error_t error_code = ext_log_upload_strategy_change_strategy(strategy, KAA_LOG_UPLOAD_VOLUME_STRATEGY); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = ext_log_upload_strategy_set_threshold_volume(strategy, DEFAULT_UPLOAD_VOLUME_THRESHOLD); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = ext_log_upload_strategy_set_threshold_count(strategy, DEFAULT_UPLOAD_COUNT_THRESHOLD); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = ext_log_upload_strategy_on_failure(NULL, NO_APPENDERS_CONFIGURED); ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE); error_code = ext_log_upload_strategy_on_failure(strategy, NO_APPENDERS_CONFIGURED); ASSERT_EQUAL(error_code, KAA_ERR_NONE); test_log_storage_context_t log_storage_context; log_storage_context.total_size = DEFAULT_UPLOAD_VOLUME_THRESHOLD; log_storage_context.record_count = DEFAULT_UPLOAD_COUNT_THRESHOLD; ext_log_upload_decision_t upload_decision = ext_log_upload_strategy_decide(strategy, &log_storage_context); ASSERT_EQUAL(upload_decision, NOOP); }
void test_upload_decision_on_failure(void) { KAA_TRACE_IN(logger); kaa_error_t error_code = KAA_ERR_NONE; size_t DEFAULT_RETRY_PERIOD = 2; size_t DEFAULT_UPLOAD_VOLUME_THRESHOLD = 8 * 1024; size_t DEFAULT_UPLOAD_COUNT_THRESHOLD = 64; error_code = ext_log_upload_strategy_change_strategy(strategy, KAA_LOG_UPLOAD_VOLUME_STRATEGY); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = ext_log_upload_strategy_set_threshold_volume(strategy, DEFAULT_UPLOAD_VOLUME_THRESHOLD); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = ext_log_upload_strategy_set_threshold_count(strategy, DEFAULT_UPLOAD_COUNT_THRESHOLD); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = ext_log_upload_strategy_set_upload_retry_period(strategy, DEFAULT_RETRY_PERIOD); ASSERT_EQUAL(error_code, KAA_ERR_NONE); error_code = ext_log_upload_strategy_on_failure(strategy, NO_APPENDERS_CONFIGURED); ASSERT_EQUAL(error_code, KAA_ERR_NONE); test_log_storage_context_t log_storage_context; ext_log_upload_decision_t upload_decision = NOOP; log_storage_context.total_size = DEFAULT_UPLOAD_VOLUME_THRESHOLD; log_storage_context.record_count = DEFAULT_UPLOAD_COUNT_THRESHOLD; upload_decision = ext_log_upload_strategy_decide(strategy, &log_storage_context); ASSERT_EQUAL(upload_decision, NOOP); sleep(DEFAULT_RETRY_PERIOD); log_storage_context.total_size = DEFAULT_UPLOAD_VOLUME_THRESHOLD; log_storage_context.record_count = DEFAULT_UPLOAD_COUNT_THRESHOLD; upload_decision = ext_log_upload_strategy_decide(strategy, &log_storage_context); ASSERT_EQUAL(upload_decision, UPLOAD); KAA_TRACE_OUT(logger); }