Beispiel #1
0
int test_lambda()
{
	const int N = 32;
	char output[N];

	STARTUP(ast, v, "(\\ {x y z} {+ x y z}) 1 2 3");
	TEST_ASSERT(lval_snprintln(v, output, N));
	TEST_ASSERT(0 == strncmp("6", output, N));
	TEARDOWN(ast, v);

	STARTUP_NO_DECLARE(ast, v, "(\\ {f & xs} {f xs}) head 1 2 3 4");
	TEST_ASSERT(lval_snprintln(v, output, N));
	TEST_ASSERT(LVAL_QEXPR == v->type);
	TEST_ASSERT(0 == strncmp("{1}", output, N));
	TEARDOWN(ast, v);

	STARTUP_NO_DECLARE(ast, v, "def {fun} (\\ {x y} { + (* 7 x) (* 2 y)})");
	TEST_ASSERT(lval_snprintln(v, output, N));
	TEST_ASSERT(0 == strncmp("()", output, N));
	TEST_ASSERT(LVAL_SEXPR == v->type);
	TEARDOWN(ast, v);

	STARTUP_NO_DECLARE(ast, v, "fun 3 8");
	TEST_ASSERT(lval_snprintln(v, output, N));
	TEST_ASSERT(LVAL_LNG == v->type);
	TEST_ASSERT(0 == strncmp("37", output, N));
	TEARDOWN(ast, v);

	return 0;
}
Beispiel #2
0
int test_qexpr_quote()
{
	const int N = 32;
	char output[N];

	STARTUP(ast, v, "eval {car (quote 1 2 3 4)}");
	TEST_ASSERT(lval_snprintln(v, output, N));
	TEST_ASSERT(0 == strncmp("{1}", output, N));
	TEST_ASSERT(LVAL_QEXPR == v->type);
	TEARDOWN(ast, v);

	STARTUP_NO_DECLARE(ast, v, "quote a b");
	TEST_ASSERT(lval_snprintln(v, output, N));
	TEST_ASSERT(0 == strncmp("{a b}", output, N));
	TEST_ASSERT(LVAL_QEXPR == v->type);
	TEARDOWN(ast, v);

	STARTUP_NO_DECLARE(ast, v, "list a b (c d)");
	TEST_ASSERT(lval_snprintln(v, output, N));
	TEST_ASSERT(0 == strncmp("{a b (c d)}", output, N));
	TEST_ASSERT(LVAL_QEXPR == v->type);
	TEARDOWN(ast, v);

	return 0;
}
Beispiel #3
0
int test_qexpr_incorrect_type()
{
	STARTUP(ast, v, "tail (+ 1 2)");
	TEST_ASSERT(LVAL_ERR == v->type);
	TEST_ASSERT(LERR_BAD_TYPE == v->err);
	TEARDOWN(ast, v);

	STARTUP(ast1, v1, "cons {1 2} 3");
	TEST_ASSERT(LVAL_ERR == v1->type);
	TEST_ASSERT(LERR_BAD_TYPE == v1->err);
	TEARDOWN(ast1, v1);
	return 0;
}
Beispiel #4
0
void
test_seq_06()
{
	int rc;
	GTM_SequenceKeyData seqkey;
	int i;

	GTM_Sequence cur;

	SETUP();

	/* create a key */
	seqkey.gsk_key    = strdup("seq1");
	seqkey.gsk_keylen = strlen(seqkey.gsk_key);
	seqkey.gsk_type   = GTM_SEQ_FULL_NAME;

	for (i=0 ; i<1000 ; i++)
	{
		cur = get_next(conn, &seqkey);
		_ASSERT( cur==i );
	}
	/* get_next() x 1000 done. */

	rc = reset_sequence(conn, &seqkey);
	_ASSERT( rc>=0 );
	
	cur = get_next(conn, &seqkey);
	_ASSERT( cur==1 );

	TEARDOWN();
}
Beispiel #5
0
void
test_node5_03()
{
	int rc;

	SETUP();

	/*
	 * active
	 */
	connect1();

	rc = node_register(conn, GTM_NODE_DATANODE,  16666, "One zero zero one", "/tmp/pgxc/data/gtm");
	_ASSERT( rc >= 0 );

	system("killall -9 gtm");
	system("./promote.sh");
	sleep(1);

	GTMPQfinish(conn);
	connect2();

	rc = node_unregister(conn, GTM_NODE_DATANODE, "One zero zero one");
	_ASSERT( rc >= 0 );

	GTMPQfinish(conn);

	TEARDOWN();
}
Beispiel #6
0
void
test_node5_02()
{
	int rc;

	SETUP();

	/*
	 * active
	 */
	connect1();

	rc = node_register(conn, GTM_NODE_DATANODE,  16666, "One zero zero one", "/tmp/pgxc/data/gtm");
	_ASSERT( rc >= 0 );

	rc = node_unregister(conn, GTM_NODE_DATANODE, "One zero zero one");
	_ASSERT( rc >= 0 );

	GTMPQfinish(conn);
	sleep(3);

	/*
	 * standby
	 */
	connect2();

	rc = node_unregister(conn, GTM_NODE_DATANODE, "One zero zero one");
	_ASSERT( rc<0 );

	GTMPQfinish(conn);

	TEARDOWN();
}
Beispiel #7
0
void
test_txn5_11()
{
	GlobalTransactionId gxid;
	int rc;
	
	SETUP();
        sleep(3);
	
	system("killall -9 gtm_standby");
	
	gxid = begin_transaction(conn, GTM_ISOLATION_SERIALIZABLE, timestamp);
        _ASSERT( gxid != InvalidGlobalTransactionId );
        _ASSERT( grep_count(LOG_ACTIVE, "Sending transaction id 3")==1 );
        _ASSERT( grep_count(LOG_ACTIVE, "Sending transaction id 3")==1 );
        _ASSERT( grep_count(LOG_ACTIVE, "gtm_standby_reconnect_to_standby(): re-connect failed. retry=0")==1 );
        _ASSERT( grep_count(LOG_ACTIVE, "gtm_standby_reconnect_to_standby(): re-connect failed. retry=1")==1 );
        _ASSERT( grep_count(LOG_ACTIVE, "gtm_standby_reconnect_to_standby(): re-connect failed. retry=2")==1 );
        _ASSERT( grep_count(LOG_ACTIVE, "communication error with standby")==1 );
        _ASSERT( grep_count(LOG_ACTIVE, "Calling report_xcwatch_gtm_failure()...")==1 );
	
	rc = commit_transaction(conn, gxid);
        _ASSERT( rc>=0 );
        _ASSERT( grep_count(LOG_ACTIVE, "Committing transaction id 3")==1 );
        _ASSERT( grep_count(LOG_STANDBY, "Committing transaction id 3")==0 );
	
	TEARDOWN();
}
Beispiel #8
0
void
test_txn5_06()
{
	GlobalTransactionId gxid;
	int rc;

	SETUP();

	gxid = begin_transaction(conn, GTM_ISOLATION_SERIALIZABLE, timestamp);
	_ASSERT( gxid != InvalidGlobalTransactionId );

	rc = prepare_transaction(conn, gxid);
	_ASSERT( rc>=0 );

	rc = abort_transaction(conn, gxid);
	_ASSERT( rc>=0 );

	system("./promote.sh");

	GTMPQfinish(conn);
	connect2();

	rc = abort_transaction(conn, gxid);
	_ASSERT( rc>=0 );

	TEARDOWN();
}
Beispiel #9
0
void
test_seq_01()
{
	int rc;
	GTM_SequenceKeyData seqkey;
	GTM_Sequence increment;
	GTM_Sequence minval;
	GTM_Sequence maxval;
	GTM_Sequence startval;
	bool cycle;

	SETUP();

	/* create a key */
	seqkey.gsk_key    = strdup("seq2");
	seqkey.gsk_keylen = strlen(seqkey.gsk_key);
	seqkey.gsk_type   = GTM_SEQ_FULL_NAME;

	increment = 1;
	minval    = 0;
	maxval    = 10000;
	startval  = 0;
	cycle     = true;

	rc = open_sequence(conn,
			   &seqkey,
			   increment,
			   minval,
			   maxval,
			   startval,
			   cycle);
	_ASSERT( rc>=0 );

	TEARDOWN();
}
Beispiel #10
0
void
test_seq_04()
{
	int rc;
	GTM_SequenceKeyData seqkey;
	GTM_Sequence increment;
	GTM_Sequence minval;
	GTM_Sequence maxval;
	GTM_Sequence startval;
	bool cycle;

	GTM_Sequence cur;

	SETUP();

	/* create a key */
	seqkey.gsk_key    = strdup("seq1");
	seqkey.gsk_keylen = strlen(seqkey.gsk_key);
	seqkey.gsk_type   = GTM_SEQ_FULL_NAME;

	cur = get_next(conn, &seqkey);
	_ASSERT( cur==0 );

	cur = get_next(conn, &seqkey);
	_ASSERT( cur==1 );

	cur = get_next(conn, &seqkey);
	_ASSERT( cur==2 );

	TEARDOWN();
}
Beispiel #11
0
int test_div_zero_dbl()
{
	STARTUP(ast, v, "(/ 1 0.0000000000000001)");
	TEST_ASSERT(LVAL_ERR == v->type);
	TEST_ASSERT(LERR_DIV_ZERO == v->err);
	TEARDOWN(ast, v);
	return 0;
}
Beispiel #12
0
int test_bad_sexpr_start()
{
	STARTUP(ast, v, "( 1 () )");
	TEST_ASSERT(LVAL_ERR == v->type);
	TEST_ASSERT(LERR_BAD_SEXPR_START == v->err);
	TEARDOWN(ast, v);
	return 0;
}
Beispiel #13
0
int test_non_number()
{
	STARTUP(ast, v, "( / ( ) )");
	TEST_ASSERT(LVAL_ERR == v->type);
	TEST_ASSERT(LERR_BAD_NUM == v->err);
	TEARDOWN(ast, v);
	return 0;
}
Beispiel #14
0
int test_eval_maxmin_dbl()
{
	STARTUP(ast, v, "max 1 2 3.3 4.4 (min 5.5 6 7 8)");
	TEST_ASSERT(LVAL_DBL == v->type);
	TEST_ASSERT(5.5 == v->data.dbl);
	TEARDOWN(ast, v);
	return 0;
}
Beispiel #15
0
int test_eval_maxmin()
{
	STARTUP(ast, v, "max 1 2 3 4 (min 5 6 7 8)");
	TEST_ASSERT(LVAL_LNG == v->type);
	TEST_ASSERT(5 == v->data.lng);
	TEARDOWN(ast, v);
	return 0;
}
Beispiel #16
0
int test_eval_pow_dbl()
{
	STARTUP(ast, v, "^ 2 .5");
	TEST_ASSERT(LVAL_DBL == v->type);
	TEST_ASSERT(sqrt(2.0) == v->data.dbl);
	TEARDOWN(ast, v);
	return 0;
}
Beispiel #17
0
int test_eval_pow()
{
	STARTUP(ast, v, "^ 2 2 2 2 2");
	TEST_ASSERT(LVAL_LNG == v->type);
	TEST_ASSERT(65536 == v->data.lng);
	TEARDOWN(ast, v);
	return 0;
}
Beispiel #18
0
int test_eval_arithmetic_dbl()
{
	STARTUP(ast, v, "+ 1.5 1.5 (- 20. 23) (* 3. 7) (/ 9 (/ 6.0 2))");
	TEST_ASSERT(LVAL_DBL == v->type);
	TEST_ASSERT(24. == v->data.dbl);
	TEARDOWN(ast, v);
	return 0;
}
Beispiel #19
0
int test_unknown_symbol()
{
	STARTUP(ast, v, "asdf 1 2 3");
	TEST_ASSERT(LVAL_ERR == v->type);
	TEST_ASSERT(LERR_BAD_SYMBOL == v->err);
	TEARDOWN(ast, v);
	return 0;
}
Beispiel #20
0
int test_qexpr_bad_args_count()
{
	STARTUP(ast, v, "cons (quote 1 2)");
	TEST_ASSERT(LVAL_ERR == v->type);
	TEST_ASSERT(LERR_BAD_ARGS_COUNT == v->err);
	TEARDOWN(ast, v);
	return 0;
}
Beispiel #21
0
int test_eval_arithmetic()
{
	STARTUP(ast, v, "+ 1 2 (- 20 23) (* 3 7) (/ 9 (/ 14 2))");
	TEST_ASSERT(LVAL_LNG == v->type);
	TEST_ASSERT(22 == v->data.lng);
	TEARDOWN(ast, v);
	return 0;
}
Beispiel #22
0
int test_qexpr_empty()
{
	STARTUP(ast, v, "cdr {}");
	TEST_ASSERT(LVAL_ERR == v->type);
	TEST_ASSERT(LERR_EMPTY == v->err);
	TEARDOWN(ast, v);
	return 0;
}
Beispiel #23
0
int test_put()
{
	const int N = 32;
	char output[N];

	STARTUP(ast, v, "= {x} 100");
	TEST_ASSERT(lval_snprintln(v, output, N));
	TEST_ASSERT(0 == strncmp("()", output, N));
	TEST_ASSERT(LVAL_SEXPR == v->type); // TODO better to return nothing
	TEARDOWN(ast, v);

	STARTUP_NO_DECLARE(ast, v, "x");
	TEST_ASSERT(LVAL_LNG == v->type);
	TEST_ASSERT(100 == v->data.lng);
	TEARDOWN(ast, v);

	return 0;
}
Beispiel #24
0
int test_qexpr_len()
{
	STARTUP(ast, v, "len {1 2 3.3 a b c}");
	TEST_ASSERT(LVAL_LNG == v->type);
	TEST_ASSERT(6 == v->data.lng);
	TEARDOWN(ast, v);

	return 0;
}
Beispiel #25
0
void
test_seq_09()
{
	GlobalTransactionId next_gxid;
	GTM_SequenceKeyData key1;
	GTM_SequenceKeyData key2;
	GTM_SequenceKeyData key3;
	int rc, i;
	GTM_SeqInfo *seq_list[1024];

	SETUP();

	key1.gsk_keylen = strlen("seq1");
	key1.gsk_key    = strdup("seq1");
	key1.gsk_type   = GTM_SEQ_FULL_NAME;

	key2.gsk_keylen = strlen("seq2");
	key2.gsk_key    = strdup("seq2");
	key3.gsk_type   = GTM_SEQ_FULL_NAME;
	key3.gsk_keylen = strlen("seq3");
	key3.gsk_key    = strdup("seq3");
	key3.gsk_type   = GTM_SEQ_FULL_NAME;

	/* name, increment, min, max, start, cycle */
	rc = open_sequence(conn, &key2, 1, 1, 10000, 5, true);
	_ASSERT( rc==0 );
	rc = open_sequence(conn, &key3, 1, 1, 10000, 7, true);
	_ASSERT( rc==0 );

	memset(seq_list, 0, sizeof(GTM_SeqInfo *) * 1024);

	rc = get_sequence_list(conn, seq_list, 1024);
	_ASSERT( rc==3 );

	_ASSERT( strncmp(seq_list[0]->gs_key->gsk_key, key1.gsk_key, 4)==0 );
	_ASSERT( strncmp(seq_list[1]->gs_key->gsk_key, key2.gsk_key, 4)==0 );
	_ASSERT( strncmp(seq_list[2]->gs_key->gsk_key, key3.gsk_key, 4)==0 );

	{
	  GTM_Sequence cur;

	  cur = get_next(conn, seq_list[0]->gs_key);
	  fprintf(stderr, "key=%s, cur=%d\n", seq_list[0]->gs_key->gsk_key, cur);
	  _ASSERT( cur==0 );

	  cur = get_next(conn, seq_list[1]->gs_key);
	  fprintf(stderr, "key=%s, cur=%d\n", seq_list[1]->gs_key->gsk_key, cur);
	  _ASSERT( cur==5 );

	  cur = get_next(conn, seq_list[2]->gs_key);
	  fprintf(stderr, "key=%s, cur=%d\n", seq_list[2]->gs_key->gsk_key, cur);
	  _ASSERT( cur==7 );
	}

	TEARDOWN();
}
Beispiel #26
0
int test_qexpr_too_many_args()
{
	STARTUP(ast, v, "tail {1 2} {3}");
	TEST_ASSERT(LVAL_ERR == v->type);
	TEST_ASSERT(LERR_TOO_MANY_ARGS == v->err);
	TEARDOWN(ast, v);

	STARTUP(ast1, v1, "head {1 2} {3}");
	TEST_ASSERT(LVAL_ERR == v1->type);
	TEST_ASSERT(LERR_TOO_MANY_ARGS == v1->err);
	TEARDOWN(ast1, v1);

	STARTUP(ast2, v2, "init {1 2} {3}");
	TEST_ASSERT(LVAL_ERR == v2->type);
	TEST_ASSERT(LERR_TOO_MANY_ARGS == v2->err);
	TEARDOWN(ast2, v2);

	return 0;
}
Beispiel #27
0
int test_qexpr_cons()
{
	const int N = 32;
	char output[N];

	STARTUP(ast, v, "cons {a} {1 2 3}");
	TEST_ASSERT(lval_snprintln(v, output, N));
	TEST_ASSERT(0 == strncmp("{a 1 2 3}", output, N)); // should it be {{a} 2 3 4}?
	TEST_ASSERT(LVAL_QEXPR == v->type);
	TEARDOWN(ast, v);

	STARTUP(ast1, v1, "cons {a b} {1 2 3}");
	TEST_ASSERT(lval_snprintln(v1, output, N));
	TEST_ASSERT(0 == strncmp("{{a b} 1 2 3}", output, N));
	TEST_ASSERT(LVAL_QEXPR == v1->type);
	TEARDOWN(ast1, v1);

	return 0;
}
Beispiel #28
0
void
test_seq_08()
{
	int rc;
	GTM_SequenceKeyData seqkey;
	GTM_SequenceKeyData newseqkey;
	int i;

	GTM_Sequence cur;

	SETUP();

	/* create a key */
	seqkey.gsk_key    = strdup("seq1");
	seqkey.gsk_keylen = strlen(seqkey.gsk_key);
	seqkey.gsk_type   = GTM_SEQ_FULL_NAME;

	cur = get_next(conn, &seqkey);
	_ASSERT( cur==0 );
	
	{
		GTM_Sequence increment;
		GTM_Sequence minval;
		GTM_Sequence maxval;
		GTM_Sequence startval;
		bool cycle;

		increment = 1;
		minval    = 100;
		maxval    = 10000;
		startval  = 100;
		cycle     = true;

		rc = alter_sequence(conn,
				    &seqkey,
				    increment,
				    minval,
				    maxval,
				    startval,
				    256, /* lastval */
				    cycle,
				    true);

		_ASSERT( rc>=0 );
	}

	cur = get_current(conn, &seqkey);
	_ASSERT( cur==100 );
	
	cur = get_next(conn, &seqkey);
	_ASSERT( cur==101 );
	
	TEARDOWN();
}
Beispiel #29
0
int test_qexpr_basic()
{
	const int N = 32;
	char output[N];

	STARTUP(ast, v, "{ {a}  b }");
	TEST_ASSERT(lval_snprintln(v, output, N));
	TEST_ASSERT(0 == strncmp("{{a} b}", output, N));
	TEARDOWN(ast, v);

	return 0;
}
Beispiel #30
0
int test_qexpr_init()
{
	const int N = 32;
	char output[N];

	STARTUP(ast, v, "init {1 2 z}");
	TEST_ASSERT(lval_snprintln(v, output, N));
	TEST_ASSERT(0 == strncmp("{1 2}", output, N));
	TEST_ASSERT(LVAL_QEXPR == v->type);
	TEARDOWN(ast, v);

	return 0;
}