/* ----------------------------------------------------------------
 *	testxact.c
 *
 *	program to test POSTGRES transaction system
 *	initialization code.
 *
 *	Identification
 *		$Header: testxact.c,v 1.2 89/02/02 16:59:53 dillon Exp $
 *
 * ----------------------------------------------------------------
 */

static char testxact_c[] = "$Header: testxact.c,v 1.2 89/02/02 16:59:53 dillon Exp $";

#include "log-access.h"
#include "time-access.h"
#include "mmgr.h"

Boolean beenHere;

char strbuf[80];

/* ----------------
 *	PrimaryTestPhase
 * ----------------
 */

void FUNCTION
   PrimaryTestPhase()
{
   int i, cnt, start, end;
   
   puts("testxact -- primary test phase");

   start = 1;
   
   do {
      Puts("number transactions  ? ");
      i = atoi(gets(strbuf));
   } while(i<1);
   end = i;
      
   for (cnt=start; cnt<end; cnt++) {

      printf("starting xact %d\n", cnt);
      StartTransactionCommand();
      printf("commiting xact %d\n", cnt);
      CommitTransactionCommand();
   }
   
   puts("\ntestxact -- END primary test phase");
}

/* ----------------
 *	TestMain
 * ----------------
 */

void FUNCTION
   TestMain()
{
   elog(DEBUG, "--> entering TestMain");
   
   if (beenHere)
      elog(FATAL, "TestMain: beenHere == true");
   else
      beenHere = (Boolean) TRUE;

   elog(DEBUG, "--> starting memory manager");
   startmmgr(M_DYNAMIC);

   PrimaryTestPhase();
    
   elog(DEBUG, "--> ending memory manager");
   endmmgr(NULL);
   
   elog(DEBUG, "--> leaving  TestMain");
}

