Prepare for tests refactoring + fix Netty4 UDP implementation
diff --git a/benchmarks/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java b/benchmarks/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java
index b55f367..5c2e85e 100644
--- a/benchmarks/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java
@@ -29,7 +29,6 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-import org.apache.mina.core.BenchmarkFactory.Type;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -63,9 +62,9 @@
this.timeout = timeout;
}
- public abstract Type getClientType();
+ public abstract BenchmarkClient getClient();
- public abstract Type getServerType();
+ public abstract BenchmarkServer getServer();
@Parameters(name = "{0} messages of size {1}")
public static Collection<Object[]> getParameters() {
@@ -94,9 +93,9 @@
@Before
public void init() throws IOException {
port = getNextAvailable();
- server = BenchmarkServerFactory.INSTANCE.get(getServerType());
+ server = getServer();
server.start(port);
- client = BenchmarkClientFactory.INSTANCE.get(getClientType());
+ client = getClient();
data = new byte[messageSize + 4];
data[0] = (byte) (messageSize >>> 24 & 255);
data[1] = (byte) (messageSize >>> 16 & 255);
@@ -119,7 +118,7 @@
CountDownLatch counter = new CountDownLatch(numberOfMessages);
CounterFilter.messageSent.set(0);
- boolean result = false;
+ boolean result = true;
System.out.println("-------------- Sending " + data.length + " bytes");
client.start(port, counter, data);
@@ -139,9 +138,10 @@
warmedUpSent += nbSent;
}
- System.out.println("Nb messages sent per second : " + nbSent);
+ System.out.print("Nb messages sent per second : " + nbSent + "\r");
}
+ System.out.println();
if (nbSeconds < 120) {
System.out.println("Average : " + (warmedUpSent / (nbSeconds - 5)) + ", for " + globalSent
+ " messages sent in " + nbSeconds + "s");
diff --git a/benchmarks/src/test/java/org/apache/mina/core/BenchmarkClientFactory.java b/benchmarks/src/test/java/org/apache/mina/core/BenchmarkClientFactory.java
deleted file mode 100644
index 1bfc492..0000000
--- a/benchmarks/src/test/java/org/apache/mina/core/BenchmarkClientFactory.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.mina.core;
-
-import org.apache.mina.core.bio.udp.BioUdpBenchmarkClient;
-import org.apache.mina.core.nio.tcp.Mina3TcpBenchmarkClient;
-import org.apache.mina.core.nio.tcp.Netty3TcpBenchmarkClient;
-import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkClient;
-import org.apache.mina.core.nio.udp.Netty3UdpBenchmarkClient;
-
-/**
- * @author <a href="http://mina.apache.org">Apache MINA Project</a>
- */
-public class BenchmarkClientFactory implements BenchmarkFactory<BenchmarkClient> {
-
- public static final BenchmarkClientFactory INSTANCE = new BenchmarkClientFactory();
-
- public BenchmarkClient get(Type type) {
- switch (type) {
- case Mina3_tcp:
- return new Mina3TcpBenchmarkClient();
- case Mina3_udp:
- return new Mina3UdpBenchmarkClient();
- case Netty3_tcp:
- return new Netty3TcpBenchmarkClient();
- case Netty3_udp:
- return new Netty3UdpBenchmarkClient();
- case Bio_tcp:
- //return new BioTcpBenchmarkClient();
- case Bio_udp:
- return new BioUdpBenchmarkClient();
- default:
- throw new IllegalArgumentException("Invalid type " + type);
- }
- }
-}
diff --git a/benchmarks/src/test/java/org/apache/mina/core/BenchmarkFactory.java b/benchmarks/src/test/java/org/apache/mina/core/BenchmarkFactory.java
deleted file mode 100644
index 7ade3b6..0000000
--- a/benchmarks/src/test/java/org/apache/mina/core/BenchmarkFactory.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.mina.core;
-
-/**
- * Common interface for client and server factories
- *
- * @author <a href="http://mina.apache.org">Apache MINA Project</a>
- */
-public interface BenchmarkFactory<T> {
- /**
- * The different types of providers
- */
- public enum Type {
- Mina3_tcp, Mina3_udp, Netty3_tcp, Netty3_udp, Netty4_tcp, Netty4_udp, Bio_tcp, Bio_udp
- }
-
- /**
- * Allocate a provider.
- *
- * @param type the provider type
- * @return the allocated provider
- */
- public T get(Type type);
-}
diff --git a/benchmarks/src/test/java/org/apache/mina/core/BenchmarkServerFactory.java b/benchmarks/src/test/java/org/apache/mina/core/BenchmarkServerFactory.java
deleted file mode 100644
index 21eeb0f..0000000
--- a/benchmarks/src/test/java/org/apache/mina/core/BenchmarkServerFactory.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.mina.core;
-
-import org.apache.mina.core.bio.udp.BioUdpBenchmarkServer;
-import org.apache.mina.core.nio.tcp.Mina3TcpBenchmarkServer;
-import org.apache.mina.core.nio.tcp.Netty3TcpBenchmarkServer;
-import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkServer;
-import org.apache.mina.core.nio.udp.Netty3UdpBenchmarkServer;
-
-/**
- * @author <a href="http://mina.apache.org">Apache MINA Project</a>
- */
-public class BenchmarkServerFactory implements BenchmarkFactory<BenchmarkServer> {
-
- public static final BenchmarkServerFactory INSTANCE = new BenchmarkServerFactory();
-
- /**
- * {@inheritedDoc}
- */
- public BenchmarkServer get(org.apache.mina.core.BenchmarkFactory.Type type) {
- switch (type) {
- case Mina3_tcp:
- return new Mina3TcpBenchmarkServer();
- case Mina3_udp:
- return new Mina3UdpBenchmarkServer();
- case Netty3_tcp:
- return new Netty3TcpBenchmarkServer();
- case Netty3_udp:
- return new Netty3UdpBenchmarkServer();
- case Bio_udp:
- return new BioUdpBenchmarkServer();
- case Bio_tcp:
- //return new BioUdpBenchmarkClient();
- default:
- throw new IllegalArgumentException("Invalid type " + type);
- }
- }
-}
diff --git a/benchmarks/src/test/java/org/apache/mina/core/BioClientVsBioServerUdpBenchmarkBinaryTest.java b/benchmarks/src/test/java/org/apache/mina/core/BioClientVsBioServerUdpBenchmarkBinaryTest.java
index f0260eb..815983d 100644
--- a/benchmarks/src/test/java/org/apache/mina/core/BioClientVsBioServerUdpBenchmarkBinaryTest.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/BioClientVsBioServerUdpBenchmarkBinaryTest.java
@@ -22,7 +22,8 @@
import java.util.Arrays;
import java.util.Collection;
-import org.apache.mina.core.BenchmarkFactory.Type;
+import org.apache.mina.core.bio.udp.BioUdpBenchmarkClient;
+import org.apache.mina.core.bio.udp.BioUdpBenchmarkServer;
import org.junit.runners.Parameterized.Parameters;
/**
@@ -42,16 +43,16 @@
* {@inheritDoc}
*/
@Override
- public Type getClientType() {
- return Type.Bio_udp;
+ public BenchmarkClient getClient() {
+ return new BioUdpBenchmarkClient();
}
/**
* {@inheritDoc}
*/
@Override
- public Type getServerType() {
- return Type.Bio_udp;
+ public BenchmarkServer getServer() {
+ return new BioUdpBenchmarkServer();
}
@Parameters(name = "{0} messages of size {1}")
diff --git a/benchmarks/src/test/java/org/apache/mina/core/BioClientVsMina3ServerUdpBenchmarkBinaryTest.java b/benchmarks/src/test/java/org/apache/mina/core/BioClientVsMina3ServerUdpBenchmarkBinaryTest.java
index 25d1980..f2f292b 100644
--- a/benchmarks/src/test/java/org/apache/mina/core/BioClientVsMina3ServerUdpBenchmarkBinaryTest.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/BioClientVsMina3ServerUdpBenchmarkBinaryTest.java
@@ -22,7 +22,8 @@
import java.util.Arrays;
import java.util.Collection;
-import org.apache.mina.core.BenchmarkFactory.Type;
+import org.apache.mina.core.bio.udp.BioUdpBenchmarkClient;
+import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkServer;
import org.junit.runners.Parameterized.Parameters;
/**
@@ -42,16 +43,16 @@
* {@inheritDoc}
*/
@Override
- public Type getClientType() {
- return Type.Bio_udp;
+ public BenchmarkClient getClient() {
+ return new BioUdpBenchmarkClient();
}
/**
* {@inheritDoc}
*/
@Override
- public Type getServerType() {
- return Type.Mina3_udp;
+ public BenchmarkServer getServer() {
+ return new Mina3UdpBenchmarkServer();
}
@Parameters(name = "{0} messages of size {1}")
diff --git a/benchmarks/src/test/java/org/apache/mina/core/Mina3ClientVsMina3ServerTcpBenchmarkBinaryTest.java b/benchmarks/src/test/java/org/apache/mina/core/Mina3ClientVsMina3ServerTcpBenchmarkBinaryTest.java
index 9135af6..600b5ae 100644
--- a/benchmarks/src/test/java/org/apache/mina/core/Mina3ClientVsMina3ServerTcpBenchmarkBinaryTest.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/Mina3ClientVsMina3ServerTcpBenchmarkBinaryTest.java
@@ -22,7 +22,8 @@
import java.util.Arrays;
import java.util.Collection;
-import org.apache.mina.core.BenchmarkFactory.Type;
+import org.apache.mina.core.nio.tcp.Mina3TcpBenchmarkClient;
+import org.apache.mina.core.nio.tcp.Mina3TcpBenchmarkServer;
import org.junit.runners.Parameterized.Parameters;
/**
@@ -42,16 +43,16 @@
* {@inheritDoc}
*/
@Override
- public Type getClientType() {
- return Type.Mina3_tcp;
+ public BenchmarkClient getClient() {
+ return new Mina3TcpBenchmarkClient();
}
/**
* {@inheritDoc}
*/
@Override
- public Type getServerType() {
- return Type.Mina3_tcp;
+ public BenchmarkServer getServer() {
+ return new Mina3TcpBenchmarkServer();
}
@Parameters(name = "{0} messages of size {1}")
diff --git a/benchmarks/src/test/java/org/apache/mina/core/Mina3ClientVsMina3ServerUdpBenchmarkBinaryTest.java b/benchmarks/src/test/java/org/apache/mina/core/Mina3ClientVsMina3ServerUdpBenchmarkBinaryTest.java
index 96d726e..7ea251b 100644
--- a/benchmarks/src/test/java/org/apache/mina/core/Mina3ClientVsMina3ServerUdpBenchmarkBinaryTest.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/Mina3ClientVsMina3ServerUdpBenchmarkBinaryTest.java
@@ -22,7 +22,8 @@
import java.util.Arrays;
import java.util.Collection;
-import org.apache.mina.core.BenchmarkFactory.Type;
+import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkClient;
+import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkServer;
import org.junit.runners.Parameterized.Parameters;
/**
@@ -42,16 +43,16 @@
* {@inheritDoc}
*/
@Override
- public Type getClientType() {
- return Type.Mina3_udp;
+ public BenchmarkClient getClient() {
+ return new Mina3UdpBenchmarkClient();
}
/**
* {@inheritDoc}
*/
@Override
- public Type getServerType() {
- return Type.Mina3_udp;
+ public BenchmarkServer getServer() {
+ return new Mina3UdpBenchmarkServer();
}
@Parameters(name = "{0} messages of size {1}")
diff --git a/benchmarks/src/test/java/org/apache/mina/core/Mina3ClientVsNetty3ServerTcpBenchmarkBinaryTest.java b/benchmarks/src/test/java/org/apache/mina/core/Mina3ClientVsNetty3ServerTcpBenchmarkBinaryTest.java
index 7ce1769..077f695 100644
--- a/benchmarks/src/test/java/org/apache/mina/core/Mina3ClientVsNetty3ServerTcpBenchmarkBinaryTest.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/Mina3ClientVsNetty3ServerTcpBenchmarkBinaryTest.java
@@ -22,7 +22,8 @@
import java.util.Arrays;
import java.util.Collection;
-import org.apache.mina.core.BenchmarkFactory.Type;
+import org.apache.mina.core.nio.tcp.Mina3TcpBenchmarkClient;
+import org.apache.mina.core.nio.tcp.Netty3TcpBenchmarkServer;
import org.junit.runners.Parameterized.Parameters;
/**
@@ -42,16 +43,16 @@
* {@inheritDoc}
*/
@Override
- public Type getClientType() {
- return Type.Mina3_tcp;
+ public BenchmarkClient getClient() {
+ return new Mina3TcpBenchmarkClient();
}
/**
* {@inheritDoc}
*/
@Override
- public Type getServerType() {
- return Type.Netty3_tcp;
+ public BenchmarkServer getServer() {
+ return new Netty3TcpBenchmarkServer();
}
@Parameters()
diff --git a/benchmarks/src/test/java/org/apache/mina/core/Netty3ClientVsMina3ServerTcpBenchmarkBinaryTest.java b/benchmarks/src/test/java/org/apache/mina/core/Netty3ClientVsMina3ServerTcpBenchmarkBinaryTest.java
index b93b799..4c30661 100644
--- a/benchmarks/src/test/java/org/apache/mina/core/Netty3ClientVsMina3ServerTcpBenchmarkBinaryTest.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/Netty3ClientVsMina3ServerTcpBenchmarkBinaryTest.java
@@ -22,7 +22,8 @@
import java.util.Arrays;
import java.util.Collection;
-import org.apache.mina.core.BenchmarkFactory.Type;
+import org.apache.mina.core.nio.tcp.Mina3TcpBenchmarkServer;
+import org.apache.mina.core.nio.tcp.Netty3TcpBenchmarkClient;
import org.junit.runners.Parameterized.Parameters;
/**
@@ -41,15 +42,15 @@
/** {@inheritDoc}
*/
@Override
- public Type getClientType() {
- return Type.Netty3_tcp;
+ public BenchmarkClient getClient() {
+ return new Netty3TcpBenchmarkClient();
}
/** {@inheritDoc}
*/
@Override
- public Type getServerType() {
- return Type.Mina3_tcp;
+ public BenchmarkServer getServer() {
+ return new Mina3TcpBenchmarkServer();
}
//TODO: analyze with Netty is so slow on large message: last test lower to 100 messages
diff --git a/benchmarks/src/test/java/org/apache/mina/core/Netty3ClientVsMina3ServerUdpBenchmarkBinaryTest.java b/benchmarks/src/test/java/org/apache/mina/core/Netty3ClientVsMina3ServerUdpBenchmarkBinaryTest.java
index 13b74ab..5a6e08d 100644
--- a/benchmarks/src/test/java/org/apache/mina/core/Netty3ClientVsMina3ServerUdpBenchmarkBinaryTest.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/Netty3ClientVsMina3ServerUdpBenchmarkBinaryTest.java
@@ -22,7 +22,8 @@
import java.util.Arrays;
import java.util.Collection;
-import org.apache.mina.core.BenchmarkFactory.Type;
+import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkServer;
+import org.apache.mina.core.nio.udp.Netty3UdpBenchmarkClient;
import org.junit.runners.Parameterized.Parameters;
/**
@@ -41,15 +42,15 @@
/** {@inheritDoc}
*/
@Override
- public Type getClientType() {
- return Type.Netty3_udp;
+ public BenchmarkClient getClient() {
+ return new Netty3UdpBenchmarkClient();
}
/** {@inheritDoc}
*/
@Override
- public Type getServerType() {
- return Type.Mina3_udp;
+ public BenchmarkServer getServer() {
+ return new Mina3UdpBenchmarkServer();
}
@Parameters(name = "{0} messages of size {1}")
diff --git a/benchmarks/src/test/java/org/apache/mina/core/Netty3ClientVsNetty3ServerTcpBenchmarkBinaryTest.java b/benchmarks/src/test/java/org/apache/mina/core/Netty3ClientVsNetty3ServerTcpBenchmarkBinaryTest.java
index 0ba293c..a0bccd6 100644
--- a/benchmarks/src/test/java/org/apache/mina/core/Netty3ClientVsNetty3ServerTcpBenchmarkBinaryTest.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/Netty3ClientVsNetty3ServerTcpBenchmarkBinaryTest.java
@@ -22,7 +22,8 @@
import java.util.Arrays;
import java.util.Collection;
-import org.apache.mina.core.BenchmarkFactory.Type;
+import org.apache.mina.core.nio.tcp.Netty3TcpBenchmarkClient;
+import org.apache.mina.core.nio.tcp.Netty3TcpBenchmarkServer;
import org.junit.runners.Parameterized.Parameters;
/**
@@ -41,15 +42,15 @@
/** {@inheritDoc}
*/
@Override
- public Type getClientType() {
- return Type.Netty3_tcp;
+ public BenchmarkClient getClient() {
+ return new Netty3TcpBenchmarkClient();
}
/** {@inheritDoc}
*/
@Override
- public Type getServerType() {
- return Type.Netty3_tcp;
+ public BenchmarkServer getServer() {
+ return new Netty3TcpBenchmarkServer();
}
//TODO: analyze with Netty is so slow on large message: last test lower to 100 messages
diff --git a/benchmarks/src/test/java/org/apache/mina/core/Netty3ClientVsNetty3ServerUdpBenchmarkBinaryTest.java b/benchmarks/src/test/java/org/apache/mina/core/Netty3ClientVsNetty3ServerUdpBenchmarkBinaryTest.java
index 5b0c74b..76d9bf8 100644
--- a/benchmarks/src/test/java/org/apache/mina/core/Netty3ClientVsNetty3ServerUdpBenchmarkBinaryTest.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/Netty3ClientVsNetty3ServerUdpBenchmarkBinaryTest.java
@@ -22,7 +22,8 @@
import java.util.Arrays;
import java.util.Collection;
-import org.apache.mina.core.BenchmarkFactory.Type;
+import org.apache.mina.core.nio.udp.Netty3UdpBenchmarkClient;
+import org.apache.mina.core.nio.udp.Netty3UdpBenchmarkServer;
import org.junit.runners.Parameterized.Parameters;
/**
@@ -41,15 +42,15 @@
/** {@inheritDoc}
*/
@Override
- public Type getClientType() {
- return Type.Netty3_udp;
+ public BenchmarkClient getClient() {
+ return new Netty3UdpBenchmarkClient();
}
/** {@inheritDoc}
*/
@Override
- public Type getServerType() {
- return Type.Netty3_udp;
+ public BenchmarkServer getServer() {
+ return new Netty3UdpBenchmarkServer();
}
@Parameters(name = "{0} messages of size {1}")
diff --git a/benchmarks/src/test/java/org/apache/mina/core/bio/udp/BioUdpBenchmarkServer.java b/benchmarks/src/test/java/org/apache/mina/core/bio/udp/BioUdpBenchmarkServer.java
index 3090565..fd9af8d 100644
--- a/benchmarks/src/test/java/org/apache/mina/core/bio/udp/BioUdpBenchmarkServer.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/bio/udp/BioUdpBenchmarkServer.java
@@ -28,6 +28,7 @@
import org.apache.mina.api.IoService;
import org.apache.mina.api.IoSession;
import org.apache.mina.core.BenchmarkServer;
+import org.apache.mina.core.CounterFilter;
import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkServer;
import org.apache.mina.session.AttributeKey;
import org.apache.mina.transport.bio.BioUdpServer;
@@ -141,7 +142,7 @@
@Override
public void messageSent(IoSession session, Object message) {
- //System.out.println("Server message sent :" + message);
+ CounterFilter.messageSent.getAndIncrement();
}
@Override
diff --git a/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Mina3UdpBenchmarkServer.java b/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Mina3UdpBenchmarkServer.java
index 48b84b8..a9bf2a9 100644
--- a/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Mina3UdpBenchmarkServer.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Mina3UdpBenchmarkServer.java
@@ -28,6 +28,7 @@
import org.apache.mina.api.IoService;
import org.apache.mina.api.IoSession;
import org.apache.mina.core.BenchmarkServer;
+import org.apache.mina.core.CounterFilter;
import org.apache.mina.session.AttributeKey;
import org.apache.mina.transport.nio.NioUdpServer;
import org.apache.mina.transport.udp.DefaultUdpSessionConfig;
@@ -141,7 +142,7 @@
@Override
public void messageSent(IoSession session, Object message) {
- //System.out.println("Server message sent :" + message);
+ CounterFilter.messageSent.getAndIncrement();
}
@Override
diff --git a/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Netty3UdpBenchmarkServer.java b/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Netty3UdpBenchmarkServer.java
index 155da87..fa2d5c8 100644
--- a/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Netty3UdpBenchmarkServer.java
+++ b/benchmarks/src/test/java/org/apache/mina/core/nio/udp/Netty3UdpBenchmarkServer.java
@@ -26,6 +26,7 @@
import java.util.Map;
import org.apache.mina.core.BenchmarkServer;
+import org.apache.mina.core.CounterFilter;
import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
@@ -39,6 +40,7 @@
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
+import org.jboss.netty.channel.WriteCompletionEvent;
import org.jboss.netty.channel.group.ChannelGroup;
import org.jboss.netty.channel.group.DefaultChannelGroup;
import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory;
@@ -165,6 +167,11 @@
}
@Override
+ public void writeComplete(ChannelHandlerContext ctx, WriteCompletionEvent e) throws Exception {
+ CounterFilter.messageSent.getAndIncrement();
+ }
+
+ @Override
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
allChannels.remove(ctx.getChannel());
}
diff --git a/benchmarks2/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java b/benchmarks2/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java
index 7b9c8ff..59e1e4a 100644
--- a/benchmarks2/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java
+++ b/benchmarks2/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java
@@ -29,7 +29,6 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-import org.apache.mina.core.BenchmarkFactory.Type;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -62,9 +61,9 @@
this.timeout = timeout;
}
- public abstract Type getClientType();
+ public abstract BenchmarkClient getClient();
- public abstract Type getServerType();
+ public abstract BenchmarkServer getServer();
@Parameters(name = "{0} messages of size {1}")
public static Collection<Object[]> getParameters() {
@@ -93,9 +92,9 @@
@Before
public void init() throws IOException {
port = getNextAvailable();
- server = BenchmarkServerFactory.INSTANCE.get(getServerType());
+ server = getServer();
server.start(port);
- client = BenchmarkClientFactory.INSTANCE.get(getClientType());
+ client = getClient();
data = new byte[messageSize + 4];
data[0] = (byte) (messageSize >>> 24 & 255);
data[1] = (byte) (messageSize >>> 16 & 255);
diff --git a/benchmarks2/src/test/java/org/apache/mina/core/BenchmarkClientFactory.java b/benchmarks2/src/test/java/org/apache/mina/core/BenchmarkClientFactory.java
deleted file mode 100644
index ecf00f7..0000000
--- a/benchmarks2/src/test/java/org/apache/mina/core/BenchmarkClientFactory.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.mina.core;
-
-import org.apache.mina.core.nio.tcp.Netty4TcpBenchmarkClient;
-import org.apache.mina.core.nio.udp.Netty4UdpBenchmarkClient;
-
-/**
- * @author <a href="http://mina.apache.org">Apache MINA Project</a>
- */
-public class BenchmarkClientFactory implements BenchmarkFactory<BenchmarkClient> {
-
- public static final BenchmarkClientFactory INSTANCE = new BenchmarkClientFactory();
-
- public BenchmarkClient get(Type type) {
- switch (type) {
- case Netty4_tcp:
- return new Netty4TcpBenchmarkClient();
- case Netty4_udp:
- return new Netty4UdpBenchmarkClient();
- default:
- throw new IllegalArgumentException("Invalid type " + type);
- }
- }
-}
diff --git a/benchmarks2/src/test/java/org/apache/mina/core/BenchmarkFactory.java b/benchmarks2/src/test/java/org/apache/mina/core/BenchmarkFactory.java
deleted file mode 100644
index 1db23ad..0000000
--- a/benchmarks2/src/test/java/org/apache/mina/core/BenchmarkFactory.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.mina.core;
-
-/**
- * Common interface for client and server factories
- *
- * @author <a href="http://mina.apache.org">Apache MINA Project</a>
- */
-public interface BenchmarkFactory<T> {
- /**
- * The different types of providers
- */
- public enum Type {
- Mina3_udp, Mina3_tcp, Netty4_tcp, Netty4_udp
- }
-
- /**
- * Allocate a provider.
- *
- * @param type the provider type
- * @return the allocated provider
- */
- public T get(Type type);
-}
diff --git a/benchmarks2/src/test/java/org/apache/mina/core/BenchmarkServerFactory.java b/benchmarks2/src/test/java/org/apache/mina/core/BenchmarkServerFactory.java
deleted file mode 100644
index 686c30f..0000000
--- a/benchmarks2/src/test/java/org/apache/mina/core/BenchmarkServerFactory.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.mina.core;
-
-import org.apache.mina.core.nio.tcp.Mina3TcpBenchmarkServer;
-import org.apache.mina.core.nio.tcp.Netty4TcpBenchmarkServer;
-import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkServer;
-import org.apache.mina.core.nio.udp.Netty4UdpBenchmarkServer;
-
-/**
- * @author <a href="http://mina.apache.org">Apache MINA Project</a>
- */
-public class BenchmarkServerFactory implements BenchmarkFactory<BenchmarkServer> {
-
- public static final BenchmarkServerFactory INSTANCE = new BenchmarkServerFactory();
-
- /**
- * {@inheritedDoc}
- */
- public BenchmarkServer get(org.apache.mina.core.BenchmarkFactory.Type type) {
- switch (type) {
- case Mina3_tcp:
- return new Mina3TcpBenchmarkServer();
- case Mina3_udp:
- return new Mina3UdpBenchmarkServer();
- case Netty4_tcp:
- return new Netty4TcpBenchmarkServer();
- case Netty4_udp:
- return new Netty4UdpBenchmarkServer();
- default:
- throw new IllegalArgumentException("Invalid type " + type);
- }
- }
-}
diff --git a/benchmarks2/src/test/java/org/apache/mina/core/Netty4BenchmarkServer.java b/benchmarks2/src/test/java/org/apache/mina/core/Netty4BenchmarkServer.java
new file mode 100644
index 0000000..2b4b92e
--- /dev/null
+++ b/benchmarks2/src/test/java/org/apache/mina/core/Netty4BenchmarkServer.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.mina.core;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.util.AttributeKey;
+
+/**
+ * A Netty 4 Server.
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public abstract class Netty4BenchmarkServer implements BenchmarkServer {
+
+ protected static final AttributeKey<State> STATE_ATTRIBUTE = new AttributeKey<State>("state");
+
+ protected static final AttributeKey<Integer> LENGTH_ATTRIBUTE = new AttributeKey<Integer>("length");
+
+ protected static enum State {
+ WAIT_FOR_FIRST_BYTE_LENGTH, WAIT_FOR_SECOND_BYTE_LENGTH, WAIT_FOR_THIRD_BYTE_LENGTH, WAIT_FOR_FOURTH_BYTE_LENGTH, READING
+ }
+
+ protected static final ByteBuf ACK = Unpooled.buffer(1);
+
+ static {
+ ACK.writeByte(0);
+ }
+
+}
diff --git a/benchmarks2/src/test/java/org/apache/mina/core/Netty4ClientVsMina3ServerTcpBenchmarkBinaryTest.java b/benchmarks2/src/test/java/org/apache/mina/core/Netty4ClientVsMina3ServerTcpBenchmarkBinaryTest.java
index e51f82c..80058e0 100644
--- a/benchmarks2/src/test/java/org/apache/mina/core/Netty4ClientVsMina3ServerTcpBenchmarkBinaryTest.java
+++ b/benchmarks2/src/test/java/org/apache/mina/core/Netty4ClientVsMina3ServerTcpBenchmarkBinaryTest.java
@@ -22,7 +22,8 @@
import java.util.Arrays;
import java.util.Collection;
-import org.apache.mina.core.BenchmarkFactory.Type;
+import org.apache.mina.core.nio.tcp.Mina3TcpBenchmarkServer;
+import org.apache.mina.core.nio.tcp.Netty4TcpBenchmarkClient;
import org.junit.runners.Parameterized.Parameters;
/**
@@ -43,15 +44,15 @@
/** {@inheritDoc}
*/
@Override
- public Type getClientType() {
- return Type.Netty4_tcp;
+ public BenchmarkClient getClient() {
+ return new Netty4TcpBenchmarkClient();
}
/** {@inheritDoc}
*/
@Override
- public Type getServerType() {
- return Type.Mina3_tcp;
+ public BenchmarkServer getServer() {
+ return new Mina3TcpBenchmarkServer();
}
//TODO: analyze with Netty is so slow on large message: last test lower to 100 messages
diff --git a/benchmarks2/src/test/java/org/apache/mina/core/Netty4ClientVsMina3ServerUdpBenchmarkBinaryTest.java b/benchmarks2/src/test/java/org/apache/mina/core/Netty4ClientVsMina3ServerUdpBenchmarkBinaryTest.java
index d1a5217..c545447 100644
--- a/benchmarks2/src/test/java/org/apache/mina/core/Netty4ClientVsMina3ServerUdpBenchmarkBinaryTest.java
+++ b/benchmarks2/src/test/java/org/apache/mina/core/Netty4ClientVsMina3ServerUdpBenchmarkBinaryTest.java
@@ -22,7 +22,8 @@
import java.util.Arrays;
import java.util.Collection;
-import org.apache.mina.core.BenchmarkFactory.Type;
+import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkServer;
+import org.apache.mina.core.nio.udp.Netty4UdpBenchmarkClient;
import org.junit.runners.Parameterized.Parameters;
/**
@@ -43,15 +44,15 @@
/** {@inheritDoc}
*/
@Override
- public Type getClientType() {
- return Type.Netty4_udp;
+ public BenchmarkClient getClient() {
+ return new Netty4UdpBenchmarkClient();
}
/** {@inheritDoc}
*/
@Override
- public Type getServerType() {
- return Type.Mina3_udp;
+ public BenchmarkServer getServer() {
+ return new Mina3UdpBenchmarkServer();
}
@Parameters(name = "{0} messages of size {1}")
diff --git a/benchmarks2/src/test/java/org/apache/mina/core/Netty4ClientVsNetty4ServerTcpBenchmarkBinaryTest.java b/benchmarks2/src/test/java/org/apache/mina/core/Netty4ClientVsNetty4ServerTcpBenchmarkBinaryTest.java
index 03db99e..b109eec 100644
--- a/benchmarks2/src/test/java/org/apache/mina/core/Netty4ClientVsNetty4ServerTcpBenchmarkBinaryTest.java
+++ b/benchmarks2/src/test/java/org/apache/mina/core/Netty4ClientVsNetty4ServerTcpBenchmarkBinaryTest.java
@@ -22,7 +22,8 @@
import java.util.Arrays;
import java.util.Collection;
-import org.apache.mina.core.BenchmarkFactory.Type;
+import org.apache.mina.core.nio.tcp.Netty4TcpBenchmarkClient;
+import org.apache.mina.core.nio.tcp.Netty4TcpBenchmarkServer;
import org.junit.runners.Parameterized.Parameters;
/**
@@ -43,15 +44,15 @@
/** {@inheritDoc}
*/
@Override
- public Type getClientType() {
- return Type.Netty4_tcp;
+ public BenchmarkClient getClient() {
+ return new Netty4TcpBenchmarkClient();
}
/** {@inheritDoc}
*/
@Override
- public Type getServerType() {
- return Type.Netty4_tcp;
+ public BenchmarkServer getServer() {
+ return new Netty4TcpBenchmarkServer();
}
//TODO: analyze with Netty is so slow on large message: last test lower to 100 messages
diff --git a/benchmarks2/src/test/java/org/apache/mina/core/Netty4ClientVsNetty4ServerUdpBenchmarkBinaryTest.java b/benchmarks2/src/test/java/org/apache/mina/core/Netty4ClientVsNetty4ServerUdpBenchmarkBinaryTest.java
index 7654549..daa87a7 100644
--- a/benchmarks2/src/test/java/org/apache/mina/core/Netty4ClientVsNetty4ServerUdpBenchmarkBinaryTest.java
+++ b/benchmarks2/src/test/java/org/apache/mina/core/Netty4ClientVsNetty4ServerUdpBenchmarkBinaryTest.java
@@ -22,7 +22,8 @@
import java.util.Arrays;
import java.util.Collection;
-import org.apache.mina.core.BenchmarkFactory.Type;
+import org.apache.mina.core.nio.udp.Netty4UdpBenchmarkClient;
+import org.apache.mina.core.nio.udp.Netty4UdpBenchmarkServer;
import org.junit.runners.Parameterized.Parameters;
/**
@@ -43,15 +44,15 @@
/** {@inheritDoc}
*/
@Override
- public Type getClientType() {
- return Type.Netty4_udp;
+ public BenchmarkClient getClient() {
+ return new Netty4UdpBenchmarkClient();
}
/** {@inheritDoc}
*/
@Override
- public Type getServerType() {
- return Type.Netty4_udp;
+ public BenchmarkServer getServer() {
+ return new Netty4UdpBenchmarkServer();
}
@Parameters(name = "{0} messages of size {1}")
diff --git a/benchmarks2/src/test/java/org/apache/mina/core/nio/tcp/Netty4TcpBenchmarkServer.java b/benchmarks2/src/test/java/org/apache/mina/core/nio/tcp/Netty4TcpBenchmarkServer.java
index 13a8a78..c7f3f84 100644
--- a/benchmarks2/src/test/java/org/apache/mina/core/nio/tcp/Netty4TcpBenchmarkServer.java
+++ b/benchmarks2/src/test/java/org/apache/mina/core/nio/tcp/Netty4TcpBenchmarkServer.java
@@ -21,7 +21,6 @@
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
@@ -31,31 +30,16 @@
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.util.Attribute;
-import io.netty.util.AttributeKey;
import java.io.IOException;
-import org.apache.mina.core.BenchmarkServer;
+import org.apache.mina.core.Netty4BenchmarkServer;
/**
- * A Netty 3 TCP Server.
+ * A Netty 4 TCP Server.
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class Netty4TcpBenchmarkServer implements BenchmarkServer {
-
- private static enum State {
- WAIT_FOR_FIRST_BYTE_LENGTH, WAIT_FOR_SECOND_BYTE_LENGTH, WAIT_FOR_THIRD_BYTE_LENGTH, WAIT_FOR_FOURTH_BYTE_LENGTH, READING
- }
-
- private static final ByteBuf ACK = Unpooled.buffer(1);
-
- static {
- ACK.writeByte(0);
- }
-
- private static final AttributeKey<State> STATE_ATTRIBUTE = new AttributeKey<State>("state");
-
- private static final AttributeKey<Integer> LENGTH_ATTRIBUTE = new AttributeKey<Integer>("length");
+public class Netty4TcpBenchmarkServer extends Netty4BenchmarkServer {
private ServerBootstrap bootstrap = null;
diff --git a/benchmarks2/src/test/java/org/apache/mina/core/nio/udp/Netty4UdpBenchmarkClient.java b/benchmarks2/src/test/java/org/apache/mina/core/nio/udp/Netty4UdpBenchmarkClient.java
index 267dffb..cc2ae09 100644
--- a/benchmarks2/src/test/java/org/apache/mina/core/nio/udp/Netty4UdpBenchmarkClient.java
+++ b/benchmarks2/src/test/java/org/apache/mina/core/nio/udp/Netty4UdpBenchmarkClient.java
@@ -37,7 +37,7 @@
import org.apache.mina.core.BenchmarkClient;
/**
- * A Netty 3 based UDP client
+ * A Netty 4 based UDP client
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public class Netty4UdpBenchmarkClient implements BenchmarkClient {
diff --git a/benchmarks2/src/test/java/org/apache/mina/core/nio/udp/Netty4UdpBenchmarkServer.java b/benchmarks2/src/test/java/org/apache/mina/core/nio/udp/Netty4UdpBenchmarkServer.java
index be1c625..c21ba76 100644
--- a/benchmarks2/src/test/java/org/apache/mina/core/nio/udp/Netty4UdpBenchmarkServer.java
+++ b/benchmarks2/src/test/java/org/apache/mina/core/nio/udp/Netty4UdpBenchmarkServer.java
@@ -20,9 +20,7 @@
package org.apache.mina.core.nio.udp;
import io.netty.bootstrap.Bootstrap;
-import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
@@ -32,31 +30,17 @@
import io.netty.channel.socket.DatagramPacket;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.util.Attribute;
-import io.netty.util.AttributeKey;
import java.io.IOException;
-import org.apache.mina.core.BenchmarkServer;
+
+import org.apache.mina.core.Netty4BenchmarkServer;
/**
- * A Netty 3 based UDP server
+ * A Netty 4 based UDP server
*
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
-public class Netty4UdpBenchmarkServer implements BenchmarkServer {
-
- private static enum State {
- WAIT_FOR_FIRST_BYTE_LENGTH, WAIT_FOR_SECOND_BYTE_LENGTH, WAIT_FOR_THIRD_BYTE_LENGTH, WAIT_FOR_FOURTH_BYTE_LENGTH, READING
- }
-
- private static final ByteBuf ACK = Unpooled.buffer(1);
-
- private static final AttributeKey<State> STATE_ATTRIBUTE = new AttributeKey<State>("state");
-
- private static final AttributeKey<Integer> LENGTH_ATTRIBUTE = new AttributeKey<Integer>("length");
-
- static {
- ACK.writeByte(0);
- }
+public class Netty4UdpBenchmarkServer extends Netty4BenchmarkServer {
private Bootstrap bootstrap;