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

davidely
18.43.2007 d0f0e78dc70d1e8ee436eb2332c3ae0e95a9266c
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -79,6 +79,7 @@
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
import org.opends.server.tasks.TaskUtils;
import org.opends.server.api.WorkQueue;
/**
 * This class defines some utility functions which can be used by test
@@ -316,6 +317,28 @@
  }
  /**
   * Bring the server to a quiescent state.  This includes waiting for all
   * operations to complete.  This can be used in a @BeforeMethod setup method
   * to make sure that the server has finished processing all operations
   * from previous tests.
   */
  public static void quiesceServer()
  {
    waitForOpsToComplete();
  }
  /**
   * This can be made public if quiesceServer becomes too heavy-weight in
   * some circumstance.
   */
  private static void waitForOpsToComplete()
  {
    WorkQueue workQueue = DirectoryServer.getWorkQueue();
    final long NO_TIMEOUT = -1;
    workQueue.waitUntilIdle(NO_TIMEOUT);
  }
  /**
   * Binds to the given socket port on the local host.
   * @return the bounded Server socket.
   *
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/BindOperationTestCase.java
@@ -34,6 +34,7 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.AddOperation;
@@ -878,6 +879,7 @@
    assertTrue(InvocationCounterPlugin.getPreParseCount() > 0);
    assertTrue(InvocationCounterPlugin.getPreOperationCount() > 0);
    assertTrue(InvocationCounterPlugin.getPostOperationCount() > 0);
    ensurePostReponseHasRun();
    assertTrue(InvocationCounterPlugin.getPostResponseCount() > 0);
  }
@@ -905,6 +907,7 @@
    assertTrue(InvocationCounterPlugin.getPreParseCount() > 0);
    assertTrue(InvocationCounterPlugin.getPreOperationCount() > 0);
    assertTrue(InvocationCounterPlugin.getPostOperationCount() > 0);
    ensurePostReponseHasRun();
    assertTrue(InvocationCounterPlugin.getPostResponseCount() > 0);
  }
@@ -1941,6 +1944,10 @@
    assertEquals(DirectoryServer.getAuthenticatedUsers().get(userDN).size(),
                 1);
    // We occasionally run into
    // ProtocolMessages.MSGID_LDAP_CLIENT_DUPLICATE_MESSAGE_ID, so we wait
    // for previous ops to complete.
    TestCaseUtils.quiesceServer();
    bindRequest = new BindRequestProtocolOp(
                           new ASN1OctetString("cn=Directory Manager"), 3,
                           new ASN1OctetString("password"));
@@ -1949,7 +1956,7 @@
    message = LDAPMessage.decode(r.readElement().decodeAsSequence());
    bindResponse = message.getBindResponseProtocolOp();
    assertEquals(bindResponse.getResultCode(), 0);
    assertEquals(bindResponse.getResultCode(), 0, message.toString());
    assertNull(DirectoryServer.getAuthenticatedUsers().get(userDN));
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/CompareOperationTestCase.java
@@ -159,6 +159,7 @@
    assertEquals(InvocationCounterPlugin.getPreParseCount(), 1);
    assertEquals(InvocationCounterPlugin.getPreOperationCount(), 1);
    assertEquals(InvocationCounterPlugin.getPostOperationCount(), 1);
    ensurePostReponseHasRun();
    assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
  }
@@ -179,6 +180,7 @@
    assertEquals(InvocationCounterPlugin.getPreParseCount(), 1);
    assertEquals(InvocationCounterPlugin.getPreOperationCount(), 0);
    assertEquals(InvocationCounterPlugin.getPostOperationCount(), 1);
    ensurePostReponseHasRun();
    assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
  }
@@ -199,6 +201,7 @@
    assertEquals(InvocationCounterPlugin.getPreParseCount(), 1);
    assertEquals(InvocationCounterPlugin.getPreOperationCount(), 0);
    assertEquals(InvocationCounterPlugin.getPostOperationCount(), 0);
    ensurePostReponseHasRun();
    assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
  }
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/OperationTestCase.java
@@ -31,6 +31,7 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.opends.server.TestCaseUtils;
import org.opends.server.util.StaticUtils;
@@ -56,7 +57,23 @@
  // The LDAPStatistics object associated with the LDAPS connection handler.
  protected LDAPStatistics ldapsStatistics;
  @BeforeMethod
  public void setUpQuiesceServer()
  {
    TestCaseUtils.quiesceServer();
  }
  /**
   * Since the PostResponse plugins are called after the response is sent
   * back to the client, a client (e.g. a test case) can get a response before
   * the PostResponse plugins have been called.  So that we can verify that the
   * PostResponse plugins were called, the tests call this method to ensure
   * that all operations in the server have been completed.
   */
  protected void ensurePostReponseHasRun()
  {
    TestCaseUtils.quiesceServer();
  }
  /**
   * Ensures that the Directory Server is running.
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/SearchOperationTestCase.java
@@ -213,6 +213,7 @@
    assertEquals(InvocationCounterPlugin.getPreParseCount(), 1);
    assertEquals(InvocationCounterPlugin.getPreOperationCount(), 1);
    assertEquals(InvocationCounterPlugin.getPostOperationCount(), 1);
    ensurePostReponseHasRun();
    assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
  }
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/core/TestModifyDNOperation.java
@@ -172,6 +172,7 @@
    assertEquals(InvocationCounterPlugin.getPreParseCount(), 1);
    assertEquals(InvocationCounterPlugin.getPreOperationCount(), 1);
    assertEquals(InvocationCounterPlugin.getPostOperationCount(), 1);
    ensurePostReponseHasRun();
    assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
  }
@@ -192,6 +193,7 @@
    assertEquals(InvocationCounterPlugin.getPreParseCount(), 1);
    assertEquals(InvocationCounterPlugin.getPreOperationCount(), 0);
    assertEquals(InvocationCounterPlugin.getPostOperationCount(), 1);
    ensurePostReponseHasRun();
    assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
  }
@@ -212,6 +214,7 @@
    assertEquals(InvocationCounterPlugin.getPreParseCount(), 1);
    assertEquals(InvocationCounterPlugin.getPreOperationCount(), 0);
    assertEquals(InvocationCounterPlugin.getPostOperationCount(), 0);
    ensurePostReponseHasRun();
    assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1);
  }