2 * Copyright (c) 2017 Mohamed Aslan <maslan@sce.carleton.ca>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
40 static struct v_node vnodes
[] = {
41 {"A", "127.0.0.1", 5000, 5,
42 {"hello", "1hello", "12hello", "world1", "world12"},
43 {"world", "world", "world", "hello", "hello"},
45 {"B", "127.0.0.1", 5001, 3,
46 {"1hello", "world", "world1", NULL
, NULL
},
47 {"world", "hello", "hello", NULL
, NULL
},
49 {"C", "127.0.0.1", 5002, 4,
50 {"hello", "12hello", "world", "world12", NULL
},
51 {"world", "world", "hello", "hello", NULL
},
57 "hello", "world", "1hello",
58 "world1", "12hello", "world12"
61 "world", "hello", "world",
62 "hello", "world", "hello"
67 struct dht_node
*node
;
72 test_thread(void *arg
)
75 struct dht_node
*n
= ((struct args
*)arg
)->node
;
81 /* read all keys/vals */
82 for (i
= 0 ; i
< N_KV
; i
++) {
83 if (!dht_get_tunable(n
, keys
[i
], &val
, N_REPLICAS
)) {
84 printf("FAILED [%s] dht_get_tunable.\n", n
->id
);
85 printf("for %s:%s\n", keys
[i
], vals
[i
]);
89 if (strcmp(vals
[i
], val
)) {
90 printf("FAILED [%s] dht_get_tunable, received bad val.\n", n
->id
);
112 n
= malloc(sizeof(struct dht_node
));
113 if (!dht_init(n
, vnodes
[me
].id
, vnodes
[me
].port
, N_REPLICAS
, 0, NULL
))
116 /* populate hashtable */
117 ht
= (struct hashtab
*)n
->ht
;
118 (void)clock_gettime(CLOCK_REALTIME
, &ts
);
119 for (i
= 0 ; i
< vnodes
[me
].n_keys
; i
++) {
120 n
->opts
->ht_put(ht
, vnodes
[me
].keys
[i
], vnodes
[me
].vals
[i
], &ts
);
123 for (i
= 0 ; i
< N_NODES
; i
++)
125 dht_add_peer(n
, vnodes
[i
].id
, vnodes
[i
].ip
, vnodes
[i
].port
);
127 a
= malloc(sizeof(struct args
));
130 if (pthread_create(&tt
, NULL
, test_thread
, a
))
131 err(1, "pthread_create");
134 errx(1, "should not reach here!");
139 main(int argc
, char **argv
)
141 int i
, status
, fail
= 0;
144 for (i
= 0 ; i
< N_NODES
; i
++) {
158 if (WIFEXITED(status
) && WEXITSTATUS(status
))