TestTimer.java: Added repeatUntilSuccess(CallableVoid callable)
| | |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | import static org.opends.server.util.TestTimer.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.io.ByteArrayOutputStream; |
| | |
| | | import org.opends.server.types.SearchResultEntry; |
| | | import org.opends.server.util.LDIFWriter; |
| | | import org.opends.server.util.TestTimer; |
| | | import org.opends.server.util.TestTimer.CallableVoid; |
| | | import org.opends.server.util.TimeThread; |
| | | import org.opends.server.workflowelement.localbackend.LocalBackendModifyDNOperation; |
| | | import org.testng.annotations.AfterClass; |
| | |
| | | .maxSleep(3, SECONDS) |
| | | .sleepTimes(100, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | timer.repeatUntilSuccess(new CallableVoid() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | public void call() throws Exception |
| | | { |
| | | final ReplicationDomainDB domainDB = replicationServer.getChangelogDB().getReplicationDomainDB(); |
| | | CursorOptions options = new CursorOptions(GREATER_THAN_OR_EQUAL_TO_KEY, ON_MATCHING_KEY); |
| | |
| | | { |
| | | assertTrue(cursor.next(), "Expected to find at least one change in replicaDB for " + replicaId); |
| | | assertEquals(cursor.getRecord().getCSN(), csn); |
| | | return END_RUN; |
| | | } |
| | | } |
| | | }); |
| | |
| | | .maxSleep(500, MILLISECONDS) |
| | | .sleepTimes(50, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | timer.repeatUntilSuccess(new CallableVoid() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | public void call() throws Exception |
| | | { |
| | | assertEquals(operation.getResultCode(), expectedResult, operation.getErrorMessage().toString()); |
| | | return END_RUN; |
| | | } |
| | | }); |
| | | } |
| | |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.util.List; |
| | | import java.util.concurrent.Callable; |
| | | |
| | | import org.assertj.core.api.Assertions; |
| | | import org.forgerock.opendj.ldap.DN; |
| | |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.util.TestTimer; |
| | | import org.opends.server.util.TestTimer.CallableVoid; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | |
| | | .maxSleep(20, SECONDS) |
| | | .sleepTimes(200, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | timer.repeatUntilSuccess(new CallableVoid() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | public void call() throws Exception |
| | | { |
| | | Assertions.assertThat(rmiConnector.jmxRmiConnectorNoClientCertificate).isNotNull(); |
| | | Assertions.assertThat(rmiConnector.jmxRmiConnectorNoClientCertificate.isActive()).isTrue(); |
| | | return null; |
| | | } |
| | | }); |
| | | return jmxConnectionHandler; |
| | |
| | | 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.opends.server.types.Entry; |
| | | import org.opends.server.types.LDIFImportConfig; |
| | | import org.opends.server.util.TestTimer; |
| | | import org.opends.server.util.TestTimer.CallableVoid; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | |
| | | .maxSleep(1, MINUTES) |
| | | .sleepTimes(200, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | timer.repeatUntilSuccess(new CallableVoid() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | public void call() throws Exception |
| | | { |
| | | LDAPReplicationDomain doToco = LDAPReplicationDomain.retrievesReplicationDomain(baseDN); |
| | | assertNotNull(doToco); |
| | | assertTrue(doToco.isConnected(), "not connected"); |
| | | debugInfo("ReplicationDomain: Import/Export is running ? " + doToco.ieRunning()); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | |
| | | .maxSleep(10, SECONDS) |
| | | .sleepTimes(100, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | timer.repeatUntilSuccess(new CallableVoid() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | public void call() throws Exception |
| | | { |
| | | assertNull(LDAPReplicationDomain.retrievesReplicationDomain(baseDN)); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | |
| | | .maxSleep(timeout, MILLISECONDS) |
| | | .sleepTimes(50, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | timer.repeatUntilSuccess(new CallableVoid() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | public void call() throws Exception |
| | | { |
| | | LDAPReplicationDomain domain = MultimasterReplication.findDomain(baseDN, null); |
| | | assertNotNull(domain); |
| | | assertTrue(domain.isConnected(), "server should have been connected to replication domain" + baseDN); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | |
| | | .maxSleep(10, SECONDS) |
| | | .sleepTimes(100, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | timer.repeatUntilSuccess(new CallableVoid() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | public void call() throws Exception |
| | | { |
| | | assertGenIdEquals(expectedGenId); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.SearchResultEntry; |
| | | import org.opends.server.util.TestTimer; |
| | | import org.opends.server.util.TestTimer.CallableVoid; |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | |
| | | .maxSleep(secTimeout, SECONDS) |
| | | .sleepTimes(1, SECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | timer.repeatUntilSuccess(new CallableVoid() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | public void call() throws Exception |
| | | { |
| | | if (rb.isConnected()) |
| | | { |
| | | logger.trace("checkConnection: connection of broker " + rb.getServerId() |
| | | + " to RS " + rb.getRsGroupId() + " obtained."); |
| | | return null; |
| | | return; |
| | | } |
| | | |
| | | rb.start(); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | |
| | | .maxSleep(timeoutInSecs, SECONDS) |
| | | .sleepTimes(100, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | timer.repeatUntilSuccess(new CallableVoid() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | public void call() throws Exception |
| | | { |
| | | final Entry newEntry = DirectoryServer.getEntry(dn); |
| | | assertNotNull(newEntry); |
| | |
| | | Attribute attr = attrs.iterator().next(); |
| | | boolean foundAttributeValue = attr.contains(ByteString.valueOfUtf8(valueString)); |
| | | assertEquals(foundAttributeValue, expectedAttributeValueFound, foundMsg); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | |
| | | .maxSleep(timeoutInMillis, MILLISECONDS) |
| | | .sleepTimes(200, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | timer.repeatUntilSuccess(new CallableVoid() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | public void call() throws Exception |
| | | { |
| | | assertEquals(DirectoryServer.entryExists(dn), exist, "Expected entry with dn \"" + dn + "\" would exist"); |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | |
| | | import java.net.SocketTimeoutException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.concurrent.Callable; |
| | | |
| | | import org.assertj.core.api.Assertions; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.api.SynchronizationProvider; |
| | |
| | | import org.opends.server.replication.service.ReplicationBroker; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.Attributes; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.Operation; |
| | | import org.opends.server.types.RawModification; |
| | | import org.opends.server.util.TestTimer; |
| | | import org.opends.server.util.TestTimer.CallableVoid; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | |
| | | .maxSleep(5, SECONDS) |
| | | .sleepTimes(100, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | timer.repeatUntilSuccess(new CallableVoid() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | public void call() throws Exception |
| | | { |
| | | String fileStr = readAsString(schemaFile); |
| | | assertTrue(fileStr.contains(stateStr), "The Schema persistentState (CSN:" + stateStr |
| | | + ") has not been saved to " + schemaFile + " : " + fileStr); |
| | | return null; |
| | | } |
| | | }); |
| | | } finally |
| | |
| | | import java.net.SocketTimeoutException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.concurrent.Callable; |
| | | |
| | | import org.assertj.core.api.Assertions; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | |
| | | import org.opends.server.types.Operation; |
| | | import org.opends.server.types.OperationType; |
| | | import org.opends.server.util.TestTimer; |
| | | import org.opends.server.util.TestTimer.CallableVoid; |
| | | import org.opends.server.util.TimeThread; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | |
| | | .maxSleep(200, SECONDS) |
| | | .sleepTimes(100, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | timer.repeatUntilSuccess(new CallableVoid() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | public void call() throws Exception |
| | | { |
| | | assertNotEquals(getMonitorDelta() , 0); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | |
| | | .maxSleep(5, SECONDS) |
| | | .sleepTimes(100, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | timer.repeatUntilSuccess(new CallableVoid() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | public void call() throws Exception |
| | | { |
| | | assertNotEquals(getMonitorAttrValue(baseDN, "replayed-updates"), initialCount); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | |
| | | |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import java.util.concurrent.Callable; |
| | | |
| | | import org.assertj.core.api.Assertions; |
| | | import org.forgerock.opendj.ldap.AttributeDescription; |
| | |
| | | import org.opends.server.types.Modification; |
| | | import org.opends.server.types.Operation; |
| | | import org.opends.server.util.TestTimer; |
| | | import org.opends.server.util.TestTimer.CallableVoid; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | |
| | | .maxSleep(2, SECONDS) |
| | | .sleepTimes(100, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | timer.repeatUntilSuccess(new CallableVoid() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | public void call() throws Exception |
| | | { |
| | | assertEquals(getEntryValue(entryDN, attrDesc), expectedValue); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | |
| | | import java.net.SocketTimeoutException; |
| | | import java.util.SortedSet; |
| | | import java.util.TreeSet; |
| | | import java.util.concurrent.Callable; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | |
| | | import org.opends.server.replication.service.ReplicationBroker; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.util.TestTimer; |
| | | import org.opends.server.util.TestTimer.CallableVoid; |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | |
| | | .maxSleep(30, SECONDS) |
| | | .sleepTimes(100, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | timer.repeatUntilSuccess(new CallableVoid() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | public void call() throws Exception |
| | | { |
| | | assertTrue(isConnected(dsId), "checkConnection: DS " + dsId + " is not connected to the RS"); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | |
| | | .maxSleep(30, SECONDS) |
| | | .sleepTimes(500, MILLISECONDS) |
| | | .toTimer(); |
| | | timer.repeatUntilSuccess(new Callable<Void>() |
| | | timer.repeatUntilSuccess(new CallableVoid() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | public void call() throws Exception |
| | | { |
| | | assertEquals(domain.getStatus(), expectedStatus); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | |
| | | * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2015 ForgeRock AS. |
| | | * Copyright 2015-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.util; |
| | | |
| | |
| | | public interface TestTimer |
| | | { |
| | | /** |
| | | * Constant that can be used at the end of {@code Callable<Void>.call()} to better explicit this |
| | | * is the end of the method. |
| | | * Equivalent to {@code Callable<Void>} or a {@code Runnable} that can throw exception. |
| | | * <p> |
| | | * <b>Note:</b> The name has been designed to stay close to {@code Callable<Void>} to allow to |
| | | * easily change test code back and forth between {@code java.util.Callable} and |
| | | * {@code CallableVoid} while writing the test code. It also avoids name collisions while writing |
| | | * the rest of the OpenDJ code base. |
| | | */ |
| | | Void END_RUN = null; |
| | | public static interface CallableVoid |
| | | { |
| | | /** |
| | | * Equivalent of {@link Runnable#run()} or {@link Callable#call()}. |
| | | * |
| | | * @throws Exception |
| | | * if an error occurred |
| | | * @see {@link Runnable#run()} |
| | | * @see {@link Callable#call()} |
| | | */ |
| | | void call() throws Exception; |
| | | } |
| | | |
| | | /** |
| | | * Repeatedly call the supplied callable (respecting a sleep interval) until: |
| | |
| | | * </ul> |
| | | * <p> |
| | | * Note: The test code in the callable can be written as any test code outside a callable. In |
| | | * particular, asserts can and should be used inside the {@link Callable#call()}. |
| | | * particular, asserts can and should be used inside the {@link Callable#call()} method. |
| | | * |
| | | * @param callable |
| | | * the callable to repeat until success |
| | |
| | | */ |
| | | <R> R repeatUntilSuccess(Callable<R> callable) throws Exception, InterruptedException; |
| | | |
| | | /** |
| | | * Repeatedly call the supplied callable (respecting a sleep interval) until: |
| | | * <ul> |
| | | * <li>it returns,</li> |
| | | * <li>it throws an exception other than {@link AssertionError},</li> |
| | | * <li>the current timer times out.</li> |
| | | * </ul> |
| | | * If the current timer times out, then it will: |
| | | * <ul> |
| | | * <li>either rethrow an {@link AssertionError} thrown by the callable,</li> |
| | | * <li>or return {@code null}.</li> |
| | | * </ul> |
| | | * <p> |
| | | * Note: The test code in the callable can be written as any test code outside a callable. In |
| | | * particular, asserts can and should be used inside the {@link TestTimer.Callable#call()} method. |
| | | * |
| | | * @param callable |
| | | * the callable to repeat until success |
| | | * @throws Exception |
| | | * The exception thrown by the provided callable |
| | | * @throws InterruptedException |
| | | * If the thread is interrupted while sleeping |
| | | */ |
| | | void repeatUntilSuccess(CallableVoid callable) throws Exception, InterruptedException; |
| | | |
| | | /** Builder for a {@link TestTimer}. */ |
| | | public static final class Builder |
| | | { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void repeatUntilSuccess(final CallableVoid callable) throws Exception, InterruptedException |
| | | { |
| | | repeatUntilSuccess(new Callable<Void>() |
| | | { |
| | | @Override |
| | | public Void call() throws Exception |
| | | { |
| | | callable.call(); |
| | | return null; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public String toString() |
| | | { |
| | | return totalNbSteps * sleepTime + " ms max sleep time" |