Beispiel #1
0
/**
 * @brief First on_send() interceptor
 */
static rd_kafka_resp_err_t on_send1 (rd_kafka_t *rk,
                                     rd_kafka_message_t *rkmessage,
                                     void *ic_opaque) {
        const struct expect expected[] = {
                { "msgid", NULL }, /* special handling */
                { "static", "hey" },
                { "multi", "multi1" },
                { "multi", "multi2" },
                { "multi", "multi3" },
                { "null", NULL },
                { "empty", "" },
                { NULL }
        };
        rd_kafka_headers_t *hdrs;
        rd_kafka_resp_err_t err;

        expect_check(__FUNCTION__, expected, rkmessage);

        err = rd_kafka_message_headers(rkmessage, &hdrs);
        if (err) /* First message has no headers. */
                return RD_KAFKA_RESP_ERR_NO_ERROR;

        rd_kafka_header_add(hdrs, "multi", -1, "multi4", -1);
        rd_kafka_header_add(hdrs, "send1", -1, "1", -1);
        rd_kafka_header_remove(hdrs, "multi");
        rd_kafka_header_add(hdrs, "multi", -1, "multi5", -1);

        return RD_KAFKA_RESP_ERR_NO_ERROR;
}
Beispiel #2
0
/**
 * @brief Second on_send() interceptor
 */
static rd_kafka_resp_err_t on_send2 (rd_kafka_t *rk,
                                     rd_kafka_message_t *rkmessage,
                                     void *ic_opaque) {
        const struct expect expected[] = {
                { "msgid", NULL }, /* special handling */
                { "static", "hey" },
                { "null", NULL },
                { "empty", "" },
                { "send1", "1" },
                { "multi", "multi5" },
                { NULL }
        };

        expect_check(__FUNCTION__, expected, rkmessage);

        return RD_KAFKA_RESP_ERR_NO_ERROR;
}
Beispiel #3
0
/**
 * @brief Final (as in no more header modifications) message check.
 */
static void msg_final_check (const char *what,
                             const rd_kafka_message_t *rkmessage) {
        const struct expect expected[] = {
                { "msgid", NULL }, /* special handling */
                { "static", "hey" },
                { "null", NULL },
                { "empty", "" },
                { "send1", "1" },
                { "multi", "multi5" },
                { NULL }
        };

        expect_check(what, expected, rkmessage);

        exp_msgid++;


}
Beispiel #4
0
/*
 * Ensure that the column having the smallest on-disk segfile is
 * chosen for headerscan during ALTER TABLE ADD COLUMN operation.
 */
