From 3bd6b1634f4a3d3a25fa6425f07c2393508d91ca Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 16 Oct 2013 14:06:22 +0000
Subject: [PATCH] HeartbeatThread.java, CTHeartbeatPublisherThread.java, DirectoryThread.java: Used StaticUtils.stackTraceToSingleLineString(e)) for logging on one line only.
---
opends/src/server/org/opends/server/replication/protocol/HeartbeatThread.java | 2
opends/src/server/org/opends/server/replication/server/ReplicationBackend.java | 103 ++++++-----------
opends/src/server/org/opends/server/replication/service/ListenerThread.java | 6
opends/src/server/org/opends/server/api/DirectoryThread.java | 2
opends/src/server/org/opends/server/replication/service/CTHeartbeatPublisherThread.java | 2
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ReplicationServerLoadBalancingTest.java | 230 +++++++++++++------------------------
6 files changed, 125 insertions(+), 220 deletions(-)
diff --git a/opends/src/server/org/opends/server/api/DirectoryThread.java b/opends/src/server/org/opends/server/api/DirectoryThread.java
index 98fa584..3b7bd5e 100644
--- a/opends/src/server/org/opends/server/api/DirectoryThread.java
+++ b/opends/src/server/org/opends/server/api/DirectoryThread.java
@@ -259,7 +259,7 @@
}
Message message = ERR_UNCAUGHT_THREAD_EXCEPTION.get(
- t.getName(), stackTraceToString(e));
+ t.getName(), stackTraceToSingleLineString(e));
logError(message);
DirectoryServer.sendAlertNotification(this,
ALERT_TYPE_UNCAUGHT_EXCEPTION, message);
diff --git a/opends/src/server/org/opends/server/replication/protocol/HeartbeatThread.java b/opends/src/server/org/opends/server/replication/protocol/HeartbeatThread.java
index c68979e..2432249 100644
--- a/opends/src/server/org/opends/server/replication/protocol/HeartbeatThread.java
+++ b/opends/src/server/org/opends/server/replication/protocol/HeartbeatThread.java
@@ -163,7 +163,7 @@
if (debugEnabled())
{
TRACER.debugInfo("Heartbeat thread could not send a heartbeat."
- + StaticUtils.stackTraceToString(e));
+ + StaticUtils.stackTraceToSingleLineString(e));
}
}
finally
diff --git a/opends/src/server/org/opends/server/replication/server/ReplicationBackend.java b/opends/src/server/org/opends/server/replication/server/ReplicationBackend.java
index e3f5e45..f11d2be 100644
--- a/opends/src/server/org/opends/server/replication/server/ReplicationBackend.java
+++ b/opends/src/server/org/opends/server/replication/server/ReplicationBackend.java
@@ -452,8 +452,8 @@
throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM,message);
}
- final List<ReplicationServerDomain> exportContainers =
- findExportContainers(exportConfig);
+ final List<ReplicationServerDomain> exportedDomains =
+ selectReplicationDomains(exportConfig.getIncludeBranches());
// Make a note of the time we started.
long startTime = System.currentTimeMillis();
@@ -461,8 +461,7 @@
// Start a timer for the progress report.
Timer timer = new Timer();
TimerTask progressTask = new ProgressTask();
- timer.scheduleAtFixedRate(progressTask, progressInterval,
- progressInterval);
+ timer.scheduleAtFixedRate(progressTask, progressInterval, progressInterval);
// Create the LDIF writer.
LDIFWriter ldifWriter;
@@ -483,19 +482,17 @@
message, e);
}
- exportRootChanges(exportContainers, exportConfig, ldifWriter);
+ exportRootChanges(exportedDomains, exportConfig, ldifWriter);
try
{
- // Iterate through the containers.
- for (ReplicationServerDomain exportContainer : exportContainers)
+ for (ReplicationServerDomain domain : exportedDomains)
{
if (exportConfig.isCancelled())
{
break;
}
- writeChangesAfterCSN(exportContainer, exportConfig, ldifWriter, null,
- null);
+ writeChangesAfterCSN(domain, exportConfig, ldifWriter, null, null);
}
}
finally
@@ -519,42 +516,42 @@
logError(message);
}
- private List<ReplicationServerDomain> findExportContainers(
- LDIFExportConfig exportConfig) throws DirectoryException
+ private List<ReplicationServerDomain> selectReplicationDomains(
+ List<DN> includeBranches) throws DirectoryException
{
- List<DN> includeBranches = exportConfig.getIncludeBranches();
- List<ReplicationServerDomain> exportContainers =
+ final List<ReplicationServerDomain> results =
new ArrayList<ReplicationServerDomain>();
- for (Iterator<ReplicationServerDomain> iter = server.getDomainIterator();
- iter.hasNext();)
+ final Iterable<ReplicationServerDomain> domains =
+ toIterable(server.getDomainIterator());
+ if (includeBranches == null || includeBranches.isEmpty())
{
- ReplicationServerDomain rsd = iter.next();
-
- // Skip containers that are not covered by the include branches.
- if (includeBranches == null || includeBranches.isEmpty())
+ for (ReplicationServerDomain domain : domains)
{
- exportContainers.add(rsd);
+ results.add(domain);
}
- else
+ return results;
+ }
+
+ for (ReplicationServerDomain domain : domains)
+ {
+ DN baseDN = DN.decode(domain.getBaseDN() + "," + BASE_DN);
+ for (DN includeBranch : includeBranches)
{
- DN baseDN = DN.decode(rsd.getBaseDN() + "," + BASE_DN);
- for (DN includeBranch : includeBranches)
+ if (includeBranch.isDescendantOf(baseDN)
+ || includeBranch.isAncestorOf(baseDN))
{
- if (includeBranch.isDescendantOf(baseDN)
- || includeBranch.isAncestorOf(baseDN))
- {
- exportContainers.add(rsd);
- }
+ results.add(domain);
+ break;
}
}
}
- return exportContainers;
+ return results;
}
/**
* Exports the root changes of the export, and one entry by domain.
*/
- private void exportRootChanges(List<ReplicationServerDomain> exportContainers,
+ private void exportRootChanges(List<ReplicationServerDomain> exportedDomains,
final LDIFExportConfig exportConfig, LDIFWriter ldifWriter)
{
AttributeType ocType = DirectoryServer.getObjectClassAttributeType();
@@ -580,30 +577,29 @@
return;
}
- for (ReplicationServerDomain exportContainer : exportContainers)
+ for (ReplicationServerDomain domain : exportedDomains)
{
if (exportConfig.isCancelled())
{
break;
}
- final ServerState serverState = exportContainer.getLatestServerState();
+ final ServerState serverState = domain.getLatestServerState();
TRACER.debugInfo("State=" + serverState);
Attribute stateAttr = Attributes.create("state", serverState.toString());
Attribute genidAttr = Attributes.create("generation-id",
- "" + exportContainer.getGenerationId() + exportContainer.getBaseDN());
+ "" + domain.getGenerationId() + domain.getBaseDN());
attrs.clear();
attrs.put(ocType, singletonList(ocAttr));
attrs.put(stateAttr.getAttributeType(), singletonList(stateAttr));
attrs.put(genidAttr.getAttributeType(), singletonList(genidAttr));
- final String dnString = exportContainer.getBaseDN() + "," + BASE_DN;
+ final String dnString = domain.getBaseDN() + "," + BASE_DN;
try
{
DN dn = DN.decode(dnString);
- ChangeRecordEntry changeRecord = new AddChangeRecordEntry(dn, attrs);
- ldifWriter.writeChangeRecord(changeRecord);
+ ldifWriter.writeChangeRecord(new AddChangeRecordEntry(dn, attrs));
}
catch (Exception e)
{
@@ -815,9 +811,7 @@
if (isExport)
{
- ChangeRecordEntry changeRecord =
- new AddChangeRecordEntry(dn, attrs);
- ldifWriter.writeChangeRecord(changeRecord);
+ ldifWriter.writeChangeRecord(new AddChangeRecordEntry(dn, attrs));
}
else
{
@@ -1202,38 +1196,15 @@
}
// Walk through all entries and send the ones that match.
- final List<ReplicationServerDomain> searchContainers =
- findSearchContainers(searchBaseDN);
- for (ReplicationServerDomain exportContainer : searchContainers)
+ final List<ReplicationServerDomain> searchedDomains =
+ selectReplicationDomains(Collections.singletonList(searchBaseDN));
+ for (ReplicationServerDomain domain : searchedDomains)
{
final CSN previousCSN = extractCSN(searchOperation);
- writeChangesAfterCSN(exportContainer, null, null, searchOperation,
- previousCSN);
+ writeChangesAfterCSN(domain, null, null, searchOperation, previousCSN);
}
}
- private List<ReplicationServerDomain> findSearchContainers(DN searchBaseDN)
- throws DirectoryException
- {
- List<ReplicationServerDomain> searchContainers =
- new ArrayList<ReplicationServerDomain>();
- for (Iterator<ReplicationServerDomain> iter = server.getDomainIterator();
- iter.hasNext();)
- {
- ReplicationServerDomain rsd = iter.next();
-
- // Skip containers that are not covered by the include branches.
- DN baseDN = DN.decode(rsd.getBaseDN() + "," + BASE_DN);
- if (searchBaseDN.isDescendantOf(baseDN)
- || searchBaseDN.isAncestorOf(baseDN))
- {
- searchContainers.add(rsd);
- }
- }
- return searchContainers;
- }
-
-
/**
* Retrieves the replication server associated to this backend.
*
diff --git a/opends/src/server/org/opends/server/replication/service/CTHeartbeatPublisherThread.java b/opends/src/server/org/opends/server/replication/service/CTHeartbeatPublisherThread.java
index 80ef7a6..76e5ef5 100644
--- a/opends/src/server/org/opends/server/replication/service/CTHeartbeatPublisherThread.java
+++ b/opends/src/server/org/opends/server/replication/service/CTHeartbeatPublisherThread.java
@@ -145,7 +145,7 @@
if (debugEnabled())
{
TRACER.debugInfo(getName() + " could not send a heartbeat: "
- + StaticUtils.stackTraceToString(e));
+ + StaticUtils.stackTraceToSingleLineString(e));
}
}
finally
diff --git a/opends/src/server/org/opends/server/replication/service/ListenerThread.java b/opends/src/server/org/opends/server/replication/service/ListenerThread.java
index 3173eb5..8eaaa71 100644
--- a/opends/src/server/org/opends/server/replication/service/ListenerThread.java
+++ b/opends/src/server/org/opends/server/replication/service/ListenerThread.java
@@ -62,10 +62,8 @@
*/
public ListenerThread(ReplicationDomain repDomain)
{
- super("Replica DS(" + repDomain.getServerId()
- + ") listener for domain \""
- + repDomain.getBaseDNString()
- + "\"");
+ super("Replica DS(" + repDomain.getServerId() + ") listener for domain \""
+ + repDomain.getBaseDNString() + "\"");
this.repDomain = repDomain;
}
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ReplicationServerLoadBalancingTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ReplicationServerLoadBalancingTest.java
index dea446c..ffb2930 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ReplicationServerLoadBalancingTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ReplicationServerLoadBalancingTest.java
@@ -29,6 +29,7 @@
import java.util.*;
+import org.assertj.core.api.Assertions;
import org.opends.messages.Category;
import org.opends.messages.Message;
import org.opends.messages.Severity;
@@ -200,14 +201,15 @@
private LDAPReplicationDomain createReplicationDomain(int serverId,
String testCase) throws Exception
{
- SortedSet<String> replServers = createRSListForTestCase(testCase);
- DN baseDn = DN.decode(TEST_ROOT_DN_STRING);
- DomainFakeCfg domainConf =
+ final SortedSet<String> replServers = createRSListForTestCase(testCase);
+ final DN baseDn = DN.decode(TEST_ROOT_DN_STRING);
+ final DomainFakeCfg domainConf =
new DomainFakeCfg(baseDn, serverId + 1, replServers, 1);
- LDAPReplicationDomain replicationDomain =
+ final LDAPReplicationDomain rd =
MultimasterReplication.createNewDomain(domainConf);
- replicationDomain.start();
- return replicationDomain;
+ rd.start();
+ assertTrue(rd.isConnected());
+ return rd;
}
/**
@@ -219,14 +221,11 @@
public void testSpreadLoad() throws Exception
{
String testCase = "testSpreadLoad";
-
debugInfo("Starting " + testCase);
-
initTest();
try
{
-
/**
* Start RS1 weigth=1, RS2 weigth=2, RS3 weigth=3, RS4 weigth=4
*/
@@ -238,7 +237,6 @@
// Start a first DS to make every RSs inter connect
rd[0] = createReplicationDomain(0, testCase);
- assertTrue(rd[0].isConnected());
// Wait for RSs inter-connections
checkRSConnectionsAndGenId(new int[] {0, 1, 2, 3},
@@ -251,20 +249,16 @@
* - RS3 has 6 DSs
* - RS4 has 8 DSs
*/
- for (int i = 1; i < NDS; i++)
- {
- rd[i] = createReplicationDomain(i, testCase);
- assertTrue(rd[i].isConnected());
- }
+ createReplicationDomains(testCase, 1, NDS);
// Now check the number of connected DSs for each RS
- assertEquals(getDSConnectedToRS(0), 2,
+ assertEquals(getNbDSsConnectedToRS(0), 2,
"Wrong expected number of DSs connected to RS1");
- assertEquals(getDSConnectedToRS(1), 4,
+ assertEquals(getNbDSsConnectedToRS(1), 4,
"Wrong expected number of DSs connected to RS2");
- assertEquals(getDSConnectedToRS(2), 6,
+ assertEquals(getNbDSsConnectedToRS(2), 6,
"Wrong expected number of DSs connected to RS3");
- assertEquals(getDSConnectedToRS(3), 8,
+ assertEquals(getNbDSsConnectedToRS(3), 8,
"Wrong expected number of DSs connected to RS4");
} finally
{
@@ -276,7 +270,7 @@
* Return the number of DSs currently connected to the RS with the passed
* index
*/
- private int getDSConnectedToRS(int rsIndex)
+ private int getNbDSsConnectedToRS(int rsIndex)
{
Iterator<ReplicationServerDomain> rsdIt = rs[rsIndex].getDomainIterator();
if (rsdIt.hasNext())
@@ -458,7 +452,6 @@
* DS1 starts and connects to RS1
*/
rd[0] = createReplicationDomain(0, testCase);
- assertTrue(rd[0].isConnected());
assertEquals(rd[0].getRsServerId(), RS1_ID);
/**
@@ -472,7 +465,6 @@
* DS2 starts and connects to RS2
*/
rd[1] = createReplicationDomain(1, testCase);
- assertTrue(rd[1].isConnected());
assertEquals(rd[1].getRsServerId(), RS2_ID);
/**
@@ -486,25 +478,22 @@
* DS3 starts and connects to RS3
*/
rd[2] = createReplicationDomain(2, testCase);
- assertTrue(rd[2].isConnected());
assertEquals(rd[2].getRsServerId(), RS3_ID);
/**
* DS4 starts and connects to RS1, RS2 or RS3
*/
rd[3] = createReplicationDomain(3, testCase);
- assertTrue(rd[3].isConnected());
int ds4ConnectedRsId = rd[3].getRsServerId();
assertTrue(ds4ConnectedRsId == RS1_ID || ds4ConnectedRsId == RS2_ID ||
ds4ConnectedRsId == RS3_ID,
- "DS4 should be connected to either RS1, RS2 or RS3 but is it is " +
+ "DS4 should be connected to either RS1, RS2 or RS3 but it is " +
"connected to RS id " + ds4ConnectedRsId);
/**
* DS5 starts and connects to one of the 2 other RSs
*/
rd[4] = createReplicationDomain(4, testCase);
- assertTrue(rd[4].isConnected());
int ds5ConnectedRsId = rd[4].getRsServerId();
assertTrue(ds5ConnectedRsId != ds4ConnectedRsId,
"DS5 should be connected to a RS which is not the same as the one of " +
@@ -514,7 +503,6 @@
* DS6 starts and connects to the RS with one DS
*/
rd[5] = createReplicationDomain(5, testCase);
- assertTrue(rd[5].isConnected());
int ds6ConnectedRsId = rd[5].getRsServerId();
assertTrue(ds6ConnectedRsId != ds4ConnectedRsId &&
ds6ConnectedRsId != ds5ConnectedRsId,
@@ -525,17 +513,13 @@
/**
* DS7 to DS12 start, we must end up with RS1, RS2 and RS3 each with 4 DSs
*/
- for (int i = 6; i < 12; i++)
- {
- rd[i] = createReplicationDomain(i, testCase);
- assertTrue(rd[i].isConnected());
- }
+ createReplicationDomains(testCase, 6, 12);
// Now check the number of connected DSs for each RS
- assertEquals(getDSConnectedToRS(0), 4,
+ assertEquals(getNbDSsConnectedToRS(0), 4,
"Wrong expected number of DSs connected to RS1");
- assertEquals(getDSConnectedToRS(1), 4,
+ assertEquals(getNbDSsConnectedToRS(1), 4,
"Wrong expected number of DSs connected to RS2");
- assertEquals(getDSConnectedToRS(2), 4,
+ assertEquals(getNbDSsConnectedToRS(2), 4,
"Wrong expected number of DSs connected to RS3");
/**
@@ -567,43 +551,30 @@
* DS13 to DS20 start, we must end up with RS1, RS2 and RS4 each with 3
* or 4 DSs (1 with 4 and the 2 others with 3) and RS3 with 10 DSs
*/
-
- for (int i = 12; i < 20; i++)
- {
- rd[i] = createReplicationDomain(i, testCase);
- assertTrue(rd[i].isConnected());
- }
+ createReplicationDomains(testCase, 12, 20);
int rsWith4DsIndex = -1; // The RS (index) that has 4 DSs
// Now check the number of connected DSs for each RS
- int rs1ConnectedDSNumber = getDSConnectedToRS(0);
- assertTrue(rs1ConnectedDSNumber == 3 || rs1ConnectedDSNumber == 4,
- "Wrong expected number of DSs connected to RS1: " +
- rs1ConnectedDSNumber);
- if (rs1ConnectedDSNumber == 4)
+ int nbDSsRS1 = getNbDSsConnectedToRS(0);
+ int nbDSsRS2 = getNbDSsConnectedToRS(1);
+ int nbDSsRS3 = getNbDSsConnectedToRS(3);
+ Assertions.assertThat(nbDSsRS1).isIn(3, 4);
+ Assertions.assertThat(nbDSsRS2).isIn(3, 4);
+ Assertions.assertThat(nbDSsRS3).isIn(3, 4);
+ if (nbDSsRS1 == 4)
{
rsWith4DsIndex = 0;
}
- int rs2ConnectedDSNumber = getDSConnectedToRS(1);
- assertTrue(rs2ConnectedDSNumber == 3 || rs2ConnectedDSNumber == 4,
- "Wrong expected number of DSs connected to RS2: " +
- rs2ConnectedDSNumber);
- if (rs2ConnectedDSNumber == 4)
+ if (nbDSsRS2 == 4)
{
rsWith4DsIndex = 1;
}
- int rs4ConnectedDSNumber = getDSConnectedToRS(3);
- assertTrue(rs4ConnectedDSNumber == 3 || rs4ConnectedDSNumber == 4,
- "Wrong expected number of DSs connected to RS4: " +
- rs4ConnectedDSNumber);
- if (rs4ConnectedDSNumber == 4)
+ if (nbDSsRS3 == 4)
{
rsWith4DsIndex = 3;
}
- int sumOfRs1Rs2Rs4 = rs1ConnectedDSNumber + rs2ConnectedDSNumber +
- rs4ConnectedDSNumber;
- assertEquals(sumOfRs1Rs2Rs4, 10, "Expected 10 DSs connected to RS1, RS2" +
- " and RS4");
- assertEquals(getDSConnectedToRS(2), 10,
+ assertEquals(nbDSsRS1 + nbDSsRS2 + nbDSsRS3, 10,
+ "Expected 10 DSs connected to RS1, RS2 and RS4");
+ assertEquals(getNbDSsConnectedToRS(2), 10,
"Wrong expected number of DSs connected to RS3");
/**
@@ -613,8 +584,7 @@
*/
// Determine the lowest id of DSs connected to the RS with 4 DSs
- Set<Integer> fourDsList = rs[rsWith4DsIndex].getDomainIterator().next().
- getConnectedDSs().keySet();
+ Set<Integer> fourDsList = getConnectedDSIdsForReplServer(rsWith4DsIndex);
assertEquals(fourDsList.size(), 4);
int lowestDsId = Integer.MAX_VALUE;
for (int id : fourDsList)
@@ -626,8 +596,7 @@
}
// Get 2 DS ids of 2 DSs connected to RS3 and stop matching DSs
- Iterator<Integer> dsIdIt = rs[2].getDomainIterator().next().
- getConnectedDSs().keySet().iterator();
+ Iterator<Integer> dsIdIt = getConnectedDSIdsForReplServer(2).iterator();
int aFirstDsOnRs3Id = dsIdIt.next() - 1;
rd[aFirstDsOnRs3Id].shutdown();
int aSecondDsOnRs3Id = dsIdIt.next() - 1;
@@ -642,18 +611,12 @@
// Check that the right DS moved away from the RS with 4 DSs and went to
// RS3 and that the 3 others did not move
- Set<Integer> dsOnRs3List = rs[2].getDomainIterator().next().
- getConnectedDSs().keySet();
+ Set<Integer> dsOnRs3List = getConnectedDSIdsForReplServer(2);
assertTrue(dsOnRs3List.contains(lowestDsId), "DS with the lowest id (" +
lowestDsId + " should have come to RS3");
- Set<Integer> threeDsList = rs[rsWith4DsIndex].getDomainIterator().next().
- getConnectedDSs().keySet();
- assertEquals(threeDsList.size(), 3);
- for (int id : threeDsList)
- {
- assertTrue(fourDsList.contains(id), "DS " + id + " should still be on "
- + "RS " + (rsWith4DsIndex+501));
- }
+ Set<Integer> threeDsList = getConnectedDSIdsForReplServer(rsWith4DsIndex);
+ // All 3 DSs should still be connected to the RS with 4 DSs
+ Assertions.assertThat(fourDsList).containsAll(threeDsList);
/**
* Start the 2 stopped DSs again, we must end up with RS1, RS2 and RS4
@@ -663,28 +626,18 @@
// Restart the 2 stopped DSs
rd[aFirstDsOnRs3Id] = createReplicationDomain(aFirstDsOnRs3Id, testCase);
- assertTrue(rd[aFirstDsOnRs3Id].isConnected());
rd[aSecondDsOnRs3Id] = createReplicationDomain(aSecondDsOnRs3Id, testCase);
- assertTrue(rd[aSecondDsOnRs3Id].isConnected());
// Now check the number of connected DSs for each RS
- rs1ConnectedDSNumber = getDSConnectedToRS(0);
- assertTrue(rs1ConnectedDSNumber == 3 || rs1ConnectedDSNumber == 4,
- "Wrong expected number of DSs connected to RS1: " +
- rs1ConnectedDSNumber);
- rs2ConnectedDSNumber = getDSConnectedToRS(1);
- assertTrue(rs2ConnectedDSNumber == 3 || rs2ConnectedDSNumber == 4,
- "Wrong expected number of DSs connected to RS2: " +
- rs2ConnectedDSNumber);
- rs4ConnectedDSNumber = getDSConnectedToRS(3);
- assertTrue(rs4ConnectedDSNumber == 3 || rs4ConnectedDSNumber == 4,
- "Wrong expected number of DSs connected to RS4: " +
- rs4ConnectedDSNumber);
- sumOfRs1Rs2Rs4 = rs1ConnectedDSNumber + rs2ConnectedDSNumber +
- rs4ConnectedDSNumber;
- assertEquals(sumOfRs1Rs2Rs4, 10, "Expected 10 DSs connected to RS1, RS2" +
- " and RS4");
- assertEquals(getDSConnectedToRS(2), 10,
- "Wrong expected number of DSs connected to RS3");
+ nbDSsRS1 = getNbDSsConnectedToRS(0);
+ nbDSsRS2 = getNbDSsConnectedToRS(1);
+ nbDSsRS3 = getNbDSsConnectedToRS(3);
+ Assertions.assertThat(nbDSsRS1).isIn(3, 4);
+ Assertions.assertThat(nbDSsRS2).isIn(3, 4);
+ Assertions.assertThat(nbDSsRS3).isIn(3, 4);
+ assertEquals(nbDSsRS1 + nbDSsRS2 + nbDSsRS3, 10,
+ "Expected 10 DSs connected to RS1, RS2 and RS4");
+ assertEquals(getNbDSsConnectedToRS(2), 10,
+ "Wrong expected number of DSs connected to RS3");
/**
* Change RS2 weight to 2, RS3 weight to 4, RS4 weight to 3, we must end
@@ -717,9 +670,8 @@
* RS1 has 2 DSs, RS2 has 4 DSs, RS3 has 8 DSs and RS4 has 6 DSs
*/
- // Restart RS2
+ // Restart RS2 and RS4
rs[1] = createReplicationServer(1, 2, testCase);
- // Restart RS4
rs[3] = createReplicationServer(3, 3, testCase);
checkForCorrectNumbersOfConnectedDSs(new int[][]{new int[] {2, 4, 8, 6}},
@@ -766,6 +718,11 @@
}
}
+ private Set<Integer> getConnectedDSIdsForReplServer(int rsIndex)
+ {
+ return rs[rsIndex].getDomainIterator().next().getConnectedDSs().keySet();
+ }
+
private void stopRs(int... rsIndexes) throws Exception
{
for (int rsIndex : rsIndexes)
@@ -779,7 +736,7 @@
}
/** Translate an int array into a human readable string */
- private static String intArrayToString(int[] ints)
+ private static String toString(int[] ints)
{
StringBuilder sb = new StringBuilder("[");
for (int i = 0; i < ints.length; i++)
@@ -795,7 +752,7 @@
}
/** Translate an int[][] array into a human readable string */
- private static String intArrayToString(int[][] ints)
+ private static String toString(int[][] ints)
{
StringBuilder sb = new StringBuilder("[");
for (int i = 0; i < ints.length; i++)
@@ -804,7 +761,7 @@
{
sb.append(",");
}
- sb.append(intArrayToString(ints[i]));
+ sb.append(toString(ints[i]));
}
sb.append("]");
return sb.toString();
@@ -847,7 +804,7 @@
{
nRSs++;
// Check for number of DSs connected to this RS
- int connectedDSs = getDSConnectedToRS(j);
+ int connectedDSs = getNbDSsConnectedToRS(j);
if (connectedDSs == expectedDSNumber)
{
nOk++;
@@ -866,7 +823,7 @@
{
// Connection verified
debugInfo("checkForCorrectNumbersOfConnectedDSs: got expected " +
- "connections " + intArrayToString(expectedDSsNumbers) + " after " + nSec +
+ "connections " + toString(expectedDSsNumbers) + " after " + nSec +
" seconds.");
return;
}
@@ -879,9 +836,9 @@
// Timeout reached, end with error
assertTrue(nSec <= secTimeout,
"checkForCorrectNumbersOfConnectedDSs: could not get expected "
- + "connections " + intArrayToString(possibleExpectedDSsNumbers)
+ + "connections " + toString(possibleExpectedDSsNumbers)
+ " after " + (nSec - 1) + " seconds. Got this result : "
- + intArrayToString(finalDSsNumbers) + " [" + msg + "]");
+ + toString(finalDSsNumbers) + " [" + msg + "]");
}
}
@@ -919,7 +876,6 @@
*/
rd[0] = createReplicationDomain(0, testCase);
- assertTrue(rd[0].isConnected());
assertEquals(rd[0].getRsServerId(), RS1_ID);
/**
@@ -935,7 +891,6 @@
*/
rd[1] = createReplicationDomain(1, testCase);
- assertTrue(rd[1].isConnected());
assertEquals(rd[1].getRsServerId(), RS2_ID);
/**
@@ -944,15 +899,11 @@
int dsIsIndex = 2;
rd[dsIsIndex] = createReplicationDomain(dsIsIndex, testCase);
- assertTrue(rd[dsIsIndex].isConnected());
-
int rsId = rd[dsIsIndex].getRsServerId();
int rsIndex = rsId - 501;
- int nDSs = getDSConnectedToRS(rsIndex);
- assertEquals(getDSConnectedToRS(rsIndex), 2, " Expected 2 DSs on RS " +
- rsId);
- debugInfo(testCase + ": DS3 connected to RS " + rsId + ", with " + nDSs
- + " DSs");
+ int nDSs = getNbDSsConnectedToRS(rsIndex);
+ assertEquals(getNbDSsConnectedToRS(rsIndex), 2, " Expected 2 DSs on RS " + rsId);
+ debugInfo(testCase + ": DS3 connected to RS " + rsId + ", with " + nDSs + " DSs");
// Be sure that DS3 stays connected to the same RS during some long time
// check every second
@@ -964,8 +915,7 @@
// Still connected to the right RS ?
assertEquals(rd[dsIsIndex].getRsServerId(), rsId, "DS3 should still be " +
"connected to RS " + rsId);
- assertEquals(getDSConnectedToRS(rsIndex), 2, " Expected 2 DSs on RS " +
- rsId);
+ assertEquals(getNbDSsConnectedToRS(rsIndex), 2, " Expected 2 DSs on RS " + rsId);
elapsedTime++;
}
@@ -1009,7 +959,6 @@
*/
rd[0] = createReplicationDomain(0, testCase);
- assertTrue(rd[0].isConnected());
assertEquals(rd[0].getRsServerId(), RS1_ID);
/**
@@ -1024,12 +973,7 @@
/**
* DS2 to DS3 start and connects to RSs
*/
-
- for (int i = 1; i < 3; i++)
- {
- rd[i] = createReplicationDomain(i, testCase);
- assertTrue(rd[i].isConnected());
- }
+ createReplicationDomains(testCase, 1, 3);
/**
* DS4 starts and connects to either RS1 RS2 or RS3 but should stay on it
@@ -1037,15 +981,11 @@
int dsIsIndex = 3;
rd[dsIsIndex] = createReplicationDomain(dsIsIndex, testCase);
- assertTrue(rd[dsIsIndex].isConnected());
-
int rsId = rd[dsIsIndex].getRsServerId();
int rsIndex = rsId - 501;
- int nDSs = getDSConnectedToRS(rsIndex);
- assertEquals(getDSConnectedToRS(rsIndex), 2, " Expected 2 DSs on RS " +
- rsId);
- debugInfo(testCase + ": DS4 connected to RS " + rsId + ", with " + nDSs
- + " DSs");
+ int nDSs = getNbDSsConnectedToRS(rsIndex);
+ assertEquals(getNbDSsConnectedToRS(rsIndex), 2, " Expected 2 DSs on RS " + rsId);
+ debugInfo(testCase + ": DS4 connected to RS " + rsId + ", with " + nDSs + " DSs");
// Be sure that DS3 stays connected to the same RS during some long time
// check every second
@@ -1057,8 +997,7 @@
// Still connected to the right RS ?
assertEquals(rd[dsIsIndex].getRsServerId(), rsId, "DS4 should still be " +
"connected to RS " + rsId);
- assertEquals(getDSConnectedToRS(rsIndex), 2, " Expected 2 DSs on RS " +
- rsId);
+ assertEquals(getNbDSsConnectedToRS(rsIndex), 2, " Expected 2 DSs on RS " + rsId);
elapsedTime++;
}
@@ -1102,7 +1041,6 @@
*/
rd[0] = createReplicationDomain(0, testCase);
- assertTrue(rd[0].isConnected());
assertEquals(rd[0].getRsServerId(), RS1_ID);
/**
@@ -1117,12 +1055,7 @@
/**
* DS2 to DS6 start and connects to RSs
*/
-
- for (int i = 1; i < 6; i++)
- {
- rd[i] = createReplicationDomain(i, testCase);
- assertTrue(rd[i].isConnected());
- }
+ createReplicationDomains(testCase, 1, 6);
/**
* DS7 starts and connects to either RS1 RS2 or RS3 but should stay on it
@@ -1130,15 +1063,11 @@
int dsIsIndex = 6;
rd[dsIsIndex] = createReplicationDomain(dsIsIndex, testCase);
- assertTrue(rd[dsIsIndex].isConnected());
-
int rsId = rd[dsIsIndex].getRsServerId();
int rsIndex = rsId - 501;
- int nDSs = getDSConnectedToRS(rsIndex);
- assertEquals(getDSConnectedToRS(rsIndex), 3, " Expected 2 DSs on RS " +
- rsId);
- debugInfo(testCase + ": DS7 connected to RS " + rsId + ", with " + nDSs
- + " DSs");
+ int nDSs = getNbDSsConnectedToRS(rsIndex);
+ assertEquals(getNbDSsConnectedToRS(rsIndex), 3, " Expected 2 DSs on RS " + rsId);
+ debugInfo(testCase + ": DS7 connected to RS " + rsId + ", with " + nDSs + " DSs");
// Be sure that DS3 stays connected to the same RS during some long time
// check every second
@@ -1150,8 +1079,7 @@
// Still connected to the right RS ?
assertEquals(rd[dsIsIndex].getRsServerId(), rsId, "DS7 should still be " +
"connected to RS " + rsId);
- assertEquals(getDSConnectedToRS(rsIndex), 3, " Expected 2 DSs on RS " +
- rsId);
+ assertEquals(getNbDSsConnectedToRS(rsIndex), 3, " Expected 2 DSs on RS " + rsId);
elapsedTime++;
}
@@ -1160,4 +1088,12 @@
endTest();
}
}
+
+ private void createReplicationDomains(String testCase, int start, int end) throws Exception
+ {
+ for (int i = start; i < end; i++)
+ {
+ rd[i] = createReplicationDomain(i, testCase);
+ }
+ }
}
--
Gitblit v1.10.0