List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:October 24 2007 2:56am
Subject:Rev 197: Added async API test. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmerge
View as plain text  
At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmerge

------------------------------------------------------------
revno: 197
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: ndbjmerge
timestamp: Tue 2007-10-23 19:46:38 -0700
message:
  Added async API test. 
added:
  java/testsuite/ndbj/QuickAsyncTest.java
quickasynctest.java-20071024021835-88iqvmlfhmy1basb-1
modified:
  java/com/mysql/cluster/ndbj/Ndb.java ndb.java-20070517181935-98huwjarzuh25b30-2
  java/com/mysql/cluster/ndbj/examples/TestAsync.java
testasync.java-20070703002120-jsnz1ul38pp1h3w3-1
=== added file 'java/testsuite/ndbj/QuickAsyncTest.java'
--- a/java/testsuite/ndbj/QuickAsyncTest.java	1970-01-01 00:00:00 +0000
+++ b/java/testsuite/ndbj/QuickAsyncTest.java	2007-10-24 02:46:38 +0000
@@ -0,0 +1,344 @@
+package testsuite.ndbj;
+
+import java.sql.Timestamp;
+import testsuite.BaseNdbjTestCase;
+import com.mysql.cluster.ndbj.*;
+
+public class QuickAsyncTest 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       = 2;
+	static int REQUEST_TRANSACTIONS_TIMEOUT   = 1000;
+
+	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;
+
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	// INITIALISATION CODE
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+	public QuickAsyncTest(String arg0) {
+		super(arg0);
+	}
+
+	public void setUp() throws Exception {
+		super.setUp();
+
+		if (!alreadySetUp) {
+			// Create required tables
+
+			System.out.print("Creating 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);");
+
+			System.out.println("done.");
+			System.out.print("Storing column indices...");
+
+			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
+
+			System.out.println("done.");
+			System.out.print("Preloading 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();                                 //
+
+			System.out.println("done.");
+
+			alreadySetUp = true;
+		}
+	}
+
+	public void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	// TEST CODE
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	public void testSingleTx_Success() {
+		
+		try {
+			trans = ndb.startTransaction();
+
+			NdbOperation orderOp1 = trans.getNdbOperation(ORDER);
+
+			orderOp1.insertTuple();
+
+			orderOp1.equal(ORDER_PARTID, 1);
+			orderOp1.equal(ORDER_ORDERID, 1);
+
+			orderOp1.setInt(ORDER_ACCOUNTID, 1);
+			orderOp1.setInt(ORDER_REQUESTID, 1);
+			orderOp1.setInt(ORDER_INSTRUMENTID, 1);
+			orderOp1.setInt(ORDER_ISBUY, 1);
+			orderOp1.setInt(ORDER_QUANTITY, 1);
+			orderOp1.setInt(ORDER_PRICE, 1);
+
+			BaseCallback callback = new OrderCallback(ndb, orderOp1.resultData());
+
+			trans.executeAsynchPrepare(ExecType.Commit,
+			                           callback,
+			                           AbortOption.AbortOnError);
+
+System.out.print("Performing sendPollNdb...");
+
+			ndb.sendPollNdb(REQUEST_TRANSACTIONS_TIMEOUT, NUM_REQUEST_TRANSACTIONS, FORCE_SEND);
+
+System.out.println("done.");
+		}
+		catch (NdbApiException e) {
+			System.out.println("Caught NdbApiException in Insert:\t" + e.getMessage());
+			e.printStackTrace();
+			assertFalse(true);
+		}
+		finally {
+		}
+	}
+
+	public void testMultiTx_Failure() {
+		
+		try {
+			trans = ndb.startTransaction();
+
+			NdbOperation orderOp1 = trans.getNdbOperation(ORDER);
+
+			orderOp1.insertTuple();
+
+			orderOp1.equal(ORDER_PARTID, 1);
+			orderOp1.equal(ORDER_ORDERID, 1);
+
+			orderOp1.setInt(ORDER_ACCOUNTID, 1);
+			orderOp1.setInt(ORDER_REQUESTID, 1);
+			orderOp1.setInt(ORDER_INSTRUMENTID, 1);
+			orderOp1.setInt(ORDER_ISBUY, 1);
+			orderOp1.setInt(ORDER_QUANTITY, 1);
+			orderOp1.setInt(ORDER_PRICE, 1);
+
+			BaseCallback callback = new OrderCallback(ndb, orderOp1.resultData());
+
+			trans.executeAsynchPrepare(ExecType.Commit,
+			                           callback,
+			                           AbortOption.AbortOnError);
+
+			trans = ndb.startTransaction();
+			NdbOperation orderOp2 = trans.getNdbOperation(ORDER);
+
+			orderOp2.insertTuple();
+
+			orderOp2.equal(ORDER_PARTID, 2);
+			orderOp2.equal(ORDER_ORDERID, 2);
+
+			orderOp2.setInt(ORDER_ACCOUNTID, 2);
+			orderOp2.setInt(ORDER_REQUESTID, 2);
+			orderOp2.setInt(ORDER_INSTRUMENTID, 2);
+			orderOp2.setInt(ORDER_ISBUY, 2);
+			orderOp2.setInt(ORDER_QUANTITY, 2);
+			orderOp2.setInt(ORDER_PRICE, 2);
+
+			OrderCallback callback2 = new OrderCallback(ndb, orderOp2.resultData());
+
+			trans.executeAsynchPrepare(ExecType.Commit,
+			                           callback2,
+			                           AbortOption.AbortOnError);
+
+System.out.print("Performing sendPollNdb...");
+
+			ndb.sendPollNdb(REQUEST_TRANSACTIONS_TIMEOUT, NUM_REQUEST_TRANSACTIONS, FORCE_SEND);
+
+System.out.println("done.");
+		}
+		catch (NdbApiException e) {
+			System.out.println("Caught NdbApiException in Insert:\t" + e.getMessage());
+			e.printStackTrace();
+			assertFalse(true);
+		}
+		finally {
+		}
+	}
+
+	class OrderCallback extends BaseCallback {
+
+		Ndb          myNdb;
+		NdbResultSet myResults;
+
+		public OrderCallback(Ndb theNdb, NdbResultSet theResults) {
+			myNdb     = theNdb;
+			myResults = theResults;
+		}
+
+		public void callback(int result, NdbTransaction myTrans) {
+			System.out.println("Finished order");
+			assertTrue(true);
+
+			myTrans.close();
+		}
+
+	}
+
+}

