List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:October 25 2007 12:11am
Subject:Rev 202: Added multiple table/multiple loop async 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: 202
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: ndbjmerge
timestamp: Wed 2007-10-24 17:10:47 -0700
message:
  Added multiple table/multiple loop async test. 
  Made a general TestCallback class. 
  Added a note about ANT_HOME to the (outofdate) README file.
added:
  java/testsuite/TestCallback.java testcallback.java-20071025000621-gt2wugdvy68mjae6-1
  java/testsuite/ndbj/MultipleAsyncTest.java
multipleasynctest.ja-20071025000638-1e8odqpjivvkiwt4-1
modified:
  README                         readme-20070228020914-u2pk759xg7thauwf-7
  java/com/mysql/cluster/mgmj/MgmApiException.java
mgmapiexception.java-20070914094439-b3vmm9orpa86yan5-1
  java/com/mysql/cluster/ndbj/Ndb.java ndb.java-20070517181935-98huwjarzuh25b30-2
  java/com/mysql/cluster/ndbj/examples/CRUDandScan.java
crudandscan.java-20070517181935-98huwjarzuh25b30-32
  java/testsuite/ndbj/QuickAsyncTest.java
quickasynctest.java-20071024021835-88iqvmlfhmy1basb-1
=== added file 'java/testsuite/TestCallback.java'
--- a/java/testsuite/TestCallback.java	1970-01-01 00:00:00 +0000
+++ b/java/testsuite/TestCallback.java	2007-10-25 00:10:47 +0000
@@ -0,0 +1,42 @@
+package testsuite;
+
+import com.mysql.cluster.ndbj.BaseCallback;
+import com.mysql.cluster.ndbj.Ndb;
+import com.mysql.cluster.ndbj.NdbResultSet;
+import com.mysql.cluster.ndbj.NdbTransaction;
+import com.mysql.cluster.ndbj.NdbTransactionImpl;
+
+public class TestCallback extends BaseCallback {
+
+		int          myCallbackNum;
+		Ndb          myNdb;
+		NdbResultSet myResults;
+		String		 myTablename = "";
+
+		public TestCallback(String tablename, int theCallbackNum, Ndb theNdb, NdbResultSet
theResults) {
+			myCallbackNum = theCallbackNum;
+			myNdb         = theNdb;
+			myResults     = theResults;
+			myTablename	  = tablename;
+		}
+
+		public TestCallback(int theCallbackNum, Ndb theNdb, NdbResultSet theResults) {
+			myCallbackNum = theCallbackNum;
+			myNdb         = theNdb;
+			myResults     = theResults;
+		}
+		
+		public void callback(int result, NdbTransaction myTrans) {
+			System.out.println("Finished " + myTablename + " " + myCallbackNum);
+			junit.framework.Assert.assertTrue(true);
+			myTrans.close();
+		}
+
+		public void callback(int res, NdbTransactionImpl trans)  { // TEMPORARY REPLACEMENT FOR
ABOVE
+			System.out.println("Finished " + myTablename + " " + myCallbackNum);
+			junit.framework.Assert.assertTrue(true);
+			
+			trans.close();
+		}
+
+	}

