Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/old/SocketConnectorTest.java')
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/old/SocketConnectorTest.java678
1 files changed, 678 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/old/SocketConnectorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/old/SocketConnectorTest.java
new file mode 100644
index 0000000000..5f77479267
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/old/SocketConnectorTest.java
@@ -0,0 +1,678 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Sympedia Methods and Tools.
+ * 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.test;
+
+
+import org.eclipse.net4j.core.Connector;
+import org.eclipse.net4j.core.DataListener;
+import org.eclipse.net4j.core.impl.BufferImpl;
+import org.eclipse.net4j.socket.impl.ActiveSocketConnectorImpl;
+import org.eclipse.net4j.socket.impl.PassiveSocketConnectorImpl;
+import org.eclipse.net4j.socket.impl.SocketAcceptorImpl;
+import org.eclipse.net4j.spring.Container;
+import org.eclipse.net4j.spring.impl.ContainerImpl;
+import org.eclipse.net4j.test.SocketConnectorTest.TestAcceptor.PassiveTestConnector;
+
+import java.nio.channels.SocketChannel;
+
+import junit.framework.TestCase;
+
+
+public class SocketConnectorTest extends TestCase
+{
+ protected static Container container = new ContainerImpl(null, (String[]) null, "container",
+ null, null);
+
+ protected PassiveTestConnector slave;
+
+ protected TestConnector client;
+
+ protected DataListener slaveListener = new DataListener()
+ {
+ public void notifyData(BufferImpl data)
+ {
+ }
+ };
+
+ // protected Pool bufferPoolMock;
+ //
+ // protected MockControl bufferPoolMockControl;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ init();
+ }
+
+ protected void init()
+ {
+ client = new TestConnector();
+ client.setApplicationContext(container);
+ client.setBeanName("client");
+
+ // bufferPoolMockControl = MockControl.createControl(Pool.class);
+ // bufferPoolMock = (Pool) bufferPoolMockControl.getMock();
+ }
+
+ protected void start()
+ {
+ // bufferPoolMockControl.replay();
+ }
+
+ protected void verify()
+ {
+ // bufferPoolMockControl.verify();
+ }
+
+ // protected BufferImpl createBuffer(int capacity, int level, boolean flipped)
+ // {
+ // BufferImpl buffer = new BufferImpl(capacity);
+ //
+ // if (level > 0)
+ // {
+ // buffer.put(Byte.MIN_VALUE); // for sequence-error-detection
+ //
+ // for (int i = 1; i < level; i++)
+ // {
+ // buffer.put((byte) (i % 256));
+ // }
+ // }
+ //
+ // if (flipped)
+ // {
+ // buffer.flip();
+ // }
+ //
+ // return buffer;
+ // }
+ //
+ // protected NodeCachingLinkedList createBufferQueue(int[] capacities, int[] levels, boolean flipped)
+ // {
+ // NodeCachingLinkedList queue = new NodeCachingLinkedList();
+ //
+ // for (int i = 0; i < levels.length; i++)
+ // {
+ // queue.add(createBuffer(capacities[i], levels[i], flipped));
+ // }
+ //
+ // return queue;
+ // }
+ //
+ // protected NodeCachingLinkedList createBufferQueue(int capacity, int[] levels, boolean flipped)
+ // {
+ // int[] capacities = new int[levels.length];
+ // Arrays.fill(capacities, capacity);
+ // return createBufferQueue(capacities, levels, flipped);
+ // }
+ //
+ // protected NodeCachingLinkedList createBufferQueue(int capacity, int level, boolean flipped)
+ // {
+ // return createBufferQueue(new int[] { capacity}, new int[] { level}, flipped);
+ // }
+
+ public final void testGet()
+ {
+ }
+
+
+ // public final void testSetGetChannelId()
+ // {
+ // pool.setChannelId((short) 4711);
+ // short result = pool.getChannelId();
+ // assertEquals("getChannelId returns the value of setChannelId", 4711, result);
+ //
+ // pool.setChannelId((short) 0);
+ // result = pool.getChannelId();
+ // assertEquals("getChannelId returns 0", 0, result);
+ // }
+ //
+ // public final void testSetGetBufferPool()
+ // {
+ // pool.setBufferPool(bufferPoolMock);
+ // Pool result = pool.getBufferPool();
+ // assertEquals("getBufferPool returns the value of setBufferPool", bufferPoolMock, result);
+ //
+ // pool.setBufferPool(null);
+ // result = pool.getBufferPool();
+ // assertNull("getBufferPool returns null", result);
+ // }
+ //
+ // public final void testSetGetConnector()
+ // {
+ // pool.setConnector(connectorMock);
+ // Connector result = pool.getConnector();
+ // assertEquals("getConnector returns the value of setConnector", connectorMock, result);
+ //
+ // pool.setConnector(null);
+ // result = pool.getConnector();
+ // assertNull("getConnector returns null", result);
+ // }
+ //
+ // public final void testSetGetDispatcher()
+ // {
+ // pool.setDispatcher(dispatcherMock);
+ // Executor result = pool.getDispatcher();
+ // assertEquals("getDispatcher returns the value of setDispatcher", dispatcherMock, result);
+ //
+ // pool.setDispatcher(null);
+ // result = pool.getDispatcher();
+ // assertNull("getDispatcher returns null", result);
+ // }
+ //
+ // public final void testSetGetMultiplexer()
+ // {
+ // pool.setMultiplexer(multiplexerMock);
+ // Multiplexer result = pool.getMultiplexer();
+ // assertEquals("getBufferPool returns the value of setMultiplexer", multiplexerMock, result);
+ //
+ // pool.setMultiplexer(null);
+ // result = pool.getMultiplexer();
+ // assertNull("getMultiplexer returns null", result);
+ // }
+ //
+ // public final void testSetGetProtocol()
+ // {
+ // pool.setProtocol(protocolMock);
+ // Protocol result = pool.getProtocol();
+ // assertEquals("getProtocol returns the value of setProtocol", protocolMock, result);
+ //
+ // pool.setProtocol(null);
+ // result = pool.getProtocol();
+ // assertNull("getProtocol returns null", result);
+ // }
+ //
+ // public final void testSetGetInternalReturnValue()
+ // {
+ // Object returnValue = new Object();
+ //
+ // pool.internalSetReturnValue(returnValue);
+ // Object result = pool.testGetReturnValue();
+ // assertEquals("testGetReturnValue returns the value of internalSetReturnValue", returnValue,
+ // result);
+ //
+ // pool.internalSetReturnValue(null);
+ // result = pool.testGetReturnValue();
+ // assertNull("testGetReturnValue returns null", result);
+ // }
+ //
+ // public final void testSetGetProtocolData()
+ // {
+ // Object protocolData = new Object();
+ //
+ // pool.setProtocolData(protocolData);
+ // Object result = pool.getProtocolData();
+ // assertEquals("getProtocolData returns the value of setProtocolData", protocolData, result);
+ //
+ // pool.setProtocolData(null);
+ // result = pool.getProtocolData();
+ // assertNull("getProtocolData returns null", result);
+ // }
+ //
+ // public final void testServiceGuards()
+ // {
+ // new ServiceInvoker(pool)
+ // {
+ // protected void invokeService(DefaultBean bean) throws Exception
+ // {
+ // ((DefaultChannel) bean).handleTransmission();
+ // }
+ // };
+ //
+ // new ServiceInvoker(pool)
+ // {
+ // protected void invokeService(DefaultBean bean) throws Exception
+ // {
+ // ((DefaultChannel) bean).notification(null);
+ // }
+ // };
+ //
+ // new ServiceInvoker(pool)
+ // {
+ // protected void invokeService(DefaultBean bean) throws Exception
+ // {
+ // ((DefaultChannel) bean).request(null);
+ // }
+ // };
+ // }
+ //
+ // public final void testValidate()
+ // {
+ // pool.setBufferPool(bufferPoolMock);
+ // pool.setDispatcher(dispatcherMock);
+ // pool.setMultiplexer(multiplexerMock);
+ // pool.testValidate();
+ //
+ // try
+ // {
+ // pool.setBufferPool(null);
+ // pool.setDispatcher(dispatcherMock);
+ // pool.setMultiplexer(multiplexerMock);
+ // pool.testValidate();
+ // fail("expected ValidationException");
+ // }
+ // catch (ValidationException expected)
+ // {
+ // TestUtils.assertContains(expected, "bufferPool");
+ // }
+ //
+ // try
+ // {
+ // pool.setBufferPool(bufferPoolMock);
+ // pool.setDispatcher(null);
+ // pool.setMultiplexer(multiplexerMock);
+ // pool.testValidate();
+ // fail("expected ValidationException");
+ // }
+ // catch (ValidationException expected)
+ // {
+ // TestUtils.assertContains(expected, "dispatcher");
+ // }
+ //
+ // try
+ // {
+ // pool.setBufferPool(bufferPoolMock);
+ // pool.setDispatcher(dispatcherMock);
+ // pool.setMultiplexer(null);
+ // pool.testValidate();
+ // fail("expected ValidationException");
+ // }
+ // catch (ValidationException expected)
+ // {
+ // TestUtils.assertContains(expected, "multiplexer");
+ // }
+ // }
+ //
+ // /**
+ // * PRECONDITION: dataSize == 0
+ // *
+ // * EXPECTATION: doesn't block;
+ // * throws IllegalArgumentException
+ // */
+ // public final void testEnsureReceiverBuffer1() throws Throwable
+ // {
+ // NodeCachingLinkedList receiverQueue = new NodeCachingLinkedList();
+ // pool.testSetReceiverQueue(receiverQueue);
+ //
+ // start();
+ // try
+ // {
+ // new BlockingDetector(pool, receiverQueue, false)
+ // {
+ // protected void blockableOperation(Object target) throws Exception
+ // {
+ // ((DefaultChannel) target).testEnsureReceiverBuffer(0);
+ // }
+ // };
+ // fail("IllegalArgumentException expected");
+ // }
+ // catch (IllegalArgumentException expected)
+ // {
+ // TestUtils.assertContains(expected, "dataSize");
+ // }
+ // verify();
+ // }
+ //
+ // /**
+ // * PRECONDITION: dataSize < 0
+ // *
+ // * EXPECTATION: doesn't block;
+ // * throws IllegalArgumentException
+ // */
+ // public final void testEnsureReceiverBuffer2() throws Throwable
+ // {
+ // NodeCachingLinkedList receiverQueue = new NodeCachingLinkedList();
+ // pool.testSetReceiverQueue(receiverQueue);
+ //
+ // start();
+ // try
+ // {
+ // new BlockingDetector(pool, receiverQueue, false)
+ // {
+ // protected void blockableOperation(Object target) throws Exception
+ // {
+ // ((DefaultChannel) target).testEnsureReceiverBuffer(-1);
+ // }
+ // };
+ // fail("IllegalArgumentException expected");
+ // }
+ // catch (IllegalArgumentException expected)
+ // {
+ // TestUtils.assertContains(expected, "dataSize");
+ // }
+ // verify();
+ // }
+ //
+ // /**
+ // * PRECONDITION: receiverBuffer exists;
+ // * 0 < level < dataSize
+ // *
+ // * EXPECTATION: doesn't block;
+ // * throws ImplementationError
+ // */
+ // public final void testEnsureReceiverBuffer3() throws Throwable
+ // {
+ // BufferImpl receiverBuffer = createBuffer(20, 3, true);
+ // pool.testSetReceiverBuffer(receiverBuffer);
+ //
+ // NodeCachingLinkedList receiverQueue = new NodeCachingLinkedList();
+ // pool.testSetReceiverQueue(receiverQueue);
+ //
+ // pool.setBufferPool(bufferPoolMock);
+ //
+ // start();
+ // try
+ // {
+ // new BlockingDetector(pool, receiverQueue, false)
+ // {
+ // protected void blockableOperation(Object target) throws Exception
+ // {
+ // ((DefaultChannel) target).testEnsureReceiverBuffer(7);
+ // }
+ // };
+ // fail("ImplementationError expected");
+ // }
+ // catch (ImplementationError expected)
+ // {
+ // TestUtils.assertContains(expected, "receiverBuffer level too low");
+ // }
+ // verify();
+ // }
+ //
+ // /**
+ // * PRECONDITION: receiverBuffer exists;
+ // * 0 < dataSize < level
+ // *
+ // * EXPECTATION: doesn't block;
+ // * receiverBuffer not returned to bufferPool
+ // */
+ // public final void testEnsureReceiverBuffer4() throws Throwable
+ // {
+ // BufferImpl receiverBuffer = createBuffer(20, 12, true);
+ // pool.testSetReceiverBuffer(receiverBuffer);
+ //
+ // NodeCachingLinkedList receiverQueue = new NodeCachingLinkedList();
+ // pool.testSetReceiverQueue(receiverQueue);
+ //
+ // pool.setBufferPool(bufferPoolMock);
+ //
+ // start();
+ // new BlockingDetector(pool, receiverQueue, false)
+ // {
+ // protected void blockableOperation(Object target) throws Exception
+ // {
+ // ((DefaultChannel) target).testEnsureReceiverBuffer(7);
+ // }
+ // };
+ // verify();
+ // }
+ //
+ // /**
+ // * PRECONDITION: receiverBuffer exists;
+ // * 0 < dataSize == level
+ // *
+ // * EXPECTATION: doesn't block;
+ // * receiverBuffer not returned to bufferPool
+ // */
+ // public final void testEnsureReceiverBuffer5() throws Throwable
+ // {
+ // BufferImpl receiverBuffer = createBuffer(20, 12, true);
+ // pool.testSetReceiverBuffer(receiverBuffer);
+ //
+ // NodeCachingLinkedList receiverQueue = new NodeCachingLinkedList();
+ // pool.testSetReceiverQueue(receiverQueue);
+ //
+ // pool.setBufferPool(bufferPoolMock);
+ //
+ // start();
+ // new BlockingDetector(pool, receiverQueue, false)
+ // {
+ // protected void blockableOperation(Object target) throws Exception
+ // {
+ // ((DefaultChannel) target).testEnsureReceiverBuffer(12);
+ // }
+ // };
+ // verify();
+ // }
+ //
+ // /**
+ // * PRECONDITION: receiverBuffer exists;
+ // * 0 == level < dataSize;
+ // * receiverQueue empty
+ // *
+ // * EXPECTATION: receiverBuffer returned to bufferPool;
+ // * blocks
+ // */
+ // public final void testEnsureReceiverBuffer6() throws Throwable
+ // {
+ // BufferImpl receiverBuffer = createBuffer(20, 0, true);
+ // pool.testSetReceiverBuffer(receiverBuffer);
+ //
+ // NodeCachingLinkedList receiverQueue = new NodeCachingLinkedList();
+ // pool.testSetReceiverQueue(receiverQueue);
+ //
+ // bufferPoolMock.put(new Integer(20), receiverBuffer);
+ // pool.setBufferPool(bufferPoolMock);
+ //
+ // start();
+ // new BlockingDetector(pool, receiverQueue, true)
+ // {
+ // protected void blockableOperation(Object target) throws Exception
+ // {
+ // ((DefaultChannel) target).testEnsureReceiverBuffer(7);
+ // }
+ // };
+ // verify();
+ // }
+ //
+ // /**
+ // * PRECONDITION: receiverBuffer exists;
+ // * 0 == level < dataSize;
+ // * receiverQueue has too small buffer
+ // *
+ // * EXPECTATION: doesn't block;
+ // * receiverBuffer returned to bufferPool
+ // * throws ImplementationError
+ // */
+ // public final void testEnsureReceiverBuffer7() throws Throwable
+ // {
+ // BufferImpl receiverBuffer = createBuffer(20, 0, true);
+ // pool.testSetReceiverBuffer(receiverBuffer);
+ //
+ // NodeCachingLinkedList receiverQueue = createBufferQueue(20, 5, true);
+ // pool.testSetReceiverQueue(receiverQueue);
+ //
+ // bufferPoolMock.put(new Integer(20), receiverBuffer);
+ // pool.setBufferPool(bufferPoolMock);
+ //
+ // start();
+ // try
+ // {
+ // new BlockingDetector(pool, receiverQueue, false)
+ // {
+ // protected void blockableOperation(Object target) throws Exception
+ // {
+ // ((DefaultChannel) target).testEnsureReceiverBuffer(7);
+ // }
+ // };
+ // fail("ImplementationError expected");
+ // }
+ // catch (ImplementationError expected)
+ // {
+ // TestUtils.assertContains(expected, "receiverBuffer level too low");
+ // }
+ // verify();
+ // }
+ //
+ // /**
+ // * PRECONDITION: receiverBuffer exists;
+ // * 0 == level < dataSize;
+ // * receiverQueue has exact buffer
+ // *
+ // * EXPECTATION: doesn't block;
+ // * receiverBuffer returned to bufferPool
+ // */
+ // public final void testEnsureReceiverBuffer8() throws Throwable
+ // {
+ // BufferImpl receiverBuffer = createBuffer(20, 0, true);
+ // pool.testSetReceiverBuffer(receiverBuffer);
+ //
+ // NodeCachingLinkedList receiverQueue = createBufferQueue(20, 7, true);
+ // pool.testSetReceiverQueue(receiverQueue);
+ //
+ // bufferPoolMock.put(new Integer(20), receiverBuffer);
+ // pool.setBufferPool(bufferPoolMock);
+ //
+ // start();
+ // new BlockingDetector(pool, receiverQueue, false)
+ // {
+ // protected void blockableOperation(Object target) throws Exception
+ // {
+ // ((DefaultChannel) target).testEnsureReceiverBuffer(7);
+ // }
+ // };
+ // verify();
+ // }
+ //
+ // /**
+ // * PRECONDITION: receiverBuffer exists;
+ // * 0 == level < dataSize;
+ // * receiverQueue has too big buffer
+ // *
+ // * EXPECTATION: doesn't block;
+ // * receiverBuffer returned to bufferPool
+ // */
+ // public final void testEnsureReceiverBuffer9() throws Throwable
+ // {
+ // BufferImpl receiverBuffer = createBuffer(20, 0, true);
+ // pool.testSetReceiverBuffer(receiverBuffer);
+ //
+ // NodeCachingLinkedList receiverQueue = createBufferQueue(20, 12, true);
+ // pool.testSetReceiverQueue(receiverQueue);
+ //
+ // bufferPoolMock.put(new Integer(20), receiverBuffer);
+ // pool.setBufferPool(bufferPoolMock);
+ //
+ // start();
+ // new BlockingDetector(pool, receiverQueue, false)
+ // {
+ // protected void blockableOperation(Object target) throws Exception
+ // {
+ // ((DefaultChannel) target).testEnsureReceiverBuffer(7);
+ // }
+ // };
+ // verify();
+ // }
+ //
+ // /**
+ // * PRECONDITION: transmitterBuffer doesn't exists
+ // *
+ // * EXPECTATION: throws ImplementationError
+ // */
+ // public final void testFlush1()
+ // {
+ // start();
+ // try
+ // {
+ // pool.flush();
+ // fail("ImplementationError expected");
+ // }
+ // catch (ImplementationError expected)
+ // {
+ // TestUtils.assertContains(expected, "transmitterBuffer must exist");
+ // }
+ // verify();
+ // }
+ //
+ // /**
+ // * PRECONDITION: transmitterBuffer exists;
+ // * level == 0
+ // *
+ // * EXPECTATION: immediately returns
+ // */
+ // public final void testFlush2()
+ // {
+ // BufferImpl transmitterBuffer = createBuffer(20, 0, false);
+ // pool.testSetTransmitterBuffer(transmitterBuffer);
+ //
+ // start();
+ // pool.flush();
+ // verify();
+ // }
+ //
+ // /**
+ // * PRECONDITION: transmitterBuffer exists;
+ // * level > 0
+ // *
+ // * EXPECTATION: transmitterBuffer is flipped;
+ // * appended to transmitterQueue;
+ // * channel is scheduled for transmission;
+ // * a new transmitterBuffer is fetched from the bufferPool;
+ // * the new transmitterBuffer is empty
+ // */
+ // public final void testFlush3()
+ // {
+ // BufferImpl transmitterBuffer = createBuffer(20, 7, false);
+ // pool.testSetTransmitterBuffer(transmitterBuffer);
+ //
+ // NodeCachingLinkedList transmitterQueue = new NodeCachingLinkedList();
+ // pool.testSetTransmitterQueue(transmitterQueue);
+ //
+ // multiplexerMock.schedule(pool);
+ // pool.setMultiplexer(multiplexerMock);
+ //
+ // bufferPoolMockControl.expectAndReturn(bufferPoolMock.get(), createBuffer(10, 10, false));
+ // pool.setBufferPool(bufferPoolMock);
+ //
+ // start();
+ // pool.flush();
+ // verify();
+ //
+ // assertTrue("transmitterBuffer is flipped", transmitterBuffer.position() == 0);
+ // assertTrue("transmitterBuffer is in transmitterQueue",
+ // transmitterQueue.get(0) == transmitterBuffer);
+ // assertNotSame("a new transmitterBuffer is expected", transmitterBuffer, pool
+ // .testGetTransmitterBuffer());
+ // assertTrue("the new transmitterBuffer must be empty", pool.testGetTransmitterBuffer()
+ // .position() == 0);
+ //
+ // }
+ protected class TestAcceptor extends SocketAcceptorImpl
+ {
+ protected Connector createSlave(SocketChannel socketChannel)
+ {
+ slave = new PassiveTestConnector();
+ slave.setApplicationContext(SocketConnectorTest.container);
+ slave.setBeanName("slave");
+ slave.setSocketChannel(socketChannel);
+ return slave;
+ }
+
+
+ protected class PassiveTestConnector extends PassiveSocketConnectorImpl
+ {
+ protected void prepareBasicChannel()
+ {
+ }
+ }
+ }
+
+
+ protected class TestConnector extends ActiveSocketConnectorImpl
+ {
+ protected void prepareBasicChannel()
+ {
+ }
+ }
+
+} \ No newline at end of file

Back to the top