[LOGBack-dev] svn commit: r505 - logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net

noreply.seb at qos.ch noreply.seb at qos.ch
Thu Aug 31 18:34:39 CEST 2006


Author: seb
Date: Thu Aug 31 18:34:38 2006
New Revision: 505

Added:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/ExternalMockSocketServer.java
Modified:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SerializationPerfsTest.java

Log:
added an ExternalMockSocketServer and modified test case to allow
tests to run with a server in a different jvm

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/ExternalMockSocketServer.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/ExternalMockSocketServer.java	Thu Aug 31 18:34:38 2006
@@ -0,0 +1,72 @@
+package ch.qos.logback.classic.net;
+
+import java.io.BufferedInputStream;
+import java.io.ObjectInputStream;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ExternalMockSocketServer {
+
+	static final String LOGGINGEVENT = "LoggingEvent";
+	static final String LOGGINGEVENT2 = "LoggingEvent2";
+	static final String MINIMALEXT = "MinimalExt";
+	static final String MINIMALSER = "MinimalSer";
+
+	static final int PORT = 4560;
+
+	static int loopLen;
+	static int clientNumber;
+
+	static List<String> msgList = new ArrayList<String>();
+	static boolean finished = false;
+
+	String className = LOGGINGEVENT;
+
+	public static void main(String[] args) {
+		if (args.length == 2) {
+			clientNumber = Integer.parseInt(args[0]);
+			loopLen = Integer.parseInt((args[1]));
+			System.out.println("Starting Server...");
+			runServer();
+		} else {
+			usage("Wrong number of arguments.");
+		}
+	}
+
+	static void usage(String msg) {
+		System.err.println(msg);
+		System.err.println("Usage: java "
+				+ ExternalMockSocketServer.class.getName() + " clientNumber loopNumber");
+		System.exit(1);
+	}
+
+	static void runServer() {
+		ObjectInputStream ois;
+		Object readObject;
+		try {
+			System.out.println("Listening on port " + PORT);
+			ServerSocket serverSocket = new ServerSocket(PORT);
+			for (int j = 0; j < clientNumber; j++) {
+				Socket socket = serverSocket.accept();
+				System.out.println("New client accepted.");
+				System.out.println("Connected to client at " + socket.getInetAddress());
+				ois = new ObjectInputStream(new BufferedInputStream(socket
+						.getInputStream()));
+				for (int i = 0; i < loopLen; i++) {
+					readObject = ois.readObject();
+					//msgList.add(readObject.toString());
+				}
+				ois.close();
+				System.out.println("Finished with this client.");
+			}
+			serverSocket.close();
+		} catch (Exception se) {
+			se.printStackTrace();
+		}
+		System.out.println("Server finished.");
+		finished = true;
+	}
+
+}

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SerializationPerfsTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SerializationPerfsTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SerializationPerfsTest.java	Thu Aug 31 18:34:38 2006
@@ -22,28 +22,54 @@
 	 * Run the test with a MockSocketServer or with a NOPOutputStream
 	 */
 	boolean runWithMockServer = true;
+	/**
+	 * <p>
+	 * Run with external mock can be done using the
+	 * ExternalMockSocketServer. It needs to be launched
+	 * from a separate JVM.
+	 * </p>
+	 * <p>
+	 * For example, with 4 test methods and a loopNumber of 10000,
+	 * you can launch the ExternalMockSocketServer this way:
+	 * </p>
+	 * <p>
+	 * <code>java ch.qos.logback.classic.net.ExternalMockSocketServer 4 20000</code>
+	 * </p>
+	 * <p>
+	 * (20000 because each methods iterate twice).
+	 * </p>
+	 */
+	boolean runWithExternalMockServer = true;
 
 	/**
 	 * Last results:
 	 * 
 	 * NOPOutputStream: 
-	 * Minimal Object Externalization: average time = 6511 after 10000 writes. 
-	 * Minimal Object Serialization: average time = 7883 after 10000 writes. 
-	 * Externalization: average time = 9641 after 10000 writes.
-	 * Serialization: average time = 25729 after 10000 writes.
+	 * Minimal Object externalization: average time = 6511 after 10000 writes. 
+	 * Minimal Object serialization: average time = 7883 after 10000 writes. 
+	 * LoggingEvent object externalization: average time = 9641 after 10000 writes.
+	 * LoggingEvent object serialization: average time = 25729 after 10000 writes.
 	 * 
-	 * MockServer: 
+	 * Internal MockServer: 
 	 * Minimal object externalization : average time = 62040 after 10000 writes.
 	 * Minimal object serialization : average time = 76237 after 10000 writes.
 	 * LoggingEvent object externalization : average time = 122714 after 10000 writes.
 	 * LoggingEvent object serialization : average time = 121711 after 10000 writes.
+	 * 
+	 * External MockServer: 
+	 * Minimal object externalization : average time = 55577 after 10000 writes.
+	 * Minimal object serialization : average time = 56669 after 10000 writes.
+	 * LoggingEvent object externalization : average time = 121477 after 10000 writes.
+	 * LoggingEvent object serialization : average time = 111148 after 10000 writes.
 	 */
 
 	public void setUp() throws Exception {
 		super.setUp();
 		if (runWithMockServer) {
-			mockServer = new MockSocketServer(loopNumber * 2);
-			mockServer.start();
+			if (!runWithExternalMockServer) {
+				mockServer = new MockSocketServer(loopNumber * 2);
+				mockServer.start();
+			}
 			oos = new ObjectOutputStream(new Socket("localhost",
 					MockSocketServer.PORT).getOutputStream());
 		} else {
@@ -70,7 +96,7 @@
 					oos.reset();
 				}
 			} catch (IOException ex) {
-				fail();
+				fail(ex.getMessage());
 			}
 		}
 
@@ -89,7 +115,7 @@
 					oos.reset();
 				}
 			} catch (IOException ex) {
-				fail();
+				fail(ex.getMessage());
 			}
 		}
 		t2 = System.nanoTime();
@@ -97,7 +123,7 @@
 		System.out.println(label + " : average time = " + total / loopNumber
 				+ " after " + loopNumber + " writes.");
 
-		if (runWithMockServer) {
+		if (runWithMockServer && !runWithExternalMockServer) {
 			mockServer.join(1000);
 			assertTrue(mockServer.finished);
 		}



More information about the logback-dev mailing list