mobject-client-test.c 5.72 KB
Newer Older
1 2 3 4 5
#include <assert.h>
#include <stdio.h>
#include <margo.h>
#include <libmobject-store.h>

6 7
const char* content = "AAAABBBBCCCCDDDDEEEEFFFF";

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);
14
    mobject_store_ioctx_t ioctx;
Matthieu Dorier's avatar
Matthieu Dorier committed
15
    mobject_store_ioctx_create(cluster, "my-object-pool", &ioctx);
16

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

57
        mobject_store_write_op_operate(write_op, ioctx, "test-object", NULL, LIBMOBJECT_OPERATION_NOFLAG);
58

59 60 61 62
        mobject_store_release_write_op(write_op);

    }

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

97 98 99 100 101 102
        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");
103

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

106 107 108 109 110 111
        {
            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");
        }
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);
        }
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);
        }
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 143 144
    }
    mobject_store_ioctx_destroy(ioctx);

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

    return 0;
}