Пример #1
0
void test_add_log_record(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;
    void *storage;

    error_code = ext_unlimited_log_storage_create(&storage, logger);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    size_t record_count = 0;
    const char *data = "DATA";
    size_t data_size = strlen("DATA");

    error_code = add_log_record(storage, data, data_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ++record_count;

    ASSERT_EQUAL(ext_log_storage_get_records_count(storage), record_count);

    error_code = add_log_record(storage, data, data_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ++record_count;

    ASSERT_EQUAL(ext_log_storage_get_records_count(storage), record_count);
    ASSERT_EQUAL(ext_log_storage_get_total_size(storage), record_count * data_size);

    ext_log_storage_destroy(storage);

    KAA_TRACE_OUT(logger);
}
Пример #2
0
void kaa_client_destroy(kaa_client_t *self)
{
    if (!self)
        return;

    self->controler = NULL;

    if (self->channel.context) {
        self->channel.destroy(self->channel.context);
        self->channel.context = NULL;
    }

    if (self->channel.context) {
        self->channel.destroy(self->channel.context);
        self->channel.context = NULL;
    }

    if (self->log_storage_context) {
        ext_log_storage_destroy(self->log_storage_context);
        self->log_storage_context = NULL;
    }

    if (self->kaa_context) {
        kaa_deinit(self->kaa_context);
        self->kaa_context = NULL;
    }

    free(self);
}
Пример #3
0
void test_allocate_log_record_buffer(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;
    void *storage;

    error_code = ext_unlimited_log_storage_create(&storage, logger);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_log_storage_allocate_log_record_buffer(storage, NULL);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    kaa_log_record_t record1 = { NULL, 0 };
    error_code = ext_log_storage_allocate_log_record_buffer(storage, &record1);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_NULL(record1.data);

    kaa_log_record_t record2 = { NULL, 256 };
    error_code = ext_log_storage_allocate_log_record_buffer(storage, &record2);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_NOT_NULL(record2.data);

    ext_log_storage_deallocate_log_record_buffer(storage, &record2);
    ext_log_storage_destroy(storage);

    KAA_TRACE_OUT(logger);
}
Пример #4
0
KAA_TEST_CASE_EX(log_setters, set_strategy_valid_parameters)
{
    (void)state;
    kaa_error_t rc;

    /* First strategy will be internally deleted */
    rc = kaa_logging_set_strategy(log_collector, &test_strategy2);
    ASSERT_EQUAL(KAA_ERR_NONE, rc);

    ext_log_storage_destroy(test_storage2);

    /* Second strategy will be deleted on test teardown */
}
Пример #5
0
KAA_TEST_CASE_EX(log_setters, set_storage_invalid_parameters)
{
    (void)state;
    kaa_error_t rc;

    rc = kaa_logging_set_storage(log_collector, NULL);
    ASSERT_EQUAL(KAA_ERR_BADPARAM, rc);

    rc = kaa_logging_set_storage(NULL, test_storage2);
    ASSERT_EQUAL(KAA_ERR_BADPARAM, rc);

    ext_log_storage_destroy(test_storage2);
    ext_log_upload_strategy_destroy(&test_strategy2);
}
Пример #6
0
void test_create_limited_storage(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;
    void *storage;

    const size_t OVERFLOW_PERCENTAGE = 152;
    const size_t ALLOWED_PERCENTAGE = 99;
    const size_t ALL_LOGS_PERCENTAGE = 100;

    error_code = ext_limited_log_storage_create(NULL, NULL, 0, 0);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_limited_log_storage_create(&storage, NULL, 0, 0);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_limited_log_storage_create(&storage, logger, 0, 0);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_limited_log_storage_create(&storage, logger, SIZE_MAX, 0);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_limited_log_storage_create(&storage, logger, SIZE_MAX, OVERFLOW_PERCENTAGE);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_limited_log_storage_create(&storage, logger, 100, ALLOWED_PERCENTAGE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ext_log_storage_destroy(storage);

    error_code = ext_limited_log_storage_create(&storage, logger, 100, ALL_LOGS_PERCENTAGE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    ext_log_storage_destroy(storage);

    KAA_TRACE_OUT(logger);
}
Пример #7
0
void kaa_client_destroy(kaa_client_t *kaa_client)
{
    if(!kaa_client)
        return;

    if (kaa_client->start_semophore) {
        sndc_sem_destroy(kaa_client->start_semophore);
        kaa_client->start_semophore = NULL;
    }

    if (kaa_client->logging_semophore) {
        sndc_sem_destroy(kaa_client->logging_semophore);
        kaa_client->logging_semophore = NULL;
    }

    if (kaa_client->operations_channel.context) {
        kaa_client->operations_channel.destroy(kaa_client->operations_channel.context);
        kaa_client->operations_channel.context = NULL;
    }

    if (kaa_client->bootstrap_channel.context) {
        kaa_client->bootstrap_channel.destroy(kaa_client->bootstrap_channel.context);
        kaa_client->bootstrap_channel.context = NULL;
    }

    if (kaa_client->log_storage_context) {
        ext_log_storage_destroy(kaa_client->log_storage_context);
        kaa_client->log_storage_context = NULL;
    }

    if (kaa_client->kaa_context) {
        kaa_deinit(kaa_client->kaa_context);
        kaa_client->kaa_context = NULL;
    }

    if (kaa_client->thread_name) {
        sndc_mem_free(kaa_client->thread_name);
    }
    sndc_mem_free(kaa_client);
}
Пример #8
0
void test_shrink_to_size(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;
    void *storage;

    const char *data = "DATA";
    size_t data_size = strlen("DATA");
    size_t TEST_RECORD_COUNT = 10;

    size_t STORAGE_SIZE = data_size * TEST_RECORD_COUNT;
    size_t PERCENT_TO_DELETE = 75;
    size_t NEW_STORAGE_SIZE = (STORAGE_SIZE * (100 - PERCENT_TO_DELETE) / 100);

    error_code = ext_limited_log_storage_create(&storage, logger, STORAGE_SIZE, PERCENT_TO_DELETE);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    size_t record_count = 0;

    while (record_count <= TEST_RECORD_COUNT) {
        error_code = add_log_record(storage, data, data_size);
        ASSERT_EQUAL(error_code, KAA_ERR_NONE);
        ++record_count;
    }

    size_t occupied_size_after_removal = 0;
    size_t record_count_after_removal = 0;
    while (occupied_size_after_removal + data_size <= NEW_STORAGE_SIZE) {
        occupied_size_after_removal += data_size;
        ++record_count_after_removal;
    }

    ASSERT_EQUAL(ext_log_storage_get_records_count(storage), record_count_after_removal + 1 /* new record added after removal */);
    ASSERT_EQUAL(ext_log_storage_get_total_size(storage), occupied_size_after_removal + data_size);

    ext_log_storage_destroy(storage);

    KAA_TRACE_OUT(logger);
}
Пример #9
0
void test_create_unlimited_storage(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;
    void *storage;

    error_code = ext_unlimited_log_storage_create(NULL, NULL);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_unlimited_log_storage_create(&storage, NULL);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_unlimited_log_storage_create(NULL, logger);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_unlimited_log_storage_create(&storage, logger);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    ext_log_storage_destroy(storage);

    KAA_TRACE_OUT(logger);
}
Пример #10
0
void test_unmark_by_bucket_id(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;
    void *storage;

    error_code = ext_unlimited_log_storage_create(&storage, logger);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    size_t record_len = 0;
    size_t TEST_RECORD_COUNT = 10;
    size_t record_count = 0;
    const char *data = "DATA";
    size_t data_size = strlen("DATA");

    while (record_count < TEST_RECORD_COUNT) {
        error_code = add_log_record(storage, data, data_size);
        ASSERT_EQUAL(error_code, KAA_ERR_NONE);
        ++record_count;
    }

    size_t buffer_size = data_size;
    char buffer[buffer_size];

    size_t bucket_id_1 = 1;
    size_t i;
    for (i = 0; i < record_count / 2; ++i) {
        error_code = ext_log_storage_write_next_record(storage, buffer, buffer_size, bucket_id_1, &record_len);
        ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    }

    size_t bucket_id_2 = 2;
    for (i = 0; i < record_count / 2; ++i) {
        error_code = ext_log_storage_write_next_record(storage, buffer, buffer_size, bucket_id_2, &record_len);
        ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    }

    size_t bucket_id_3 = 3;
    error_code = ext_log_storage_write_next_record(storage, buffer, buffer_size, bucket_id_3, &record_len);
    ASSERT_EQUAL(error_code, KAA_ERR_NOT_FOUND);

    error_code = ext_log_storage_remove_by_bucket_id(storage, bucket_id_2);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_log_storage_write_next_record(storage, buffer, buffer_size, bucket_id_3, &record_len);
    ASSERT_EQUAL(error_code, KAA_ERR_NOT_FOUND);

    error_code = ext_log_storage_unmark_by_bucket_id(storage, bucket_id_1);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    size_t bucket_id_4 = 4;
    for (i = 0; i < record_count / 2; ++i) {
        error_code = ext_log_storage_write_next_record(storage, buffer, buffer_size, bucket_id_4, &record_len);
        ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    }

    error_code = ext_log_storage_write_next_record(storage, buffer, buffer_size, bucket_id_3, &record_len);
    ASSERT_EQUAL(error_code, KAA_ERR_NOT_FOUND);

    error_code = ext_log_storage_remove_by_bucket_id(storage, bucket_id_4);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    ASSERT_EQUAL(ext_log_storage_get_records_count(storage), 0);
    ASSERT_EQUAL(ext_log_storage_get_total_size(storage), 0);

    ext_log_storage_destroy(storage);

    KAA_TRACE_OUT(logger);
}
Пример #11
0
void test_write_next_log_record(void)
{
    KAA_TRACE_IN(logger);

    kaa_error_t error_code;
    void *storage;

    error_code = ext_unlimited_log_storage_create(&storage, logger);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);

    size_t bucket_id = 0;
    size_t record_len = 0;

    error_code = ext_log_storage_write_next_record(storage, NULL, 0, 0, NULL);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_log_storage_write_next_record(storage, NULL, 33, 0, NULL);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_log_storage_write_next_record(storage, NULL, 33, bucket_id, NULL);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    error_code = ext_log_storage_write_next_record(storage, NULL, 33, bucket_id, &record_len);
    ASSERT_NOT_EQUAL(error_code, KAA_ERR_NONE);

    size_t record_count = 0;
    const char *data = "DATA";
    size_t data_size = strlen("DATA");

    error_code = add_log_record(storage, data, data_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ++record_count;
    error_code = add_log_record(storage, data, data_size);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ++record_count;

    size_t buffer_size = (record_count + 1) * data_size;
    char buffer[buffer_size];

    bucket_id = 1;
    error_code = ext_log_storage_write_next_record(storage, buffer, 1, bucket_id, &record_len);
    ASSERT_EQUAL(error_code, KAA_ERR_INSUFFICIENT_BUFFER);

    error_code = ext_log_storage_write_next_record(storage, buffer, buffer_size, bucket_id, &record_len);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(record_len, data_size);

    error_code = ext_log_storage_write_next_record(storage, buffer + record_len, buffer_size - record_len, bucket_id, &record_len);
    ASSERT_EQUAL(error_code, KAA_ERR_NONE);
    ASSERT_EQUAL(record_len, data_size);

    error_code = ext_log_storage_write_next_record(storage, buffer + 2 * record_len, buffer_size - 2 * record_len, bucket_id, &record_len);
    ASSERT_EQUAL(error_code, KAA_ERR_NOT_FOUND);

    int res = memcmp(buffer, data, data_size);
    ASSERT_EQUAL(res, 0);
    res = memcmp(buffer + data_size, data, data_size);
    ASSERT_EQUAL(res, 0);

    ext_log_storage_destroy(storage);

    KAA_TRACE_OUT(logger);
}