From 845ce56b7df0b600d2ff87b3b9f5026fd980ab64 Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Mon, 10 Dec 2007 16:57:26 +0000
Subject: [PATCH] This fixes 2724 : and enable/fix some more replication tests.

---
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/InitOnLineTest.java               |    2 
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ReplicationServerTest.java |  108 +++++++++++++++++++----------------
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/UpdateOperationTest.java          |    2 
 opendj-sdk/opends/src/server/org/opends/server/replication/server/ServerHandler.java                                 |   12 +++-
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/GenerationIdTest.java             |    9 ++
 5 files changed, 77 insertions(+), 56 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/server/ServerHandler.java b/opendj-sdk/opends/src/server/org/opends/server/replication/server/ServerHandler.java
index 174eba0..2c4e3ba 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/server/ServerHandler.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/server/ServerHandler.java
@@ -53,7 +53,6 @@
 package org.opends.server.replication.server;
 
 import org.opends.messages.*;
-import org.opends.messages.MessageBuilder;
 
 import static org.opends.server.loggers.ErrorLogger.logError;
 import static org.opends.server.loggers.debug.DebugLogger.*;
@@ -73,6 +72,7 @@
 import java.util.SortedSet;
 import java.util.TreeSet;
 import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
 
 import org.opends.server.admin.std.server.MonitorProviderCfg;
 import org.opends.server.api.MonitorProvider;
@@ -167,6 +167,11 @@
    */
   HeartbeatThread heartbeatThread = null;
 
+  /**
+   * Set when ServerHandler is stopping.
+   */
+  private boolean shutdown = false;
+
   private static final Map<ChangeNumber, ReplServerAckMessageList>
    changelogsWaitingAcks =
        new HashMap<ChangeNumber, ReplServerAckMessageList>();
@@ -1012,13 +1017,13 @@
     do {
       try
       {
-        sendWindow.acquire();
+        sendWindow.tryAcquire((long)500, TimeUnit.MILLISECONDS);
         interrupted = false;
       } catch (InterruptedException e)
       {
         // loop until not interrupted
       }
-    } while (interrupted);
+    } while ((interrupted) && (!shutdown));
     this.incrementOutCount();
     return msg;
   }
@@ -1504,6 +1509,7 @@
    */
   public void shutdown()
   {
+    shutdown  = true;
     try
     {
       session.close();
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/GenerationIdTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/GenerationIdTest.java
index 8a20d02..ae5e626 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/GenerationIdTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/GenerationIdTest.java
@@ -1241,7 +1241,7 @@
    * at the moement when the replication is enabled.
    * @throws Exception
    */
-  @Test(enabled=true)
+  @Test(enabled=false)
   public void testServerStop() throws Exception
   {
     String testCase = "testServerStop";
@@ -1285,4 +1285,11 @@
       debugInfo("Successfully ending " + testCase);
     }
   }
+  @Test(enabled=true)
+  public void generationIdTest() throws Exception
+  {
+    testSingleRS();
+    testMultiRS();
+    testServerStop();
+  }
 }
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/InitOnLineTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/InitOnLineTest.java
index c76195b..ccdac3c 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/InitOnLineTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/InitOnLineTest.java
@@ -1135,7 +1135,7 @@
     changelog1 = null;
   }
   
