コード例 #1
0
ファイル: data_file_tests.c プロジェクト: emiddleton/sky
int test_sky_data_file_deduplicate_insertion_event_data() {
    struct tagbstring STR1 = bsStatic("foo");
    struct tagbstring STR2 = bsStatic("bar");
    struct tagbstring STR3 = bsStatic("zzz");
    int rc;
    sky_event *event;
    sky_data_file *data_file;
    INIT_DATA_FILE("tests/fixtures/data_files/dedup/0/a", 0);

    // Add initial event.
    event = sky_event_create(1, 10LL, 1);
    event->data_count = 8;
    event->data = calloc(event->data_count, sizeof(*event->data));
    event->data[0] = sky_event_data_create_string(-1, &STR2);
    event->data[1] = sky_event_data_create_int(-2, 200);
    event->data[2] = sky_event_data_create_double(-3, 1.0);
    event->data[3] = sky_event_data_create_boolean(-4, false);
    event->data[4] = sky_event_data_create_string(1, &STR1);
    event->data[5] = sky_event_data_create_int(2, 100);
    event->data[6] = sky_event_data_create_double(3, 100.2);
    event->data[7] = sky_event_data_create_boolean(4, true);
    rc = sky_data_file_add_event(data_file, event);
    mu_assert_int_equals(rc, 0);
    
    ASSERT_DATA_FILE("tests/fixtures/data_files/dedup/0/b");

    // Add the same event data, different timestamp.
    event->timestamp = 11LL;
    rc = sky_data_file_add_event(data_file, event);
    mu_assert_int_equals(rc, 0);
    sky_event_free(event);
    
    ASSERT_DATA_FILE("tests/fixtures/data_files/dedup/0/c");

    // Add somewhat different object state event.
    event = sky_event_create(1, 12LL, 0);
    event->data_count = 4;
    event->data = calloc(event->data_count, sizeof(*event->data));
    event->data[0] = sky_event_data_create_string(1, &STR3);
    event->data[1] = sky_event_data_create_int(2, 20);
    event->data[2] = sky_event_data_create_double(3, 100.2);
    event->data[3] = sky_event_data_create_boolean(4, false);
    rc = sky_data_file_add_event(data_file, event);
    mu_assert_int_equals(rc, 0);
    sky_event_free(event);

    ASSERT_DATA_FILE("tests/fixtures/data_files/dedup/0/d");

    sky_data_file_free(data_file);
    return 0;
}
コード例 #2
0
ファイル: event_tests.c プロジェクト: emiddleton/sky
// Action-only event.
int test_sky_event_action_event_sizeof() {
    sky_event *event = sky_event_create(0, 1325376000000LL, 20);
    size_t sz = sky_event_sizeof(event);
    mu_assert_long_equals(sz, 13L);
    sky_event_free(event);
    return 0;
}
コード例 #3
0
ファイル: importer.c プロジェクト: dasfaha/sky
int sky_importer_process_event(sky_importer *importer, bstring source,
                               jsmntok_t *tokens, uint32_t *index)
{
    int rc;
    check(importer != NULL, "Importer required");
    check(source != NULL, "Source required");
    check(tokens != NULL, "Tokens required");
    check(index != NULL, "Token index required");

    jsmntok_t *event_token = &tokens[*index];
    (*index)++;

    // Open table if it hasn't been already.
    if(!importer->table->opened) {
        check(sky_table_open(importer->table) == 0, "Unable to open table");
    }

    // Create the event object.
    sky_event *event = sky_event_create(0, 0, 0); check_mem(event);
        
    // Process over child tokens.
    int32_t i;
    for(i=0; i<(event_token->size/2); i++) {
        jsmntok_t *token = &tokens[*index];
        (*index)++;
        
        if(sky_importer_tokstr_equal(source, token, "timestamp")) {
            bstring timestamp = sky_importer_token_parse_bstring(source, &tokens[(*index)++]);
            rc = sky_timestamp_parse(timestamp, &event->timestamp);
            check(rc == 0, "Unable to parse timestamp");
            bdestroy(timestamp);
        }
        else if(sky_importer_tokstr_equal(source, token, "objectId")) {
            event->object_id = (sky_object_id_t)sky_importer_token_parse_int(source, &tokens[(*index)++]);
        }
        else if(sky_importer_tokstr_equal(source, token, "action")) {
            sky_action *action = NULL;
            bstring action_name = sky_importer_token_parse_bstring(source, &tokens[(*index)++]);
            rc = sky_action_file_find_action_by_name(importer->table->action_file, action_name, &action);
            check(rc == 0, "Unable to find action: %s", bdata(action_name));
            event->action_id = action->id;
        }
        else if(sky_importer_tokstr_equal(source, token, "data")) {
            rc = sky_importer_process_event_data(importer, event, source, tokens, index);
            check(rc == 0, "Unable to import event data");
        }
        else {
            sentinel("Invalid token at char %d", tokens[*index].start);
        }
    }
    
    // Add event.
    rc = sky_table_add_event(importer->table, event);
    check(rc == 0, "Unable to add event");
    
    return 0;

error:
    return -1;
}
コード例 #4
0
ファイル: event_tests.c プロジェクト: emiddleton/sky
// Action + data event.
int test_sky_event_action_data_event_sizeof() {
    sky_event *event = sky_event_create(0, 1325376000000LL, 100);
    sky_event_set_data(event, 1, &foo);
    sky_event_set_data(event, 2, &bar);
    size_t sz = sky_event_sizeof(event);
    mu_assert_long_equals(sz, 27L);
    sky_event_free(event);
    return 0;
}
コード例 #5
0
ファイル: event_tests.c プロジェクト: emiddleton/sky
// Action event.
int test_sky_event_action_event_pack() {
    size_t sz;
    void *addr = calloc(ACTION_EVENT_DATA_LENGTH, 1);
    sky_event *event = sky_event_create(0, 30LL, 20);
    sky_event_pack(event, addr, &sz);
    sky_event_free(event);
    mu_assert_long_equals(sz, ACTION_EVENT_DATA_LENGTH);
    mu_assert_mem(addr, &ACTION_EVENT_DATA, ACTION_EVENT_DATA_LENGTH);
    free(addr);
    return 0;
}
コード例 #6
0
ファイル: event_tests.c プロジェクト: emiddleton/sky
int test_sky_event_create() {
    sky_event *event = sky_event_create(10, 1325376000000LL, 200);
    mu_assert(event != NULL, "Unable to allocate event");
    mu_assert(event->timestamp == 1325376000000LL, "Event timestamp not assigned");
    mu_assert(event->object_id == 10, "Event object id not assigned");
    mu_assert(event->action_id == 200, "Event action id not assigned");
    mu_assert(event->data == NULL, "Event data non-null");
    mu_assert(event->data_count == 0, "Event data count not initialized");

    sky_event_free(event);

    return 0;
}
コード例 #7
0
ファイル: event_tests.c プロジェクト: emiddleton/sky
// Data event.
int test_sky_event_data_event_pack() {
    size_t sz;
    void *addr = calloc(DATA_EVENT_DATA_LENGTH, 1);
    sky_event *event = sky_event_create(0, 30LL, 0);
    sky_event_set_data(event, 1, &foo);
    sky_event_set_data(event, 2, &bar);
    sky_event_pack(event, addr, &sz);
    sky_event_free(event);
    mu_assert_long_equals(sz, DATA_EVENT_DATA_LENGTH);
    mu_assert_mem(addr, &DATA_EVENT_DATA, DATA_EVENT_DATA_LENGTH);
    free(addr);
    return 0;
}
コード例 #8
0
ファイル: block_tests.c プロジェクト: dasfaha/sky
int test_sky_block_get_path_stats_with_event_in_existing_path() {
    sky_data_file *data_file;
    INIT_DATA_FILE("tests/fixtures/blocks/path_stats/a");
    sky_block_path_stat *paths = NULL;
    uint32_t path_count = 0;
    sky_event *event = sky_event_create(3, 7LL, 20);
    int rc = sky_block_get_path_stats(data_file->blocks[0], event, &paths, &path_count);
    mu_assert_int_equals(rc, 0);
    mu_assert_int_equals(path_count, 2);
    ASSERT_PATH_STAT(paths[0], 3, 0L, 41L, 52L);
    ASSERT_PATH_STAT(paths[1], 10, 41L, 60L, 19L);
    sky_event_free(event);
    sky_data_file_free(data_file);
    return 0;
}
コード例 #9
0
ファイル: event_tests.c プロジェクト: emiddleton/sky
// Action event.
int test_sky_event_action_event_unpack() {
    size_t sz;
    sky_event *event = sky_event_create(0, 0, 0);
    sky_event_unpack(event, &ACTION_EVENT_DATA, &sz);

    mu_assert_long_equals(sz, ACTION_EVENT_DATA_LENGTH);
    mu_assert_int64_equals(event->timestamp, 30LL);
    mu_assert(event->action_id == 20, "Expected action id to equal 20");
    mu_assert(event->object_id == 0, "Expected object id to equal 0");
    mu_assert(event->data == NULL, "Expected data to be NULL");
    mu_assert(event->data_count == 0, "Expected data count to be 0");

    sky_event_free(event);
    
    return 0;
}
コード例 #10
0
ファイル: event_tests.c プロジェクト: emiddleton/sky
int test_sky_event_unset_data() {
    sky_event_data *data = NULL;

    sky_event *event = sky_event_create(0, 0, 0);
    sky_event_set_data(event, 10, &foo);
    sky_event_set_data(event, 20, &bar);
    mu_assert(event->data_count == 2, "Expected data count to be 2");
    sky_event_unset_data(event, 10);
    mu_assert(event->data_count == 1, "Expected data count to be 1");

    sky_event_get_data(event, 10, &data);
    mu_assert(data == NULL, "Expected data 10 be NULL");
    sky_event_get_data(event, 20, &data);
    mu_assert(biseqcstr(data->string_value, "bar"), "Expected data 20 to equal 'bar'");

    sky_event_free(event);

    return 0;
}
コード例 #11
0
ファイル: path.c プロジェクト: gitaccount2/sky
// Deserializes a path to a memory location.
//
// path - The path to unpack.
// ptr  - The pointer to the current location.
// sz   - The number of bytes written.
//
// Returns 0 if successful, otherwise returns -1.
int sky_path_unpack(sky_path *path, void *ptr, size_t *sz)
{
    int rc;
    size_t _sz;
    void *start = ptr;

    // Validate.
    check(path != NULL, "Path required");
    check(ptr != NULL, "Pointer required");

    // Read object id & event data length.
    path->object_id = *((sky_object_id_t*)ptr);
    ptr += sizeof(sky_object_id_t);
    size_t event_data_length = *((sky_path_event_data_length_t*)ptr);
    ptr += sizeof(sky_path_event_data_length_t);

    // Unpack events.
    int index = 0;
    void *endptr = ptr + event_data_length;
    while(ptr < endptr) {
        path->event_count++;
        path->events = realloc(path->events, sizeof(sky_event*) * path->event_count);
        check_mem(path->events);

        path->events[index] = sky_event_create(path->object_id, 0, 0);
        rc = sky_event_unpack(path->events[index], ptr, &_sz);
        check(rc == 0, "Unable to unpack event at %p", ptr);
        ptr += _sz;
        
        index++;
    }

    // Store number of bytes read.
    if(sz != NULL) {
        *sz = (ptr-start);
    }

    return 0;

error:
    *sz = 0;
    return -1;
}
コード例 #12
0
ファイル: eadd_message_tests.c プロジェクト: gitaccount2/sky
int test_sky_add_event_message_worker_map() {
    importtmp("tests/fixtures/add_event_message/1/import.json");
    sky_table *table = sky_table_create();
    table->path = bfromcstr("tmp");
    table->default_tablet_count = 1;
    sky_table_open(table);

    struct tagbstring XYZ_STR = bsStatic("xyz");
    sky_add_event_message *message = sky_add_event_message_create();
    message->event = sky_event_create(10, 1000L, 20);
    message->event->data_count = 4;
    message->event->data = calloc(message->event->data_count, sizeof(*message->event->data));
    message->event->data[0] = sky_event_data_create_string(1, &XYZ_STR);
    message->event->data[1] = sky_event_data_create_int(2, 200);
    message->event->data[2] = sky_event_data_create_double(3, 100.2);
    message->event->data[3] = sky_event_data_create_boolean(4, true);
    sky_worker *worker = sky_worker_create();
    worker->data = (void*)message;

    void *null = NULL;
    int rc = sky_add_event_message_worker_map(worker, table->tablets[0], &null);
    mu_assert_int_equals(rc, 0);

    void *data;
    size_t data_length;
    sky_tablet_get_path(table->tablets[0], 10, &data, &data_length);
    mu_assert_int_equals(rc, 0);
    mu_assert_mem(
        data, 
        "\x03\xE8\x03\x00\x00\x00\x00\x00\x00\x14\x00\x15\x00\x00\x00\x01"
        "\xA3\x78\x79\x7A\x02\xD1\x00\xC8\x03\xCB\x40\x59\x0C\xCC\xCC\xCC"
        "\xCC\xCD\x04\xC3",
        data_length
    );

    free(data);
    sky_add_event_message_free(message);
    sky_worker_free(worker);
    sky_table_free(table);
    return 0;
}
コード例 #13
0
ファイル: event_tests.c プロジェクト: emiddleton/sky
// Action+Data event.
int test_sky_event_action_data_event_unpack() {
    size_t sz;
    sky_event *event = sky_event_create(0, 0, 0);
    sky_event_unpack(event, &ACTION_DATA_EVENT_DATA, &sz);

    mu_assert_long_equals(sz, ACTION_DATA_EVENT_DATA_LENGTH);
    mu_assert_int64_equals(event->timestamp, 30LL);
    mu_assert(event->action_id == 20, "Expected action id to equal 20");
    mu_assert(event->object_id == 0, "Expected object id to equal 0");
    mu_assert(event->data != NULL, "Expected data to not be NULL");
    mu_assert(event->data_count == 2, "Expected data count to be 2");

    sky_event_data *data = NULL;
    sky_event_get_data(event, 1, &data);
    mu_assert(biseqcstr(data->string_value, "foo"), "Expected data 1 to equal 'foo'");
    sky_event_get_data(event, 2, &data);
    mu_assert(biseqcstr(data->string_value, "bar"), "Expected data 1 to equal 'bar'");

    sky_event_free(event);
    
    return 0;
}