=== modified file 'java/com/mysql/cluster/ndbj/Ndb.java'
--- a/java/com/mysql/cluster/ndbj/Ndb.java	2007-10-24 00:21:46 +0000
+++ b/java/com/mysql/cluster/ndbj/Ndb.java	2007-10-24 02:46:38 +0000
@@ -124,4 +124,8 @@
 	public NdbTransaction startTransaction(NdbTable table, int keyData) throws
NdbApiException;
 
 	public java.math.BigInteger getAutoIncrementValue(NdbTable myTable, long cacheSize)
throws NdbApiException;
+
+	public int sendPollNdb(int aMillisecondNumber, int minNoOfEventsToWakeup, int forceSend)
throws NdbApiException;
+
+	public int sendPollNdb(int aMillisecondNumber, int minNoOfEventsToWakeup) throws
NdbApiException;
 }
\ No newline at end of file

=== modified file 'java/com/mysql/cluster/ndbj/examples/TestAsync.java'
--- a/java/com/mysql/cluster/ndbj/examples/TestAsync.java	2007-10-24 00:21:46 +0000
+++ b/java/com/mysql/cluster/ndbj/examples/TestAsync.java	2007-10-24 02:46:38 +0000
@@ -240,7 +240,7 @@
       rs = myOper.resultData();
       TestBaseCallback cb = new TestBaseCallback(myNdb,rs);
       
-      myTrans.executeAsynchPrepare(ExecType.Commit, cb );
+      myTrans.executeAsynchPrepare(ExecType.Commit, cb, AbortOption.AbortOnError);
       cbs.add(cb);
 
 //      foo=myRecAttr.int32_value();

Thread
Rev 197: Added async API test. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmergeMonty Taylor24 Oct