=== added file 'java/testsuite/ndbj/MultipleAsyncTest.java'
--- a/java/testsuite/ndbj/MultipleAsyncTest.java	1970-01-01 00:00:00 +0000
+++ b/java/testsuite/ndbj/MultipleAsyncTest.java	2007-10-25 00:10:47 +0000
@@ -0,0 +1,192 @@
+package testsuite.ndbj;
+
+import testsuite.BaseNdbjTestCase;
+import testsuite.TestCallback;
+import com.mysql.cluster.ndbj.*;
+
+public class MultipleAsyncTest 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 tablename1      = "t_multi_async1";
+	static String tablename2      = "t_multi_async2";
+	static String tablename3      = "t_multi_async3";
+
+
+
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	// INITIALISATION CODE
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+	public MultipleAsyncTest(String arg0) {
+		super(arg0);
+	}
+
+	public void setUp() throws Exception {
+		super.setUp();
+
+		if (!alreadySetUp) {
+			// Create required tables
+
+			System.out.print("Creating tables...");
+
+			this.createTable(tablename1, 
+				"    (ATTR1 INT UNSIGNED auto_increment not null," +
+				"     ATTR2 INT UNSIGNED NOT NULL," +
+				"     PRIMARY KEY (ATTR1) )" + 
+				"  ENGINE=NDBCLUSTER");
+			this.createTable(tablename2, 
+					"    (ATTR1 INT UNSIGNED auto_increment not null," +
+					"     ATTR2 INT UNSIGNED NOT NULL," +
+					"     PRIMARY KEY (ATTR1) )" + 
+					"  ENGINE=NDBCLUSTER");			
+			this.createTable(tablename3, 
+							"    (ATTR1 INT UNSIGNED auto_increment not null," +
+							"     ATTR2 INT UNSIGNED NOT NULL," +
+							"     PRIMARY KEY (ATTR1) )" + 
+							"  ENGINE=NDBCLUSTER");
+
+			System.out.println("done.");
+			System.out.print("Storing column indices...");
+
+	
+
+			alreadySetUp = true;
+		}
+	}
+
+	public void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	// TEST CODE
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	public void testMultipleOperation() {
+
+		try {
+			for (int loop = 0;
+			loop < 100;
+			loop++) {
+				// Process request transaction
+
+
+				BaseCallback callback;
+
+				// Process response transaction
+
+				trans = ndb.startTransaction();
+
+				NdbOperation firstOp;
+				NdbOperation secondOp;
+				NdbOperation thirdOp;
+
+				for (int elementCount = 0;
+				elementCount < NUMBER_OF_ELEMENT_INSERTIONS;
+				elementCount++) {
+					int id = (NUMBER_OF_ELEMENT_INSERTIONS * loop) + elementCount;
+
+					trans = ndb.startTransaction();
+
+					firstOp = trans.getNdbOperation(tablename1);
+
+					firstOp.insertTuple();
+
+					firstOp.equal("ATTR1", id);
+					firstOp.setInt("ATTR2", id);
+
+					if (!USE_SYNCHRONOUS) {
+						callback = new TestCallback(tablename1, id, ndb, firstOp.resultData());
+
+						trans.executeAsynchPrepare(ExecType.Commit,
+								callback,
+								AbortOption.AbortOnError);
+					}
+
+					trans = ndb.startTransaction();
+
+					secondOp = trans.getNdbOperation(tablename1);
+
+					secondOp.insertTuple();
+
+					secondOp.equal("ATTR1", id);
+					secondOp.setInt("ATTR2", id);
+
+					if (!USE_SYNCHRONOUS) {
+						callback = new TestCallback(tablename2, id, ndb, firstOp.resultData());
+
+						trans.executeAsynchPrepare(ExecType.Commit,
+								callback,
+								AbortOption.AbortOnError);
+					}
+
+					trans = ndb.startTransaction();
+
+					thirdOp = trans.getNdbOperation(tablename3);
+
+
+					thirdOp.insertTuple();
+
+					thirdOp.equal("ATTR1", id);
+					thirdOp.setInt("ATTR2", id);
+
+					if (!USE_SYNCHRONOUS) {
+						callback = new TestCallback(tablename3, id, ndb, firstOp.resultData());
+
+						trans.executeAsynchPrepare(ExecType.Commit,
+								callback,
+								AbortOption.AbortOnError);
+					}
+				}
+
+				if (USE_SYNCHRONOUS) {
+					trans.execute(ExecType.Commit, AbortOption.AbortOnError, true);
+				}
+				else {
+
+					ndb.sendPollNdb(REQUEST_TRANSACTIONS_TIMEOUT, NUM_REQUEST_TRANSACTIONS,
FORCE_SEND);	
+				}
+			}
+
+			System.out.println("Performing cooldown");
+
+			ndb.sendPollNdb(100000, 100000, FORCE_SEND);	
+
+		}
+		catch (NdbApiException e) {
+			System.out.println("Caught NdbApiException in Insert:\t" + e.getMessage());
+			e.printStackTrace();
+			junit.framework.Assert.assertTrue(true);
+			assertFalse(true);
+		}
+		finally {
+			if (trans!=null) {
+				trans.close();
+			}
+		}
+	}
+
+
+
+}

=== modified file 'README'
--- a/README	2007-03-22 04:55:31 +0000
+++ b/README	2007-10-25 00:10:47 +0000
@@ -3,3 +3,5 @@
 Things are built with a normal ./configure; make. There is no make install yet. 
 
 To get the configure, just run autoreconf -i 
+
+On RedHat systems, for Java, JAVA_HOME and ANT_HOME need to be set properly. On
Debian/Ubuntu systems, the alternatives system should work fine. 

