Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2018-04-24 23:11:15 -0400
committerEike Stepper2018-04-24 23:11:15 -0400
commitd3d54f27b1c256e2416c4cd0e873d2764b5edcaf (patch)
tree2919657523ec8493ec381829004426ecd99bbfb2
parentcdd0658a95a41d9adb12fe218451f57eec100b75 (diff)
downloadcdo-d3d54f27b1c256e2416c4cd0e873d2764b5edcaf.tar.gz
cdo-d3d54f27b1c256e2416c4cd0e873d2764b5edcaf.tar.xz
cdo-d3d54f27b1c256e2416c4cd0e873d2764b5edcaf.zip
[534014] ReconnectingSession fails to reconnect the second time
https://bugs.eclipse.org/bugs/show_bug.cgi?id=534014
-rw-r--r--plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/RecoveringCDOSessionImpl.java18
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ReconnectingSessionTest.java135
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java8
3 files changed, 144 insertions, 17 deletions
diff --git a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/RecoveringCDOSessionImpl.java b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/RecoveringCDOSessionImpl.java
index 04ac972933..5f67b15497 100644
--- a/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/RecoveringCDOSessionImpl.java
+++ b/plugins/org.eclipse.emf.cdo.net4j/src/org/eclipse/emf/cdo/internal/net4j/RecoveringCDOSessionImpl.java
@@ -123,9 +123,8 @@ public abstract class RecoveringCDOSessionImpl extends CDONet4jSessionImpl
unhookSessionProtocol();
List<AfterRecoveryRunnable> runnables = recoverSession();
- // Check if the the sessionProtocol was replaced. (This may not be the case
+ // Check if the sessionProtocol was replaced. (This may not be the case
// if the protocol is wrapped inside a DelegatingSessionProtocol.)
- //
CDOSessionProtocol newSessionProtocol = getSessionProtocol();
if (newSessionProtocol != oldSessionProtocol)
{
@@ -223,6 +222,17 @@ public abstract class RecoveringCDOSessionImpl extends CDONet4jSessionImpl
}
}
+ @Override
+ public void setSessionProtocol(CDOSessionProtocol sessionProtocol)
+ {
+ super.setSessionProtocol(sessionProtocol);
+
+ // Bug 534014: The DelegatingSessionProtocol of this session is deactivated by CDOSessionImpl.sessionProtocolListener
+ // when the delegate protocol becomes inactive. The super.setSessionProtocol() method just replaces the delegate
+ // protocol but doesn't reactivate the DelegatingSessionProtocol. Reactivate it now.
+ LifecycleUtil.activate(getSessionProtocol());
+ }
+
protected IConnector removeTCPConnector()
{
return (IConnector)container.removeElement("org.eclipse.net4j.connectors", "tcp", repositoryConnectorDescription);
@@ -276,7 +286,7 @@ public abstract class RecoveringCDOSessionImpl extends CDONet4jSessionImpl
/**
* @author Eike Stepper
*/
- public final class OpenViewRunnable implements AfterRecoveryRunnable
+ private static final class OpenViewRunnable implements AfterRecoveryRunnable
{
private int viewID;
@@ -300,7 +310,7 @@ public abstract class RecoveringCDOSessionImpl extends CDONet4jSessionImpl
/**
* @author Eike Stepper
*/
- private static class AutoCloser implements IListener
+ private static final class AutoCloser implements IListener
{
public void notifyEvent(IEvent event)
{
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ReconnectingSessionTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ReconnectingSessionTest.java
index fc66511079..d2a0cfa0db 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ReconnectingSessionTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ReconnectingSessionTest.java
@@ -35,7 +35,6 @@ import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
/**
* @author Eike Stepper
@@ -63,7 +62,7 @@ public class ReconnectingSessionTest extends AbstractCDOTest
transaction.commit();
ITCPAcceptor acceptor = null;
- CDONet4jSession session2 = null;
+ CDONet4jSession reconnectingSession = null;
try
{
@@ -80,12 +79,12 @@ public class ReconnectingSessionTest extends AbstractCDOTest
ReconnectingCDOSessionConfiguration configuration = CDONet4jUtil.createReconnectingSessionConfiguration(ADDRESS2, repositoryName, clientContainer);
configuration.setHeartBeatEnabled(true);
- session2 = (CDONet4jSession)openSession(configuration);
- dumpEvents(session2);
+ reconnectingSession = (CDONet4jSession)openSession(configuration);
+ dumpEvents(reconnectingSession);
final CountDownLatch recoveryStarted = new CountDownLatch(1);
final CountDownLatch recoveryFinished = new CountDownLatch(1);
- session2.addListener(new IListener()
+ reconnectingSession.addListener(new IListener()
{
public void notifyEvent(final IEvent event)
{
@@ -105,10 +104,10 @@ public class ReconnectingSessionTest extends AbstractCDOTest
}
});
- IConnector connector2 = (IConnector)session2.options().getNet4jProtocol().getChannel().getMultiplexer();
- dumpEvents(connector2);
+ IConnector connector = (IConnector)reconnectingSession.options().getNet4jProtocol().getChannel().getMultiplexer();
+ dumpEvents(connector);
- CDOView view = session2.openView();
+ CDOView view = reconnectingSession.openView();
CDOResource resource2 = view.getResource(getResourcePath("res1"));
assertEquals(1, resource2.getContents().size());
@@ -119,13 +118,13 @@ public class ReconnectingSessionTest extends AbstractCDOTest
IOUtil.OUT().println();
IOUtil.OUT().println("Deactivating acceptor...");
LifecycleUtil.deactivate(acceptor);
- recoveryStarted.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
+ await(recoveryStarted);
IOUtil.OUT().println();
IOUtil.OUT().println("Reactivating acceptor...");
acceptor = TCPUtil.getAcceptor(serverContainer, ADDRESS2);
dumpEvents(acceptor);
- recoveryFinished.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
+ await(recoveryFinished);
IOUtil.OUT().println();
IOUtil.OUT().println("Committing...");
@@ -135,7 +134,117 @@ public class ReconnectingSessionTest extends AbstractCDOTest
}
finally
{
- LifecycleUtil.deactivate(session2);
+ LifecycleUtil.deactivate(reconnectingSession);
+ LifecycleUtil.deactivate(acceptor);
+ }
+ }
+
+ public void testReconnectTwice() throws Exception
+ {
+ disableConsole();
+
+ CDOSession session1 = openSession();
+ CDOTransaction transaction = session1.openTransaction();
+ CDOResource[] resource1 = { transaction.createResource(getResourcePath("res0")), transaction.createResource(getResourcePath("res1")) };
+ resource1[0].getContents().add(getModel1Factory().createCategory());
+ resource1[1].getContents().add(getModel1Factory().createCategory());
+ transaction.commit();
+
+ ITCPAcceptor acceptor = null;
+ CDONet4jSession reconnectingSession = null;
+
+ try
+ {
+ IManagedContainer serverContainer = getServerContainer();
+ dumpEvents(serverContainer);
+
+ acceptor = TCPUtil.getAcceptor(serverContainer, ADDRESS2);
+ dumpEvents(acceptor);
+
+ String repositoryName = session1.getRepositoryInfo().getName();
+ IManagedContainer clientContainer = getClientContainer();
+ dumpEvents(clientContainer);
+
+ ReconnectingCDOSessionConfiguration configuration = CDONet4jUtil.createReconnectingSessionConfiguration(ADDRESS2, repositoryName, clientContainer);
+ configuration.setHeartBeatEnabled(true);
+
+ reconnectingSession = (CDONet4jSession)openSession(configuration);
+ dumpEvents(reconnectingSession);
+
+ for (int i = 0; i < 2; i++)
+ {
+ IOUtil.OUT().println();
+ IOUtil.OUT().println("=================================================================");
+ IOUtil.OUT().println(" Run " + (i + 1));
+ IOUtil.OUT().println("=================================================================");
+ IOUtil.OUT().println();
+
+ if (i == 1)
+ {
+ System.out.println();
+ }
+
+ final CountDownLatch recoveryStarted = new CountDownLatch(1);
+ final CountDownLatch recoveryFinished = new CountDownLatch(1);
+ reconnectingSession.addListener(new IListener()
+ {
+ public void notifyEvent(final IEvent event)
+ {
+ if (event instanceof CDOSessionRecoveryEvent)
+ {
+ CDOSessionRecoveryEvent recoveryEvent = (CDOSessionRecoveryEvent)event;
+ switch (recoveryEvent.getType())
+ {
+ case STARTED:
+ recoveryStarted.countDown();
+ break;
+ case FINISHED:
+ recoveryFinished.countDown();
+ break;
+ }
+ }
+ }
+ });
+
+ IConnector connector2 = (IConnector)reconnectingSession.options().getNet4jProtocol().getChannel().getMultiplexer();
+ dumpEvents(connector2);
+
+ CDOView view = reconnectingSession.openView();
+ CDOResource resource = view.getResource(getResourcePath("res" + i));
+ assertEquals(1, resource.getContents().size());
+
+ resource1[i].getContents().add(getModel1Factory().createCategory());
+ commitAndSync(transaction, view);
+ assertEquals(2, resource.getContents().size());
+
+ IOUtil.OUT().println();
+ IOUtil.OUT().println("Deactivating acceptor...");
+ LifecycleUtil.deactivate(acceptor);
+ await(recoveryStarted);
+
+ IOUtil.OUT().println();
+ IOUtil.OUT().println("Reactivating acceptor...");
+ acceptor = TCPUtil.getAcceptor(serverContainer, ADDRESS2);
+ dumpEvents(acceptor);
+ await(recoveryFinished);
+
+ IOUtil.OUT().println();
+ IOUtil.OUT().println("Committing...");
+ resource1[i].getContents().add(getModel1Factory().createCategory());
+ commitAndSync(transaction, view);
+ assertEquals(3, resource.getContents().size());
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ throw ex;
+ }
+ finally
+ {
+ IOUtil.OUT().println();
+ IOUtil.OUT().println("Finally...");
+ LifecycleUtil.deactivate(reconnectingSession);
LifecycleUtil.deactivate(acceptor);
}
}
@@ -207,7 +316,7 @@ public class ReconnectingSessionTest extends AbstractCDOTest
IOUtil.OUT().println();
IOUtil.OUT().println("Deactivating acceptor...");
LifecycleUtil.deactivate(acceptor);
- recoveryStarted.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
+ await(recoveryStarted);
IOUtil.OUT().println();
IOUtil.OUT().println("Committing...");
@@ -218,7 +327,7 @@ public class ReconnectingSessionTest extends AbstractCDOTest
IOUtil.OUT().println("Reactivating acceptor...");
acceptor = TCPUtil.getAcceptor(serverContainer, ADDRESS2);
dumpEvents(acceptor);
- recoveryFinished.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
+ await(recoveryFinished);
assertEquals(3, resource2.getContents().size());
}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java
index 162ea1cdb5..aea3b9e3e1 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java
@@ -857,6 +857,14 @@ public abstract class AbstractOMTest extends TestCase
});
}
+ public static final void await(CountDownLatch latch) throws InterruptedException, TimeoutException
+ {
+ if (!latch.await(DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS))
+ {
+ throw new TimeoutException("Latch timed out: " + latch);
+ }
+ }
+
/**
* @author Eike Stepper
*/

Back to the top