summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-09-13 04:17:11 (EDT)
committerEike Stepper2007-09-13 04:17:11 (EDT)
commit28ba1a2743954c71571b88c5aa4495af0ce99646 (patch)
treec41410b9e028d06ff8be190649f69a6ac0d10bf9
parent34cc0fca811b47cf602855eabd4f43058bf90a89 (diff)
downloadcdo-28ba1a2743954c71571b88c5aa4495af0ce99646.zip
cdo-28ba1a2743954c71571b88c5aa4495af0ce99646.tar.gz
cdo-28ba1a2743954c71571b88c5aa4495af0ce99646.tar.bz2
[201267] Failover strategy for CDO/NET4J
https://bugs.eclipse.org/bugs/show_bug.cgi?id=201267
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/FailingExceptionTest.java86
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/Indication3.java52
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/Request3.java50
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalClientProtocolFactory.java33
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java5
5 files changed, 225 insertions, 1 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/FailingExceptionTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/FailingExceptionTest.java
new file mode 100644
index 0000000..6f74779
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/FailingExceptionTest.java
@@ -0,0 +1,86 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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;
+
+import org.eclipse.net4j.IChannel;
+import org.eclipse.net4j.signal.FailOverStrategy;
+import org.eclipse.net4j.signal.IFailOverStrategy;
+import org.eclipse.net4j.tests.signal.Request1;
+import org.eclipse.net4j.tests.signal.Request3;
+import org.eclipse.net4j.tests.signal.TestSignalClientProtocolFactory;
+import org.eclipse.net4j.tests.signal.TestSignalServerProtocolFactory;
+import org.eclipse.net4j.util.container.IManagedContainer;
+
+/**
+ * @author Eike Stepper
+ */
+public class FailingExceptionTest extends AbstractTransportTest
+{
+ @Override
+ protected IManagedContainer createContainer()
+ {
+ IManagedContainer container = super.createContainer();
+ container.registerFactory(new TestSignalServerProtocolFactory());
+ container.registerFactory(new TestSignalClientProtocolFactory());
+ return container;
+ }
+
+ public void testFailingBefore() throws Exception
+ {
+ startTransport();
+ IChannel channel = getConnector().openChannel(TestSignalClientProtocolFactory.TYPE, null);
+
+ // Simulate a disconnect from the server.
+ getAcceptor().deactivate();
+
+ int data = 0x0a;
+ IFailOverStrategy failOverStrategy = new FailOverStrategy();
+
+ // Exception HERE
+ Request1 request = new Request1(channel, data);
+
+ int result = failOverStrategy.send(request);
+ assertEquals(data, result);
+ }
+
+ public void testFailingDuring() throws Exception
+ {
+ startTransport();
+ IChannel channel = getConnector().openChannel(TestSignalClientProtocolFactory.TYPE, null);
+
+ int data = 0x0a;
+ IFailOverStrategy failOverStrategy = new FailOverStrategy();
+
+ // Exception HERE
+ Request1 request = new Request1(channel, data);
+
+ // Simulate a disconnect from the server.
+ getAcceptor().deactivate();
+
+ int result = failOverStrategy.send(request);
+ assertEquals(data, result);
+ }
+
+ public void testFailingDuring2() throws Exception
+ {
+ startTransport();
+ IChannel channel = getConnector().openChannel(TestSignalClientProtocolFactory.TYPE, null);
+
+ int data = 0x0a;
+ IFailOverStrategy failOverStrategy = new FailOverStrategy();
+
+ // Exception HERE
+ Request3 request = new Request3(channel, data);
+
+ int result = failOverStrategy.send(request, 1000);
+ assertEquals(data, result);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/Indication3.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/Indication3.java
new file mode 100644
index 0000000..b490d6a
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/Indication3.java
@@ -0,0 +1,52 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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.signal;
+
+import org.eclipse.net4j.signal.IndicationWithResponse;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class Indication3 extends IndicationWithResponse
+{
+ private int data;
+
+ public Indication3()
+ {
+ }
+
+ public int getData()
+ {
+ return data;
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return TestSignalProtocol.SIGNAL3;
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws IOException
+ {
+ data = in.readInt();
+ }
+
+ @Override
+ protected void responding(ExtendedDataOutputStream out) throws IOException
+ {
+ getProtocol().deactivate();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/Request3.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/Request3.java
new file mode 100644
index 0000000..e82ee5e
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/Request3.java
@@ -0,0 +1,50 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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.signal;
+
+import org.eclipse.net4j.IChannel;
+import org.eclipse.net4j.signal.RequestWithConfirmation;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class Request3 extends RequestWithConfirmation<Integer>
+{
+ private int data;
+
+ public Request3(IChannel channel, int data)
+ {
+ super(channel);
+ this.data = data;
+ }
+
+ @Override
+ protected short getSignalID()
+ {
+ return TestSignalProtocol.SIGNAL3;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws IOException
+ {
+ out.writeInt(data);
+ }
+
+ @Override
+ protected Integer confirming(ExtendedDataInputStream in) throws IOException
+ {
+ return in.readInt();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalClientProtocolFactory.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalClientProtocolFactory.java
new file mode 100644
index 0000000..de2a753
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalClientProtocolFactory.java
@@ -0,0 +1,33 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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.signal;
+
+import org.eclipse.net4j.util.factory.ProductCreationException;
+
+import org.eclipse.internal.net4j.ClientProtocolFactory;
+
+/**
+ * @author Eike Stepper
+ */
+public class TestSignalClientProtocolFactory extends ClientProtocolFactory
+{
+ public static final String TYPE = TestSignalServerProtocolFactory.TYPE;
+
+ public TestSignalClientProtocolFactory()
+ {
+ super(TYPE);
+ }
+
+ public TestSignalProtocol create(String description) throws ProductCreationException
+ {
+ return new TestSignalProtocol();
+ }
+}
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 7fab121..49985e8 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
@@ -23,6 +23,8 @@ public class TestSignalProtocol extends SignalProtocol
public static final short SIGNAL1 = 1;
public static final short SIGNAL2 = 2;
+
+ public static final short SIGNAL3 = 3;
public TestSignalProtocol()
{
@@ -42,8 +44,9 @@ public class TestSignalProtocol extends SignalProtocol
return new Indication1();
case SIGNAL2:
return new Indication2();
+ case SIGNAL3:
+ return new Indication3();
}
-
return null;
}
}