2005-01-19 00:51:54 +00:00
|
|
|
#include <../../src/apps/cht/cht.h>
|
|
|
|
#include <assert.h>
|
|
|
|
int main(int argc, char ** argv) {
|
|
|
|
char * conf = "client.conf";
|
|
|
|
|
|
|
|
if(argc == 2) {
|
|
|
|
conf = argv[1];
|
|
|
|
} else if(argc > 2) {
|
|
|
|
printf("Usage: %s [client.conf]\n", argv[0]);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tinit();
|
|
|
|
|
|
|
|
DfaSet * cht_client = cHtClientInit(conf);
|
2005-02-16 04:11:14 +00:00
|
|
|
// pthread_t main_worker_loop =
|
|
|
|
spawn_main_thread(cht_client);
|
2005-01-19 00:51:54 +00:00
|
|
|
|
|
|
|
// cht_evals go here...
|
|
|
|
|
|
|
|
int xid = 1;//NULL_MACHINE; // What's the deal with this? ;)
|
2005-02-24 21:12:36 +00:00
|
|
|
clusterHashTable_t new_ht;
|
|
|
|
cHtCreate(xid, cht_client, &new_ht);
|
2005-01-19 00:51:54 +00:00
|
|
|
int i;
|
2005-02-06 03:48:12 +00:00
|
|
|
for(i = 0; i < 10000; i++) {
|
2005-01-19 00:51:54 +00:00
|
|
|
int one = i; int two = i+1;
|
2005-02-24 21:12:36 +00:00
|
|
|
cHtInsert(xid, cht_client, &new_ht, &one, sizeof(int), &two, sizeof(int));
|
2005-02-06 03:48:12 +00:00
|
|
|
int newOne, newTwo;
|
|
|
|
newOne = i;
|
|
|
|
newTwo = 0;
|
2006-05-25 00:02:46 +00:00
|
|
|
size_t newLen = sizeof(int);
|
2005-02-24 21:12:36 +00:00
|
|
|
int ret = cHtLookup(xid, cht_client, &new_ht, &newOne, sizeof(int), &newTwo, &newLen);
|
2005-02-03 02:01:23 +00:00
|
|
|
// xid++;
|
2005-02-06 03:48:12 +00:00
|
|
|
//printf("lookup returned %d (%d->%d)\n", ret, newOne, newTwo);
|
|
|
|
assert(ret);
|
|
|
|
assert(newOne == one);
|
|
|
|
assert(newTwo == two);
|
|
|
|
assert(newLen == sizeof(int));
|
2005-01-19 00:51:54 +00:00
|
|
|
}
|
2005-02-06 03:48:12 +00:00
|
|
|
cHtCommit(xid, cht_client);
|
|
|
|
|
|
|
|
for(i = 0; i < 10000; i+=10) {
|
|
|
|
int one = i; int two = -1;
|
2006-05-25 00:02:46 +00:00
|
|
|
size_t size = sizeof(int);
|
2005-02-24 21:12:36 +00:00
|
|
|
int removed = cHtRemove(xid, cht_client, &new_ht, &one, sizeof(int), &two, &size);
|
2005-02-06 03:48:12 +00:00
|
|
|
assert(removed);
|
|
|
|
|
|
|
|
size = sizeof(int);
|
|
|
|
two = -1;
|
2005-02-24 21:12:36 +00:00
|
|
|
removed = cHtRemove(xid, cht_client, &new_ht, &one, sizeof(int), &two, &size);
|
2005-02-06 03:48:12 +00:00
|
|
|
assert(!removed);
|
|
|
|
|
|
|
|
int newOne, newTwo;
|
|
|
|
newOne = i;
|
|
|
|
newTwo = 0;
|
2006-05-25 00:02:46 +00:00
|
|
|
size_t newLen = sizeof(int);
|
2005-02-24 21:12:36 +00:00
|
|
|
int ret = cHtLookup(xid, cht_client, &new_ht, &newOne, sizeof(int), &newTwo, &newLen);
|
2005-02-06 03:48:12 +00:00
|
|
|
|
|
|
|
assert(!ret);
|
|
|
|
|
|
|
|
}
|
|
|
|
cHtAbort(xid, cht_client);
|
|
|
|
exit(0); // @todo this test case should continue on...
|
|
|
|
for(i = 0; i < 10000; i++) {
|
|
|
|
int one = i; int two = i+1;
|
|
|
|
// cHtInsert(xid, cht_client, new_ht, &one, sizeof(int), &two, sizeof(int));
|
2005-01-19 00:51:54 +00:00
|
|
|
int newOne, newTwo;
|
|
|
|
newOne = i;
|
|
|
|
newTwo = 0;
|
2006-05-25 00:02:46 +00:00
|
|
|
size_t newLen = sizeof(int);
|
2005-02-24 21:12:36 +00:00
|
|
|
int ret = cHtLookup(xid, cht_client, &new_ht, &newOne, sizeof(int), &newTwo, &newLen);
|
2005-02-03 02:01:23 +00:00
|
|
|
// xid++;
|
2005-01-20 23:58:29 +00:00
|
|
|
//printf("lookup returned %d (%d->%d)\n", ret, newOne, newTwo);
|
|
|
|
assert(ret);
|
2005-01-19 00:51:54 +00:00
|
|
|
assert(newOne == one);
|
|
|
|
assert(newTwo == two);
|
|
|
|
assert(newLen == sizeof(int));
|
|
|
|
}
|
2005-02-03 02:01:23 +00:00
|
|
|
cHtCommit(xid, cht_client);
|
2005-02-06 03:48:12 +00:00
|
|
|
|
2005-01-20 23:58:29 +00:00
|
|
|
/** @todo devise a way to cleanly shut a CHT down. */
|
2005-01-19 00:51:54 +00:00
|
|
|
|
|
|
|
// dfa_free(cht_client);
|
|
|
|
}
|