List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:November 1 2007 2:37pm
Subject:Rev 207: Merged changes from devel. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/telco-6.3
View as plain text  
At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/telco-6.3

------------------------------------------------------------
revno: 207
revision-id: mtaylor@stripped
parent: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: telco-6.3
timestamp: Thu 2007-11-01 14:37:01 +0000
message:
  Merged changes from devel.
added:
  java/testsuite/ndbj/QuickBFTest.java quickbftest.java-20071101143506-knxv9uo02grm6jx8-1
    ------------------------------------------------------------
    revno: 192.1.25.1.12
    revision-id: mtaylor@stripped
    parent: mtaylor@stripped
    committer: Monty Taylor <mtaylor@stripped>
    branch nick: ndbjmerge
    timestamp: Thu 2007-11-01 14:35:09 +0000
    message:
      Checked in a test program. 
    added:
      java/testsuite/ndbj/QuickBFTest.java
quickbftest.java-20071101143506-knxv9uo02grm6jx8-1
=== added file 'java/testsuite/ndbj/QuickBFTest.java'
--- a/java/testsuite/ndbj/QuickBFTest.java	1970-01-01 00:00:00 +0000
+++ b/java/testsuite/ndbj/QuickBFTest.java	2007-11-01 14:35:09 +0000
@@ -0,0 +1,487 @@
+package testsuite.ndbj;
+
+import java.util.*;
+import testsuite.BaseNdbjTestCase;
+import com.mysql.cluster.ndbj.*;
+
+public class QuickBFTest extends BaseNdbjTestCase {
+
+	static boolean alreadySetUp = false;
+
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	// GENERAL STUFF
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	static int MAXIMUM_OPERATION_VOLUME       = 300; // TO DO: Calculate this
+
+	static int NUMBER_OF_ELEMENT_INSERTIONS   = 25;
+
+	static int NUM_REQUEST_TRANSACTIONS       = 5;
+	static int NUM_RESPONSE_TRANSACTIONS      = 5;
+	static int NUM_WRITE_POS_TRANSACTIONS     = 5;
+
+	static int REQUEST_TRANSACTIONS_TIMEOUT   = 1;
+	static int RESPONSE_TRANSACTIONS_TIMEOUT  = 1;
+	static int WRITE_POS_TRANSACTIONS_TIMEOUT = 1; 
+
+	static int FORCE_SEND                     = 1;
+
+	static boolean USE_SYNCHRONOUS            = false;
+
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	// TABLE METADATA
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	static String ORDER      = "accountspike_order";
+	static String EXECUTION  = "accountspike_execution";
+	static String TRADE      = "accountspike_trade";
+	static String SETTLEMENT = "accountspike_settlement";
+	static String POSITION   = "accountspike_position";
+
+	static int ORDER_PARTID;
+	static int ORDER_ORDERID;
+	static int ORDER_ACCOUNTID;
+	static int ORDER_REQUESTID;
+	static int ORDER_INSTRUMENTID;
+	static int ORDER_ISBUY;
+	static int ORDER_QUANTITY;
+	static int ORDER_PRICE;
+
+	static int EXECUTION_PARTID;
+	static int EXECUTION_EXECUTIONID;
+	static int EXECUTION_ACCOUNTID;
+	static int EXECUTION_ORDERID;
+
+	static int TRADE_PARTID;
+	static int TRADE_TRADEID;
+	static int TRADE_ACCOUNTID;
+	static int TRADE_ORDERID;
+	static int TRADE_PRICE;
+	static int TRADE_QUANTITY;
+			
+	static int SETTLEMENT_PARTID;
+	static int SETTLEMENT_SETTLEMENTID;
+	static int SETTLEMENT_ACCOUNTID;
+	static int SETTLEMENT_TRADEID1;
+	static int SETTLEMENT_TRADEID2;
+	static int SETTLEMENT_QUANTITY;
+	static int SETTLEMENT_VALUE;
+
+	static int POSITION_PARTID;
+	static int POSITION_ACCOUNTID;
+	static int POSITION_INSTRUMENTID;
+	static int POSITION_UMBUY_QUANTITY;
+	static int POSITION_UMSELL_QUANTITY;
+	static int POSITION_MATCHED_QUANTITY;
+	static int POSITION_UMBUY_PRODUCT;
+	static int POSITION_UMSELL_PRODUCT;
+	static int POSITION_MATCHED_PRODUCT;
+
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	// OTHER
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	static int myTransactionCount      = 0;
+	static int myTotalTransactionCount = 0;
+
+	ArrayList<NdbTransaction> myCompletedTransactionList = new
ArrayList<NdbTransaction>();
+	ArrayList<NdbTransaction> myTransactionList = new
ArrayList<NdbTransaction>();
+
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	// INITIALISATION CODE
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	public static void main(String[] args) {
+		junit.textui.TestRunner.run(QuickBFTest.class);
+	}
+
+	public QuickBFTest(String arg0) {
+		super(arg0);
+	}
+
+	public void setUp() throws Exception {
+		super.setUp();
+
+		if (!alreadySetUp) {
+			// Create required tables
+
+			createTable(ORDER, "("                                       +
+					"`partid`       SMALLINT UNSIGNED NOT NULL," +
+					"`orderid`      INT      UNSIGNED NOT NULL," +
+					"`accountid`    INT      UNSIGNED NOT NULL," +
+					"`requestid`    INT      UNSIGNED NOT NULL," +
+					"`instrumentid` INT      UNSIGNED NOT NULL," +
+					"`isbuy`        SMALLINT          NOT NULL," +
+					"`quantity`     INT      UNSIGNED NOT NULL," +
+					"`price`        INT               NOT NULL," +
+					"PRIMARY KEY(partid, orderid)"               +
+					") ENGINE=ndb PARTITION BY KEY (partid);");
+
+			createTable("accountspike_execution", "("                   +
+					"`partid`      SMALLINT UNSIGNED NOT NULL," +
+					"`executionid` INT      UNSIGNED NOT NULL," +
+					"`accountid`   INT      UNSIGNED NOT NULL," +
+					"`orderid`     INT      UNSIGNED NOT NULL," +
+					"PRIMARY KEY(partid, executionid)"          +
+					") ENGINE=ndb PARTITION BY KEY (partid);");
+
+			createTable("accountspike_trade", "("                     +
+					"`partid`    SMALLINT UNSIGNED NOT NULL," +
+					"`tradeid`   INT      UNSIGNED NOT NULL," +
+					"`accountid` INT      UNSIGNED NOT NULL," +
+					"`orderid`   INT      UNSIGNED NOT NULL," +
+					"`price`     INT      UNSIGNED NOT NULL," +
+					"`quantity`  INT               NOT NULL," +
+					"PRIMARY KEY(partid, tradeid)"            +
+					") ENGINE=ndb PARTITION BY KEY (partid);");
+
+			createTable("accountspike_settlement", "("                   +
+					"`partid`       SMALLINT UNSIGNED NOT NULL," +
+					"`settlementid` INT      UNSIGNED NOT NULL," +
+					"`accountid`    INT      UNSIGNED NOT NULL," +
+					"`tradeid1`     INT      UNSIGNED NOT NULL," +
+					"`tradeid2`     INT      UNSIGNED NOT NULL," +
+					"`quantity`     INT               NOT NULL," +
+					"`value`        INT               NOT NULL," +
+					"PRIMARY KEY(partid, settlementid)"          +
+					") ENGINE=ndb PARTITION BY KEY (partid);");
+
+			createTable("accountspike_position", "("                         +
+					"`partid`           SMALLINT UNSIGNED NOT NULL," +
+					"`accountid`        INT      UNSIGNED NOT NULL," +
+					"`instrumentid`     INT      UNSIGNED NOT NULL," +
+					"`umbuy_quantity`   INT               NOT NULL," +
+					"`umsell_quantity`  INT               NOT NULL," +
+					"`matched_quantity` INT               NOT NULL," +
+					"`umbuy_product`    INT               NOT NULL," +
+					"`umsell_product`   INT               NOT NULL," +
+					"`matched_product`  INT               NOT NULL," +
+					"PRIMARY KEY(partid, accountid, instrumentid)"   +
+					") ENGINE=ndb PARTITION BY KEY (partid);");
+
+			NdbDictionary dictionary = ndb.getDictionary();
+
+			NdbTable  orderTable = dictionary.getTable(ORDER);
+			ORDER_PARTID         = orderTable.getColumn("partid").getColumnNo();
+			ORDER_ORDERID        = orderTable.getColumn("orderid").getColumnNo();
+			ORDER_ACCOUNTID      = orderTable.getColumn("accountid").getColumnNo();
+			ORDER_REQUESTID      = orderTable.getColumn("requestid").getColumnNo();
+			ORDER_INSTRUMENTID   = orderTable.getColumn("instrumentid").getColumnNo();
+			ORDER_ISBUY          = orderTable.getColumn("isbuy").getColumnNo();
+			ORDER_QUANTITY       = orderTable.getColumn("quantity").getColumnNo();
+			ORDER_PRICE          = orderTable.getColumn("price").getColumnNo();
+
+			NdbTable  execTable   = dictionary.getTable(EXECUTION);
+			EXECUTION_PARTID      = execTable.getColumn("partid").getColumnNo();
+			EXECUTION_EXECUTIONID = execTable.getColumn("executionid").getColumnNo();
+			EXECUTION_ACCOUNTID   = execTable.getColumn("accountid").getColumnNo();
+			EXECUTION_ORDERID     = execTable.getColumn("orderid").getColumnNo();
+
+			NdbTable  tradeTable = dictionary.getTable(TRADE);
+			TRADE_PARTID         = tradeTable.getColumn("partid").getColumnNo();
+			TRADE_TRADEID        = tradeTable.getColumn("tradeid").getColumnNo();
+			TRADE_ACCOUNTID      = tradeTable.getColumn("accountid").getColumnNo();
+			TRADE_ORDERID        = tradeTable.getColumn("orderid").getColumnNo();
+			TRADE_PRICE          = tradeTable.getColumn("price").getColumnNo();
+			TRADE_QUANTITY       = tradeTable.getColumn("quantity").getColumnNo();
+			
+			NdbTable  settTable = dictionary.getTable(SETTLEMENT);
+			SETTLEMENT_PARTID       = settTable.getColumn("partid").getColumnNo();
+			SETTLEMENT_SETTLEMENTID = settTable.getColumn("settlementid").getColumnNo();
+			SETTLEMENT_ACCOUNTID    = settTable.getColumn("accountid").getColumnNo();
+			SETTLEMENT_TRADEID1     = settTable.getColumn("tradeid1").getColumnNo();
+			SETTLEMENT_TRADEID2     = settTable.getColumn("tradeid2").getColumnNo();
+			SETTLEMENT_QUANTITY     = settTable.getColumn("quantity").getColumnNo();
+			SETTLEMENT_VALUE        = settTable.getColumn("value").getColumnNo();
+
+			NdbTable  positTable      = dictionary.getTable(POSITION);
+			POSITION_PARTID           = positTable.getColumn("partid").getColumnNo();
+			POSITION_ACCOUNTID        = positTable.getColumn("accountid").getColumnNo();
+			POSITION_INSTRUMENTID     = positTable.getColumn("instrumentid").getColumnNo();
+			POSITION_UMBUY_QUANTITY   = positTable.getColumn("umbuy_quantity").getColumnNo();
+			POSITION_UMSELL_QUANTITY  = positTable.getColumn("umsell_quantity").getColumnNo();
+			POSITION_MATCHED_QUANTITY = positTable.getColumn("matched_quantity").getColumnNo();
+			POSITION_UMBUY_PRODUCT    = positTable.getColumn("umbuy_product").getColumnNo();
+			POSITION_UMSELL_PRODUCT   = positTable.getColumn("umsell_product").getColumnNo();
+			POSITION_MATCHED_PRODUCT  = positTable.getColumn("matched_product").getColumnNo();
+
+			// Preload an appropriate volume of operations
+
+			trans = ndb.startTransaction();                // TO DO: Need to do this for each data
node 
+			                                               //
+			for (long preloadVolume = 0;                   //
+			     preloadVolume < MAXIMUM_OPERATION_VOLUME; //
+			     preloadVolume++ ) {                       //
+				trans.getNdbOperation(ORDER);          //
+			}                                              //
+			                                               //
+			trans.close();                                 //
+
+			alreadySetUp = true;
+		}
+	}
+
+	public void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	// TEST CODE
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	public void testOperation() {
+		
+		try {
+			for (int loop = 0;
+                             loop < 100;
+			     loop++) {
+			// Process request transaction
+
+			NdbOperation orderOp;
+			BaseCallback callback;
+
+			for (int elementCount = 1;
+			     elementCount < NUMBER_OF_ELEMENT_INSERTIONS + 1;
+			     elementCount++) {
+				int id = (NUMBER_OF_ELEMENT_INSERTIONS * loop) + elementCount;
+
+				trans = ndb.startTransaction();
+				myTransactionList.add(trans);
+
+				orderOp = trans.getNdbOperation(ORDER);
+
+				orderOp.insertTuple();
+
+				orderOp.equal(ORDER_PARTID, id);
+				orderOp.equal(ORDER_ORDERID, id);
+
+				orderOp.setInt(ORDER_ACCOUNTID, id);
+				orderOp.setInt(ORDER_REQUESTID, id);
+				orderOp.setInt(ORDER_INSTRUMENTID, id);
+				orderOp.setInt(ORDER_ISBUY, id);
+				orderOp.setInt(ORDER_QUANTITY, id);
+				orderOp.setInt(ORDER_PRICE, id);
+
+				if (!USE_SYNCHRONOUS) {
+					callback = new OrderCallback(id, ndb, orderOp.resultData());
+
+					trans.executeAsynchPrepare(ExecType.Commit,
+        		                                           callback,
+					                           AbortOption.AbortOnError);
+				}
+			} 
+
+			if (USE_SYNCHRONOUS) {
+				trans.execute(ExecType.Commit, AbortOption.AbortOnError, true);
+			}
+			else {
+				System.out.println("Performing first sendPollNdb. ");
+				sendPollNdb(REQUEST_TRANSACTIONS_TIMEOUT, NUM_REQUEST_TRANSACTIONS, FORCE_SEND);
+				System.out.println("Completed first sendPollNdb.");
+
+				clearTransactions();
+			}
+
+			// Process response transaction
+
+			trans = ndb.startTransaction();
+
+			NdbOperation executionOp;
+			NdbOperation tradeOp;
+			NdbOperation settlementOp;
+
+			for (int elementCount = 1;
+			     elementCount < NUMBER_OF_ELEMENT_INSERTIONS + 1;
+			     elementCount++) {
+				int id = (NUMBER_OF_ELEMENT_INSERTIONS * loop) + elementCount;
+				
+				trans = ndb.startTransaction();
+myTransactionList.add(trans);
+
+				executionOp = trans.getNdbOperation(EXECUTION);
+
+				executionOp.insertTuple();
+
+				executionOp.equal(EXECUTION_PARTID, id);
+				executionOp.equal(EXECUTION_EXECUTIONID, id);
+
+				executionOp.setInt(EXECUTION_ACCOUNTID, id);
+				executionOp.setInt(EXECUTION_ORDERID, id);
+
+				if (!USE_SYNCHRONOUS) {
+					callback = new ExecutionCallback(id, ndb, executionOp.resultData());
+
+					trans.executeAsynchPrepare(ExecType.Commit,
+        		                                           callback,
+					                           AbortOption.AbortOnError);
+				}
+				
+				trans = ndb.startTransaction();
+myTransactionList.add(trans);
+
+				tradeOp = trans.getNdbOperation(TRADE);
+
+				tradeOp.insertTuple();
+
+				tradeOp.equal(TRADE_PARTID, id);
+				tradeOp.equal(TRADE_TRADEID, id);
+
+				tradeOp.setInt(TRADE_ACCOUNTID, id);
+				tradeOp.setInt(TRADE_ORDERID, id);
+				tradeOp.setInt(TRADE_PRICE, id);
+				tradeOp.setInt(TRADE_QUANTITY, id);
+
+				if (!USE_SYNCHRONOUS) {
+					callback = new TradeCallback(id, ndb, executionOp.resultData());
+
+					trans.executeAsynchPrepare(ExecType.Commit,
+        		                                           callback,
+					                           AbortOption.AbortOnError);
+				}
+
+				trans = ndb.startTransaction();
+myTransactionList.add(trans);
+
+				settlementOp = trans.getNdbOperation(SETTLEMENT);
+
+				settlementOp.insertTuple();
+
+				settlementOp.equal(SETTLEMENT_PARTID, id);
+				settlementOp.equal(SETTLEMENT_SETTLEMENTID, id);
+
+				settlementOp.setInt(SETTLEMENT_ACCOUNTID, id);
+				settlementOp.setInt(SETTLEMENT_TRADEID1, id);
+				settlementOp.setInt(SETTLEMENT_TRADEID2, id);
+				settlementOp.setInt(SETTLEMENT_QUANTITY, id);
+				settlementOp.setInt(SETTLEMENT_VALUE, id);
+
+				if (!USE_SYNCHRONOUS) {
+					callback = new SettlementCallback(id, ndb, executionOp.resultData());
+
+					trans.executeAsynchPrepare(ExecType.Commit,
+        		                                           callback,
+					                           AbortOption.AbortOnError);
+				}
+			}
+
+			if (USE_SYNCHRONOUS) {
+				trans.execute(ExecType.Commit, AbortOption.AbortOnError, true);
+			}
+			else {
+				System.out.println("Performing second sendPollNdb. ");
+				sendPollNdb(REQUEST_TRANSACTIONS_TIMEOUT, NUM_REQUEST_TRANSACTIONS, FORCE_SEND);	
+				System.out.println("Completed second sendPollNdb.");
+
+				clearTransactions();
+			}
+			}
+			System.out.println("Performing cooldown");
+
+			sendPollNdb(100000, 100000, FORCE_SEND);	
+
+			System.out.println("Test completed.");
+
+		}
+		catch (NdbApiException e) {
+			System.out.println("Caught NdbApiException in Insert:\t" + e.getMessage());
+			e.printStackTrace();
+			assertFalse(true);
+		}
+		finally {
+		}
+	}
+
+	private int sendPollNdb(int aMillisecondNumber, int minNoOfEventsToWakeup, int
forceSend) throws NdbApiException {
+		return ((Ndb) ndb).sendPollNdb(aMillisecondNumber, minNoOfEventsToWakeup, forceSend);
+	}
+
+	private void clearTransactions() {
+		System.out.print("Clearing complete transactions");
+
+		Iterator tranIter = myCompletedTransactionList.iterator();
+
+		while (tranIter.hasNext()) {
+			System.out.print(".");
+			NdbTransaction completeTransaction = (NdbTransaction) tranIter.next();
+			completeTransaction.close();
+		}
+
+		myCompletedTransactionList.clear();
+
+		System.out.println(" done.");
+	}
+
+	class CountingCallback extends BaseCallback {
+
+		int          myCallbackNum;
+		Ndb          myNdb;
+		NdbResultSet myResults;
+
+		public CountingCallback(int theCallbackNum, Ndb theNdb, NdbResultSet theResults) {
+			myTransactionCount++;
+			myTotalTransactionCount++;
+
+			myCallbackNum = theCallbackNum;
+			myNdb         = theNdb;
+			myResults     = theResults;
+			
+			System.out.println("Creating " + this.getClass().getName() + " " + myCallbackNum +
+			                       ": Current transaction volume " + myTransactionCount +
+			                       " (" + myTotalTransactionCount + ")");
+		}
+
+		public void callback(int result, NdbTransaction myTrans) {
+			myTransactionCount--;
+			System.out.println("Finished " + this.getClass().getName() + " " + myCallbackNum +
+			                       ": Current transaction volume " + myTransactionCount +
+			                       " (" + myTotalTransactionCount + ")");
+			
+			// myTrans.close();
+			myCompletedTransactionList.add(myTrans);
+		}
+
+		public void callback(int res, NdbTransactionImpl trans)  { // TEMPORARY REPLACEMENT FOR
ABOVE
+			myTransactionCount--;
+			System.out.println("Finished " + this.getClass().getName() + " " + myCallbackNum +
+			                       ": Current transaction volume " + myTransactionCount +
+			                       " (" + myTotalTransactionCount + ")");
+
+			// trans.close();
+			myCompletedTransactionList.add(trans);
+		}
+
+	}
+
+	class OrderCallback extends CountingCallback {
+
+		public OrderCallback(int theCallbackNum, Ndb theNdb, NdbResultSet theResults) {
+			super(theCallbackNum, theNdb, theResults);
+		}
+
+	}
+
+	class ExecutionCallback extends CountingCallback {
+
+		public ExecutionCallback(int theCallbackNum, Ndb theNdb, NdbResultSet theResults) {
+			super(theCallbackNum, theNdb, theResults);
+		}
+
+	}
+
+	class TradeCallback extends CountingCallback {
+
+		public TradeCallback(int theCallbackNum, Ndb theNdb, NdbResultSet theResults) {
+			super(theCallbackNum, theNdb, theResults);
+		}
+
+	}
+
+	class SettlementCallback extends CountingCallback {
+	
+		public SettlementCallback(int theCallbackNum, Ndb theNdb, NdbResultSet theResults) {
+			super(theCallbackNum, theNdb, theResults);
+		}
+
+	}
+
+}

Thread
Rev 207: Merged changes from devel. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/telco-6.3Monty Taylor1 Nov