void
test__column_to_scan(void **state)
{
	List *drop_segno_list = NIL;
	RelationData reldata;
	AOCSFileSegInfo *segInfos[4];
	int numcols = 3;
	int col;

	/* Empty segment, should be skipped over */
	segInfos[0] = (AOCSFileSegInfo *)
			malloc(sizeof(AOCSFileSegInfo) + sizeof(AOCSVPInfoEntry)*numcols);
	segInfos[0]->segno = 3;
	segInfos[0]->state = AOSEG_STATE_DEFAULT;
	segInfos[0]->total_tupcount = 0;
	segInfos[0]->vpinfo.nEntry = 3; /* number of columns */
	segInfos[0]->vpinfo.entry[0].eof = 200;
	segInfos[0]->vpinfo.entry[0].eof_uncompressed = 200;
	segInfos[0]->vpinfo.entry[1].eof = 100;
	segInfos[0]->vpinfo.entry[1].eof_uncompressed = 165;
	segInfos[0]->vpinfo.entry[2].eof = 50;
	segInfos[0]->vpinfo.entry[2].eof_uncompressed = 85;

	/* Valid segment, col=1 is the smallest */
	segInfos[1] = (AOCSFileSegInfo *)
			malloc(sizeof(AOCSFileSegInfo) + sizeof(AOCSVPInfoEntry)*numcols);
	segInfos[1]->segno = 2;
	segInfos[1]->total_tupcount = 51;
	segInfos[1]->state = AOSEG_STATE_DEFAULT;
	segInfos[1]->vpinfo.nEntry = 3; /* number of columns */
	segInfos[1]->vpinfo.entry[0].eof = 120;
	segInfos[1]->vpinfo.entry[0].eof_uncompressed = 200;
	segInfos[1]->vpinfo.entry[1].eof = 100;
	segInfos[1]->vpinfo.entry[1].eof_uncompressed = 100;
	segInfos[1]->vpinfo.entry[2].eof = 320;
	segInfos[1]->vpinfo.entry[2].eof_uncompressed = 400;

	/* AWATING_DROP segment, should be skipped over */
	segInfos[2] = (AOCSFileSegInfo *)
			malloc(sizeof(AOCSFileSegInfo) + sizeof(AOCSVPInfoEntry)*numcols);
	segInfos[2]->segno = 3;
	segInfos[2]->state = AOSEG_STATE_AWAITING_DROP;
	segInfos[2]->total_tupcount = 15;
	segInfos[2]->vpinfo.nEntry = 3; /* number of columns */
	segInfos[2]->vpinfo.entry[0].eof = 141;
	segInfos[2]->vpinfo.entry[0].eof_uncompressed = 200;
	segInfos[2]->vpinfo.entry[1].eof = 51;
	segInfos[2]->vpinfo.entry[1].eof_uncompressed = 65;
	segInfos[2]->vpinfo.entry[2].eof = 20;
	segInfos[2]->vpinfo.entry[2].eof_uncompressed = 80;

	/* Valid segment, col=0 is the smallest */
	segInfos[3] = (AOCSFileSegInfo *)
			malloc(sizeof(AOCSFileSegInfo) + sizeof(AOCSVPInfoEntry)*numcols);
	segInfos[3]->segno = 1;
	segInfos[3]->state = AOSEG_STATE_USECURRENT;
	segInfos[3]->total_tupcount = 135;
	segInfos[3]->vpinfo.nEntry = 3; /* number of columns */
	segInfos[3]->vpinfo.entry[0].eof = 60;
	segInfos[3]->vpinfo.entry[0].eof_uncompressed = 80;
	segInfos[3]->vpinfo.entry[1].eof = 500;
	segInfos[3]->vpinfo.entry[1].eof_uncompressed = 650;
	segInfos[3]->vpinfo.entry[2].eof = 100;
	segInfos[3]->vpinfo.entry[2].eof_uncompressed = 120;

	/* AOCSDrop should be called with segno 3 to drop */
	drop_segno_list = lappend_int(drop_segno_list, 3);
	Gp_role = GP_ROLE_EXECUTE;
	expect_value(AOCSDrop, aorel, &reldata);
	expect_check(AOCSDrop, compaction_segno, check_segno_list, drop_segno_list);
	will_be_called(AOCSDrop);

	/* Column 1 (vpe index 1) has the smallest eof */
	col = column_to_scan(segInfos, 4, numcols, &reldata);
	assert_int_equal(col, 1);
}
Beispiel #5
0
struct plugin *helper_get_example_plugin(void)
{
  struct plugin *p = MALLOC(struct plugin);
  struct function *f = MALLOC(struct function);

  if (!p || !f)
    LOG_ERROR("[test] Failed to alloc mem for example plugin.\n");

  p->key = (string) {.str = "0123456789ABCDEF",
                     .length = sizeof("0123456789ABCDEF") - 1};
  p->name = (string) {.str = "plugin name",
                      .length = sizeof("plugin name") - 1};
  p->description = (string) {.str = "plugin desc",
                             .length = sizeof("plugin desc") - 1};
  p->license = (string) {.str = "plugin license",
                         .length = sizeof("plugin license") - 1};
  p->author = (string) {.str = "plugin author",
                        .length = sizeof("plugin author") - 1};

  p->callid = 0;

  f->name = (string) {.str = "function name",
                      .length = sizeof("function name") - 1};
  f->description = (string) {.str = "function desc",
                             .length = sizeof("function desc") - 1};
  f->args[0] = (string) {.str = "arg 1",
                         .length = sizeof("arg 1") - 1};
  f->args[1] = (string) {.str = "arg 2",
                         .length = sizeof("arg 2") - 1};

