greenplumn xactdesc_test 源码

  • 2022-08-18
  • 浏览 (508)

greenplumn xactdesc_test 代码

文件路径:/src/backend/access/rmgrdesc/test/xactdesc_test.c

#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include "cmockery.h"

#include "postgres.h"

#include "utils/memutils.h"
#include "access/xlog.h"
#include "pgtime.h"

/* Actual function body */
#include "../xactdesc.c"

static void
test_xactdescprepareCommit(void **state)
{
	StringInfo buf = makeStringInfo();

	XLogReaderState *record = palloc(sizeof(XLogReaderState));
	XLogRecGetData(record) = palloc(sizeof(TwoPhaseFileHeader));
	record->decoded_record = palloc(sizeof(TwoPhaseFileHeader));

	XLogRecGetInfo(record) = XLOG_XACT_PREPARE;
	TwoPhaseFileHeader* tpfh = (TwoPhaseFileHeader*) XLogRecGetData(record);

	tpfh->prepared_at = 617826371830030;
	tpfh->tablespace_oid_to_delete_on_commit = 42;
	tpfh->tablespace_oid_to_delete_on_abort = InvalidOid;

	/* Can not use save_state() here, so emulate it */
	tpfh->gidlen = strlen("4242424242-0000000042") + 1;
	strcpy((char *)tpfh + sizeof(*tpfh), "4242424242-0000000042");

	xact_desc(buf, record);

	assert_string_equal("at = 2019-07-30 18:26:11.83003+00; gid = 4242424242-0000000042; tablespace_oid_to_delete_on_commit = 42", buf->data);
}

static void
test_xactdescprepareAbort(void **state)
{
	StringInfo buf = makeStringInfo();

	XLogReaderState *record = palloc(sizeof(XLogReaderState));
	XLogRecGetData(record) = palloc(sizeof(TwoPhaseFileHeader));
	record->decoded_record = palloc(sizeof(TwoPhaseFileHeader));

	XLogRecGetInfo(record) = XLOG_XACT_PREPARE;
	TwoPhaseFileHeader* tpfh = (TwoPhaseFileHeader*) XLogRecGetData(record);

	tpfh->prepared_at = 617826371830030;
	tpfh->tablespace_oid_to_delete_on_commit = InvalidOid;
	tpfh->tablespace_oid_to_delete_on_abort = 42;

	/* Can not use save_state() here, so emulate it */
	tpfh->gidlen = strlen("4242424242-0000000042") + 1;
	strcpy((char *)tpfh + sizeof(*tpfh), "4242424242-0000000042");

	xact_desc(buf, record);

	assert_string_equal("at = 2019-07-30 18:26:11.83003+00; gid = 4242424242-0000000042; tablespace_oid_to_delete_on_abort = 42", buf->data);
}

static void
test_xactdescprepareNone(void **state)
{
	StringInfo buf = makeStringInfo();

	XLogReaderState *record = palloc(sizeof(XLogReaderState));
	XLogRecGetData(record) = palloc(sizeof(TwoPhaseFileHeader));
	record->decoded_record = palloc(sizeof(TwoPhaseFileHeader));

	XLogRecGetInfo(record) = XLOG_XACT_PREPARE;
	TwoPhaseFileHeader* tpfh = (TwoPhaseFileHeader*) XLogRecGetData(record);

	tpfh->prepared_at = 617826371830030;
	tpfh->tablespace_oid_to_delete_on_commit = InvalidOid;
	tpfh->tablespace_oid_to_delete_on_abort = InvalidOid;

	/* Can not use save_state() here, so emulate it */
	tpfh->gidlen = strlen("4242424242-0000000042") + 1;
	strcpy((char *)tpfh + sizeof(*tpfh), "4242424242-0000000042");

	xact_desc(buf, record);

	assert_string_equal("at = 2019-07-30 18:26:11.83003+00; gid = 4242424242-0000000042", buf->data);
}

int
main(int argc, char* argv[])
{
	cmockery_parse_arguments(argc, argv);

	MemoryContextInit();
	pg_timezone_initialize();

	const UnitTest tests[] = {
		unit_test(test_xactdescprepareCommit),
		unit_test(test_xactdescprepareAbort),
		unit_test(test_xactdescprepareNone)
	};

	return run_tests(tests);
}

相关信息

greenplumn 源码目录

相关文章

greenplumn adminpack 源码

greenplumn verify_nbtree 源码

greenplumn auth_delay 源码

greenplumn auto_explain 源码

greenplumn blcost 源码

greenplumn blinsert 源码

greenplumn bloom 源码

greenplumn blscan 源码

greenplumn blutils 源码

greenplumn blvacuum 源码

0  赞