提交 aed03077 authored 作者: colm's avatar colm 提交者: Mike Jerris

FS-9775: Bucket synchronization fixes & Updated tests

上级 a42ed8f8
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-function"
//#include "ks.h"
#include "../src/dht/ks_dht.h"
......@@ -7,6 +8,8 @@
ks_dhtrt_routetable_t* rt;
ks_pool_t* pool;
static ks_thread_t *threads[10];
int doquery(ks_dhtrt_routetable_t* rt, uint8_t* id, enum ks_dht_nodetype_t type, enum ks_afflags_t family)
{
......@@ -22,7 +25,8 @@ int doquery(ks_dhtrt_routetable_t* rt, uint8_t* id, enum ks_dht_nodetype_t type,
void test01()
{
printf("testbuckets - test01 start\n"); fflush(stdout);
printf("*** testbuckets - test01 start\n"); fflush(stdout);
ks_dhtrt_routetable_t* rt;
ks_dhtrt_initroute(&rt, pool);
ks_dhtrt_deinitroute(&rt);
......@@ -66,11 +70,13 @@ void test01()
exit(104);
}
printf("*** testbuckets - test01 complete\n"); fflush(stdout);
printf("*** testbuckets - test01 complete\n\n\n"); fflush(stdout);
}
void test02()
{
printf("*** testbuckets - test02 start\n"); fflush(stdout);
ks_dht_node_t* peer;
ks_dht_nodeid_t nodeid;
memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE);
......@@ -126,6 +132,8 @@ void test02()
qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, ifv4);
printf("\n*** AF_INET count expected 4, actual %d\n", qcount); fflush(stdout);
printf("*** testbuckets - test02 finished\n"); fflush(stdout);
return;
}
......@@ -133,6 +141,8 @@ void test02()
void test03()
{
printf("*** testbuckets - test03 start\n"); fflush(stdout);
ks_dht_node_t* peer;
ks_dht_nodeid_t nodeid;
memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE);
......@@ -177,33 +187,36 @@ void test03()
int qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, both);
printf("\n** local query count expected 3, actual %d\n", qcount); fflush(stdout);
printf("\n** local query count expected 2, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_REMOTE, both);
printf("\n*** remote query count expected 6, actual %d\n", qcount); fflush(stdout);
printf("\n*** remote query count expected 20, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, both);
printf("\n*** both query count expected 9, actual %d\n", qcount); fflush(stdout);
printf("\n*** both query count expected 20, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, ifv4);
printf("\n*** local AF_INET query count expected 1, actual %d\n", qcount); fflush(stdout);
printf("\n*** local AF_INET query count expected 2, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_LOCAL, ifv6);
printf("\n*** local AF_INET6 query count expected 2, actual %d\n", qcount); fflush(stdout);
printf("\n*** local AF_INET6 query count expected 0, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, ifv6);
printf("\n*** AF_INET6 count expected 5, actual %d\n", qcount); fflush(stdout);
printf("\n*** AF_INET6 count expected 20, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_REMOTE, ifv4);
printf("\n** remote AF_INET query count expected 3, actual %d\n", qcount); fflush(stdout);
printf("\n*** remote AF_INET query count expected 20, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_REMOTE, ifv6);
printf("\n*** remote AF_INET6 query count expected 3, actual %d\n", qcount); fflush(stdout);
printf("\n*** remote AF_INET6 query count expected 20, actual %d\n", qcount); fflush(stdout);
qcount = doquery(rt, nodeid.id, KS_DHT_BOTH, ifv4);
printf("\n*** AF_INET count expected 4, actual %d\n", qcount); fflush(stdout);
printf("\n*** AF_INET count expected 20, actual %d\n", qcount); fflush(stdout);
printf("*** testbuckets - test03 finished\n\n\n"); fflush(stdout);
return;
}
void test04()
{
printf("*** testbuckets - test04 start\n"); fflush(stdout);
ks_dht_node_t* peer;
ks_dht_nodeid_t nodeid;
memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE);
......@@ -242,16 +255,193 @@ void test04()
printf("*** query on 10k nodes in %d ms\n", tx);
printf("*** testbuckets - test04 finished\n\n\n"); fflush(stdout);
return;
}
/* test read/write node locking */
void test05()
{
printf("*** testbuckets - test05 start\n"); fflush(stdout);
ks_dht_node_t* peer, *peer1, *peer2;
ks_dht_nodeid_t nodeid;
ks_status_t s;
memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE);
char ipv6[] = "1234:1234:1234:1234";
char ipv4[] = "123.123.123.123";
unsigned short port = 7001;
ks_dhtrt_create_node(rt, nodeid, KS_DHT_REMOTE, ipv4, port, &peer);
peer1 = ks_dhtrt_find_node(rt, nodeid);
printf("test05 - first find compelete\n"); fflush(stdout);
peer2 = ks_dhtrt_find_node(rt, nodeid);
printf("test05 - second find compelete\n"); fflush(stdout);
ks_dhtrt_delete_node(rt, peer);
printf("test05 - delete compelete\n"); fflush(stdout);
s = ks_dhtrt_release_node(peer1);
if (s == KS_STATUS_FAIL) printf("release 1 failed\n"); fflush(stdout);
int main(int argx, char* argv[]) {
s = ks_dhtrt_release_node(peer2);
if (s == KS_STATUS_FAIL) printf("release 1 failed\n");
printf("*** testbuckets - test05 finished\n\n\n"); fflush(stdout);
return;
}
static int gindex = 1;
static ks_mutex_t *glock;
static int gstop = 0;
static int test06loops = 1000;
static int test06nodes = 200; /* max at 255 */
static void *test06ex1(ks_thread_t *thread, void *data)
{
while(!gstop) {
ks_dhtrt_process_table(rt);
ks_sleep(100);
}
return NULL;
}
static void *test06ex2(ks_thread_t *thread, void *data)
{
ks_dht_nodeid_t nodeid;
ks_dhtrt_querynodes_t query;
while(!gstop) {
memset(&query, 0, sizeof(query));
memset(query.nodeid.id, 0xef, KS_DHT_NODEID_SIZE);
query.max = 30;
query.family = ifv4;
query.type = KS_DHT_REMOTE;
ks_dhtrt_findclosest_nodes(rt, &query);
ks_sleep(10000);
for(int i=0; i<query.count; ++i) {
ks_dhtrt_release_node(query.nodes[i]);
ks_sleep(10000);
}
ks_sleep(2000000);
}
return NULL;
}
static void *test06ex(ks_thread_t *thread, void *data)
{
ks_dht_node_t* peer;
ks_dht_nodeid_t nodeid;
char ipv6[] = "1234:1234:1234:1234";
char ipv4[] = "123.123.123.123";
unsigned short port = 7000;
memset(nodeid.id, 0xef, KS_DHT_NODEID_SIZE);
int *pi = data;
int i = *pi;
ks_mutex_lock(glock);
nodeid.id[0] = ++gindex;
ks_mutex_unlock(glock);
printf("starting thread with i of %d\n", gindex); fflush(stdout);
for(int loop=0; loop<test06loops; ++loop) {
for (int i=0; i<test06nodes; ++i) {
++nodeid.id[19];
ks_dhtrt_create_node(rt, nodeid, KS_DHT_LOCAL, ipv4, port, &peer);
ks_sleep(1000);
}
for (int i=0; i<test06nodes; ++i) {
peer = ks_dhtrt_find_node(rt, nodeid);
if (peer) {
ks_dhtrt_delete_node(rt, peer);
ks_sleep(400);
}
--nodeid.id[19];
}
}
return 0;
}
void test06()
{
int i;
ks_mutex_create(&glock, KS_MUTEX_FLAG_DEFAULT, pool);
ks_thread_t* t0;
ks_thread_create(&t0, test06ex1, NULL, pool);
ks_thread_t* t1;
ks_thread_create(&t1, test06ex2, NULL, pool);
for(i = 0; i < 10; i++) {
ks_thread_create(&threads[i], test06ex, &i, pool);
}
printf("all threads started\n"); fflush(stdout);
for(i = 0; i < 10; i++) {
ks_thread_join(threads[i]);
}
gstop = 1;
ks_thread_join(t1);
ks_thread_join(t0);
printf("all threads completed\n"); fflush(stdout);
ks_dhtrt_dump(rt, 7);
return;
}
int main(int argc, char* argv[]) {
printf("testdhtbuckets - start\n");
int tests[10];
if (argc == 0) {
tests[1] = 1;
tests[2] = 1;
tests[3] = 1;
tests[4] = 1;
tests[5] = 1;
tests[6] = 0;
tests[7] = 0;
tests[8] = 0;
tests[9] = 0;
}
else {
for(int tix=1; tix<10 && tix<argc; ++tix) {
long i = strtol(argv[tix], NULL, 0);
tests[i] = 1;
}
}
ks_init();
ks_status_t status;
......@@ -272,12 +462,41 @@ int main(int argx, char* argv[]) {
ks_dhtrt_initroute(&rt, pool);
ks_dhtrt_deinitroute(&rt);
ks_dhtrt_initroute(&rt, pool);
test01();
test02();
test03();
test04();
if (tests[1] == 1) {
ks_dhtrt_initroute(&rt, pool);
test01();
ks_dhtrt_deinitroute(&rt);
}
if (tests[2] == 1) {
ks_dhtrt_initroute(&rt, pool);
test02();
ks_dhtrt_deinitroute(&rt);
}
if (tests[3] == 1) {
ks_dhtrt_initroute(&rt, pool);
test03();
ks_dhtrt_deinitroute(&rt);
}
if (tests[4] == 1) {
ks_dhtrt_initroute(&rt, pool);
test04();
ks_dhtrt_deinitroute(&rt);
}
if (tests[5] == 1) {
ks_dhtrt_initroute(&rt, pool);
test05();
ks_dhtrt_deinitroute(&rt);
}
if (tests[6] == 1) {
ks_dhtrt_initroute(&rt, pool);
test06();
ks_dhtrt_deinitroute(&rt);
}
return 0;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论