From: Adam Dickmeiss Date: Tue, 29 Sep 2009 11:00:17 +0000 (+0200) Subject: Allow slow database wait to be set. X-Git-Tag: v3.0.49~3^2 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=a37f819598462f7ecc85b28bd56190e87e761bce;p=yaz-moved-to-github.git Allow slow database wait to be set. The dummy Database Slow may be followed by an integer.. This integer specifies the time for an operation to execute - in seconds. --- diff --git a/ztest/ztest.c b/ztest/ztest.c index f426eb9..170fba5 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -83,24 +83,27 @@ static int get_hit_count(Z_Query *q) return h; } -int ztest_search(void *handle, bend_search_rr *rr) +/** \brief checks if it's a dummy Slow database.. + \param basename database name to check + \param association backend association (or NULL if not available) + \retval 1 is slow database + \retval 0 is not a slow database + + The Slow database is for testing.. It allows us to simulate + a slow server... +*/ +static int check_slow(const char *basename, bend_association association) { - if (rr->num_bases != 1) - { - rr->errcode = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP; - return 0; - } - /* Throw Database unavailable if other than Default or Slow */ - if (!yaz_matchstr(rr->basenames[0], "Default")) - ; /* Default is OK in our test */ - else if(!yaz_matchstr(rr->basenames[0], "Slow")) + if (strncmp(basename, "Slow", 4) == 0) { #if HAVE_UNISTD_H + int i, w = 3; + if (basename[4]) + sscanf(basename+4, "%d", &w); /* wait up to 3 seconds and check if connection is still alive */ - int i; - for (i = 0; i<3; i++) + for (i = 0; i < w; i++) { - if (!bend_assoc_is_alive(rr->association)) + if (association && !bend_assoc_is_alive(association)) { yaz_log(YLOG_LOG, "search aborted"); break; @@ -108,6 +111,23 @@ int ztest_search(void *handle, bend_search_rr *rr) sleep(1); } #endif + return 1; + } + return 0; +} + +int ztest_search(void *handle, bend_search_rr *rr) +{ + if (rr->num_bases != 1) + { + rr->errcode = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP; + return 0; + } + /* Throw Database unavailable if other than Default or Slow */ + if (!yaz_matchstr(rr->basenames[0], "Default")) + ; /* Default is OK in our test */ + else if (check_slow(rr->basenames[0], rr->association)) + { rr->estimated_hit_count = 1; } else @@ -636,13 +656,8 @@ int ztest_scan(void *handle, bend_scan_rr *q) /* Throw Database unavailable if other than Default or Slow */ if (!yaz_matchstr(q->basenames[0], "Default")) ; /* Default is OK in our test */ - else if(!yaz_matchstr(q->basenames[0], "Slow")) - { -#if HAVE_UNISTD_H - sleep(3); -#endif + else if (check_slow(q->basenames[0], 0 /* no assoc for scan */)) ; - } else { q->errcode = YAZ_BIB1_DATABASE_UNAVAILABLE;