  p->function = f;
  return p;
}

void helper_free_plugin(struct plugin *p)
{
  FREE(p->function);
  FREE(p);
}


/* Builds a register call and executes handle_register in order
 * to register the plugin. */
void helper_register_plugin(struct plugin *p)
{
  connection_request_event_info info;
  struct message_request *register_request;
  array *meta, *functions, *func1, *args;
  struct api_error err = ERROR_INIT;

  info.request.msgid = 1;
  register_request = &info.request;
  assert_non_null(register_request);

  info.api_error = err;

  info.con = CALLOC(1, struct connection);
  info.con->closed = true;
  info.con->msgid = 1;
  info.con->id = (uint64_t) randommod(281474976710656LL);

  assert_non_null(info.con);

  strlcpy(info.con->cc.pluginkeystring, p->key.str, p->key.length+1);

  connect_to_db();
  assert_int_equal(0, connection_init());

  /* first level arrays:
   *
   * [meta] args->obj[0]
   * [functions] args->obj[1]
   */
  register_request->params.size = 2;
  register_request->params.obj = CALLOC(2, struct message_object);
  register_request->params.obj[0].type = OBJECT_TYPE_ARRAY;
  register_request->params.obj[1].type = OBJECT_TYPE_ARRAY;

  /* meta array:
   *
   * [name]
   * [desciption]
   * [author]
   * [license]
   */
  meta = &register_request->params.obj[0].data.params;
  meta->size = 4;
  meta->obj = CALLOC(meta->size, struct message_object);
  meta->obj[0].type = OBJECT_TYPE_STR;
  meta->obj[0].data.string = cstring_copy_string(p->name.str);
  meta->obj[1].type = OBJECT_TYPE_STR;
  meta->obj[1].data.string = cstring_copy_string(p->description.str);
  meta->obj[2].type = OBJECT_TYPE_STR;
  meta->obj[2].data.string = cstring_copy_string(p->author.str);
  meta->obj[3].type = OBJECT_TYPE_STR;
  meta->obj[3].data.string = cstring_copy_string(p->license.str);

  functions = &register_request->params.obj[1].data.params;
  functions->size = 1;
  functions->obj = CALLOC(functions->size, struct message_object);
  functions->obj[0].type = OBJECT_TYPE_ARRAY;

  func1 = &functions->obj[0].data.params;
  func1->size = 3;
  func1->obj = CALLOC(3, struct message_object);
  func1->obj[0].type = OBJECT_TYPE_STR;
  func1->obj[0].data.string = cstring_copy_string(p->function->name.str);
  func1->obj[1].type = OBJECT_TYPE_STR;
  func1->obj[1].data.string = cstring_copy_string(p->function->description.str);
  func1->obj[2].type = OBJECT_TYPE_ARRAY;

  /* function arguments */
  args = &func1->obj[2].data.params;
  args->size = 2;
  args->obj = CALLOC(2, struct message_object);
  args->obj[0].type = OBJECT_TYPE_STR;
  args->obj[0].data.string = cstring_copy_string(p->function->args[0].str);
  args->obj[1].type = OBJECT_TYPE_STR;
  args->obj[1].data.string = cstring_copy_string(p->function->args[1].str);

  /* before running function, it must be registered successfully */
  info.api_error.isset = false;
  expect_check(__wrap_crypto_write, &deserialized,
                validate_register_response,
                NULL);

  info.con->refcount++;

  connection_hashmap_put(info.con->id, info.con);
  pluginkeys_hashmap_put(info.con->cc.pluginkeystring, info.con->id);

  assert_int_equal(0, handle_register(info.con->id, &info.request,
      info.con->cc.pluginkeystring, &info.api_error));
  assert_false(info.api_error.isset);

  //hashmap_put(uint64_t, ptr_t)(connections, info.con->id, info.con);
  free_params(register_request->params);
  //FREE(args->obj);
  //FREE(func1->obj);
  //FREE(functions->obj);
  //FREE(meta->obj);
  //FREE(register_request->params.obj);
}

