summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-10 04:57:58 (EDT)
committerEike Stepper2007-10-10 04:57:58 (EDT)
commit816a0cb35047860e8e157efb63ffa96888066ba2 (patch)
treeccec963af6dc0fb9dee7e59249333504fc35a2b8
parent36f12139e30265c4aaebc91cf691ae3debb368b2 (diff)
downloadcdo-816a0cb35047860e8e157efb63ffa96888066ba2.zip
cdo-816a0cb35047860e8e157efb63ffa96888066ba2.tar.gz
cdo-816a0cb35047860e8e157efb63ffa96888066ba2.tar.bz2
[205877] NoConnectionPendingException in ConnectorTest
https://bugs.eclipse.org/bugs/show_bug.cgi?id=205877
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java31
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java35
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java6
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java18
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java2
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ConnectorTest.java67
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Acceptor.java43
7 files changed, 122 insertions, 80 deletions
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java
index 3c16ca4..ed9fe8d 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java
@@ -16,7 +16,6 @@ import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.tcp.ITCPAcceptor;
import org.eclipse.net4j.tcp.ITCPSelector;
import org.eclipse.net4j.tcp.ITCPSelectorListener;
-import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.internal.net4j.Acceptor;
@@ -134,7 +133,7 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPSelectorL
ServerSocket socket = serverSocketChannel.socket();
socket.bind(addr);
- if (address == null)
+ if (addr == null)
{
address = socket.getInetAddress().toString();
if (address.startsWith("/"))
@@ -177,8 +176,11 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPSelectorL
}
socketChannel.configureBlocking(false);
- TCPServerConnector connector = createConnector(socketChannel);
- addConnector(connector);
+ TCPServerConnector connector = new TCPServerConnector(this);
+ prepareConnector(connector);
+ connector.setSocketChannel(socketChannel);
+ connector.setSelector(selector);
+ connector.activate();
}
}
catch (ClosedChannelException ex)
@@ -187,11 +189,7 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPSelectorL
}
catch (Exception ex)
{
- if (isActive())
- {
- OM.LOG.error(ex);
- }
-
+ if (isActive()) OM.LOG.error(ex);
deactivate();
}
}
@@ -202,23 +200,10 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPSelectorL
return MessageFormat.format("TCPAcceptor[{0}:{1}]", address, port); //$NON-NLS-1$
}
- protected TCPServerConnector createConnector(SocketChannel socketChannel)
- {
- TCPServerConnector connector = new TCPServerConnector();
- connector.setSocketChannel(socketChannel);
- connector.setSelector(selector);
- return connector;
- }
-
@Override
protected void doBeforeActivate() throws Exception
{
super.doBeforeActivate();
- if (StringUtil.isEmpty(address))
- {
- throw new IllegalStateException("No address"); //$NON-NLS-1$
- }
-
if (selector == null)
{
throw new IllegalStateException("selector == null");
@@ -238,7 +223,7 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPSelectorL
serverSocketChannel.configureBlocking(false);
selector.orderRegistration(serverSocketChannel, this);
- if (startSynchronously)
+ if (startLatch != null)
{
if (!startLatch.await(synchronousStartTimeout, TimeUnit.MILLISECONDS))
{
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java
index 39ce603..c1f3026 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java
@@ -28,7 +28,6 @@ import org.eclipse.net4j.util.security.INegotiationContext;
import org.eclipse.internal.net4j.Channel;
import org.eclipse.internal.net4j.Connector;
-import java.net.ConnectException;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectionKey;
@@ -140,25 +139,19 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
leaveConnecting();
}
}
- catch (ConnectException ex)
+ // catch (ConnectException ex)
+ // {
+ // // if (TRACER.isEnabled()) TRACER.trace(ex.getMessage());
+ // OM.LOG.error(ex);
+ // }
+ catch (ClosedChannelException ex)
{
- if (TRACER.isEnabled()) TRACER.trace(ex.getMessage());
+ deactivate();
}
catch (Exception ex)
{
OM.LOG.error(ex);
- }
- }
-
- private void leaveConnecting()
- {
- if (getNegotiator() == null)
- {
- setState(ConnectorState.CONNECTED);
- }
- else
- {
- setState(ConnectorState.NEGOTIATING);
+ deactivate();
}
}
@@ -381,6 +374,18 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
}
}
+ private void leaveConnecting()
+ {
+ if (getNegotiator() == null)
+ {
+ setState(ConnectorState.CONNECTED);
+ }
+ else
+ {
+ setState(ConnectorState.NEGOTIATING);
+ }
+ }
+
/**
* @author Eike Stepper
*/
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java
index 4c042ee..4363415 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java
@@ -146,8 +146,8 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
{
try
{
- processOperations(true);
processOperations(false);
+ processOperations(true);
if (selector != null && selector.select() > 0)
{
Iterator<SelectionKey> it = selector.selectedKeys().iterator();
@@ -327,7 +327,7 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
{
if (TRACER.isEnabled())
{
- TRACER.format("Ordering {0} operation {1}", client, operation);
+ TRACER.format("Ordering {0} operation {1}", client ? "client" : "server", operation);
}
if (client)
@@ -353,7 +353,7 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
{
if (TRACER.isEnabled())
{
- TRACER.format("Ordering {0} operation {1}", client, operation);
+ TRACER.format("Executing {0} operation {1}", client ? "client" : "server", operation);
}
operation.run();
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java
index 3e7b0d3..ce733c0 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java
@@ -14,6 +14,7 @@ import org.eclipse.net4j.ConnectorException;
import org.eclipse.net4j.ConnectorLocation;
import org.eclipse.net4j.ConnectorState;
+import java.nio.channels.SelectionKey;
import java.text.MessageFormat;
/**
@@ -21,8 +22,16 @@ import java.text.MessageFormat;
*/
public class TCPServerConnector extends TCPConnector
{
- public TCPServerConnector()
+ private TCPAcceptor acceptor;
+
+ public TCPServerConnector(TCPAcceptor acceptor)
+ {
+ this.acceptor = acceptor;
+ }
+
+ public TCPAcceptor getAcceptor()
{
+ return acceptor;
}
public ConnectorLocation getLocation()
@@ -74,4 +83,11 @@ public class TCPServerConnector extends TCPConnector
return MessageFormat.format("ServerTCPConnector[{3}@{0}:{1}]", getHost(), getPort(), getUserID()); //$NON-NLS-1$
}
}
+
+ @Override
+ public void handleRegistration(SelectionKey selectionKey)
+ {
+ super.handleRegistration(selectionKey);
+ acceptor.addConnector(this);
+ }
}
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 d0b68f3..fe1eb3b 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
@@ -33,7 +33,7 @@ public class AllTests
suite.addTestSuite(SynchronizingCorrelatorTest.class);
suite.addTestSuite(TestBufferPool.class);
suite.addTestSuite(SecurityTest.class);
- // TODO suite.addTestSuite(ConnectorTest.class);
+ suite.addTestSuite(ConnectorTest.class);
// $JUnit-END$
return suite;
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ConnectorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ConnectorTest.java
index f654978..d5825a8 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ConnectorTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ConnectorTest.java
@@ -15,18 +15,18 @@ import org.eclipse.net4j.Net4jUtil;
import org.eclipse.net4j.internal.tcp.TCPAcceptor;
import org.eclipse.net4j.internal.tcp.TCPClientConnector;
import org.eclipse.net4j.internal.tcp.TCPSelector;
-import org.eclipse.net4j.internal.tcp.TCPServerConnector;
import org.eclipse.net4j.internal.util.security.ChallengeNegotiator;
import org.eclipse.net4j.internal.util.security.PasswordCredentials;
import org.eclipse.net4j.internal.util.security.PasswordCredentialsProvider;
import org.eclipse.net4j.internal.util.security.Randomizer;
import org.eclipse.net4j.internal.util.security.ResponseNegotiator;
import org.eclipse.net4j.internal.util.security.UserManager;
+import org.eclipse.net4j.tcp.ITCPSelector;
import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.tests.AbstractOMTest;
-import java.nio.channels.SocketChannel;
+import java.nio.channels.ServerSocketChannel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -68,21 +68,28 @@ public class ConnectorTest extends AbstractOMTest
@Override
protected void doTearDown() throws Exception
{
+ cleanup();
+ super.doTearDown();
+ }
+
+ private void cleanup() throws Exception
+ {
+ sleep(100);
+ LifecycleUtil.deactivate(connector);
LifecycleUtil.deactivate(responseNegotiator);
LifecycleUtil.deactivate(credentialsProvider);
- LifecycleUtil.deactivate(connector);
+ connector = null;
responseNegotiator = null;
credentialsProvider = null;
- connector = null;
+ LifecycleUtil.deactivate(acceptor);
LifecycleUtil.deactivate(challengeNegotiator);
LifecycleUtil.deactivate(userManager);
LifecycleUtil.deactivate(randomizer);
- LifecycleUtil.deactivate(acceptor);
+ acceptor = null;
challengeNegotiator = null;
userManager = null;
randomizer = null;
- acceptor = null;
LifecycleUtil.deactivate(selector);
LifecycleUtil.deactivate(bufferPool);
@@ -90,13 +97,11 @@ public class ConnectorTest extends AbstractOMTest
selector = null;
bufferPool = null;
threadPool = null;
-
- super.doTearDown();
}
public void testDeferredActivation() throws Exception
{
- final long DELAY = 1000L;
+ final long DELAY = 500L;
threadPool = Executors.newCachedThreadPool();
LifecycleUtil.activate(threadPool);
@@ -109,10 +114,10 @@ public class ConnectorTest extends AbstractOMTest
acceptor = new TCPAcceptor()
{
@Override
- protected TCPServerConnector createConnector(SocketChannel socketChannel)
+ public void handleAccept(ITCPSelector selector, ServerSocketChannel serverSocketChannel)
{
ConcurrencyUtil.sleep(DELAY);
- return super.createConnector(socketChannel);
+ super.handleAccept(selector, serverSocketChannel);
}
};
@@ -139,6 +144,24 @@ public class ConnectorTest extends AbstractOMTest
assertEquals(true, connector.isActive());
}
+ public void testDeferredActivation100() throws Exception
+ {
+ for (int i = 0; i < 100; i++)
+ {
+ System.out.println();
+ System.out.println();
+ System.out.println();
+ System.out.println("#####################################################");
+ System.out.println(" RUN = " + i);
+ System.out.println("#####################################################");
+ System.out.println();
+ System.out.println();
+ System.out.println();
+ testDeferredActivation();
+ cleanup();
+ }
+ }
+
public void testNegotiationSuccess() throws Exception
{
threadPool = Executors.newCachedThreadPool();
@@ -167,7 +190,7 @@ public class ConnectorTest extends AbstractOMTest
acceptor.setSynchronousStartTimeout(TIMEOUT);
acceptor.setBufferProvider(bufferPool);
acceptor.setReceiveExecutor(threadPool);
- acceptor.setNegotiator(challengeNegotiator);
+ // acceptor.setNegotiator(challengeNegotiator);
acceptor.setSelector(selector);
acceptor.setAddress("0.0.0.0");
acceptor.setPort(2036);
@@ -183,7 +206,7 @@ public class ConnectorTest extends AbstractOMTest
connector = new TCPClientConnector();
connector.setBufferProvider(bufferPool);
connector.setReceiveExecutor(threadPool);
- connector.setNegotiator(responseNegotiator);
+ // connector.setNegotiator(responseNegotiator);
connector.setSelector(selector);
connector.setHost("localhost");
connector.setPort(2036);
@@ -193,6 +216,24 @@ public class ConnectorTest extends AbstractOMTest
assertEquals(true, connected);
}
+ public void testNegotiationSuccess100() throws Exception
+ {
+ for (int i = 0; i < 100; i++)
+ {
+ System.out.println();
+ System.out.println();
+ System.out.println();
+ System.out.println("#####################################################");
+ System.out.println(" RUN = " + i);
+ System.out.println("#####################################################");
+ System.out.println();
+ System.out.println();
+ System.out.println();
+ testNegotiationSuccess();
+ cleanup();
+ }
+ }
+
public void testNegotiationFailure() throws Exception
{
ExecutorService threadPool = Executors.newCachedThreadPool();
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Acceptor.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Acceptor.java
index 3295b0b..3221071 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Acceptor.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Acceptor.java
@@ -139,37 +139,32 @@ public abstract class Acceptor extends Container<IConnector> implements IAccepto
return getAcceptedConnectors();
}
- protected void addConnector(Connector connector)
+ public void prepareConnector(Connector connector)
{
- try
+ connector.setNegotiator(negotiator);
+ connector.setBufferProvider(bufferProvider);
+ connector.setReceiveExecutor(receiveExecutor);
+ connector.setProtocolFactoryRegistry(protocolFactoryRegistry);
+ connector.setProtocolPostProcessors(protocolPostProcessors);
+ }
+
+ public void addConnector(Connector connector)
+ {
+ synchronized (acceptedConnectors)
{
- connector.addListener(lifecycleEventConverter);
- connector.setNegotiator(negotiator);
- connector.setBufferProvider(bufferProvider);
- connector.setReceiveExecutor(receiveExecutor);
- connector.setProtocolFactoryRegistry(protocolFactoryRegistry);
- connector.setProtocolPostProcessors(protocolPostProcessors);
- connector.activate();
-
- synchronized (acceptedConnectors)
- {
- acceptedConnectors.add(connector);
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.trace("Added connector " + connector); //$NON-NLS-1$
- }
-
- fireElementAddedEvent(connector);
+ acceptedConnectors.add(connector);
}
- catch (Exception ex)
+
+ connector.addListener(lifecycleEventConverter);
+ if (TRACER.isEnabled())
{
- OM.LOG.error(ex);
+ TRACER.trace("Added connector " + connector); //$NON-NLS-1$
}
+
+ fireElementAddedEvent(connector);
}
- protected void removeConnector(IConnector connector)
+ public void removeConnector(IConnector connector)
{
connector.removeListener(lifecycleEventConverter);
synchronized (acceptedConnectors)