From bcf53e9c644ba543ebce96e0ce422805e11292e6 Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Mon, 09 Jul 2007 07:08:13 +0000
Subject: [PATCH] Fix the replication WindowProbeTest and enable back this test.

---
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java |   96 +++++++++++++++++++++++++++++++++--------------
 1 files changed, 67 insertions(+), 29 deletions(-)

diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java
index af0c8b7..ed59add 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java
@@ -540,8 +540,8 @@
 
       for (int i =0; i< THREADS; i++)
       {
-        producer[i].join();
-        reader[i].join();
+        producer[i].join(60000);
+        reader[i].join(60000);
       }
     }
     finally
@@ -761,13 +761,25 @@
    * Test that the Replication sends back correctly WindowsUpdate
    * when we send a WindowProbe.
    */
-  @Test(enabled=false)
+  @Test(enabled=true)
   public void windowProbeTest() throws Exception
   {
     final int WINDOW = 10;
     /*
-     * Open a socket connection to the replication server
+     * Open a session to the replication server.
+     *
+     * Some other tests may have been running before and therefore
+     * may have pushed some changes to the Replication Server
+     * When a new session is opened, the Replication Server is therefore
+     * going to send all thoses old changes to this Replication Server.
+     * To avoid this, this test open a first session, save the
+     * ServerState from the ReplicationServer, close the session
+     * and re-open a new connection providing the ServerState it just
+     * received from the first session.
+     * This should guarantee that old changes are not perturbing this test.
      */
+
+    // open the first session to the
     InetSocketAddress ServerAddr = new InetSocketAddress(
         InetAddress.getByName("localhost"), replicationServerPort);
     Socket socket = new Socket();
@@ -776,34 +788,60 @@
     socket.connect(ServerAddr, 500);
     SocketSession session = new SocketSession(socket);
 
-    /*
-     * Send our ServerStartMessage.
-     */
-    ServerStartMessage msg =
-      new ServerStartMessage((short) 1723, DN.decode("dc=example,dc=com"),
-          0, 0, 0, 0, WINDOW, (long) 5000, new ServerState(),
+    try
+    {
+      // send a ServerStartMessage with an empty ServerState.
+      ServerStartMessage msg =
+        new ServerStartMessage((short) 1723, DN.decode("dc=example,dc=com"),
+            0, 0, 0, 0, WINDOW, (long) 5000, new ServerState(),
+            ProtocolVersion.currentVersion());
+      session.publish(msg);
+
+      // Read the Replication Server state from the ReplServerStartMessage that
+      // comes back.
+      ReplServerStartMessage replStartMsg =
+        (ReplServerStartMessage) session.receive();
+      int serverwindow = replStartMsg.getWindowSize();
+      ServerState replServerState = replStartMsg.getServerState();
+
+      // close the session
+      session.close();
+
+      // open a new session to the replication Server
+      socket = new Socket();
+      socket.setReceiveBufferSize(1000000);
+      socket.setTcpNoDelay(true);
+      socket.connect(ServerAddr, 500);
+      session = new SocketSession(socket);
+
+      // send a ServerStartMessage containing the ServerState that was just
+      // received.
+      msg = new ServerStartMessage(
+          (short) 1724, DN.decode("dc=example,dc=com"),
+          0, 0, 0, 0, WINDOW, (long) 5000, replServerState,
           ProtocolVersion.currentVersion());
-    session.publish(msg);
+      session.publish(msg);
 
-    /*
-     * Read the ReplServerStartMessage that should come back.
-     */
-    session.setSoTimeout(10000);
-    ReplServerStartMessage replStartMsg =
-      (ReplServerStartMessage) session.receive();
-    int serverwindow = replStartMsg.getWindowSize();
+      // Read the ReplServerStartMessage that come back.
+      session.receive();
 
-    // push a WindowProbe message 
-    session.publish(new WindowProbe());
-    
-    WindowMessage windowMsg = (WindowMessage) session.receive();
-    assertEquals(serverwindow, windowMsg.getNumAck());
-    
-    // check that this did not change the window by sending a probe again.
-    session.publish(new WindowProbe());
-    
-    windowMsg = (WindowMessage) session.receive();
-    assertEquals(serverwindow, windowMsg.getNumAck());
+      // Now comes the real test : check that the Replication Server
+      // answers correctly to a WindowProbe Message.
+      session.publish(new WindowProbe());
+
+      WindowMessage windowMsg = (WindowMessage) session.receive();
+      assertEquals(serverwindow, windowMsg.getNumAck());
+
+      // check that this did not change the window by sending a probe again.
+      session.publish(new WindowProbe());
+
+      windowMsg = (WindowMessage) session.receive();
+      assertEquals(serverwindow, windowMsg.getNumAck());
+    }
+    finally
+    {
+      session.close();
+    }
   }
 
 

--
Gitblit v1.10.0