本文整理汇总了C++中TEST_FAIL函数的典型用法代码示例。如果您正苦于以下问题:C++ TEST_FAIL函数的具体用法?C++ TEST_FAIL怎么用?C++ TEST_FAIL使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TEST_FAIL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main_0035_api_version
int main_0035_api_version (int argc, char **argv) {
rd_kafka_t *rk;
rd_kafka_conf_t *conf;
const struct rd_kafka_metadata *metadata;
rd_kafka_resp_err_t err;
test_timing_t t_meta;
test_conf_init(&conf, NULL, 30);
test_conf_set(conf, "socket.timeout.ms", "12000");
rk = test_create_handle(RD_KAFKA_PRODUCER, conf);
TEST_SAY("Querying for metadata\n");
TIMING_START(&t_meta, "metadata()");
err = rd_kafka_metadata(rk, 0, NULL, &metadata, 10*1000);
TIMING_STOP(&t_meta);
if (err)
TEST_FAIL("metadata() failed: %s",
rd_kafka_err2str(err));
if (TIMING_DURATION(&t_meta) / 1000 > 11*1000)
TEST_FAIL("metadata() took too long: %.3fms",
(float)TIMING_DURATION(&t_meta) / 1000.0f);
rd_kafka_metadata_destroy(metadata);
TEST_SAY("Metadata succeeded\n");
rd_kafka_destroy(rk);
return 0;
}
示例2: rebalance_cb
static void rebalance_cb (rd_kafka_t *rk,
rd_kafka_resp_err_t err,
rd_kafka_topic_partition_list_t *partitions,
void *opaque) {
char *memberid = rd_kafka_memberid(rk);
TEST_SAY("%s: MemberId \"%s\": Consumer group rebalanced: %s\n",
rd_kafka_name(rk), memberid, rd_kafka_err2str(err));
if (memberid)
free(memberid);
test_print_partition_list(partitions);
switch (err)
{
case RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS:
assign_cnt++;
rd_kafka_assign(rk, partitions);
break;
case RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS:
if (assign_cnt == 0)
TEST_FAIL("asymetric rebalance_cb\n");
assign_cnt--;
rd_kafka_assign(rk, NULL);
break;
default:
TEST_FAIL("rebalance failed: %s\n",
rd_kafka_err2str(err));
break;
}
}
示例3: test_conf_init
rd_kafka_topic_t *test_create_producer_topic (rd_kafka_t *rk,
const char *topic, ...) {
rd_kafka_topic_t *rkt;
rd_kafka_topic_conf_t *topic_conf;
char errstr[512];
va_list ap;
const char *name, *val;
test_conf_init(NULL, &topic_conf, 20);
va_start(ap, topic);
while ((name = va_arg(ap, const char *)) &&
(val = va_arg(ap, const char *))) {
if (rd_kafka_topic_conf_set(topic_conf, name, val,
errstr, sizeof(errstr)) != RD_KAFKA_CONF_OK)
TEST_FAIL("Conf failed: %s\n", errstr);
}
va_end(ap);
/* Make sure all replicas are in-sync after producing
* so that consume test wont fail. */
rd_kafka_topic_conf_set(topic_conf, "request.required.acks", "-1",
errstr, sizeof(errstr));
rkt = rd_kafka_topic_new(rk, topic, topic_conf);
if (!rkt)
TEST_FAIL("Failed to create topic: %s\n",
rd_kafka_err2str(rd_kafka_errno2err(errno)));
return rkt;
}
示例4: test_wait_exit
/**
* Wait 'timeout' seconds for rdkafka to kill all its threads and clean up.
*/
void test_wait_exit (int timeout) {
int r;
time_t start = time(NULL);
while ((r = rd_kafka_thread_cnt()) && timeout-- >= 0) {
TEST_SAY("%i thread(s) in use by librdkafka, waiting...\n", r);
rd_sleep(1);
}
TEST_SAY("%i thread(s) in use by librdkafka\n", r);
if (r > 0) {
TEST_FAIL("%i thread(s) still active in librdkafka", r);
}
timeout -= (int)(time(NULL) - start);
if (timeout > 0) {
TEST_SAY("Waiting %d seconds for all librdkafka memory "
"to be released\n", timeout);
if (rd_kafka_wait_destroyed(timeout * 1000) == -1)
TEST_FAIL("Not all internal librdkafka "
"objects destroyed\n");
}
}
示例5: TEST_FAIL
bool ViewerConfig::loadFromStorage(SettingsManager *storage)
{
bool loadAllOk = true;
TEST_FAIL(storage->getInt(_T("LogLevel"), &m_logLevel), loadAllOk);
setLogLevel(m_logLevel);
TEST_FAIL(storage->getInt(_T("ListenPort"), &m_listenPort), loadAllOk);
TEST_FAIL(storage->getInt(_T("HistoryLimit"), &m_historyLimit), loadAllOk);
setHistoryLimit(m_historyLimit);
//
// FIXME: Why registry entry has "NoToolbar" name but
// meaning of code in what, that is this flag is set then
// toolbar become visible.
//
TEST_FAIL(storage->getBoolean(_T("NoToolbar"), &m_showToolbar), loadAllOk);
if (storage->getBoolean(_T("SkipFullScreenPrompt"), &m_promptOnFullscreen)) {
m_promptOnFullscreen = !m_promptOnFullscreen;
} else {
loadAllOk = false;
}
return loadAllOk;
}
示例6: do_test_kafka_new_failures
/**
* @brief When rd_kafka_new() succeeds it takes ownership of the config object,
* but when it fails the config object remains in application custody.
* These tests makes sure that's the case (preferably run with valgrind)
*/
static void do_test_kafka_new_failures (void) {
rd_kafka_conf_t *conf;
rd_kafka_t *rk;
char errstr[512];
conf = rd_kafka_conf_new();
rk = rd_kafka_new(RD_KAFKA_PRODUCER, conf, errstr, sizeof(errstr));
TEST_ASSERT(rk, "kafka_new() failed: %s", errstr);
rd_kafka_destroy(rk);
/* Set an erroneous configuration value that is not checked
* by conf_set() but by rd_kafka_new() */
conf = rd_kafka_conf_new();
if (rd_kafka_conf_set(conf, "partition.assignment.strategy",
"range,thiswillfail", errstr, sizeof(errstr)) !=
RD_KAFKA_CONF_OK)
TEST_FAIL("%s", errstr);
rk = rd_kafka_new(RD_KAFKA_PRODUCER, conf, errstr, sizeof(errstr));
TEST_ASSERT(!rk, "kafka_new() should have failed");
/* config object should still belong to us,
* correct the erroneous config and try again. */
if (rd_kafka_conf_set(conf, "partition.assignment.strategy", NULL,
errstr, sizeof(errstr)) !=
RD_KAFKA_CONF_OK)
TEST_FAIL("%s", errstr);
rk = rd_kafka_new(RD_KAFKA_PRODUCER, conf, errstr, sizeof(errstr));
TEST_ASSERT(rk, "kafka_new() failed: %s", errstr);
rd_kafka_destroy(rk);
}
示例7: rebalance_cb
static void rebalance_cb (rd_kafka_t *rk, rd_kafka_resp_err_t err,
rd_kafka_topic_partition_list_t *parts, void *opaque) {
int i;
TEST_SAY("rebalance_cb: %s:\n", rd_kafka_err2str(err));
test_print_partition_list(parts);
if (parts->cnt < partitions)
TEST_FAIL("rebalance_cb: Expected %d partitions, not %d",
partitions, parts->cnt);
switch (err)
{
case RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS:
for (i = 0 ; i < parts->cnt ; i++) {
if (i < partitions)
parts->elems[i].offset = msgcnt / 2;
else
parts->elems[i].offset = RD_KAFKA_OFFSET_END;
}
TEST_SAY("Use these offsets:\n");
test_print_partition_list(parts);
test_consumer_assign("HL.REBALANCE", rk, parts);
break;
case RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS:
test_consumer_unassign("HL.REBALANCE", rk);
break;
default:
TEST_FAIL("rebalance_cb: error: %s", rd_kafka_err2str(err));
}
}
示例8: handle_drs
/**
* Handle delivery reports
*/
static void handle_drs (rd_kafka_event_t *rkev) {
const rd_kafka_message_t *rkmessage;
while ((rkmessage = rd_kafka_event_message_next(rkev))) {
int msgid = *(int *)rkmessage->_private;
free(rkmessage->_private);
TEST_SAYL(3,"Got rkmessage %s [%"PRId32"] @ %"PRId64": %s\n",
rd_kafka_topic_name(rkmessage->rkt),
rkmessage->partition, rkmessage->offset,
rd_kafka_err2str(rkmessage->err));
if (rkmessage->err != RD_KAFKA_RESP_ERR_NO_ERROR)
TEST_FAIL("Message delivery failed: %s\n",
rd_kafka_err2str(rkmessage->err));
if (msgid != msgid_next) {
fails++;
TEST_FAIL("Delivered msg %i, expected %i\n",
msgid, msgid_next);
return;
}
msgid_next = msgid+1;
}
}
示例9: consume_messages
static void consume_messages (uint64_t testid, const char *topic,
int32_t partition, int msg_base, int batch_cnt,
int msgcnt) {
rd_kafka_t *rk;
rd_kafka_topic_t *rkt;
rd_kafka_conf_t *conf;
rd_kafka_topic_conf_t *topic_conf;
int i;
test_conf_init(&conf, &topic_conf, 20);
/* Create kafka instance */
rk = test_create_handle(RD_KAFKA_CONSUMER, conf);
rkt = rd_kafka_topic_new(rk, topic, topic_conf);
if (!rkt)
TEST_FAIL("Failed to create topic: %s\n",
rd_kafka_err2str(rd_kafka_last_error()));
TEST_SAY("Consuming %i messages from partition %i\n",
batch_cnt, partition);
/* Consume messages */
if (rd_kafka_consume_start(rkt, partition,
RD_KAFKA_OFFSET_TAIL(batch_cnt)) == -1)
TEST_FAIL("consume_start(%i, -%i) failed: %s",
(int)partition, batch_cnt,
rd_kafka_err2str(rd_kafka_last_error()));
for (i = 0 ; i < batch_cnt ; i++) {
rd_kafka_message_t *rkmessage;
rkmessage = rd_kafka_consume(rkt, partition, tmout_multip(5000));
if (!rkmessage)
TEST_FAIL("Failed to consume message %i/%i from "
"partition %i: %s",
i, batch_cnt, (int)partition,
rd_kafka_err2str(rd_kafka_last_error()));
if (rkmessage->err)
TEST_FAIL("Consume message %i/%i from partition %i "
"has error: %s",
i, batch_cnt, (int)partition,
rd_kafka_err2str(rkmessage->err));
verify_consumed_msg(testid, partition, msg_base+i, rkmessage);
rd_kafka_message_destroy(rkmessage);
}
rd_kafka_consume_stop(rkt, partition);
/* Destroy topic */
rd_kafka_topic_destroy(rkt);
/* Destroy rdkafka instance */
TEST_SAY("Destroying kafka instance %s\n", rd_kafka_name(rk));
rd_kafka_destroy(rk);
}
示例10: verify_consumed_msg0
static void verify_consumed_msg0 (const char *func, int line,
uint64_t testid, int32_t partition,
int msgnum,
rd_kafka_message_t *rkmessage) {
uint64_t in_testid;
int in_part;
int in_msgnum;
char buf[128];
if (rkmessage->len != 0)
TEST_FAIL("Incoming message not NULL: %i bytes",
(int)rkmessage->len);
if (rkmessage->key_len +1 >= sizeof(buf))
TEST_FAIL("Incoming message key too large (%i): "
"not sourced by this test",
(int)rkmessage->key_len);
rd_snprintf(buf, sizeof(buf), "%.*s",
(int)rkmessage->key_len, (char *)rkmessage->key);
if (sscanf(buf, "testid=%"SCNu64", partition=%i, msg=%i",
&in_testid, &in_part, &in_msgnum) != 3)
TEST_FAIL("Incorrect key format: %s", buf);
if (testid != in_testid ||
(partition != -1 && partition != in_part) ||
(msgnum != -1 && msgnum != in_msgnum) ||
(in_msgnum < 0 || in_msgnum > cons_msgs_size))
goto fail_match;
if (test_level > 2) {
TEST_SAY("%s:%i: Our testid %"PRIu64", part %i (%i), "
"msg %i/%i did "
", key's: \"%s\"\n",
func, line,
testid, (int)partition, (int)rkmessage->partition,
msgnum, cons_msgs_size, buf);
}
if (cons_msgs_cnt == cons_msgs_size) {
TEST_SAY("Too many messages in cons_msgs (%i) while reading "
"message key \"%s\"\n",
cons_msgs_cnt, buf);
verify_consumed_msg_check();
TEST_FAIL("See above error(s)");
}
cons_msgs[cons_msgs_cnt++] = in_msgnum;
return;
fail_match:
TEST_FAIL("%s:%i: Our testid %"PRIu64", part %i, msg %i/%i did "
"not match message's key: \"%s\"\n",
func, line,
testid, (int)partition, msgnum, cons_msgs_size, buf);
}
示例11: rebalance_cb
static void rebalance_cb (rd_kafka_t *rk, rd_kafka_resp_err_t err,
rd_kafka_topic_partition_list_t *partitions,
void *opaque) {
int i;
char *memberid = rd_kafka_memberid(rk);
TEST_SAY("%s: MemberId \"%s\": Consumer group rebalanced: %s\n",
rd_kafka_name(rk), memberid, rd_kafka_err2str(err));
if (memberid)
free(memberid);
test_print_partition_list(partitions);
switch (err) {
case RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS:
assign_cnt++;
rd_kafka_assign(rk, partitions);
mtx_lock(&lock);
consumers_running = 1;
mtx_unlock(&lock);
for (i = 0; i < partitions->cnt && i < MAX_THRD_CNT; ++i) {
rd_kafka_topic_partition_t part = partitions->elems[i];
rd_kafka_queue_t *rkqu;
/* This queue is loosed in partition-consume. */
rkqu = rd_kafka_queue_get_partition(rk, part.topic,
part.partition);
rd_kafka_queue_forward(rkqu, NULL);
tids[part.partition] = spawn_thread(rkqu,
part.partition);
}
rebalanced = 1;
break;
case RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS:
if (assign_cnt == 0)
TEST_FAIL("asymetric rebalance_cb");
assign_cnt--;
rd_kafka_assign(rk, NULL);
mtx_lock(&lock);
consumers_running = 0;
mtx_unlock(&lock);
break;
default:
TEST_FAIL("rebalance failed: %s", rd_kafka_err2str(err));
break;
}
}
示例12: partition_consume
static int partition_consume (void *args) {
part_consume_info_t *info = (part_consume_info_t *)args;
rd_kafka_queue_t *rkqu = info->rkqu;
int partition = info->partition;
int64_t ts_start = test_clock();
int max_time = (test_session_timeout_ms + 3000) * 1000;
int running = 1;
free(args); /* Free the parameter struct dynamically allocated for us */
while (ts_start + max_time > test_clock() && running &&
is_consuming()) {
rd_kafka_message_t *rkmsg;
rkmsg = rd_kafka_consume_queue(rkqu, 500);
if (!rkmsg)
continue;
else if (rkmsg->err == RD_KAFKA_RESP_ERR__PARTITION_EOF)
running = 0;
else if (rkmsg->err) {
mtx_lock(&lock);
TEST_FAIL("Message error "
"(at offset %" PRId64 " after "
"%d/%d messages and %dms): %s",
rkmsg->offset, consumed_msg_cnt, exp_msg_cnt,
(int)(test_clock() - ts_start) / 1000,
rd_kafka_message_errstr(rkmsg));
mtx_unlock(&lock);
} else {
if (rkmsg->partition != partition) {
mtx_lock(&lock);
TEST_FAIL("Message consumed has partition %d "
"but we expected partition %d.",
rkmsg->partition, partition);
mtx_unlock(&lock);
}
}
rd_kafka_message_destroy(rkmsg);
mtx_lock(&lock);
if (running && ++consumed_msg_cnt >= exp_msg_cnt) {
TEST_SAY("All messages consumed\n");
running = 0;
}
mtx_unlock(&lock);
}
rd_kafka_queue_destroy(rkqu);
return thrd_success;
}
示例13: do_test_stats_timer
/**
* Enable statistics with a set interval, make sure the stats callbacks are
* called within reasonable intervals.
*/
static void do_test_stats_timer (void) {
rd_kafka_t *rk;
rd_kafka_conf_t *conf;
const int exp_calls = 10;
char errstr[512];
struct state state;
test_timing_t t_new;
memset(&state, 0, sizeof(state));
state.interval = 600*1000;
test_conf_init(&conf, NULL, 200);
test_conf_set(conf, "statistics.interval.ms", "600");
rd_kafka_conf_set_stats_cb(conf, stats_cb);
rd_kafka_conf_set_opaque(conf, &state);
TIMING_START(&t_new, "rd_kafka_new()");
rk = rd_kafka_new(RD_KAFKA_CONSUMER, conf, errstr, sizeof(errstr));
TIMING_STOP(&t_new);
if (!rk)
TEST_FAIL("Failed to create instance: %s\n", errstr);
TEST_SAY("Starting wait loop for %d expected stats_cb calls "
"with an interval of %dms\n",
exp_calls, state.interval/1000);
while (state.calls < exp_calls) {
test_timing_t t_poll;
TIMING_START(&t_poll, "rd_kafka_poll()");
rd_kafka_poll(rk, 100);
TIMING_STOP(&t_poll);
if (TIMING_DURATION(&t_poll) > 150*1000)
TEST_WARN("rd_kafka_poll(rk,100) "
"took more than 50%% extra\n");
}
rd_kafka_destroy(rk);
if (state.calls > exp_calls)
TEST_SAY("Got more calls than expected: %d > %d\n",
state.calls, exp_calls);
if (state.fails)
TEST_FAIL("%d/%d intervals failed\n", state.fails, state.calls);
else
TEST_SAY("All %d intervals okay\n", state.calls);
}
示例14: test_multiple_writes
int test_multiple_writes(void)
{
const char *output = "Zorba!\n";
int maxcount = 5;
int fd = open(g_testfilepath, O_CREAT|O_RDWR, 0644);
int i = 0;
int total = 0;
int result = 0;
int old_errno = errno;
TEST_START();
if (fd < 0) {
TEST_FAIL();
TEST_COMPLETE_FAIL("Unable to create file %s\n"
"Errno %d: %s\n",
g_testfilepath, old_errno, strerror(old_errno));
}
TEST_OK();
for (i=0; i<maxcount; i++) {
total = 0;
result = 0;
while (total < strlen(output)) {
result = write(fd, output + total, strlen(output));
old_errno = errno;
if (result < 0) {
close(fd);
TEST_FAIL();
TEST_COMPLETE_FAIL("Unable to write to file %s\n"
"Errno %d: %s\n",
g_testfilepath, old_errno,
strerror(old_errno));
}
total += result;
}
}
TEST_OK();
if (close(fd) < 0) {
TEST_FAIL();
TEST_COMPLETE_FAIL("Unable to close %s\nErrno %d: %s\n",
g_testfilepath, errno, strerror(errno));
}
TEST_OK();
TEST_COMPLETE_OK();
}
示例15: dr_cb
/**
* Delivery reported callback.
* Called for each message once to signal its delivery status.
*/
static void dr_cb (rd_kafka_t *rk, void *payload, size_t len,
rd_kafka_resp_err_t err, void *opaque, void *msg_opaque) {
if (err != RD_KAFKA_RESP_ERR_NO_ERROR)
TEST_FAIL("Message delivery failed: %s\n",
rd_kafka_err2str(err));
if (prod_msg_remains == 0)
TEST_FAIL("Too many messages delivered (prod_msg_remains %i)",
prod_msg_remains);
prod_msg_remains--;
}