mobject-client-test.c 5.83 KB
Newer Older
Matthieu Dorier's avatar
Matthieu Dorier committed
1 2 3 4 5
#include <assert.h>
#include <stdio.h>
#include <margo.h>
#include <libmobject-store.h>

6 7
const char* content = "AAAABBBBCCCCDDDDEEEEFFFF";

Matthieu Dorier's avatar
Matthieu Dorier committed
8 9 10
/* Main function. */
int main(int argc, char** argv)
{
Matthieu Dorier's avatar
Matthieu Dorier committed
11 12 13
    mobject_store_t cluster;
    mobject_store_create(&cluster, "admin");
    mobject_store_connect(cluster);
Matthieu Dorier's avatar
Matthieu Dorier committed
14
    mobject_store_ioctx_t ioctx;
Matthieu Dorier's avatar
Matthieu Dorier committed
15
    mobject_store_ioctx_create(cluster, "my-object-pool", &ioctx);
Matthieu Dorier's avatar
Matthieu Dorier committed
16

17 18 19 20 21
    char* objects[] = { "object1_abcd", "object2_efgh", "object3_ijkl" };

    int i;
    for(i=0; i<3; i++) {

Matthieu Dorier's avatar
Matthieu Dorier committed
22
    fprintf(stderr, "********** WRITE PHASE **********\n");
Matthieu Dorier's avatar
Matthieu Dorier committed
23 24 25 26 27 28
    { // WRITE OP TEST

        mobject_store_write_op_t write_op = mobject_store_create_write_op();

        // Add a "create" operation
        mobject_store_write_op_create(write_op, LIBMOBJECT_CREATE_EXCLUSIVE, NULL);
29 30
        // Add a "write_full" operation to write "AAAABBBB"
        mobject_store_write_op_write_full(write_op, content, 8);
31
        // Add a "write" operation to write "CCCC", content should then be "AAAABBBBCCCC"
32
        mobject_store_write_op_write(write_op, content+8, 4, 8);
33 34
        // Add a "writesame" operation to write "DDDD" in two "DD",
        // content should then be "AAAABBBBCCCCDDDD"
35
        mobject_store_write_op_writesame(write_op, content+12, 2, 4, 12);
36
        // Add a "append" operation to append "EEEEFFFF"
37
        // content should then be "AAAABBBBCCCCDDDDEEEEFFFFF"
38
        mobject_store_write_op_append(write_op, content+16, 8);
Matthieu Dorier's avatar
Matthieu Dorier committed
39
        // Add a "remove" operation
40 41
//        mobject_store_write_op_remove(write_op);
        // Add a "truncate" operation to remove the "FFFF" part
42
        // content should then be "AAAABBBBCCCCDDDDEEEE"
43
        mobject_store_write_op_truncate(write_op, 20);
44
        // Add a "zero" operation zero-ing the "BBBBCCCC"
45
        // content should then be "AAAA********DDDDEEEE" where "*" represent 0s
46
        mobject_store_write_op_zero(write_op, 4, 8);
Matthieu Dorier's avatar
Matthieu Dorier committed
47 48 49 50
        // Add a "omap_set" operation
        const char* keys[]   = { "matthieu", "rob", "shane", "phil", "robl" };
        const char* values[] = { "mdorier@anl.gov", "rross@anl.gov", "ssnyder@anl.gov", "carns@anl.gov", "robl@anl.gov" };
        size_t val_sizes[]   = { 16, 14, 16, 14, 13 };
Matthieu Dorier's avatar
Matthieu Dorier committed
51
        mobject_store_write_op_omap_set(write_op, keys, values, val_sizes, 5);
52 53 54 55 56 57 58
        // keys will be sorted and stored as follows:
        /* matthieu => mdorier@anl.gov
           phil     => carns@anl.gov
           rob      => rross@anl.gov
           robl     => robl@anl.gov
           shane    => ssnyder@anl.gov
        */
Matthieu Dorier's avatar
Matthieu Dorier committed
59
        // Add a omap_rm_keys" operation
60 61
//        mobject_store_write_op_omap_rm_keys(write_op, keys, 5);

62
        mobject_store_write_op_operate(write_op, ioctx, objects[i], NULL, LIBMOBJECT_OPERATION_NOFLAG);
63

Matthieu Dorier's avatar
Matthieu Dorier committed
64 65 66 67
        mobject_store_release_write_op(write_op);

    }

Matthieu Dorier's avatar
Matthieu Dorier committed
68
    fprintf(stderr, "********** READ PHASE **********\n");
Matthieu Dorier's avatar
Matthieu Dorier committed
69 70 71 72 73 74 75 76
    { // READ OP TEST

        mobject_store_read_op_t read_op = mobject_store_create_read_op();

        // Add "stat" operation
        uint64_t psize;
        time_t pmtime;
        int prval1;
Matthieu Dorier's avatar
Matthieu Dorier committed
77
        mobject_store_read_op_stat(read_op, &psize, &pmtime, &prval1);
Matthieu Dorier's avatar
Matthieu Dorier committed
78 79 80 81
        // Add "read" operation
        char read_buf[512];
        size_t bytes_read;
        int prval2;
82
        mobject_store_read_op_read(read_op, 0, 512, read_buf, &bytes_read, &prval2);
Matthieu Dorier's avatar
Matthieu Dorier committed
83
        // Add "omap_get_keys" operation
84
        const char* start_after1 = "rob";
Matthieu Dorier's avatar
Matthieu Dorier committed
85 86
        mobject_store_omap_iter_t iter3;
        int prval3;
87
        // the following should return ["robl","shane"] 
88
        mobject_store_read_op_omap_get_keys(read_op, start_after1, 7, &iter3, &prval3);
Matthieu Dorier's avatar
Matthieu Dorier committed
89
        // Add "omap_get_vals" operation
90 91
        const char* start_after2 = "matthieu";
        const char* filter_prefix2 = "p";
Matthieu Dorier's avatar
Matthieu Dorier committed
92 93
        mobject_store_omap_iter_t iter4;
        int prval4;
94
        // the following should return ["phil"], and  its associated value
95
        mobject_store_read_op_omap_get_vals(read_op, start_after2, filter_prefix2, 3, &iter4, &prval4);
Matthieu Dorier's avatar
Matthieu Dorier committed
96
        // Add "omap_get_vals_by_keys" operation
97 98
        const char* keys[] = {"matthieu", "robl"};
        mobject_store_omap_iter_t iter5;
Matthieu Dorier's avatar
Matthieu Dorier committed
99
        int prval5;
100
        mobject_store_read_op_omap_get_vals_by_keys(read_op, keys, 2, &iter5, &prval5);
Matthieu Dorier's avatar
Matthieu Dorier committed
101

102
        mobject_store_read_op_operate(read_op, ioctx, objects[i],LIBMOBJECT_OPERATION_NOFLAG);
Matthieu Dorier's avatar
Matthieu Dorier committed
103 104 105 106 107

        mobject_store_release_read_op(read_op);

        // print the results of the read operations
        printf("Client received the following results:\n");
108

Matthieu Dorier's avatar
Matthieu Dorier committed
109
        printf("stat: psize=%ld pmtime=%lld prval=%d\n", psize, (long long)pmtime, prval1);
110

111 112 113 114 115 116
        {
            printf("read: bytes_read = %ld, prval=%d content: ", bytes_read, prval2);
            unsigned i;
            for(i=0; i<bytes_read; i++) printf("%c", read_buf[i] ? read_buf[i] : '*' );
            printf("\n");
        }
Matthieu Dorier's avatar
Matthieu Dorier committed
117
        printf("omap_get_keys: prval=%d\n", prval3);
118 119 120 121 122 123 124 125 126
        {
            char* key = NULL;
            char* val = NULL;
            size_t size;
            do {
                mobject_store_omap_get_next(iter3, &key, &val, &size);
                if(key) printf("===> key: \"%s\"\n", key);
            } while(key);
        }
Matthieu Dorier's avatar
Matthieu Dorier committed
127
        printf("omap_get_vals: prval=%d\n", prval4);
128 129 130 131 132 133 134 135 136
        {
            char* key = NULL;
            char* val = NULL;
            size_t size;
            do {
                mobject_store_omap_get_next(iter4, &key, &val, &size);
                if(key) printf("===> key: \"%s\" , val: %s \n", key, val);
            } while(key);
        }
Matthieu Dorier's avatar
Matthieu Dorier committed
137
        printf("omap_get_vals_by_keys: prval=%d\n", prval5);
138 139 140 141 142 143 144 145 146
        {
            char* key = NULL;
            char* val = NULL;
            size_t size;
            do {
                mobject_store_omap_get_next(iter5, &key, &val, &size);
                if(key) printf("===> key: \"%s\" , val: %s \n", key, val);
            } while(key);
        }
Matthieu Dorier's avatar
Matthieu Dorier committed
147
    }
148 149

    }
Matthieu Dorier's avatar
Matthieu Dorier committed
150 151
    mobject_store_ioctx_destroy(ioctx);

Matthieu Dorier's avatar
Matthieu Dorier committed
152
    mobject_store_shutdown(cluster);
Matthieu Dorier's avatar
Matthieu Dorier committed
153 154 155

    return 0;
}