=== modified file 'java/com/mysql/cluster/mgmj/MgmApiException.java'
--- a/java/com/mysql/cluster/mgmj/MgmApiException.java	2007-10-23 05:12:33 +0000
+++ b/java/com/mysql/cluster/mgmj/MgmApiException.java	2007-10-25 00:10:47 +0000
@@ -1,10 +1,9 @@
 package com.mysql.cluster.mgmj;
 
-import com.mysql.cluster.ndbj.NdbError; 
-
 public class MgmApiException extends com.mysql.cluster.ndbj.NdbApiException {
 
-
+	protected static final long serialVersionUID = 1L;
+	
 	public MgmApiException(long error) {
 		super(error);
 	}

=== modified file 'java/com/mysql/cluster/ndbj/Ndb.java'
--- a/java/com/mysql/cluster/ndbj/Ndb.java	2007-10-24 02:46:38 +0000
+++ b/java/com/mysql/cluster/ndbj/Ndb.java	2007-10-25 00:10:47 +0000
@@ -1,6 +1,5 @@
 package com.mysql.cluster.ndbj;
 
-import java.math.BigInteger;
 
 /**
 *

=== modified file 'java/com/mysql/cluster/ndbj/examples/CRUDandScan.java'
--- a/java/com/mysql/cluster/ndbj/examples/CRUDandScan.java	2007-10-23 23:47:41 +0000
+++ b/java/com/mysql/cluster/ndbj/examples/CRUDandScan.java	2007-10-25 00:10:47 +0000
@@ -169,9 +169,9 @@
 				 * Here we have a multi-part primary key, so we call the equal() method once for
 				 * each part of the primary key.
 				 */
-				op.equal("id", i);
+				op.equalInt("id", i);
 				
-				op.equal("arrivalTime", timeStamp);
+				op.equalTimestamp("arrivalTime", timeStamp);
 				
 				/**
 				 * We use the set<X>() methods to set the values for columns in the row we are
going to insert.
@@ -190,8 +190,8 @@
 		    for (int i=0;i<NUM_ROWS_TO_INSERT;i++) {
 				NdbOperation op = trans.getNdbOperation("ndbj_multi_pk");	
 				op.writeTuple();
-				op.equal("id", i);
-				op.equal("arrivalTime", new Timestamp(System.currentTimeMillis()));
+				op.equalInt("id", i);
+				op.equalTimestamp("arrivalTime", new Timestamp(System.currentTimeMillis()));
 				op.setString("firstName", "Jim");
 				op.setString("lastName", "Dowling");
 		    }
@@ -248,8 +248,8 @@
 			/**
 			 * Here we have a multi-part primary key, and we call equal() on both parts of the
primary key. 
 			 */
-			op.equal("id", 1);
-			op.equal("arrivalTime", timeStamp);
+			op.equalInt("id", 1);
+			op.equalTimestamp("arrivalTime", timeStamp);
 			
 			/**
 			 * We use the getValue() methods to indicate that we want to retrieve the value for a
column in the NdbResultSet.
@@ -341,8 +341,8 @@
 			/**
 			 * Here we have a multi-part primary key, we call equal() on both parts of the primary
key.
 			 */
-			op.equal("id", 1);
-			op.equal("arrivalTime", timeStamp);
+			op.equalInt("id", 1);
+			op.equalTimestamp("arrivalTime", timeStamp);
 			
 			/**
 			 * We use the set<X>() methods to set the values for columns in the row we are
going to insert.
@@ -406,8 +406,8 @@
 			 * Here we have a multi-part primary key, so we call the equal() method once for
 			 * each part of the primary key.
 			 */
-			op.equal("id", 1);
-			op.equal("arrivalTime", timeStamp);
+			op.equalInt("id", 1);
+			op.equalTimestamp("arrivalTime", timeStamp);
 			
 
 			/**
@@ -463,7 +463,7 @@
 			/**
 			 * Here we have a multi-part primary key, and we call equal() on both parts of the
primary key. 
 			 */
-			op.equal("id", 1);
+			op.equalInt("id", 1);
 			
 			/**
 			 * We use the getValue() methods to indicate that we want to retrieve the value for a
column in the NdbResultSet.
@@ -544,7 +544,7 @@
 			/**
 			 * Here we have a multi-part primary key, and we call equal() on both parts of the
primary key. 
 			 */
-			op.equal("lastName", "Dowling");
+			op.equalString("lastName", "Dowling");
 			
 			/**
 			 * We use the getValue() methods to indicate that we want to retrieve the value for a
column in the NdbResultSet.

=== modified file 'java/testsuite/ndbj/QuickAsyncTest.java'
--- a/java/testsuite/ndbj/QuickAsyncTest.java	2007-10-24 03:27:43 +0000
+++ b/java/testsuite/ndbj/QuickAsyncTest.java	2007-10-25 00:10:47 +0000
@@ -1,7 +1,7 @@
 package testsuite.ndbj;
 
-import java.sql.Timestamp;
 import testsuite.BaseNdbjTestCase;
+import testsuite.TestCallback;
 import com.mysql.cluster.ndbj.*;
 
 public class QuickAsyncTest extends BaseNdbjTestCase {
@@ -81,11 +81,11 @@
 
 			orderOp1.insertTuple();
 
-			orderOp1.equal("ATTR1", 1);
+			orderOp1.equalInt("ATTR1", 1);
 
 			orderOp1.setInt("ATTR2", 1);
 			
-			BaseCallback callback = new OrderCallback(ndb, orderOp1.resultData());
+			BaseCallback callback = new TestCallback(1, ndb, orderOp1.resultData());
 
 			trans.executeAsynchPrepare(ExecType.Commit,
 			                           callback,
@@ -116,12 +116,12 @@
 			orderOp1.insertTuple();
 
 
-			orderOp1.equal("ATTR1", 1);
+			orderOp1.equalInt("ATTR1", 1);
 
 			orderOp1.setInt("ATTR2", 1);
 
 
-			BaseCallback callback = new OrderCallback(ndb, orderOp1.resultData());
+			BaseCallback callback = new TestCallback(1, ndb, orderOp1.resultData());
 
 			trans.executeAsynchPrepare(ExecType.Commit,
 			                           callback,
@@ -132,11 +132,11 @@
 
 			orderOp2.insertTuple();
 
-			orderOp2.equal("ATTR1", 1);
+			orderOp2.equalInt("ATTR1", 1);
 
 			orderOp2.setInt("ATTR2", 1);
 
-			OrderCallback callback2 = new OrderCallback(ndb, orderOp2.resultData());
+			TestCallback callback2 = new TestCallback(2, ndb, orderOp2.resultData());
 
 			trans.executeAsynchPrepare(ExecType.Commit,
 			                           callback2,
@@ -156,24 +156,71 @@
 		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();
-		}
-
+	
+	public void testOperation() {
+		
+		try {
+			for (int loop = 0;
+			loop < 100;
+			loop++) {
+				// Process request transaction
+
+				NdbOperation orderOp;
+				BaseCallback callback;
+
+				for (int elementCount = 0;
+				elementCount < NUMBER_OF_ELEMENT_INSERTIONS;
+				elementCount++) {
+					int id = (NUMBER_OF_ELEMENT_INSERTIONS * loop) + elementCount;
+
+					trans = ndb.startTransaction();
+
+					orderOp = trans.getNdbOperation(tablename);
+
+					orderOp.insertTuple();
+
+
+					orderOp.equalInt("ATTR1", id);
+
+					orderOp.setInt("ATTR2", id);
+
+
+					if (!USE_SYNCHRONOUS) {
+						callback = new TestCallback(tablename, id, ndb, orderOp.resultData());
+
+						trans.executeAsynchPrepare(ExecType.Commit,
+								callback,
+								AbortOption.AbortOnError);
+					}
+				} 
+
+				if (USE_SYNCHRONOUS) {
+					trans.execute(ExecType.Commit, AbortOption.AbortOnError, true);
+				}
+				else {
+					ndb.sendPollNdb(REQUEST_TRANSACTIONS_TIMEOUT, NUM_REQUEST_TRANSACTIONS, FORCE_SEND);
+				}
+
+
+			}
+
+			System.out.println("Performing cooldown");
+
+			ndb.sendPollNdb(100000, 100000, FORCE_SEND);	
+
+		}
+		catch (NdbApiException e) {
+			System.out.println("Caught NdbApiException in Insert:\t" + e.getMessage());
+			e.printStackTrace();
+			assertFalse(true);
+		}
+		finally {
+			if (trans!=null) {
+				trans.close();
+			}
+		}
 	}
 
+
+
 }

Thread
Rev 202: Added multiple table/multiple loop async test. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmergeMonty Taylor25 Oct