| | |
| | | */ |
| | | 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; |
| | | |
| | |
| | | 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; |
| | |
| | | |
| | | 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; |
| | | |
| | |
| | | "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 { |
| | |
| | | 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 |
| | |
| | | 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); |
| | | }); |
| | | } |
| | | |
| | | /** |