mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

gbellato
09.08.2007 546128b39c0ee78e9ff726366678321586cb58e3
Fix the replication WindowProbeTest and enable back this test.

The problem was that because of some tests running before this test
they were changes in the replication server when this test was run.
The test now open a first session to read the serverState of the
replication server then open a second session using this serverState
as its own.

1 files modified
96 ■■■■■ changed files
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java 96 ●●●●● patch | view | raw | blame | history
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();
    }
  }