X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=ztest%2Fztest.c;h=c95c4718abf5feeb6b68f268f0fffde1182ed4b4;hp=974d2da885bed979082fe83b54148a7d3f0c1e2e;hb=1141af3a859ba06226d7b3dd19eb3f83fa2f8753;hpb=379504a233e3e2cc85bca1e7b6d864f1395aec7c diff --git a/ztest/ztest.c b/ztest/ztest.c index 974d2da..c95c471 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 @@ -117,6 +137,29 @@ int ztest_search(void *handle, bend_search_rr *rr) return 0; } + if (rr->extra_args) + { + Z_SRW_extra_arg *a; + WRBUF response_xml = wrbuf_alloc(); + wrbuf_puts(response_xml, ""); + for (a = rr->extra_args; a; a = a->next) + { + wrbuf_puts(response_xml, "name); + wrbuf_puts(response_xml, "\""); + if (a->value) + { + wrbuf_puts(response_xml, " value=\""); + wrbuf_xmlputs(response_xml, a->value); + wrbuf_puts(response_xml, "\""); + } + wrbuf_puts(response_xml, "/>"); + } + wrbuf_puts(response_xml, ""); + rr->extra_response_data = + odr_strdup(rr->stream, wrbuf_cstr(response_xml)); + wrbuf_destroy(response_xml); + } rr->hits = get_hit_count(rr->query); return 0; } @@ -134,10 +177,10 @@ int ztest_esrequest(void *handle, bend_esrequest_rr *rr) if (rr->esr->packageName) yaz_log(log_level, "packagename: %s", rr->esr->packageName); - yaz_log(log_level, "Waitaction: %d", *rr->esr->waitAction); + yaz_log(log_level, "Waitaction: " ODR_INT_PRINTF, *rr->esr->waitAction); - yaz_log(log_level, "function: %d", *rr->esr->function); + yaz_log(log_level, "function: " ODR_INT_PRINTF, *rr->esr->function); if (!rr->esr->taskSpecificParameters) { @@ -172,7 +215,7 @@ int ztest_esrequest(void *handle, bend_esrequest_rr *rr) { yaz_log(log_level, "resultsetItem"); yaz_log(log_level, "setId: %s", n->resultSetItem->resultSetId); - yaz_log(log_level, "item: %d", *n->resultSetItem->item); + yaz_log(log_level, "item: " ODR_INT_PRINTF, *n->resultSetItem->item); } if (n->itemRequest) { @@ -254,7 +297,8 @@ int ztest_esrequest(void *handle, bend_esrequest_rr *rr) } if (item_req) { - yaz_log(log_level, "ILL protocol version = %d", + yaz_log(log_level, "ILL protocol version = " + ODR_INT_PRINTF, *item_req->protocol_version_num); } } @@ -345,7 +389,8 @@ int ztest_esrequest(void *handle, bend_esrequest_rr *rr) yaz_log(log_level, " specialUpdate"); break; default: - yaz_log(log_level, " unknown (%d)", *toKeep->action); + yaz_log(log_level, " unknown (" ODR_INT_PRINTF ")", + *toKeep->action); } } if (toKeep->databaseName) @@ -402,8 +447,7 @@ int ztest_esrequest(void *handle, bend_esrequest_rr *rr) ext->u.update->u.taskPackage->originPart = keep; ext->u.update->u.taskPackage->targetPart = targetPart; - keep->action = (int *) odr_malloc(rr->stream, sizeof(int)); - *keep->action = *toKeep->action; + keep->action = odr_intdup(rr->stream, *toKeep->action); keep->databaseName = odr_strdup(rr->stream, toKeep->databaseName); keep->schema = 0; @@ -635,13 +679,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;