List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:October 30 2007 7:17pm
Subject:Rev 224: Merged in new test from David Shepherd for testing ImmediatePollTimeout in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel
View as plain text  
At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel

------------------------------------------------------------
revno: 224
revision-id: mtaylor@stripped
parent: mtaylor@stripped
parent: root@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: devel
timestamp: Tue 2007-10-30 19:17:06 +0000
message:
  Merged in new test from David Shepherd for testing ImmediatePollTimeout
added:
  java/testsuite/ndbj/ImmediatePollTimeoutTest.java
immediatepolltimeout-20071030180642-3bfrv97t3q8mc2m6-1
    ------------------------------------------------------------
    revno: 222.1.1
    revision-id: root@stripped
    parent: mtaylor@stripped
    committer: root <root@stripped>
    branch nick: work
    timestamp: Tue 2007-10-30 18:06:46 +0000
    message:
      h
    added:
      java/testsuite/ndbj/ImmediatePollTimeoutTest.java
immediatepolltimeout-20071030180642-3bfrv97t3q8mc2m6-1
=== added file 'java/testsuite/ndbj/ImmediatePollTimeoutTest.java'
--- a/java/testsuite/ndbj/ImmediatePollTimeoutTest.java	1970-01-01 00:00:00 +0000
+++ b/java/testsuite/ndbj/ImmediatePollTimeoutTest.java	2007-10-30 18:06:46 +0000
@@ -0,0 +1,180 @@
+package testsuite.ndbj;
+
+import java.util.*;
+
+import testsuite.BaseNdbjTestCase;
+import com.mysql.cluster.ndbj.*;
+
+public class ImmediatePollTimeoutTest extends BaseNdbjTestCase {
+
+	static boolean alreadySetUp                   = false;
+	static long    ourTotalTransactionCount       = 0;
+	static long    ourOutstandingTransactionCount = 0;
+	static long    ourCallbackCount               = 0;
+
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	// GENERAL STUFF
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	static int MAXIMUM_OPERATION_VOLUME       = 300; // TO DO: Calculate this
+
+	static int NUMBER_OF_ELEMENT_INSERTIONS   = 50;
+
+	static int NUM_REQUEST_TRANSACTIONS       = 2;
+	static int REQUEST_TRANSACTIONS_TIMEOUT   = 0;
+
+	static int FORCE_SEND                     = 1;
+
+	static boolean USE_SYNCHRONOUS            = false;
+
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	// TABLE METADATA
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	static String tablename      = "t_immediatepolltimeouttest";
+
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	// INITIALISATION CODE
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+	public ImmediatePollTimeoutTest(String arg0) {
+		super(arg0);
+	}
+
+	public void setUp() throws Exception {
+		super.setUp();
+
+		if (!alreadySetUp) {
+			// Create required tables
+
+			System.out.print("Creating tables...");
+
+			this.createTable(tablename, 
+				"    (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...");
+			System.out.println("done.");
+
+			alreadySetUp = true;
+		}
+	}
+
+	public void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+	// TEST CODE
+	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	public void testOperation() {
+		
+		HashMap<Integer,BaseCallback> hash=new HashMap<Integer,BaseCallback>();
+	
+		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);
+
+					callback = new MyCallback(hash, id, ndb, orderOp.resultData());
+					hash.put(callback.hashCode(), callback);
+
+					trans.executeAsynchPrepare(ExecType.Commit,
+							callback,
+							AbortOption.AbortOnError);
+
+					ourOutstandingTransactionCount++;
+				}
+
+				ourCallbackCount = 0;
+
+				ndb.sendPreparedTransactions(FORCE_SEND);
+
+				long then = System.nanoTime();
+				ndb.pollNdb(REQUEST_TRANSACTIONS_TIMEOUT);
+				long now = System.nanoTime();
+
+				ourOutstandingTransactionCount = ourOutstandingTransactionCount - ourCallbackCount;
+				System.out.println("Poll took " + (now - then) + " nanos (" + ourCallbackCount + 
+							" txs received) [" + ourOutstandingTransactionCount + " outstanding]");
+			}
+
+			System.out.println("Performing cooldown");
+
+			ourCallbackCount = 0;
+
+			long then = System.nanoTime();
+			ndb.pollNdb(100000,100000);
+			long now = System.nanoTime();
+
+			ourOutstandingTransactionCount = ourOutstandingTransactionCount - ourCallbackCount;
+			System.out.println("Closedown poll took " + (now - then) + " nanos (" +
ourCallbackCount + 
+						" txs received) [" + ourOutstandingTransactionCount + " outstanding]");
+		}
+		catch (NdbApiException e) {
+			System.out.println("Caught NdbApiException in Insert:\t" + e.getMessage());
+			e.printStackTrace();
+			assertFalse(true);
+		}
+		finally {
+			// Do something ;o)
+		}
+	}
+
+	class HashCallback extends BaseCallback {
+	
+
+	    int                            myCallbackNum;
+	    Ndb                            myNdb;
+	    NdbResultSet                   myResults;
+	    HashMap<Integer, BaseCallback> myMap;
+
+	    public HashCallback(HashMap<Integer, BaseCallback> theMap, int theCallbackNum,
Ndb theNdb, NdbResultSet theResults) {
+		myMap         = theMap;
+		myCallbackNum = theCallbackNum;
+		myNdb         = theNdb;
+		myResults     = theResults;
+	    }
+    
+	    public void callback(int res, NdbTransactionImpl trans) { 
+
+		if (res!=0)
System.out.println("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHASSSSSSSSSSSSSSSSSSSSHHH");
+	
+		trans.close();
+		myMap.remove(this.hashCode());
+
+		ourCallbackCount++;
+	    }
+    
+	}
+
+	class MyCallback extends HashCallback {
+
+	    public MyCallback(HashMap<Integer, BaseCallback> theMap,int theCallbackNum,
Ndb theNdb, NdbResultSet theResults) {
+		super(theMap, theCallbackNum, theNdb, theResults);
+	    }
+
+	}
+
+}

Thread
Rev 224: Merged in new test from David Shepherd for testing ImmediatePollTimeout in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/develMonty Taylor30 Oct