Exemple #1
0
//suite
int main(void) {

    arena = Arena_new();

    store = OeBdb_new(1, "data", true);
    assert(store);

    testTxnCommitPut();
    testBogusTxnPut();
    testCommitTake();
    testCommitRMW();
    testRollback();

    for (int i = 0; i < 100; i++) {
        testCommitRMW();
    }
    testDetectDeadlock();

    OeStore_stats(store);
    int close_ret = OeStore_free(&store);
    assert(close_ret == 0);

    //test_update_of_expired_txn();
    //test_commit_of_expired_txn();

    Arena_free(arena);
    Arena_dispose(&arena);

    return 0;
}
void testPutOne(void *n) {

    char *name = (char *) n;

    Arena_T arena = Arena_new();
    printf("putting name: %s\n", (char *) name);

    OeStoreHolder holder = OeStoreHolder_new(arena);
    DataObject data = OeStoreHolder_get_data(holder);
    OeStoreHolder_set_txn_id( holder, 0 ); //unlocked
    OeStoreHolder_set_lease_expire_time( holder, oec_get_time_milliseconds() + 600000);
    OeStoreHolder_set_lock( holder, OESTORE_UNLOCKED );

    DataObject_set_nbytes( data, strlen(bytes) + 1 );
    DataObject_set_bytes( data, bytes );
    DataObject_add_attr( data, "key1" );
    DataObject_add_attr( data, (char *) name );
    DataObject_add_attr( data, "key2" );
    DataObject_add_attr( data, "seeme2three" );
    DataObject_add_attr( data, morenonse);
    DataObject_add_attr( data, "somebadvalue" );

    int ret;
    while ( (ret = OeStore_put( store, holder, arena)) ) {
        if (ret == OE_STORE_PLEASE_RETRY) {
            if (ret == OE_STORE_PLEASE_RETRY) {
                printf("put one retry for deadlock\n");
                continue;
            }
        }
    }
    assert(!ret);
    printf("put name: %s\n", (char *) name);
    Arena_dispose(&arena);
}
void testTakeOne(void *dummy) {

    Arena_T arena = Arena_new();
    const int MAX_RESULTS = 1;

    DataObjectList keylists = DataObjectList_new(arena);
    DataObject keys = DataObjectList_new_data_object(keylists);
    DataObject_add_attr(keys, "key2");
    DataObject_add_attr(keys, "seeme2three");

    OeStoreHolder results[MAX_RESULTS + 1];
    memset(results, 0, sizeof *results);
    size_t result_count = 0;

    OeStoreQuery query = OeStoreQuery_new(arena, MAX_RESULTS);
    OeStoreQuery_set_take(query, true);
    OeStoreQuery_set_tuple(query, false);
    OeStoreQuery_set_ifexists(query, false);
    OeStoreQuery_set_value_lists(query, keylists);

    int ret;
    while ( (
             ret = OeStore_get(store, query)
             ) ) {

        if (ret == OE_STORE_PLEASE_RETRY) {
            printf("take one retry for deadlock\n");
            OeStoreQuery_reset_nitems_found(query);
            continue;
        }
        if (ret == OE_STORE_ITEM_NOTFOUND) continue;
        result_count = OeStoreQuery_get_nitems_found(query);
        if (result_count == 0) continue;
    }
    assert(!ret);
    assert(result_count = 1);

    OeStoreHolder result = OeStoreQuery_get_store_holder(query, 0);
    DataObject data = OeStoreHolder_get_data(result);
    Iterator iter = DataObject_iterator(data, true);
    //Iterator iter = DataObject_iterator(data, false);
    printf("take result key1: %s\n", (char *) Iterator_next(iter)); //0
    printf("take result val1: %s\n", (char *) Iterator_next(iter)); //1
    printf("take result key2: %s\n", (char *) Iterator_next(iter)); //0
    assert(strcmp(Iterator_next(iter), "seeme2three") == 0);
    assert(strcmp(DataObject_get_bytes(data), "nonesense") == 0);
    assert(OeStoreHolder_get_lock(result) == OESTORE_TAKE_LOCK);
    Arena_dispose(&arena);
}
Exemple #4
0
void OepClient_free(T *acp) {
    assert(acp && *acp);
    T _this_ = *acp;
    assert(_this_);
    assert(_this_->arena);
    assert(_this_->net);
    OeSession session = _this_->session;
    //OeNet_stop(_this_->net);
    //OeNet_free(&_this_->net);
    Arena_dispose(&_this_->arena);
    if (session) {
        OeSession_free(&session);
    }
    *acp = NULL;
}
Exemple #5
0
static unsigned test_arena_resize() {
    
    Arena_T arena   = Arena_new();
    char * aChar;

    
    Mem_set_arena(arena);
    
    aChar           = ALLOC(sizeof(char));
    *aChar          = 'a';
    test_assert(*aChar == 'a');

    REALLOC(aChar, 100);
    strcpy(aChar + 1, "bcdefghilmnopqrstuvz");
    test_assert_str(aChar, "abcdefghilmnopqrstuvz");

    REALLOC(aChar, 10);
    aChar[9]        = '\0';
    test_assert_str(aChar, "abcdefghi");

    REALLOC(aChar, 100000);
    test_assert_str(aChar, "abcdefghi");

    REALLOC(aChar, 1);
    aChar[1] = '\0';
    test_assert_str(aChar, "a");

    REALLOC(aChar, 100);
    strcpy(aChar, "abcd");
    REALLOC(aChar, 2);
    aChar[2] = '\0';
    test_assert_str(aChar, "ab");

    Mem_set_default();

    Arena_dispose(&arena);
    Arena_remove_free_blocks();
    

    return TEST_SUCCESS;
}
Exemple #6
0
void (OEK_Context_free)( OEK_Context **contextp ) {
    assert(contextp && *contextp);
    OEK_Context *context = *contextp;
    Arena_T arena = context->arena;
    Arena_dispose( &arena );
}