-  @Test(enabled=false)
+  @Test(enabled=true)
   public void initializeTargetExportMultiSS() throws Exception
   {
     try
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/UpdateOperationTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/UpdateOperationTest.java
index 58395af..4593095 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/UpdateOperationTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/UpdateOperationTest.java
@@ -1253,7 +1253,7 @@
   /**
    * Tests done using directly the ReplicationBroker interface.
    */
-  @Test(enabled=false, dataProvider="assured")
+  @Test(enabled=true, dataProvider="assured")
   public void updateOperations(boolean assured) throws Exception
   {
     logError(Message.raw(
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 b1c7d60..fc5180d 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
@@ -83,10 +83,6 @@
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
-import org.opends.messages.Category;
-import org.opends.messages.Message;
-import org.opends.messages.Severity;
-import org.opends.server.loggers.ErrorLogger;
 import org.opends.server.tools.LDAPModify;
 import org.opends.server.tools.LDAPSearch;
 
@@ -132,7 +128,7 @@
 
     ReplServerFakeConfiguration conf =
       new ReplServerFakeConfiguration(replicationServerPort, null, 0, 1, 0, 0, null);
-    replicationServer = new ReplicationServer(conf);
+    replicationServer = new ReplicationServer(conf);;
   }
 
   private void debugInfo(String s)
@@ -145,6 +141,31 @@
   }
 
   /**
+   * The tests in this class only works in a specific order.
+   * This method is used to make sure that this order is always respected.
+   * (Using testng dependency does not work)
+   */
+  @Test(enabled=true)
+  public void replicationServerTest() throws Exception
+  {
+    replicationServer.clearDb();
+    changelogBasic();
+    multipleWriterMultipleReader();
+    newClientLateServer1();
+    newClient();
+    newClientWithFirstChanges();
+    newClientWithChangefromServer1();
+    newClientWithChangefromServer2();
+    newClientWithUnknownChanges();
+    oneWriterMultipleReader();
+    changelogChaining();
+    exportBackend();
+    backupRestore();
+    stopChangelog();
+    windowProbeTest();
+  }
+
+  /**
    * Basic test of the replicationServer code :
    *  Connect 2 clients to the replicationServer and exchange messages
    *  between the clients.
@@ -152,9 +173,9 @@
    * Note : Other tests in this file depends on this test and may need to
    *        change if this test is modified.
    */
-  @Test(enabled=true)
-  public void changelogBasic() throws Exception
+  private void changelogBasic() throws Exception
   {
+    replicationServer.clearDb();
     debugInfo("Starting changelogBasic");
     ReplicationBroker server1 = null;
     ReplicationBroker server2 = null;
@@ -273,8 +294,7 @@
    * Test that a new client see the change that was sent in the
    * previous test.
    */
-  @Test(enabled=false, dependsOnMethods = { "changelogBasic" })
-  public void newClient() throws Exception
+  private void newClient() throws Exception
   {
     debugInfo("Starting newClient");
     ReplicationBroker broker = null;
@@ -346,8 +366,7 @@
    * Test that a client that has already seen the first change now see the
    * second change
    */
-  @Test(enabled=true, dependsOnMethods = { "changelogBasic" })
-  public void newClientWithFirstChanges() throws Exception
+  private void newClientWithFirstChanges() throws Exception
   {
     debugInfo("Starting newClientWithFirstChanges");
     /*
@@ -366,8 +385,7 @@
    * Test with a client that has already seen a Change that the
    * ReplicationServer has not seen.
    */
-  @Test(enabled=true, dependsOnMethods = { "changelogBasic" })
-  public void newClientWithUnknownChanges() throws Exception
+  private void newClientWithUnknownChanges() throws Exception
   {
     /*
      * Create a ServerState with wrongChangeNumberServer1
@@ -383,8 +401,7 @@
    * Test that a client that has already seen the first change from server 1
    * now see the first change from server 2
    */
-  @Test(enabled=false, dependsOnMethods = { "changelogBasic" })
-  public void newClientWithChangefromServer1() throws Exception
+  private void newClientWithChangefromServer1() throws Exception
   {
     /*
      * Create a ServerState updated with the first change from server 1
@@ -399,8 +416,7 @@
    * Test that a client that has already seen the first chaneg from server 2
    * now see the first change from server 1
    */
-  @Test(enabled=false, dependsOnMethods = { "changelogBasic" })
-  public void newClientWithChangefromServer2() throws Exception
+  private void newClientWithChangefromServer2() throws Exception
   {
     /*
      * Create a ServerState updated with the first change from server 1
@@ -415,8 +431,7 @@
    * Test that a client that has not seen the second change from server 1
    * now receive it.
    */
-  @Test(enabled=true, dependsOnMethods = { "changelogBasic" })
-  public void newClientLateServer1() throws Exception
+  private void newClientLateServer1() throws Exception
   {
     /*
      * Create a ServerState updated with the first change from server 1
@@ -432,15 +447,14 @@
    * Test that newClient() and newClientWithFirstChange() still works
    * after stopping and restarting the replicationServer.
    */
-  @Test(enabled=true, dependsOnMethods = { "changelogBasic" })
-  public void stopChangelog() throws Exception
+  private void stopChangelog() throws Exception
   {
     replicationServer.remove();
     configure();
-    //newClient();
+    newClient();
     newClientWithFirstChanges();
     newClientWithChangefromServer1();
-    //newClientWithChangefromServer2();
+    newClientWithChangefromServer2();
   }
 
   /**
@@ -453,8 +467,7 @@
    * This test i sconfigured by a relatively low stress
    * but can be changed using TOTAL_MSG and CLIENT_THREADS consts.
    */
-  @Test(enabled=true, groups="slow")
-  public void oneWriterMultipleReader() throws Exception
+  private void oneWriterMultipleReader() throws Exception
   {
     ReplicationBroker server = null;
     int TOTAL_MSG = 1000;     // number of messages to send during the test
@@ -535,8 +548,7 @@
    * This test is sconfigured for a relatively low stress
    * but can be changed using TOTAL_MSG and THREADS consts.
    */
-  @Test(enabled=true, groups="slow")
-  public void multipleWriterMultipleReader() throws Exception
+  private void multipleWriterMultipleReader() throws Exception
   {
     ReplicationBroker server = null;
     final int TOTAL_MSG = 1000;   // number of messages to send during the test
@@ -610,8 +622,7 @@
    * - Check that client 2 receives the changes published by client 1
    *
    */
-  @Test(enabled=true)
-  public void changelogChaining() throws Exception
+  private void changelogChaining() throws Exception
   {
     for (int itest = 0; itest <2; itest++)
     {
@@ -800,8 +811,7 @@
    * Test that the Replication sends back correctly WindowsUpdate
    * when we send a WindowProbe.
    */
-  @Test(enabled=true)
-  public void windowProbeTest() throws Exception
+  private void windowProbeTest() throws Exception
   {
     final int WINDOW = 10;
     /*
@@ -999,8 +1009,7 @@
   /*
    * Test backup and restore of the Replication server backend
    */
-   @Test(enabled=true)
-   public void backupRestore() throws Exception
+   private void backupRestore() throws Exception
    {
      debugInfo("Starting backupRestore");
 
@@ -1023,8 +1032,7 @@
     * - Launch a full export
     * - Launch a partial export on one of the 2 domains
     */
-    @Test(enabled=true)
-    public void exportBackend() throws Exception
+    private void exportBackend() throws Exception
     {
       debugInfo("Starting exportBackend");
 
@@ -1227,8 +1235,7 @@
     * Testing searches on the backend of the replication server.
     * @throws Exception
     */
-   @Test(enabled=false)
-   public void searchBackend() throws Exception
+   private void searchBackend() throws Exception
    {
      debugInfo("Starting searchBackend");
 
@@ -1237,7 +1244,7 @@
          new ASN1OctetString("cn=monitor"),
          SearchScope.WHOLE_SUBTREE,
          LDAPFilter.decode("(objectclass=*)"));
-     assertEquals(op2.getResultCode(), ResultCode.SUCCESS, 
+     assertEquals(op2.getResultCode(), ResultCode.SUCCESS,
          op2.getErrorMessage().toString());
 
      replicationServer.clearDb();
@@ -1285,12 +1292,13 @@
      DN baseDN=DN.decode("dc=replicationChanges");
      //Test the group membership control causes search to be skipped.
      InternalSearchOperation internalSearch =
-             new InternalSearchOperation(conn, conn.nextOperationID(),
-                                         conn.nextMessageID(), requestControls,
-                                         baseDN,
-                                         SearchScope.WHOLE_SUBTREE,
-                                         DereferencePolicy.NEVER_DEREF_ALIASES,
-                                         0, 0, false, filter, null, null);
+             new InternalSearchOperation(
+                 conn, InternalClientConnection.nextOperationID(),
+                 InternalClientConnection.nextMessageID(), requestControls,
+                 baseDN,
+                 SearchScope.WHOLE_SUBTREE,
+                 DereferencePolicy.NEVER_DEREF_ALIASES,
+                 0, 0, false, filter, null, null);
      internalSearch.run();
      assertTrue(internalSearch.getResultCode() == ResultCode.SUCCESS);
      assertTrue(internalSearch.getSearchEntries().isEmpty());
@@ -1405,16 +1413,16 @@
      assertEquals(op.getResultCode(), ResultCode.SUCCESS);
      assertEquals(op.getSearchEntries().size(), 5);
 
-     
+
      if (server1 != null)
        server1.stop();
 
      debugInfo("Successfully ending searchBackend");
    }
 
-   private static final ByteArrayOutputStream oStream = 
+   private static final ByteArrayOutputStream oStream =
      new ByteArrayOutputStream();
-   private static final ByteArrayOutputStream eStream = 
+   private static final ByteArrayOutputStream eStream =
      new ByteArrayOutputStream();
 
    private void testReplicationBackendACIs()
@@ -1438,7 +1446,7 @@
      debugInfo("Entries:" + entries);
      assertEquals(0, retVal,  "Returned error: " + eStream);
      assertEquals(entries, "",  "Returned entries: " + entries);
-       
+
      // test search as directory manager returns content
      String[] args3 =
      {
@@ -1460,7 +1468,7 @@
      debugInfo("Entries:" + entries);
      assertEquals(0, retVal,  "Returned error: " + eStream);
      assertTrue(!entries.equalsIgnoreCase(""), "Returned entries: " + entries);
-     
+
      // test write fails : unwilling to perform
      try
      {
@@ -1480,7 +1488,7 @@
            "-f", path
        };
 
-       retVal = 
+       retVal =
          LDAPModify.mainModify(args4, false, oStream, eStream);
        assertEquals(retVal, 53, "Returned error: " + eStream);
      } catch(Exception e) {}

--
Gitblit v1.10.0