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

Valery Kharseko
yesterday 3be885b70108e0efd3cd8508c1a0b6169a8003cd
Wait for replication monitor counters in ProtocolWindowTest (#1348)

## Summary

Replace the fixed delay after filling the replication window with a
bounded `TestTimer` wait. Check `sent-updates` and `missing-changes` on
the same broker monitor entry and include both actual values if the
assertion fails. Keep the check that the broker receives all 120
changes.

The background monitor refresh can lag behind the test's original
two-second pause. The failure surfaced in the Maven build for #1311.
[Ubuntu / Java 17
job](https://github.com/OpenIdentityPlatform/OpenDJ/actions/runs/46256902401/job/141327530619#step:16)

## Verification

- With the monitoring interval temporarily set to 12 seconds, reproduced
the original `missing-changes` assertion failure and verified that the
updated test passed at the same interval.
- With the default interval, all 16 targeted tests passed on macOS with
Java 17 across `ProtocolWindowTest`, `ReplicationDomainMonitorTest`, and
`ReplicationServerDomainMonitorTest`.
- `git diff --check` passed.
1 files modified
47 ■■■■■ changed files
opendj-server-legacy/src/test/java/org/opends/server/replication/ProtocolWindowTest.java 47 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/replication/ProtocolWindowTest.java
@@ -17,12 +17,14 @@
 */
package org.opends.server.replication;
import static java.util.concurrent.TimeUnit.*;
import static org.forgerock.opendj.ldap.SearchScope.*;
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.testng.Assert.*;
import java.net.SocketTimeoutException;
import java.util.Arrays;
import java.util.List;
import java.util.NoSuchElementException;
@@ -47,6 +49,8 @@
import org.opends.server.types.Modification;
import org.opends.server.types.Operation;
import org.opends.server.types.OperationType;
import org.opends.server.types.SearchResultEntry;
import org.opends.server.util.TestTimer;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -61,6 +65,7 @@
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
  private static final int BROKER_SERVER_ID = 12;
  private static final int WINDOW_SIZE = 10;
  private static final int REPLICATION_QUEUE_SIZE = 100;
@@ -110,7 +115,7 @@
          "Unable to add the synchronized server");
    configEntriesToCleanup.add(repDomainEntry.getName());
    ReplicationBroker broker = openReplicationSession(baseDN, 12,
    ReplicationBroker broker = openReplicationSession(baseDN, BROKER_SERVER_ID,
        WINDOW_SIZE, replServerPort, 1000);
    try {
@@ -148,11 +153,7 @@
      int count = WINDOW_SIZE * 2 + REPLICATION_QUEUE_SIZE;
      processModify(count);
      // let some time to the message to reach the replicationServer client
      Thread.sleep(2000);
      // check that the replicationServer only sent WINDOW_SIZE messages
      searchUpdateSent();
      waitForSaturatedWindow();
      int rcvCount=0;
      try
@@ -217,19 +218,29 @@
    return searchNbMonitorEntries("(max-rcv-window=" + windowSize + ")");
  }
  /**
   * Search that the replicationServer has stopped sending changes after
   * having reach the limit of the window size.
   * And that the number of waiting changes is accurate.
   * Do this by checking the monitoring information.
   */
  private void searchUpdateSent() throws Exception
  /** Waits for the broker's monitor entry to report a full window and the remaining changes. */
  private void waitForSaturatedWindow() throws Exception
  {
    assertEquals(searchNbMonitorEntries("(sent-updates=" + WINDOW_SIZE + ")"), 1);
    final int nb = searchNbMonitorEntries(
        "(missing-changes=" + (REPLICATION_QUEUE_SIZE + WINDOW_SIZE) + ")");
    assertEquals(nb, 1);
    String monitorFilter = "(&(cn=Connected directory server*)(server-id=" + BROKER_SERVER_ID
        + ")(domain-name=" + baseDN + "))";
    // The monitor publisher refreshes missing-changes in the background.
    TestTimer timer = new TestTimer.Builder()
        .maxSleep(30, SECONDS)
        .sleepTimes(200, MILLISECONDS)
        .toTimer();
    timer.repeatUntilSuccess(() ->
    {
      InternalSearchOperation op = connection.processSearch(
          newSearchRequest("cn=replication,cn=monitor", WHOLE_SUBTREE, monitorFilter));
      assertEquals(op.getResultCode(), ResultCode.SUCCESS);
      assertEquals(op.getEntriesSent(), 1, "Monitor entry for replication broker " + BROKER_SERVER_ID);
      SearchResultEntry entry = op.getSearchEntries().getFirst();
      Long sentUpdates = entry.parseAttribute("sent-updates").asLong();
      Long missingChanges = entry.parseAttribute("missing-changes").asLong();
      Assertions.assertThat(Arrays.asList(sentUpdates, missingChanges))
          .as("sent-updates and missing-changes for replication broker %s", BROKER_SERVER_ID)
          .containsExactly((long) WINDOW_SIZE, (long) REPLICATION_QUEUE_SIZE + WINDOW_SIZE);
    });
  }
  /**