| | |
| | | */ |
| | | package org.opends.server.replication; |
| | | |
| | | import static java.util.concurrent.TimeUnit.*; |
| | | |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | import static org.testng.Assert.*; |
| | |
| | | import java.util.SortedSet; |
| | | import java.util.TreeSet; |
| | | import java.util.UUID; |
| | | import java.util.concurrent.Callable; |
| | | |
| | | import org.assertj.core.api.Assertions; |
| | | import org.assertj.core.api.SoftAssertions; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.LDIFImportConfig; |
| | | import org.opends.server.util.TestTimer; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | |
| | | |
| | | addSynchroServerEntry(synchroServerLdif); |
| | | |
| | | int waitCo=0; |
| | | LDAPReplicationDomain doToco=null; |
| | | while(waitCo<50) |
| | | |
| | | TestTimer timer = new TestTimer.Builder() |
| | | .maxSleep(1, MINUTES) |
| | | .sleepTimes(200, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | { |
| | | doToco = LDAPReplicationDomain.retrievesReplicationDomain(baseDN); |
| | | if (doToco != null && doToco.isConnected()) |
| | | @Override |
| | | public Void call() throws Exception |
| | | { |
| | | break; |
| | | } |
| | | Thread.sleep(waitCo * 200); |
| | | waitCo++; |
| | | } |
| | | LDAPReplicationDomain doToco = LDAPReplicationDomain.retrievesReplicationDomain(baseDN); |
| | | assertNotNull(doToco); |
| | | assertTrue(doToco.isConnected(), "not connected after #attempt="+waitCo); |
| | | assertTrue(doToco.isConnected(), "not connected"); |
| | | debugInfo("ReplicationDomain: Import/Export is running ? " + doToco.ieRunning()); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | configEntriesToCleanup.remove(synchroServerDN); |
| | | |
| | | LDAPReplicationDomain replDomainToDis = null; |
| | | |
| | | try |
| | | { |
| | | int waitCo=0; |
| | | while(waitCo<30) |
| | | // check replication domain gets disconnected |
| | | TestTimer timer = new TestTimer.Builder() |
| | | .maxSleep(10, SECONDS) |
| | | .sleepTimes(100, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | { |
| | | replDomainToDis = LDAPReplicationDomain.retrievesReplicationDomain(baseDN); |
| | | Thread.sleep(200); |
| | | waitCo++; |
| | | @Override |
| | | public Void call() throws Exception |
| | | { |
| | | assertNull(LDAPReplicationDomain.retrievesReplicationDomain(baseDN)); |
| | | return null; |
| | | } |
| | | assertNull(replDomainToDis); |
| | | }); |
| | | } |
| | | catch (DirectoryException e) |
| | | { |
| | |
| | | * Waits for the connection from server1 to the replication domain to |
| | | * establish itself up automagically. |
| | | */ |
| | | private void waitConnectionToReplicationDomain(DN baseDN, int timeout) |
| | | private void waitConnectionToReplicationDomain(final DN baseDN, int timeout) throws Exception |
| | | { |
| | | long start = System.currentTimeMillis(); |
| | | while (System.currentTimeMillis() - start <= timeout) |
| | | TestTimer timer = new TestTimer.Builder() |
| | | .maxSleep(timeout, MILLISECONDS) |
| | | .sleepTimes(50, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | { |
| | | LDAPReplicationDomain domain = MultimasterReplication.findDomain(baseDN, null); |
| | | if (domain != null && domain.isConnected()) |
| | | { |
| | | break; |
| | | assertNotNull(domain); |
| | | assertTrue(domain.isConnected(), "server should have been connected to replication domain" + baseDN); |
| | | return null; |
| | | } |
| | | } |
| | | assertTrue(MultimasterReplication.findDomain(baseDN, null).isConnected(), |
| | | "After waiting " + (System.currentTimeMillis() - start) |
| | | + " ms, server should have been connected to replication domain " |
| | | + baseDN); |
| | | }); |
| | | } |
| | | |
| | | private Entry createSetGenerationIdTask(Long genId, String additionalAttribute) throws Exception |
| | |
| | | } |
| | | } |
| | | |
| | | private void waitForStableGenerationId(long expectedGenId) throws Exception |
| | | private void waitForStableGenerationId(final long expectedGenId) throws Exception |
| | | { |
| | | int wait = 0; |
| | | while (wait < 100) |
| | | TestTimer timer = new TestTimer.Builder() |
| | | .maxSleep(10, SECONDS) |
| | | .sleepTimes(100, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | { |
| | | if (replServer1.getGenerationId(baseDN) == expectedGenId |
| | | && replServer2.getGenerationId(baseDN) == expectedGenId |
| | | && replServer3.getGenerationId(baseDN) == expectedGenId) |
| | | @Override |
| | | public Void call() throws Exception |
| | | { |
| | | break; |
| | | } |
| | | wait++; |
| | | Thread.sleep(100); |
| | | } |
| | | assertGenIdEquals(expectedGenId); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void assertGenIdEquals(long expectedGenId) |
| | | { |
| | | assertEquals(replServer1.getGenerationId(baseDN), expectedGenId, " in replServer1"); |
| | | assertEquals(replServer2.getGenerationId(baseDN), expectedGenId, " in replServer2"); |
| | | assertEquals(replServer3.getGenerationId(baseDN), expectedGenId, " in replServer3"); |
| | | SoftAssertions softly = new SoftAssertions(); |
| | | softly.assertThat(replServer1.getGenerationId(baseDN)).as("in replServer1").isEqualTo(expectedGenId); |
| | | softly.assertThat(replServer2.getGenerationId(baseDN)).as("in replServer2").isEqualTo(expectedGenId); |
| | | softly.assertThat(replServer3.getGenerationId(baseDN)).as("in replServer3").isEqualTo(expectedGenId); |
| | | softly.assertAll(); |
| | | } |
| | | |
| | | private boolean isDegradedDueToGenerationId(ReplicationServer rs, int serverId) |