james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject svn commit: r1688160 - in /james/mpt/trunk/core/src/main/java/org/apache/james/mpt/protocol: FileProtocolSessionBuilder.java ProtocolSession.java ProtocolSessionBuilder.java
Date Mon, 29 Jun 2015 08:57:12 GMT
Author: btellier
Date: Mon Jun 29 08:57:11 2015
New Revision: 1688160

URL: http://svn.apache.org/r1688160
Log:
MAILBOX-155 Adding LOG instruction to MPT, for debug purposes

Modified:
    james/mpt/trunk/core/src/main/java/org/apache/james/mpt/protocol/FileProtocolSessionBuilder.java
    james/mpt/trunk/core/src/main/java/org/apache/james/mpt/protocol/ProtocolSession.java
    james/mpt/trunk/core/src/main/java/org/apache/james/mpt/protocol/ProtocolSessionBuilder.java

Modified: james/mpt/trunk/core/src/main/java/org/apache/james/mpt/protocol/FileProtocolSessionBuilder.java
URL: http://svn.apache.org/viewvc/james/mpt/trunk/core/src/main/java/org/apache/james/mpt/protocol/FileProtocolSessionBuilder.java?rev=1688160&r1=1688159&r2=1688160&view=diff
==============================================================================
--- james/mpt/trunk/core/src/main/java/org/apache/james/mpt/protocol/FileProtocolSessionBuilder.java
(original)
+++ james/mpt/trunk/core/src/main/java/org/apache/james/mpt/protocol/FileProtocolSessionBuilder.java
Mon Jun 29 08:57:11 2015
@@ -35,7 +35,12 @@ import org.apache.commons.io.IOUtils;
  * @version $Revision$
  */
 public class FileProtocolSessionBuilder extends ProtocolSessionBuilder {
-    
+
+    public static final String DEBUG = "DEBUG";
+    public static final String INFO = "INFO";
+    public static final String WARN = "WARN";
+    public static final String ERR = "ERR";
+
     /**
      * Builds a ProtocolSession by reading lines from the test file with the
      * supplied name.
@@ -119,6 +124,20 @@ public class FileProtocolSessionBuilder
                         throw new Exception("Invalid line length on WAIT instruction : "
+ next);
                     }
                 }
+                else if (next.startsWith(LOG)) {
+                    String logInstruction = next.substring(4);
+                    if (logInstruction.startsWith(DEBUG)) {
+                        session.LOG(sessionNumber, ProtocolSession.LolLevel.Debug, logInstruction.substring(6));
+                    } else if (logInstruction.startsWith(INFO)) {
+                        session.LOG(sessionNumber, ProtocolSession.LolLevel.Info, logInstruction.substring(5));
+                    } else if (logInstruction.startsWith(WARN)) {
+                        session.LOG(sessionNumber, ProtocolSession.LolLevel.Warn, logInstruction.substring(5));
+                    } else if (logInstruction.startsWith(ERR)) {
+                        session.LOG(sessionNumber, ProtocolSession.LolLevel.Err, logInstruction.substring(4));
+                    } else {
+                        throw new Exception("Unrecognized log level for " + next);
+                    }
+                }
                 else if (next.startsWith(OPEN_UNORDERED_BLOCK_TAG)) {
                     List<String> unorderedLines = new ArrayList<String>(5);
                     next = reader.readLine();

Modified: james/mpt/trunk/core/src/main/java/org/apache/james/mpt/protocol/ProtocolSession.java
URL: http://svn.apache.org/viewvc/james/mpt/trunk/core/src/main/java/org/apache/james/mpt/protocol/ProtocolSession.java?rev=1688160&r1=1688159&r2=1688160&view=diff
==============================================================================
--- james/mpt/trunk/core/src/main/java/org/apache/james/mpt/protocol/ProtocolSession.java
(original)
+++ james/mpt/trunk/core/src/main/java/org/apache/james/mpt/protocol/ProtocolSession.java
Mon Jun 29 08:57:11 2015
@@ -27,6 +27,8 @@ import java.util.regex.Pattern;
 
 import org.apache.james.mpt.api.ProtocolInteractor;
 import org.apache.james.mpt.api.Session;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A protocol session which can be run against a reader and writer, which checks
@@ -38,6 +40,8 @@ import org.apache.james.mpt.api.Session;
  */
 public class ProtocolSession implements ProtocolInteractor {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(ProtocolSession.class);
+
     private boolean continued = false;
 
     private boolean continuationExpected = false;
@@ -58,6 +62,13 @@ public class ProtocolSession implements
         return continueAfterFailure;
     }
 
+    enum LolLevel {
+        Debug,
+        Info,
+        Warn,
+        Err
+    }
+
     public final void setContinueAfterFailure(boolean continueAfterFailure) {
         this.continueAfterFailure = continueAfterFailure;
     }
@@ -186,6 +197,11 @@ public class ProtocolSession implements
         testElements.add(new WaitElement(timeToWaitInMs));
     }
 
+    public void LOG(int sessionNumber, LolLevel level, String message) {
+        this.maxSessionNumber = Math.max(this.maxSessionNumber, sessionNumber);
+        testElements.add(new LogElement(level, message));
+    }
+
     /**
      * A client request, which write the specified message to a Writer.
      */
@@ -501,6 +517,43 @@ public class ProtocolSession implements
         }
 
         @Override
+        public boolean isClient() {
+            return false;
+        }
+    }
+
+    /**
+     * Allow you to wait a given time at a given point of the test script
+     */
+    private class LogElement implements ProtocolElement {
+
+        private final LolLevel level;
+        private final String message;
+
+        public LogElement(LolLevel level, String message) {
+            this.level = level;
+            this.message = message;
+        }
+
+        @Override
+        public void testProtocol(Session[] sessions, boolean continueAfterFailure) throws
Exception {
+            switch (level) {
+            case Debug:
+                LOGGER.debug(message);
+                break;
+            case Info:
+                LOGGER.info(message);
+                break;
+            case Warn:
+                LOGGER.warn(message);
+                break;
+            case Err:
+                LOGGER.error(message);
+                break;
+            }
+        }
+
+        @Override
         public boolean isClient() {
             return false;
         }

Modified: james/mpt/trunk/core/src/main/java/org/apache/james/mpt/protocol/ProtocolSessionBuilder.java
URL: http://svn.apache.org/viewvc/james/mpt/trunk/core/src/main/java/org/apache/james/mpt/protocol/ProtocolSessionBuilder.java?rev=1688160&r1=1688159&r2=1688160&view=diff
==============================================================================
--- james/mpt/trunk/core/src/main/java/org/apache/james/mpt/protocol/ProtocolSessionBuilder.java
(original)
+++ james/mpt/trunk/core/src/main/java/org/apache/james/mpt/protocol/ProtocolSessionBuilder.java
Mon Jun 29 08:57:11 2015
@@ -39,6 +39,8 @@ import org.apache.james.mpt.api.Protocol
  */
 public class ProtocolSessionBuilder {
 
+    public static final String LOG = "LOG";
+
     public static final String WAIT = "WAIT";
 
     public static final String SERVER_CONTINUATION_TAG = "S: \\+";



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message