[jboss-svn-commits] JBL Code SVN: r14179 - labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Aug 13 13:10:56 EDT 2007


Author: ldimaggi at redhat.com
Date: 2007-08-13 13:10:56 -0400 (Mon, 13 Aug 2007)
New Revision: 14179

Modified:
   labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test/HelloWorldTest.java
   labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test/Helpers.java
Log:
test/Helpers.java
    Added routine to repeated look for event file - so we can remove sleep's from tests per Kurt's code review

test/HelloWorldTest.java
    Changed to make use of the new routine in Helpers.java




Modified: labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test/HelloWorldTest.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test/HelloWorldTest.java	2007-08-13 17:09:52 UTC (rev 14178)
+++ labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test/HelloWorldTest.java	2007-08-13 17:10:56 UTC (rev 14179)
@@ -48,8 +48,14 @@
 
 	public void testMessage() throws Exception {
 		sendMessage();
-        
-		Thread.sleep(10000); // wait for message to post.
+
+		/* Verify that the message file is created */
+		boolean fileExists = Helpers.checkForFile(LOG_FILE);
+		if (!fileExists) {
+			fail ("Event file " + LOG_FILE + " not created - test marked as failing");
+		}        
+
+		//Thread.sleep(10000); // wait for message to post.
         //Code review Kurt: This is going to make the build
         //really lengthy. We should have a little "waitForFile"
         //Utility to look for the file. (with a max wait time (test fails).
@@ -58,8 +64,8 @@
 		String theMessage = (String) theTable.get("Message1");
 		assertEquals("The strings should match", theMessage, JMS_MESSAGE);
 		//assertEquals("The strings should match", "non-matchinf message", JMS_MESSAGE);
-        File target = new File(Helpers.getTempDir(LOG_FILE));
-        target.delete();
+	        File target = new File(Helpers.getTempDir(LOG_FILE));
+        	target.delete();
 	}
 
 	public void sendMessage() throws Exception {

Modified: labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test/Helpers.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test/Helpers.java	2007-08-13 17:09:52 UTC (rev 14178)
+++ labs/jbossesb/trunk/product/samples/quickstarts/tests/src/org/jboss/soa/esb/quickstart/test/Helpers.java	2007-08-13 17:10:56 UTC (rev 14179)
@@ -37,6 +37,8 @@
 public class Helpers {
 	public static final String START_TAG = "[jbesb-filename]";
 	public static final String END_TAG = "[/jbesb-filename]\n";
+	public static final int FILE_TIMER = 3000;
+	public static final int FILE_COUNTER = 3;
 
 	/* Read the message files into a hash */
 	public static Hashtable getMessageString(String fileName) {
@@ -56,6 +58,24 @@
 		}
 		return returnTable;
 	} /* method */
+
+	/* Determine if the event file has been written */
+	public static boolean checkForFile(String fileName) throws Exception {
+		boolean wasFileFound = false;
+		/* Look for file, if it's there, set the boolean and return, if it's
+		 * not, wait and try again */
+		for (int i = 0; i < FILE_COUNTER; i++) {
+			boolean exists = (new File(fileName)).exists();
+			if (exists) {
+				wasFileFound = true;
+				break;
+			} 
+			else {
+				Thread.sleep(FILE_TIMER);
+			}
+		}
+		return wasFileFound;
+	} /* method */
     
     public static String getTempDir(String filename) 
     {




More information about the jboss-svn-commits mailing list