mobject-client-test.c 5.64 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 22

    { // 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);
23 24
        // Add a "write_full" operation to write "AAAABBBB"
        mobject_store_write_op_write_full(write_op, content, 8);
25
        // Add a "write" operation to write "CCCC", content should then be "AAAABBBBCCCC"
26
        mobject_store_write_op_write(write_op, content+8, 4, 8);
27 28
        // Add a "writesame" operation to write "DDDD" in two "DD",
        // content should then be "AAAABBBBCCCCDDDD"
29
        mobject_store_write_op_writesame(write_op, content+12, 2, 4, 12);
30
        // Add a "append" operation to append "EEEEFFFF"
31
        // content should then be "AAAABBBBCCCCDDDDEEEEFFFFF"
32
        mobject_store_write_op_append(write_op, content+16, 8);
Matthieu Dorier's avatar
Matthieu Dorier committed
33
        // Add a "remove" operation
34 35
//        mobject_store_write_op_remove(write_op);
        // Add a "truncate" operation to remove the "FFFF" part
36
        // content should then be "AAAABBBBCCCCDDDDEEEE"
37
        mobject_store_write_op_truncate(write_op, 20);
38
        // Add a "zero" operation zero-ing the "BBBBCCCC"
39
        // content should then be "AAAA********DDDDEEEE" where "*" represent 0s
40
        mobject_store_write_op_zero(write_op, 4, 8);
Matthieu Dorier's avatar
Matthieu Dorier committed
41 42 43 44
        // 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 };
45
//        mobject_store_write_op_omap_set(write_op, keys, values, val_sizes, 5);
46 47 48 49 50 51 52
        // 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
53
        // Add a omap_rm_keys" operation
54 55
//        mobject_store_write_op_omap_rm_keys(write_op, keys, 5);

Matthieu Dorier's avatar
Matthieu Dorier committed
56
        mobject_store_write_op_operate(write_op, ioctx, "test-object", NULL, LIBMOBJECT_OPERATION_NOFLAG);
57

Matthieu Dorier's avatar
Matthieu Dorier committed
58 59 60 61 62 63 64 65 66 67 68 69
        mobject_store_release_write_op(write_op);

    }

    { // 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;
70
//        mobject_store_read_op_stat(read_op, &psize, &pmtime, &prval1);
Matthieu Dorier's avatar
Matthieu Dorier committed
71 72 73 74
        // Add "read" operation
        char read_buf[512];
        size_t bytes_read;
        int prval2;
75
        mobject_store_read_op_read(read_op, 0, 512, read_buf, &bytes_read, &prval2);
Matthieu Dorier's avatar
Matthieu Dorier committed
76
        // Add "omap_get_keys" operation
77
#if 0
78
        const char* start_after1 = "rob";
Matthieu Dorier's avatar
Matthieu Dorier committed
79 80
        mobject_store_omap_iter_t iter3;
        int prval3;
81
        // the following should return ["robl","shane"] 
82
        mobject_store_read_op_omap_get_keys(read_op, start_after1, 7, &iter3, &prval3);
Matthieu Dorier's avatar
Matthieu Dorier committed
83
        // Add "omap_get_vals" operation
84 85
        const char* start_after2 = "matthieu";
        const char* filter_prefix2 = "p";
Matthieu Dorier's avatar
Matthieu Dorier committed
86 87
        mobject_store_omap_iter_t iter4;
        int prval4;
88
        // the following should return ["phil"], and  its associated value
89
        mobject_store_read_op_omap_get_vals(read_op, start_after2, filter_prefix2, 3, &iter4, &prval4);
Matthieu Dorier's avatar
Matthieu Dorier committed
90
        // Add "omap_get_vals_by_keys" operation
91 92
        const char* keys[] = {"matthieu", "robl"};
        mobject_store_omap_iter_t iter5;
Matthieu Dorier's avatar
Matthieu Dorier committed
93
        int prval5;
94
        mobject_store_read_op_omap_get_vals_by_keys(read_op, keys, 2, &iter5, &prval5);
95
#endif
Matthieu Dorier's avatar
Matthieu Dorier committed
96 97 98 99 100 101
        mobject_store_read_op_operate(read_op, ioctx, "test-object",LIBMOBJECT_OPERATION_NOFLAG);

        mobject_store_release_read_op(read_op);

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

103 104
//        printf("stat: psize=%ld pmtime=%lld prval=%d\n", psize, (long long)pmtime, prval1);

105 106 107 108 109 110
        {
            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");
        }
111
#if 0
Matthieu Dorier's avatar
Matthieu Dorier committed
112
        printf("omap_get_keys: prval=%d\n", prval3);
113 114 115 116 117 118 119 120 121
        {
            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
122
        printf("omap_get_vals: prval=%d\n", prval4);
123 124 125 126 127 128 129 130 131
        {
            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
132
        printf("omap_get_vals_by_keys: prval=%d\n", prval5);
133 134 135 136 137 138 139 140 141
        {
            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);
        }
142
#endif
Matthieu Dorier's avatar
Matthieu Dorier committed
143 144 145
    }
    mobject_store_ioctx_destroy(ioctx);

Matthieu Dorier's avatar
Matthieu Dorier committed
146
    mobject_store_shutdown(cluster);
Matthieu Dorier's avatar
Matthieu Dorier committed
147 148 149

    return 0;
}