From 5fbe2f7032d3113bff70dd775555967c992964e5 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 24 Aug 2015 10:53:01 +0000
Subject: [PATCH] AssuredReplicationPluginTest.java: Used ReplicationTestCase.waitForSpecificMsg*(). Code cleanup
---
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AssuredReplicationPluginTest.java | 101 +++++++++------------------------
opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java | 31 ++++-----
2 files changed, 41 insertions(+), 91 deletions(-)
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java
index 7a56c7d..9ee3a1b 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/ReplicationTestCase.java
@@ -832,7 +832,8 @@
* @param msgType Class of the message we are waiting for.
* @return The expected message if it comes in time or fails (assertion).
*/
- protected static <T extends ReplicationMsg> T waitForSpecificMsg(Session session, Class<T> msgType) {
+ protected static <T extends ReplicationMsg> T waitForSpecificMsg(Session session, Class<T> msgType) throws Exception
+ {
return (T) waitForSpecificMsgs(session, (ReplicationBroker) null, msgType);
}
@@ -843,19 +844,24 @@
* @param msgType Class of the message we are waiting for.
* @return The expected message if it comes in time or fails (assertion).
*/
- protected static <T extends ReplicationMsg> T waitForSpecificMsg(ReplicationBroker broker, Class<T> msgType) {
+ protected static <T extends ReplicationMsg> T waitForSpecificMsg(ReplicationBroker broker, Class<T> msgType)
+ throws Exception
+ {
return (T) waitForSpecificMsgs(null, broker, msgType);
}
- protected static ReplicationMsg waitForSpecificMsgs(Session session, Class<?>... msgTypes) {
+ protected static ReplicationMsg waitForSpecificMsgs(Session session, Class<?>... msgTypes) throws Exception
+ {
return waitForSpecificMsgs(session, null, msgTypes);
}
- protected static ReplicationMsg waitForSpecificMsgs(ReplicationBroker broker, Class<?>... msgTypes) {
+ protected static ReplicationMsg waitForSpecificMsgs(ReplicationBroker broker, Class<?>... msgTypes) throws Exception
+ {
return waitForSpecificMsgs(null, broker, msgTypes);
}
private static ReplicationMsg waitForSpecificMsgs(Session session, ReplicationBroker broker, Class<?>... msgTypes)
+ throws Exception
{
assertTrue(session != null || broker != null, "One of Session or ReplicationBroker parameter must not be null");
assertTrue(session == null || broker == null, "Only one of Session or ReplicationBroker parameter must not be null");
@@ -869,22 +875,13 @@
while (!timedOut)
{
ReplicationMsg replMsg = null;
- try
+ if (session != null)
{
- if (session != null)
- {
- replMsg = session.receive();
- }
- else if (broker != null)
- {
- replMsg = broker.receive();
- }
+ replMsg = session.receive();
}
- catch (Exception ex)
+ else if (broker != null)
{
- ex.printStackTrace();
- fail("Exception waiting for " + msgTypes2 + " message : "
- + ex.getClass().getName() + " : " + ex.getMessage());
+ replMsg = broker.receive();
}
if (msgTypes2.contains(replMsg.getClass()))
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AssuredReplicationPluginTest.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AssuredReplicationPluginTest.java
index 18f0cd3..86ae1e1 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AssuredReplicationPluginTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/AssuredReplicationPluginTest.java
@@ -69,10 +69,8 @@
@SuppressWarnings("javadoc")
public class AssuredReplicationPluginTest extends ReplicationTestCase
{
-
public class MonitorAssertions
{
-
private Map<String, Long> attributeValues = new HashMap<>();
public MonitorAssertions(DN baseDN) throws Exception
@@ -147,9 +145,7 @@
}
}
- /**
- * Before starting the tests configure some stuff.
- */
+ /** Before starting the tests configure some stuff. */
@BeforeClass
@Override
public void setUp() throws Exception
@@ -170,9 +166,7 @@
addEntry(TestCaseUtils.entryFromLdifString(topEntry));
}
- /**
- * Add an entry in the database.
- */
+ /** Add an entry in the database. */
private void addEntry(Entry entry) throws Exception
{
debugInfo("AddEntry " + entry.getName());
@@ -276,7 +270,6 @@
*/
private class FakeReplicationServer extends Thread
{
-
private ServerSocket listenSocket;
private boolean shutdown;
private Session session;
@@ -352,9 +345,7 @@
this.isAssured = assured;
}
- /**
- * Starts the fake RS, expecting and testing the passed scenario.
- */
+ /** Starts the fake RS, expecting and testing the passed scenario. */
public void start(int scenario)
{
gen = new CSNGenerator(3, 0L);
@@ -366,9 +357,7 @@
start();
}
- /**
- * Wait for DS connections.
- */
+ /** Wait for DS connections. */
@Override
public void run()
{
@@ -411,9 +400,7 @@
}
}
- /**
- * Shutdown the Replication Server service and all its connections.
- */
+ /** Shutdown the Replication Server service and all its connections. */
public void shutdown()
{
if (shutdown)
@@ -443,7 +430,7 @@
{
{
// Receive server start
- ServerStartMsg serverStartMsg = (ServerStartMsg) session.receive();
+ ServerStartMsg serverStartMsg = waitForSpecificMsg(session, ServerStartMsg.class);
baseDN = serverStartMsg.getBaseDN();
serverState = serverStartMsg.getServerState();
@@ -463,7 +450,6 @@
session.stopEncryption();
}
- // Read start session or stop
ReplicationMsg msg = session.receive();
if (msg instanceof StopMsg){
// Disconnection of DS looking for best server
@@ -509,9 +495,7 @@
return scenarioExecuted;
}
- /**
- * Handle client connection then call code specific to configured test.
- */
+ /** Handle client connection then call code specific to configured test. */
private void handleClientConnection() throws Exception
{
debugInfo("handleClientConnection " + testcase + " " + scenario);
@@ -570,27 +554,20 @@
*/
private AckMsg sendAssuredAddMsg(Entry entry, String parentUid) throws Exception
{
- {
- AddMsg addMsg =
- new AddMsg(gen.newCSN(), entry.getName(), UUID.randomUUID().toString(),
- parentUid,
- entry.getObjectClassAttribute(),
- entry.getAttributes(), null );
+ AddMsg addMsg = new AddMsg(
+ gen.newCSN(), entry.getName(), UUID.randomUUID().toString(),
+ parentUid, entry.getObjectClassAttribute(), entry.getAttributes(), null);
- // Send add message in assured mode
- addMsg.setAssured(isAssured);
- addMsg.setAssuredMode(assuredMode);
- addMsg.setSafeDataLevel(safeDataLevel);
- session.publish(addMsg);
+ // Send add message in assured mode
+ addMsg.setAssured(isAssured);
+ addMsg.setAssuredMode(assuredMode);
+ addMsg.setSafeDataLevel(safeDataLevel);
+ session.publish(addMsg);
- // Read and return matching ack
- return (AckMsg)session.receive();
- }
+ return waitForSpecificMsg(session, AckMsg.class);
}
- /**
- * Read the coming update and check parameters are not assured.
- */
+ /** Read the coming update and check parameters are not assured. */
private void executeNotAssuredScenario() throws Exception
{
checkAssuredParametersOnReceivedUpdateMsg();
@@ -598,10 +575,7 @@
scenarioExecuted = true;
}
- /**
- * Read the coming update and make the client time out by not sending back
- * the ack.
- */
+ /** Read the coming update and make the client time out by not sending back the ack. */
private void executeTimeoutScenario() throws Exception
{
checkAssuredParametersOnReceivedUpdateMsg();
@@ -612,9 +586,7 @@
// blocked at least for the programmed timeout time.
}
- /**
- * Read the coming update, sleep some time then send back an ack.
- */
+ /** Read the coming update, sleep some time then send back an ack. */
private void executeNoTimeoutScenario() throws Exception
{
UpdateMsg updateMsg = checkAssuredParametersOnReceivedUpdateMsg();
@@ -650,9 +622,7 @@
return updateMsg;
}
- /**
- * Read the coming safe read mode updates and send back acks with errors.
- */
+ /** Read the coming safe read mode updates and send back acks with errors. */
private void executeSafeReadManyErrorsScenario() throws Exception
{
// Read first update
@@ -688,9 +658,7 @@
scenarioExecuted = true;
}
- /**
- * Read the coming safe data mode updates and send back acks with errors.
- */
+ /** Read the coming safe data mode updates and send back acks with errors. */
private void executeSafeDataManyErrorsScenario() throws Exception
{
// Read first update
@@ -723,12 +691,9 @@
// let timeout occur
scenarioExecuted = true;
}
-
}
- /**
- * Return various group id values.
- */
+ /** Return various group id values. */
@DataProvider(name = "rsGroupIdProvider")
private Object[][] rsGroupIdProvider()
{
@@ -940,14 +905,10 @@
}
}
- /**
- * Tests parameters sent in session handshake and updates, when not using
- * assured replication.
- */
+ /** Tests parameters sent in session handshake and updates, when not using assured replication. */
@Test
public void testNotAssuredSession() throws Exception
{
-
String testcase = "testNotAssuredSession";
try
{
@@ -1136,9 +1097,7 @@
// Wait for connection of domain to RS
waitForConnectionToRs(testcase, replicationServer);
- /*
- * Send an update from the RS and get the ack
- */
+ /* Send an update from the RS and get the ack */
// Make the RS send an assured add message
String entryStr = "dn: ou=assured-sr-reply-entry," + SAFE_READ_DN + "\n" +
@@ -1183,9 +1142,7 @@
return;
}
- /*
- * Send un update with error from the RS and get the ack with error
- */
+ /* Send an update with error from the RS and get the ack with error */
// Make the RS send a not possible assured add message
@@ -1449,9 +1406,7 @@
}
}
- /**
- * Delete an entry from the database.
- */
+ /** Delete an entry from the database. */
private void deleteEntry(String dn) throws Exception
{
DN realDN = DN.valueOf(dn);
@@ -1493,9 +1448,7 @@
SearchResultEntry entry = op.getSearchEntries().getFirst();
assertNotNull(entry);
- /*
- * Find the multi valued attribute matching the requested assured mode
- */
+ /* Find the multi valued attribute matching the requested assured mode */
String assuredAttr;
switch(assuredMode)
{
--
Gitblit v1.10.0