/* Builds a run request */
void helper_build_run_request(struct message_request *rr,
    struct plugin *plugin,
    message_object_type metaarraytype,
    size_t metasize,
    message_object_type metaclientidtype,
    message_object_type metacallidtype,
    message_object_type functionnametype,
    message_object_type argstype
)
{
  array argsarray = ARRAY_INIT;
  array *meta;

  rr->msgid = 1;

  rr->params.size = 3;
  rr->params.obj = CALLOC(rr->params.size, struct message_object);
  rr->params.obj[0].type = metaarraytype;

  meta = &rr->params.obj[0].data.params;
  meta->size = metasize;
  meta->obj = CALLOC(meta->size, struct message_object);
  meta->obj[0].type = metaclientidtype;
  meta->obj[0].data.string = cstring_copy_string(plugin->key.str);
  meta->obj[1].type = metacallidtype;

  rr->params.obj[1].type = functionnametype;
  rr->params.obj[1].data.string = cstring_copy_string(plugin->function->name.str);

  argsarray.size = 2;
  argsarray.obj = CALLOC(argsarray.size, struct message_object);
  argsarray.obj[0].type = OBJECT_TYPE_STR; /* first argument */
  argsarray.obj[0].data.string = cstring_copy_string(plugin->function->args[0].str);
  argsarray.obj[1].type = OBJECT_TYPE_STR; /* second argument */
  argsarray.obj[1].data.string = cstring_copy_string(plugin->function->args[1].str);

  rr->params.obj[2].type = argstype;
  rr->params.obj[2].data.params = argsarray;
}


void helper_build_result_request(struct message_request *rr,
    struct plugin *plugin,
    message_object_type metaarraytype,
    size_t metasize,
    message_object_type metacallidtype,
    message_object_type argstype)
{
  array argsarray = ARRAY_INIT;
  array *meta;

  rr->msgid = 1;

  rr->params.size = 2;
  rr->params.obj = CALLOC(rr->params.size, struct message_object);
  rr->params.obj[0].type = metaarraytype;
  meta = &rr->params.obj[0].data.params;
  meta->size = metasize;
  meta->obj = CALLOC(meta->size, struct message_object);
  meta->obj[0].type = metacallidtype;
  meta->obj[0].data.uinteger = plugin->callid;

  argsarray.size = 2;
  argsarray.obj = CALLOC(argsarray.size, struct message_object);
  argsarray.obj[0].type = OBJECT_TYPE_STR; /* first argument */
  argsarray.obj[0].data.string = cstring_copy_string(plugin->function->args[0].str);
  argsarray.obj[1].type = OBJECT_TYPE_STR; /* second argument */
  argsarray.obj[1].data.string = cstring_copy_string(plugin->function->args[1].str);

  rr->params.obj[1].type = argstype;
  rr->params.obj[1].data.params = argsarray;
}

void helper_request_set_callid(struct message_request *rr,
  message_object_type callidtype)
{
  array *meta = &rr->params.obj[0].data.params;

  meta->obj[0].type = callidtype;
}

void helper_request_set_meta_size(struct message_request *rr,
  message_object_type metatype, uint64_t metasize)
{
  rr->params.obj[0].type = metatype;
  rr->params.obj[0].data.params.size = metasize;
}

void helper_request_set_args_size(struct message_request *rr,
  message_object_type argstype, uint64_t argssize)
{
  rr->params.obj[1].type = argstype;
  rr->params.obj[1].data.params.size = argssize;
}

void helper_request_set_function_name(struct message_request *rr,
  message_object_type nametype, char *name)
{
  free_string(rr->params.obj[1].data.string);
  rr->params.obj[1].type = nametype;
  rr->params.obj[1].data.string = cstring_copy_string(name);
}

void helper_request_set_pluginkey_type(struct message_request *rr,
  message_object_type pluginkeytype, char *pluginkey)
{
  array *meta = &rr->params.obj[0].data.params;

  free_string(meta->obj[0].data.string);
  meta->obj[0].data.string = cstring_copy_string(pluginkey);
  meta->obj[0].type = pluginkeytype;
}