List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:October 26 2007 11:22pm
Subject:Rev 205: Added test for events. 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: 205
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: ndbjmerge
timestamp: Fri 2007-10-26 16:22:21 -0700
message:
  Added test for events.
added:
  java/com/mysql/cluster/ndbj/examples/TestEvent.java
testevent.java-20071026232217-5tigfbdmcudrnbbx-1
=== added file 'java/com/mysql/cluster/ndbj/examples/TestEvent.java'
--- a/java/com/mysql/cluster/ndbj/examples/TestEvent.java	1970-01-01 00:00:00 +0000
+++ b/java/com/mysql/cluster/ndbj/examples/TestEvent.java	2007-10-26 23:22:21 +0000
@@ -0,0 +1,171 @@
+package com.mysql.cluster.ndbj.examples;
+
+import java.sql.*;
+
+import java.lang.*; 
+import java.util.Date;
+import java.util.ArrayList;
+import com.mysql.cluster.ndbj.*;
+
+
+public class TestEvent { 
+
+  private static Date beginTime;
+  private static Date initEndTime;
+  private static Date endTime;
+  private static long minTime = 10;
+  private static long maxTime = 0;
+
+  private static int num_iter = 0; 
+  private static int INSERT_NUM = 0; 
+
+  private Connection conn; 
+
+  static { 
+    System.loadLibrary("ndbj");
+  }
+
+
+  public static void main(String argv[]) throws SQLException{ 
+
+    if (argv.length<5) { 
+      System.out.println("Usage:\n\tjava testevent <connstring> <database>
<tablename> <eventname> <polltime>"); 
+      System.exit(1);
+    }
+
+    String connectString=argv[0];
+    String database=argv[1];
+    String tableName=argv[2];
+    String eventName=argv[3];
+    int pollTime=Integer.parseInt(argv[4]);
+
+    System.out.println("connecting to cluster");
+    
+    try { 
+      NdbClusterConnection connection =
NdbFactory.createNdbClusterConnection(connectString);
+      
+      try {
+	  if (connection.connect(5,3,true)==-1) { 
+	      System.out.println("Connect to cluster management server failed.");
+	      System.exit(-1);
+	  }
+      } catch (Exception e) { 
+	  System.out.println(e.getMessage());
+	  System.exit(-1);
+      }
+      
+      
+      
+      try { 
+	  connection.waitUntilReady(30,30); 
+      } catch (Exception e) { 
+	  System.out.println("Cluster was not ready within 30 secs.");
+	  System.exit(-1);
+      }
+
+      Ndb myNdb = connection.createNdb( database , 4) ;
+
+
+
+      NdbDictionary dict=myNdb.getDictionary();
+      NdbTable table = dict.getTable(tableName);
+      NdbResultSet [] currRecAttr = new NdbResultSet[table.getNoOfColumns()];
+      NdbResultSet [] preRecAttr = new NdbResultSet[table.getNoOfColumns()];
+
+      System.out.println("running tests:");
+      
+      
+      NdbEventOperation eop = myNdb.createEventOperation(eventName);	 
+      
+      NdbColumn col=null;
+      System.out.println("Number of Colums=" + table.getNoOfColumns());
+      for(int i=0; i<table.getNoOfColumns(); i++)
+	  {
+	      col=table.getColumn(i);
+	      String name=col.getName();
+	      System.out.println("Setting up column : " + name); 
+	      if(col==null)
+		  System.out.println("damn");
+	      currRecAttr[i] = eop.getValue(name);	      	      
+	      if(currRecAttr[i]==null)
+		  System.out.println("damn curr=null");
+	      preRecAttr[i] = eop.getPreValue(name);
+	      if(preRecAttr[i]==null)
+		  System.out.println("damn pre=null");
+	  }
+	      
+      System.out.println("done");
+
+      eop.execute();
+      int i=0;
+      int j=0;
+      boolean start=false;
+      long startTime=0;
+      int counter=0, evt=1000;
+      
+      while(i<10000)
+	  {
+	      System.out.println("polling");
+	      int r = myNdb.pollEvents(pollTime);
+	      if(r>0)
+		  {
+
+
+		      if(!start&& counter==0) 
+		        {
+			    startTime = System.currentTimeMillis();
+			    start=true;
+			}
+
+		      while((eop=myNdb.nextEvent())!= null)
+			  {
+			      if(eop.isOverrun()>0)
+				  {
+				      System.out.println("Fook");
+				  }
+
+			      if(!eop.isConsistent())
+				  {
+				      System.out.println("Fook");
+				  }
+			      			    
+			      System.out.print("a_curr=" + 
+					       currRecAttr[0]. .getInt64());
+			      System.out.print("b_curr=" + 
+					       currRecAttr[1].getString());
+			     /* 
+				System.out.print(" b_curr=" + 
+				currRecAttr[1].getString());
+				System.out.print(" a_prev=" + 
+				preRecAttr[0].int32_value());
+			     */
+			      System.out.print("\n");
+			     
+
+			      String  x  = currRecAttr[1].getString();
+			      x=null;
+			      counter++;
+			  }
+
+		      if(counter % evt == 0 )
+			  {
+			      System.out.println("received "+ evt +  "events");
+			  }
+		      
+		  }
+	      i++;
+	      //      stopTime = System.currentTimeMillis()-startTime;
+	  }
+      myNdb.dropEventOperation((NdbEventOperationImpl)eop);
+      
+      
+      
+  }
+  catch(Exception e)
+      {
+	  e.printStackTrace();
+      }
+  
+  }
+}
+

Thread
Rev 205: Added test for events. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmergeMonty Taylor27 Oct