From 99d61d666d09a86ecb98ee17e0138543592a04f8 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Tue, 04 Jun 2013 20:06:59 +0000
Subject: [PATCH] Fix unit test regression introduced in previous fix for OPENDJ-866 (Local RS is named differently).
---
opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java | 107 ++++++++++++++++++++++++++---------
opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java | 6 +-
opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java | 39 ++++--------
3 files changed, 95 insertions(+), 57 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
index f73fe0d..e52b41b 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
@@ -601,9 +601,6 @@
pendingChanges =
new PendingChanges(generator, this);
- startPublishService(replicationServers, window, heartbeatInterval,
- configuration.getChangetimeHeartbeatInterval());
-
remotePendingChanges = new RemotePendingChanges(getServerState());
// listen for changes on the configuration
@@ -611,6 +608,9 @@
// register as an AlertGenerator
DirectoryServer.registerAlertGenerator(this);
+
+ startPublishService(replicationServers, window, heartbeatInterval,
+ configuration.getChangetimeHeartbeatInterval());
}
/**
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java b/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java
index 987998f..be2db38 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java
@@ -59,6 +59,7 @@
import org.opends.messages.Message;
import org.opends.messages.MessageBuilder;
+import org.opends.server.core.DirectoryServer;
import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.replication.common.ChangeNumber;
import org.opends.server.replication.common.DSInfo;
@@ -194,6 +195,15 @@
private int mustRunBestServerCheckingAlgorithm = 0;
/**
+ * The monitor provider for this replication domain. The name of the monitor
+ * includes the local address and must therefore be re-registered every time
+ * the session is re-established or destroyed. The monitor provider can only
+ * be created (i.e. non-null) if there is a replication domain, which is not
+ * the case in unit tests.
+ */
+ private final ReplicationMonitor monitor;
+
+ /**
* Creates a new ReplicationServer Broker for a particular ReplicationDomain.
*
* @param replicationDomain The replication domain that is creating us.
@@ -233,6 +243,14 @@
this.maxRcvWindow = window;
this.halfRcvWindow = window / 2;
this.changeTimeHeartbeatSendInterval = changeTimeHeartbeatInterval;
+
+ /*
+ * Only create a monitor if there is a replication domain (this is not the
+ * case in some unit tests).
+ */
+ this.monitor = replicationDomain != null ? new ReplicationMonitor(
+ replicationDomain) : null;
+ registerReplicationMonitor();
}
/**
@@ -1107,12 +1125,7 @@
{
if (!connected)
{
- ProtocolSession localSession = session;
- if (localSession != null)
- {
- localSession.close();
- session = null;
- }
+ setSession(null);
}
}
}
@@ -1305,7 +1318,7 @@
// updates, store it.
if (keepConnection)
{
- session = localSession;
+ setSession(localSession);
}
return replServerInfo;
@@ -1414,11 +1427,8 @@
server, baseDn, stackTraceToSingleLineString(e));
logError(message);
- if (session != null)
- {
- session.close();
- session = null;
- }
+ setSession(null);
+
// Be sure to return null.
topologyMsg = null;
}
@@ -1489,11 +1499,8 @@
server, baseDn, stackTraceToSingleLineString(e));
logError(message);
- if (session != null)
- {
- session.close();
- session = null;
- }
+ setSession(null);
+
// Be sure to return null.
topologyMsg = null;
}
@@ -2188,7 +2195,7 @@
rsGroupId = -1;
rsServerId = -1;
rsServerUrl = null;
- session = null;
+ setSession(null);
}
while (true)
@@ -2713,10 +2720,8 @@
rsGroupId = -1;
rsServerId = -1;
rsServerUrl = null;
- if (session != null)
- {
- session.close();
- }
+ setSession(null);
+ deregisterReplicationMonitor();
}
}
@@ -2875,12 +2880,8 @@
*/
public boolean isSessionEncrypted()
{
- boolean isEncrypted = false;
- if (session != null)
- {
- return session.isEncrypted();
- }
- return isEncrypted;
+ final ProtocolSession tmp = session;
+ return tmp != null ? tmp.isEncrypted() : false;
}
/**
@@ -3131,4 +3132,54 @@
return tmp != null ? tmp.getLocalUrl() : "";
}
+ /**
+ * Returns the replication monitor associated with this broker.
+ *
+ * @return The replication monitor.
+ */
+ ReplicationMonitor getReplicationMonitor()
+ {
+ // Only invoked by replication domain so always non-null.
+ return monitor;
+ }
+
+ private void setSession(final ProtocolSession newSession)
+ {
+ // De-register the monitor with the old name.
+ deregisterReplicationMonitor();
+
+ final ProtocolSession oldSession = session;
+ if (oldSession != null)
+ {
+ oldSession.close();
+ }
+ session = newSession;
+
+ // Re-register the monitor with the new name.
+ registerReplicationMonitor();
+ }
+
+ private void registerReplicationMonitor()
+ {
+ /*
+ * The monitor should not be registered if this is a unit test because the
+ * replication domain is null.
+ */
+ if (monitor != null)
+ {
+ DirectoryServer.registerMonitorProvider(monitor);
+ }
+ }
+
+ private void deregisterReplicationMonitor()
+ {
+ /*
+ * The monitor should not be deregistered if this is a unit test because the
+ * replication domain is null.
+ */
+ if (monitor != null)
+ {
+ DirectoryServer.deregisterMonitorProvider(monitor);
+ }
+ }
}
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java b/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java
index c4d4f1b..4dc31ec 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java
@@ -49,7 +49,6 @@
import org.opends.server.api.DirectoryThread;
import org.opends.server.backends.task.Task;
import org.opends.server.config.ConfigException;
-import org.opends.server.core.DirectoryServer;
import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.replication.common.AssuredMode;
import org.opends.server.replication.common.ChangeNumber;
@@ -189,11 +188,6 @@
private static Map<String, ReplicationDomain> domains =
new HashMap<String, ReplicationDomain>();
- /**
- * The Monitor in charge of replication monitoring.
- */
- private ReplicationMonitor monitor;
-
/*
* Assured mode properties
*/
@@ -1480,11 +1474,9 @@
}
if (debugEnabled())
- TRACER.debugInfo(
- "[IE] In " + this.monitor.getMonitorInstanceName()
- + " export ends with "
- + " connected=" + broker.isConnected()
- + " exportRootException=" + exportRootException);
+ TRACER.debugInfo("[IE] In " + getReplicationMonitorInstanceName()
+ + " export ends with " + " connected=" + broker.isConnected()
+ + " exportRootException=" + exportRootException);
if (exportRootException != null)
{
@@ -1591,6 +1583,11 @@
}
+ private String getReplicationMonitorInstanceName()
+ {
+ return broker.getReplicationMonitor().getMonitorInstanceName();
+ }
+
/*
* For all remote servers in tht start list,
* - wait it has finished the import and present the expected generationID
@@ -1839,9 +1836,8 @@
msg = broker.receive(false, false, true);
if (debugEnabled())
- TRACER.debugInfo(
- "[IE] In " + this.monitor.getMonitorInstanceName() +
- ", receiveEntryBytes " + msg);
+ TRACER.debugInfo("[IE] In " + getReplicationMonitorInstanceName()
+ + ", receiveEntryBytes " + msg);
if (msg == null)
{
@@ -1892,9 +1888,9 @@
ieContext.msgCnt);
broker.publish(amsg, false);
if (debugEnabled())
- TRACER.debugInfo(
- "[IE] In " + this.monitor.getMonitorInstanceName() +
- ", publish InitializeRcvAckMsg" + amsg);
+ TRACER.debugInfo("[IE] In "
+ + getReplicationMonitorInstanceName()
+ + ", publish InitializeRcvAckMsg" + amsg);
}
}
return entryBytes;
@@ -3006,15 +3002,7 @@
changetimeHeartbeatInterval);
broker.start(replicationServers);
-
- /*
- * Create a replication monitor object responsible for publishing
- * monitoring information below cn=monitor.
- */
- monitor = new ReplicationMonitor(this);
}
-
- DirectoryServer.registerMonitorProvider(monitor);
}
}
@@ -3101,7 +3089,6 @@
*/
public void stopDomain()
{
- DirectoryServer.deregisterMonitorProvider(monitor);
disableService();
domains.remove(serviceID);
}
--
Gitblit v1.10.0