コード例 #1
0
TEST(Outputs, json_es) {
    int ret;
    int size = sizeof(JSON_ES) - 1;
    flb_ctx_t *ctx;
    flb_input_t *input;
    flb_output_t *output;

    ctx = flb_create();
    EXPECT_TRUE(ctx != NULL);

    input = flb_input(ctx, (char *) "lib", NULL);
    EXPECT_TRUE(input != NULL);
    flb_input_set(input, "tag", "test");

    output = flb_output(ctx, (char *) "es", NULL);
    EXPECT_TRUE(output != NULL);
    flb_output_set(output, "tag", "test");

    ret = flb_start(ctx);
    EXPECT_EQ(ret, 0);

    flb_lib_push(input, (char *) JSON_ES, size);

    flb_stop(ctx);
    flb_destroy(ctx);
}
コード例 #2
0
TEST(Outputs, json_invalid) {
    int i;
    int ret;
    int total;
    int bytes;
    char *p = (char *) JSON_INVALID;
    flb_ctx_t *ctx;
    flb_input_t *input;
    flb_output_t *output;

    ctx = flb_create();

    input = flb_input(ctx, (char *) "lib", NULL);
    EXPECT_TRUE(input != NULL);
    flb_input_set(input, "tag", "test");

    output = flb_output(ctx, (char *) "stdout", NULL);
    EXPECT_TRUE(output != NULL);
    flb_output_set(output, "tag", "test");

    ret = flb_start(ctx);
    EXPECT_EQ(ret, 0);

    total = 0;
    for (i = 0; i < (int) sizeof(JSON_INVALID) - 1; i++) {
        bytes = flb_lib_push(input, p + i, 1);
        EXPECT_EQ(bytes, 1);
        total++;
    }

    flb_stop(ctx);
    flb_destroy(ctx);
}
コード例 #3
0
TEST(Inputs, flush_5s)
{
    int           ret    = 0;
    flb_ctx_t    *ctx    = NULL;
    int in_ffd;
    int out_ffd;

    /* initialize */
    ret = pthread_mutex_init(&result_mutex, NULL);
    result = 0;
    EXPECT_EQ(ret, 0);

    ctx = flb_create();

    in_ffd = flb_input(ctx, (char *) "random", NULL);
    EXPECT_TRUE(in_ffd >= 0);
    flb_input_set(ctx, in_ffd, "tag", "test", NULL);

    out_ffd = flb_output(ctx, (char *) "lib", (void*)callback_test);
    EXPECT_TRUE(out_ffd >= 0);
    flb_output_set(ctx, out_ffd, "match", "test", NULL);

    ret = flb_start(ctx);
    EXPECT_EQ(ret, 0);

    /* start test */
    sleep(2);
    pthread_mutex_lock(&result_mutex);
    ret = result; /* 2sec passed, no data should be flushed */
    pthread_mutex_unlock(&result_mutex);
    EXPECT_EQ(ret, 0);

    sleep(3);
    pthread_mutex_lock(&result_mutex);
    ret = result; /* 5sec passed, data should be flushed */
    pthread_mutex_unlock(&result_mutex);
    EXPECT_EQ(ret, 1);


    /* finalize */
    flb_stop(ctx);
    flb_destroy(ctx);

    ret = pthread_mutex_destroy(&result_mutex);
    EXPECT_EQ(ret, 0);
}