Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-08-15 03:06:35 -0400
committerEike Stepper2012-08-15 03:06:35 -0400
commit7eb4acd2f91f852946fb40ad647740dc69e8b69b (patch)
treec41bce7ac0ad531ecd3b8fa77420b8ae88f03deb /plugins/org.eclipse.net4j.tests/src/org
parent7cc89ae0efe2ab1fd6d4ed071b4a6f96852ff336 (diff)
downloadcdo-7eb4acd2f91f852946fb40ad647740dc69e8b69b.tar.gz
cdo-7eb4acd2f91f852946fb40ad647740dc69e8b69b.tar.xz
cdo-7eb4acd2f91f852946fb40ad647740dc69e8b69b.zip
[259086] Protocol versions should be checked
https://bugs.eclipse.org/bugs/show_bug.cgi?id=259086
Diffstat (limited to 'plugins/org.eclipse.net4j.tests/src/org')
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java11
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java116
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_259086_Test.java141
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java33
4 files changed, 254 insertions, 47 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
index 6543c4dc52..6044b890f8 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
@@ -11,6 +11,7 @@
package org.eclipse.net4j.tests;
import org.eclipse.net4j.tests.bugzilla.Bugzilla_241463_Test;
+import org.eclipse.net4j.tests.bugzilla.Bugzilla_259086_Test;
import org.eclipse.net4j.tests.bugzilla.Bugzilla_262875_Test;
import org.eclipse.net4j.util.tests.ExpectedIOTest;
import org.eclipse.net4j.util.tests.ExtendedIOTest;
@@ -44,26 +45,22 @@ public class AllTests
suite.addTestSuite(StringCompressorTest.class);
suite.addTestSuite(ChannelTest.JVM.class);
suite.addTestSuite(ChannelTest.TCP.class);
- // suite.addTestSuite(ChannelTest.SSL.class);
suite.addTestSuite(TCPConnectorTest.TCP.class);
- // suite.addTestSuite(TCPConnectorTest.SSL.class);
suite.addTestSuite(TransportTest.JVM.class);
suite.addTestSuite(TransportTest.TCP.class);
- // suite.addTestSuite(TransportTest.SSL.class);
suite.addTestSuite(SignalTest.TCP.class);
- // suite.addTestSuite(SignalTest.SSL.class);
suite.addTestSuite(SignalMonitorTest.TCP.class);
- // suite.addTestSuite(SignalMonitorTest.SSL.class);
suite.addTestSuite(ExceptionTest.TCP.class);
- // suite.addTestSuite(ExceptionTest.SSL.class);
suite.addTestSuite(SecurityTest.class);
suite.addTestSuite(QueueWorkerWorkSerializerTest.class);
suite.addTestSuite(ExpectedIOTest.class);
// Bugzillas
+ suite.addTestSuite(Bugzilla_241463_Test.JVM.class);
suite.addTestSuite(Bugzilla_241463_Test.TCP.class);
- // suite.addTestSuite(Bugzilla_241463_Test.SSL.class);
suite.addTestSuite(Bugzilla_262875_Test.class);
+ suite.addTestSuite(Bugzilla_259086_Test.JVM.class);
+ suite.addTestSuite(Bugzilla_259086_Test.TCP.class);
// Defs
// suite.addTestSuite(TestDefTest.class);
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java
index 95d46d8b6e..2b31b8c758 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java
@@ -7,32 +7,30 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - maintenance (SSL)
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - maintenance (SSL)
*/
package org.eclipse.net4j.tests.bugzilla;
-import org.eclipse.net4j.TransportInjector;
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.internal.jvm.JVMAcceptor;
+import org.eclipse.net4j.internal.jvm.JVMAcceptorFactory;
+import org.eclipse.net4j.internal.jvm.JVMClientConnector;
+import org.eclipse.net4j.internal.jvm.JVMServerConnector;
import org.eclipse.net4j.internal.tcp.TCPAcceptor;
import org.eclipse.net4j.internal.tcp.TCPAcceptorFactory;
-import org.eclipse.net4j.internal.tcp.TCPConnectorFactory;
-import org.eclipse.net4j.internal.tcp.TCPSelectorFactory;
-import org.eclipse.net4j.internal.tcp.TCPSelectorInjector;
import org.eclipse.net4j.internal.tcp.TCPServerConnector;
import org.eclipse.net4j.internal.tcp.ssl.SSLAcceptor;
import org.eclipse.net4j.internal.tcp.ssl.SSLAcceptorFactory;
-import org.eclipse.net4j.internal.tcp.ssl.SSLConnectorFactory;
import org.eclipse.net4j.internal.tcp.ssl.SSLServerConnector;
+import org.eclipse.net4j.jvm.JVMUtil;
import org.eclipse.net4j.tcp.ITCPAcceptor;
import org.eclipse.net4j.tcp.ITCPSelector;
+import org.eclipse.net4j.tcp.TCPUtil;
+import org.eclipse.net4j.tcp.ssl.SSLUtil;
import org.eclipse.net4j.tests.AbstractTransportTest;
-import org.eclipse.net4j.tests.ChannelTest;
import org.eclipse.net4j.tests.signal.TestSignalProtocol;
-import org.eclipse.net4j.util.concurrent.ExecutorServiceFactory;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.container.ManagedContainer;
-import org.eclipse.net4j.util.security.RandomizerFactory;
-
-import org.eclipse.internal.net4j.buffer.BufferProviderFactory;
import org.eclipse.spi.net4j.InternalChannel;
@@ -41,6 +39,8 @@ import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
/**
+ * See bug 241463.
+ *
* @author Eike Stepper
*/
public class Bugzilla_241463_Test extends AbstractTransportTest
@@ -49,30 +49,15 @@ public class Bugzilla_241463_Test extends AbstractTransportTest
protected IManagedContainer createContainer()
{
IManagedContainer container = new ManagedContainer();
+ Net4jUtil.prepareContainer(container);
+ JVMUtil.prepareContainer(container);
+ TCPUtil.prepareContainer(container);
+ SSLUtil.prepareContainer(container);
- // Net4j
- container.registerFactory(new ExecutorServiceFactory());
- container.registerFactory(new BufferProviderFactory());
- container.registerFactory(new RandomizerFactory());
- container.addPostProcessor(new TransportInjector());
+ container.registerFactory(new FakeJVMAcceptorFactory());
+ container.registerFactory(new FakeTCPAcceptorFactory());
+ container.registerFactory(new FakeSSLAcceptorFactory());
- container.registerFactory(new TCPSelectorFactory());
- container.addPostProcessor(new TCPSelectorInjector());
-
- if (useSSLTransport())
- {
- // SSL
- container.registerFactory(new FakeSSLAcceptorFactory());
- container.registerFactory(new SSLConnectorFactory());
- }
- else
- {
- // TCP
- container.registerFactory(new FakeAcceptorFactory());
- container.registerFactory(new TCPConnectorFactory());
- }
-
- // Test
container.registerFactory(new TestSignalProtocol.Factory());
return container;
}
@@ -95,7 +80,42 @@ public class Bugzilla_241463_Test extends AbstractTransportTest
/**
* @author Eike Stepper
*/
- private static final class FakeAcceptorFactory extends TCPAcceptorFactory
+ private static final class FakeJVMAcceptorFactory extends JVMAcceptorFactory
+ {
+ @Override
+ public JVMAcceptor create(String description)
+ {
+ JVMAcceptor acceptor = new JVMAcceptor()
+ {
+ @Override
+ public JVMServerConnector handleAccept(JVMClientConnector client)
+ {
+ JVMServerConnector connector = new JVMServerConnector(client)
+ {
+ @Override
+ public InternalChannel inverseOpenChannel(short channelID, String protocolID, int protocolVersion)
+ {
+ throw new RuntimeException("Simulated problem"); //$NON-NLS-1$
+ }
+ };
+
+ connector.setName(client.getName());
+ connector.setConfig(getConfig());
+ connector.activate();
+ addConnector(connector);
+ return connector;
+ }
+ };
+
+ acceptor.setName(description);
+ return acceptor;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class FakeTCPAcceptorFactory extends TCPAcceptorFactory
{
@Override
public TCPAcceptor create(String description)
@@ -108,7 +128,7 @@ public class Bugzilla_241463_Test extends AbstractTransportTest
return new TCPServerConnector(this)
{
@Override
- public InternalChannel inverseOpenChannel(short channelIndex, String protocolID)
+ public InternalChannel inverseOpenChannel(short channelID, String protocolID, int protocolVersion)
{
throw new RuntimeException("Simulated problem"); //$NON-NLS-1$
}
@@ -132,7 +152,6 @@ public class Bugzilla_241463_Test extends AbstractTransportTest
{
SSLAcceptor acceptor = new SSLAcceptor()
{
-
@Override
public void handleAccept(ITCPSelector selector, ServerSocketChannel serverSocketChannel)
{
@@ -146,11 +165,12 @@ public class Bugzilla_241463_Test extends AbstractTransportTest
SSLServerConnector connector = new SSLServerConnector(this)
{
@Override
- public InternalChannel inverseOpenChannel(short channelID, String protocolID)
+ public InternalChannel inverseOpenChannel(short channelID, String protocolID, int protocolVersion)
{
throw new RuntimeException("Simulated problem"); //$NON-NLS-1$
}
};
+
prepareConnector(connector);
connector.setSocketChannel(socketChannel);
connector.setSelector(selector);
@@ -177,7 +197,25 @@ public class Bugzilla_241463_Test extends AbstractTransportTest
/**
* @author Eike Stepper
*/
- public static final class TCP extends ChannelTest
+ public static final class JVM extends Bugzilla_241463_Test
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return true;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TCP extends Bugzilla_241463_Test
{
@Override
protected boolean useJVMTransport()
@@ -195,7 +233,7 @@ public class Bugzilla_241463_Test extends AbstractTransportTest
/**
* @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
*/
- public static final class SSL extends ChannelTest
+ public static final class SSL extends Bugzilla_241463_Test
{
@Override
protected boolean useJVMTransport()
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_259086_Test.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_259086_Test.java
new file mode 100644
index 0000000000..b842f0abd8
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_259086_Test.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.bugzilla;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.jvm.JVMUtil;
+import org.eclipse.net4j.tcp.TCPUtil;
+import org.eclipse.net4j.tcp.ssl.SSLUtil;
+import org.eclipse.net4j.tests.AbstractTransportTest;
+import org.eclipse.net4j.tests.signal.TestSignalProtocol;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.container.ManagedContainer;
+
+/**
+ * @author Eike Stepper
+ */
+public class Bugzilla_259086_Test extends AbstractTransportTest
+{
+ private static final int SERVER_PROTOCOL_VERSION = 4711;
+
+ @Override
+ protected IManagedContainer createContainer()
+ {
+ IManagedContainer container = new ManagedContainer();
+ Net4jUtil.prepareContainer(container);
+ JVMUtil.prepareContainer(container);
+ TCPUtil.prepareContainer(container);
+ SSLUtil.prepareContainer(container);
+ container.registerFactory(new TestSignalProtocol.Factory(SERVER_PROTOCOL_VERSION));
+ return container;
+ }
+
+ public void testVersionMatch() throws Exception
+ {
+ startTransport();
+
+ IConnector connector = getConnector();
+ connector.setOpenChannelTimeout(2000L);
+
+ new TestSignalProtocol(connector, SERVER_PROTOCOL_VERSION);
+ }
+
+ public void testVersionMissing() throws Exception
+ {
+ startTransport();
+
+ IConnector connector = getConnector();
+ connector.setOpenChannelTimeout(2000L);
+
+ try
+ {
+ new TestSignalProtocol(connector);
+ fail("Exception expected"); //$NON-NLS-1$
+ }
+ catch (Exception expected)
+ {
+ expected.printStackTrace();
+ }
+ }
+
+ public void testVersionMismatch() throws Exception
+ {
+ startTransport();
+
+ IConnector connector = getConnector();
+ connector.setOpenChannelTimeout(2000L);
+
+ try
+ {
+ new TestSignalProtocol(connector, SERVER_PROTOCOL_VERSION - 1);
+ fail("Exception expected"); //$NON-NLS-1$
+ }
+ catch (Exception expected)
+ {
+ expected.printStackTrace();
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class JVM extends Bugzilla_259086_Test
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return true;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TCP extends Bugzilla_259086_Test
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class SSL extends Bugzilla_259086_Test
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return true;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java
index 88f2a1265d..f8f3ebb74c 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java
@@ -11,6 +11,7 @@
package org.eclipse.net4j.tests.signal;
import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.protocol.IProtocol2;
import org.eclipse.net4j.signal.SignalProtocol;
import org.eclipse.net4j.signal.SignalReactor;
import org.eclipse.net4j.util.factory.ProductCreationException;
@@ -41,6 +42,15 @@ public class TestSignalProtocol extends SignalProtocol<Object>
public static final String SIMULATED_EXCEPTION = "Simulated exception"; //$NON-NLS-1$
+ private int version = super.getVersion();
+
+ public TestSignalProtocol(IConnector connector, int version)
+ {
+ this();
+ this.version = version;
+ open(connector);
+ }
+
public TestSignalProtocol(IConnector connector)
{
this();
@@ -53,6 +63,17 @@ public class TestSignalProtocol extends SignalProtocol<Object>
}
@Override
+ public int getVersion()
+ {
+ return version;
+ }
+
+ public void setVersion(int version)
+ {
+ this.version = version;
+ }
+
+ @Override
protected SignalReactor createSignalReactor(short signalID)
{
switch (signalID)
@@ -107,6 +128,14 @@ public class TestSignalProtocol extends SignalProtocol<Object>
*/
public static class Factory extends ServerProtocolFactory
{
+ private int version = IProtocol2.UNSPECIFIED_VERSION;
+
+ public Factory(int version)
+ {
+ this();
+ this.version = version;
+ }
+
public Factory()
{
super(PROTOCOL_NAME);
@@ -114,7 +143,9 @@ public class TestSignalProtocol extends SignalProtocol<Object>
public TestSignalProtocol create(String description) throws ProductCreationException
{
- return new TestSignalProtocol();
+ TestSignalProtocol protocol = new TestSignalProtocol();
+ protocol.setVersion(version);
+ return protocol;
}
}
}

Back to the top