[LOGBack-dev] svn commit: r501 - in logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net: . testObjectBuilders
noreply.seb at qos.ch
noreply.seb at qos.ch
Thu Aug 31 15:01:05 CEST 2006
Author: seb
Date: Thu Aug 31 15:01:05 2006
New Revision: 501
Modified:
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/MockSocketServer.java
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/SocketAppenderTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/MinimalExtBuilder.java
Log:
- Modified perf test to use a MockSocketServer and actually consume events
- Modified MockSocketServer so that we can use it to check multiple object, not only LoggingEvent objects
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/MockSocketServer.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/MockSocketServer.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/MockSocketServer.java Thu Aug 31 15:01:05 2006
@@ -16,8 +16,6 @@
import java.util.ArrayList;
import java.util.List;
-import ch.qos.logback.classic.spi.LoggingEvent;
-
/**
*
*
@@ -25,6 +23,11 @@
*/
public class MockSocketServer extends Thread {
+ 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;
final int loopLen;
@@ -32,6 +35,8 @@
List<String> msgList = new ArrayList<String>();
boolean finished = false;
+ String className = LOGGINGEVENT;
+
MockSocketServer(int loopLen) {
super();
this.loopLen = loopLen;
@@ -39,24 +44,25 @@
@Override
public void run() {
+ ObjectInputStream ois;
+ Object readObject;
try {
- System.out.println("Listening on port " + PORT);
+ //System.out.println("Listening on port " + PORT);
ServerSocket serverSocket = new ServerSocket(PORT);
- ObjectInputStream ois;
- LoggingEvent event;
+ //System.out.println("Waiting to accept a new client.");
+ Socket socket = serverSocket.accept();
+ //System.out.println("Connected to client at " + socket.getInetAddress());
+ ois = new ObjectInputStream(new BufferedInputStream(socket
+ .getInputStream()));
for (int i = 0; i < loopLen; i++) {
- System.out.println("Waiting to accept a new client.");
- Socket socket = serverSocket.accept();
- System.out.println("Connected to client at " + socket.getInetAddress());
- ois = new ObjectInputStream(new BufferedInputStream(socket
- .getInputStream()));
- event = (LoggingEvent) ois.readObject();
- msgList.add(event.getMessage());
+ readObject = ois.readObject();
+ msgList.add(readObject.toString());
}
+ ois.close();
+ serverSocket.close();
} catch (Exception se) {
se.printStackTrace();
}
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 15:01:05 2006
@@ -2,50 +2,75 @@
import java.io.IOException;
import java.io.ObjectOutputStream;
+import java.net.Socket;
+import junit.framework.TestCase;
import ch.qos.logback.classic.net.testObjectBuilders.Builder;
import ch.qos.logback.classic.net.testObjectBuilders.LoggingEvent2Builder;
import ch.qos.logback.classic.net.testObjectBuilders.LoggingEventBuilder;
import ch.qos.logback.classic.net.testObjectBuilders.MinimalExtBuilder;
import ch.qos.logback.classic.net.testObjectBuilders.MinimalSerBuilder;
-import junit.framework.TestCase;
-
public class SerializationPerfsTest extends TestCase {
ObjectOutputStream oos;
+ MockSocketServer mockServer;
- int loopNumber = 5000;
+ int loopNumber = 10000;
int resetFrequency = 100;
-
+ /**
+ * Run the test with a MockSocketServer or with a NOPOutputStream
+ */
+ boolean runWithMockServer = true;
+
/**
* Last results:
*
- * 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.
+ * 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.
+ *
+ * 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.
*/
public void setUp() throws Exception {
super.setUp();
- oos = new ObjectOutputStream(new NOPOutputStream());
+ if (runWithMockServer) {
+ mockServer = new MockSocketServer(loopNumber * 2);
+ mockServer.start();
+ oos = new ObjectOutputStream(new Socket("localhost",
+ MockSocketServer.PORT).getOutputStream());
+ } else {
+ oos = new ObjectOutputStream(new NOPOutputStream());
+ }
}
public void tearDown() throws Exception {
super.tearDown();
+ oos.close();
oos = null;
+ mockServer = null;
}
- public void testPerf(Builder builder, String label) throws IOException {
-
+ public void runPerfTest(Builder builder, String label) throws Exception {
+
// first run for just in time compiler
int counter = 0;
for (int i = 0; i < loopNumber; i++) {
- oos.writeObject(builder.build(i));
- oos.flush();
- if (++counter >= resetFrequency) {
- oos.reset();
+ try {
+ oos.writeObject(builder.build(i));
+ oos.flush();
+ if (++counter >= resetFrequency) {
+ oos.reset();
+ }
+ } catch (IOException ex) {
+ fail();
}
}
@@ -54,37 +79,47 @@
Long t2;
Long total = 0L;
counter = 0;
+ // System.out.println("Beginning mesured run");
t1 = System.nanoTime();
for (int i = 0; i < loopNumber; i++) {
- oos.writeObject(builder.build(i));
- oos.flush();
- if (++counter >= resetFrequency) {
- oos.reset();
+ try {
+ oos.writeObject(builder.build(i));
+ oos.flush();
+ if (++counter >= resetFrequency) {
+ oos.reset();
+ }
+ } catch (IOException ex) {
+ fail();
}
}
t2 = System.nanoTime();
total += (t2 - t1);
- System.out.println(label+" : average time = "
- + total / loopNumber + " after " + loopNumber + " writes.");
+ System.out.println(label + " : average time = " + total / loopNumber
+ + " after " + loopNumber + " writes.");
+
+ if (runWithMockServer) {
+ mockServer.join(1000);
+ assertTrue(mockServer.finished);
+ }
}
- public void testWithMinimalExternalization() throws IOException {
+ public void testWithMinimalExternalization() throws Exception {
Builder builder = new MinimalExtBuilder();
- testPerf(builder, "Minimal object externalization");
+ runPerfTest(builder, "Minimal object externalization");
}
- public void testWithMinimalSerialization() throws IOException {
+ public void testWithMinimalSerialization() throws Exception {
Builder builder = new MinimalSerBuilder();
- testPerf(builder, "Minimal object serialization");
+ runPerfTest(builder, "Minimal object serialization");
}
- public void testWithExternalization() throws IOException {
+ public void testWithExternalization() throws Exception {
Builder builder = new LoggingEventBuilder();
- testPerf(builder, "LoggingEvent object externalization");
+ runPerfTest(builder, "LoggingEvent object externalization");
}
- public void testWithSerialization() throws IOException {
+ public void testWithSerialization() throws Exception {
Builder builder = new LoggingEvent2Builder();
- testPerf(builder, "LoggingEvent object serialization");
+ runPerfTest(builder, "LoggingEvent object serialization");
}
}
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SocketAppenderTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SocketAppenderTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/SocketAppenderTest.java Thu Aug 31 15:01:05 2006
@@ -38,7 +38,7 @@
// finish much sooner than that.
mockServer.join(2000);
assertTrue(mockServer.finished);
- assertEquals("test", mockServer.msgList.get(0));
+ assertTrue(mockServer.msgList.get(0).startsWith("ch.qos.logback.classic.spi.LoggingEvent@"));
}
}
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/MinimalExtBuilder.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/MinimalExtBuilder.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/testObjectBuilders/MinimalExtBuilder.java Thu Aug 31 15:01:05 2006
@@ -20,6 +20,10 @@
String message;
+ //public no-args constructor is needed for Externalization
+ public MinimalExt() {
+ }
+
public MinimalExt(int i) {
// 45 characters message
message = "aaaaabbbbbcccccdddddaaaaabbbbbcccccdddddaaaa" + i;
More information about the logback-dev
mailing list