At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel
------------------------------------------------------------
revno: 251
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: devel
timestamp: Wed 2007-11-14 12:19:39 -0800
message:
Added OutofConnectionProblemTest to testsuite.
added:
java/testsuite/ndbj/OutOfConnectionProblemTest.java
outofconnectionprobl-20071114201416-ycjx0i6uz5umawy0-1
=== added file 'java/testsuite/ndbj/OutOfConnectionProblemTest.java'
--- a/java/testsuite/ndbj/OutOfConnectionProblemTest.java 1970-01-01 00:00:00 +0000
+++ b/java/testsuite/ndbj/OutOfConnectionProblemTest.java 2007-11-14 20:19:39 +0000
@@ -0,0 +1,183 @@
+package testsuite.ndbj;
+
+import java.util.*;
+import java.sql.Timestamp;
+import testsuite.BaseNdbjTestCase;
+import com.mysql.cluster.ndbj.*;
+
+public class OutOfConnectionProblemTest extends BaseNdbjTestCase {
+
+ static boolean alreadySetUp = false;
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // GENERAL STUFF
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ static final int NUMBER_OF_TEST_ITERATIONS = 10000;
+
+ static final int NUMBER_OF_ELEMENT_INSERTIONS = 25;
+
+ static final int NUM_TRANSACTIONS = 5;
+ static final int TRANSACTIONS_TIMEOUT = 1;
+ static final int FORCE_SEND = 1;
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // TABLE METADATA
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ static final String PROBTABLE = "OutOfConnectionProblemTable";
+
+ static int PROBTABLE_FIELD1;
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // OTHER
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ static int myTransactionCount = 0;
+ static int myTotalTransactionCount = 0;
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // INITIALISATION CODE
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(OutOfConnectionProblemTest.class);
+ }
+
+ public OutOfConnectionProblemTest(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+
+ if (!alreadySetUp) {
+ // Create required tables
+
+ createTable(PROBTABLE, "(field1 SMALLINT UNSIGNED NOT NULL, PRIMARY KEY(field1))
ENGINE=ndb PARTITION BY KEY (field1);");
+
+ NdbDictionary dictionary = ndb.getDictionary();
+
+ NdbTable probTable = dictionary.getTable(PROBTABLE);
+ PROBTABLE_FIELD1 = probTable.getColumn("field1").getColumnNo();
+ }
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ // TEST CODE
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ public void testOperation() {
+
+ try {
+ long startTime = System.currentTimeMillis();
+
+ for (int iteration = 0;
+ iteration < NUMBER_OF_TEST_ITERATIONS;
+ iteration++) {
+ generateRequestTxs(iteration);
+
+ sendPollNdb(TRANSACTIONS_TIMEOUT, NUM_TRANSACTIONS, FORCE_SEND);
+ }
+
+ System.out.println("Performing cooldown");
+
+ pollNdb(100000, myTransactionCount);
+
+ long endTime = System.currentTimeMillis();
+ long elapsedTime = endTime - startTime;
+
+ System.out.println("Test completed with no exceptions and took " + elapsedTime / 1000
+ " seconds");
+ }
+ catch (NdbApiException e) {
+ System.out.println("Caught NdbApiException in Insert:\t" + e.getMessage());
+ e.printStackTrace();
+ assertFalse(true);
+ }
+ finally {
+ System.out.println("End of test.");
+ }
+ }
+
+ public void generateRequestTxs(int theLastBatch) throws NdbApiException {
+
+ boolean success = false;
+
+ NdbOperation orderOp;
+ BaseCallback callback;
+
+ try {
+
+ for (int elementCount = 1;
+ elementCount < (NUMBER_OF_ELEMENT_INSERTIONS) + 1;
+ elementCount++) {
+
+ int id = (NUMBER_OF_ELEMENT_INSERTIONS * theLastBatch) + elementCount;
+
+ trans = startCountedTransaction();
+
+ orderOp = trans.getNdbOperation(PROBTABLE);
+
+ orderOp.insertTuple();
+
+ orderOp.equalInt(PROBTABLE_FIELD1, id);
+
+ callback = new CountingCallback(id, ndb, orderOp.resultData(), trans);
+
+ trans.executeAsynchPrepare(ExecType.Commit,
+ callback,
+ AbortOption.AbortOnError);
+ }
+
+
+ success = true;
+ }
+ finally {
+System.out.println("Started " + myTotalTransactionCount + " txs in total " + (success ?
"(no errors)" : "(errors, aborting)"));
+ }
+ }
+
+ private NdbTransaction startCountedTransaction() throws NdbApiException {
+ myTransactionCount++;
+ myTotalTransactionCount++;
+
+ return ndb.startTransaction();
+ }
+
+ private int sendPollNdb(int aMillisecondNumber, int minNoOfEventsToWakeup, int
forceSend) throws NdbApiException {
+ ndb.sendPreparedTransactions(forceSend);
+
+ return pollNdb(aMillisecondNumber, minNoOfEventsToWakeup);
+ }
+
+ private int pollNdb(int aMillisecondNumber, int minNoOfEventsToWakeup) throws
NdbApiException {
+ int numberOfCallbacks = ndb.pollNdb(aMillisecondNumber, minNoOfEventsToWakeup);
+
+ System.out.println("Poll produced " + numberOfCallbacks + " callbacks (" +
myTransactionCount +
+ " txs outstanding) [Total " + myTotalTransactionCount + "]");
+
+ return numberOfCallbacks;
+ }
+
+ class CountingCallback extends BaseCallback {
+
+ public CountingCallback(int theCallbackNum, Ndb theNdb, NdbResultSet theResults,
NdbTransaction trans) {
+ super(trans);
+ }
+
+ public void callback(int theResult) {
+ myTransactionCount--;
+ //System.out.print("Callback (" + theTrans + "): ");
+
+ //System.out.print("Transaction was " + (theTrans.isClosed() ? "closed" : "open") + "
(before close()) " );
+ theTrans.close();
+ //System.out.println("and is now " + (theTrans.isClosed() ? "closed" : "open") );
+ }
+
+ }
+
+}
| Thread |
|---|
| • Rev 251: Added OutofConnectionProblemTest to testsuite. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel | Monty Taylor | 14 Nov |