This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/master by this push:
new 72c8cfd Attempting to make IT run more stable
72c8cfd is described below
commit 72c8cfdcb42d4698670f92e1b8cb7b65191820c3
Author: Francesco Chicchiriccò <[email protected]>
AuthorDate: Thu Jul 16 10:41:51 2020 +0200
Attempting to make IT run more stable
---
fit/core-reference/pom.xml | 5 +
.../TestNotificationRecipientsProvider.java | 1 -
.../org/apache/syncope/fit/AbstractITCase.java | 31 ++---
.../fit/core/AbstractNotificationTaskITCase.java | 39 +++---
.../syncope/fit/core/AbstractTaskITCase.java | 144 +++++++++------------
.../org/apache/syncope/fit/core/AuditITCase.java | 22 ++--
.../org/apache/syncope/fit/core/BatchITCase.java | 20 +--
.../org/apache/syncope/fit/core/GroupITCase.java | 30 ++---
.../apache/syncope/fit/core/KeymasterITCase.java | 28 ++--
.../org/apache/syncope/fit/core/LoggerITCase.java | 43 +++---
.../syncope/fit/core/NotificationTaskITCase.java | 46 +++----
.../apache/syncope/fit/core/PullTaskITCase.java | 71 ++++------
.../apache/syncope/fit/core/PushTaskITCase.java | 27 ++--
.../org/apache/syncope/fit/core/ReportITCase.java | 81 ++++--------
.../apache/syncope/fit/core/SchedTaskITCase.java | 76 +++++------
15 files changed, 278 insertions(+), 386 deletions(-)
diff --git a/fit/core-reference/pom.xml b/fit/core-reference/pom.xml
index dc9f8a9..25bcb63 100644
--- a/fit/core-reference/pom.xml
+++ b/fit/core-reference/pom.xml
@@ -203,6 +203,11 @@ under the License.
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
diff --git
a/fit/core-reference/src/main/java/org/apache/syncope/fit/core/reference/TestNotificationRecipientsProvider.java
b/fit/core-reference/src/main/java/org/apache/syncope/fit/core/reference/TestNotificationRecipientsProvider.java
index 366db9e..44e6922 100644
---
a/fit/core-reference/src/main/java/org/apache/syncope/fit/core/reference/TestNotificationRecipientsProvider.java
+++
b/fit/core-reference/src/main/java/org/apache/syncope/fit/core/reference/TestNotificationRecipientsProvider.java
@@ -30,5 +30,4 @@ public class TestNotificationRecipientsProvider implements
RecipientsProvider {
public Set<String> provideRecipients(final Notification notification) {
return Set.of(getClass().getSimpleName() + "@syncope.apache.org");
}
-
}
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
index 881063f..a77e475 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
@@ -18,9 +18,9 @@
*/
package org.apache.syncope.fit;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.fail;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
@@ -35,6 +35,8 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.BasicAttribute;
@@ -794,30 +796,17 @@ public abstract class AbstractITCase {
final int maxWaitSeconds,
final String sql, final Class<T> requiredType, final Object...
args) {
- int i = 0;
- int maxit = maxWaitSeconds;
-
- T object = null;
-
- do {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- }
-
+ AtomicReference<T> object = new AtomicReference<>();
+ await().atMost(maxWaitSeconds, TimeUnit.SECONDS).pollInterval(1,
TimeUnit.SECONDS).until(() -> {
try {
- object = jdbcTemplate.queryForObject(sql, requiredType, args);
+ object.set(jdbcTemplate.queryForObject(sql, requiredType,
args));
+ return object.get() != null;
} catch (Exception e) {
- LOG.warn("While executing query {}", sql, e);
+ return false;
}
+ });
- i++;
- } while (object == null && i < maxit);
- if (object == null) {
- fail("Timeout when executing query " + sql);
- }
-
- return object;
+ return object.get();
}
protected OIDCRPTO buildOIDCRP() {
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractNotificationTaskITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractNotificationTaskITCase.java
index 93d852f..454c54f 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractNotificationTaskITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractNotificationTaskITCase.java
@@ -18,11 +18,13 @@
*/
package org.apache.syncope.fit.core;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.fail;
import java.io.InputStream;
import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
@@ -77,31 +79,20 @@ public abstract class AbstractNotificationTaskITCase
extends AbstractTaskITCase
return found;
}
- protected static boolean verifyMail(
- final String sender,
- final String subject,
- final String mailAddress,
- final int maxWaitSeconds) throws Exception {
+ protected static void verifyMail(
+ final String sender,
+ final String subject,
+ final String mailAddress,
+ final int maxWaitSeconds) throws Exception {
- boolean read = false;
-
- int i = 0;
-
- // wait for completion (executions incremented)
- do {
+ AtomicReference<Boolean> read = new AtomicReference<>(false);
+ await().atMost(MAX_WAIT_SECONDS, TimeUnit.SECONDS).pollInterval(1,
TimeUnit.SECONDS).until(() -> {
try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
+ read.set(pop3(sender, subject, mailAddress));
+ return read.get();
+ } catch (Exception e) {
+ return false;
}
-
- read = pop3(sender, subject, mailAddress);
-
- i++;
- } while (!read && i < maxWaitSeconds);
- if (i == maxWaitSeconds) {
- fail("Timeout when attempting to read e-mail to " + mailAddress);
- }
-
- return read;
+ });
}
}
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java
index bf3b7fc..8b483cf 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java
@@ -18,18 +18,18 @@
*/
package org.apache.syncope.fit.core;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.fail;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
import org.apache.syncope.client.lib.SyncopeClient;
import org.apache.syncope.common.lib.SyncopeConstants;
import org.apache.syncope.common.lib.request.ResourceDR;
@@ -38,6 +38,7 @@ import org.apache.syncope.common.lib.to.ExecTO;
import org.apache.syncope.common.lib.to.NotificationTaskTO;
import org.apache.syncope.common.lib.to.PagedResult;
import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.ExecStatus;
import org.apache.syncope.common.lib.types.ResourceDeassociationAction;
import org.apache.syncope.common.lib.types.TaskType;
import org.apache.syncope.common.rest.api.beans.AnyQuery;
@@ -53,35 +54,6 @@ public abstract class AbstractTaskITCase extends
AbstractITCase {
protected static final String SCHED_TASK_KEY =
"e95555d2-1b09-42c8-b25b-f4c4ec597979";
- protected static class ThreadExec implements Callable<ExecTO> {
-
- private final TaskService taskService;
-
- private final TaskType type;
-
- private final String taskKey;
-
- private final int maxWaitSeconds;
-
- private final boolean dryRun;
-
- public ThreadExec(
- final TaskService taskService, final TaskType type, final
String taskKey,
- final int maxWaitSeconds, final boolean dryRun) {
-
- this.taskService = taskService;
- this.type = type;
- this.taskKey = taskKey;
- this.maxWaitSeconds = maxWaitSeconds;
- this.dryRun = dryRun;
- }
-
- @Override
- public ExecTO call() throws Exception {
- return execProvisioningTask(taskService, type, taskKey,
maxWaitSeconds, dryRun);
- }
- }
-
/**
* Remove initial and synchronized users to make test re-runnable.
*/
@@ -118,39 +90,29 @@ public abstract class AbstractTaskITCase extends
AbstractITCase {
}
protected static ExecTO execTask(
- final TaskService taskService, final TaskType type, final String
taskKey,
- final String initialStatus, final int maxWaitSeconds, final
boolean dryRun) {
-
- TaskTO taskTO = taskService.read(type, taskKey, true);
- assertNotNull(taskTO);
- assertNotNull(taskTO.getExecutions());
-
- int preSyncSize = taskTO.getExecutions().size();
- ExecuteQuery query = new
ExecuteQuery.Builder().key(taskTO.getKey()).dryRun(dryRun).build();
- ExecTO execution = taskService.execute(query);
+ final TaskService taskService,
+ final TaskType type,
+ final String taskKey,
+ final String initialStatus,
+ final int maxWaitSeconds,
+ final boolean dryRun) {
+
+ AtomicReference<TaskTO> taskTO = new
AtomicReference<>(taskService.read(type, taskKey, true));
+ int preSyncSize = taskTO.get().getExecutions().size();
+ ExecTO execution = taskService.execute(new
ExecuteQuery.Builder().key(taskKey).dryRun(dryRun).build());
assertEquals(initialStatus, execution.getStatus());
assertNotNull(execution.getExecutor());
-
- int i = 0;
- // wait for completion (executions incremented)
- do {
+ await().atMost(maxWaitSeconds, TimeUnit.SECONDS).pollInterval(1,
TimeUnit.SECONDS).until(() -> {
try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
+ taskTO.set(taskService.read(type, taskKey, true));
+ return preSyncSize < taskTO.get().getExecutions().size();
+ } catch (Exception e) {
+ return false;
}
+ });
- taskTO = taskService.read(type, taskTO.getKey(), true);
-
- assertNotNull(taskTO);
- assertNotNull(taskTO.getExecutions());
-
- i++;
- } while (preSyncSize == taskTO.getExecutions().size() && i <
maxWaitSeconds);
- if (i == maxWaitSeconds) {
- fail("Timeout when executing task " + taskKey);
- }
- return taskTO.getExecutions().get(taskTO.getExecutions().size() - 1);
+ return
taskTO.get().getExecutions().get(taskTO.get().getExecutions().size() - 1);
}
public static ExecTO execProvisioningTask(
@@ -167,51 +129,63 @@ public abstract class AbstractTaskITCase extends
AbstractITCase {
NotificationJob.Status.SENT.name(), maxWaitSeconds, false);
}
- protected void execProvisioningTasks(final TaskService taskService, final
TaskType type, final Set<String> taskKeys,
- final int maxWaitSeconds, final boolean dryRun) throws Exception {
+ protected void execProvisioningTasks(
+ final TaskService taskService,
+ final TaskType type,
+ final Set<String> taskKeys,
+ final int maxWaitSeconds,
+ final boolean dryRun) throws Exception {
ExecutorService service =
Executors.newFixedThreadPool(taskKeys.size());
List<Future<ExecTO>> futures = new ArrayList<>();
- taskKeys.forEach(key -> {
- futures.add(service.submit(new ThreadExec(taskService, type, key,
maxWaitSeconds, dryRun)));
+ taskKeys.forEach(taskKey -> {
+ futures.add(service.submit(() -> {
+ try {
+ return execProvisioningTask(taskService, type, taskKey,
maxWaitSeconds, dryRun);
+ } catch (Exception e) {
+ ExecTO failure = new ExecTO();
+ failure.setRefKey(taskKey);
+ failure.setStatus(ExecStatus.FAILURE.name());
+ failure.setMessage(e.getMessage());
+ return failure;
+ }
+ }));
+
// avoid flooding the test server
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
+ // ignore
}
});
- for (Future<ExecTO> future : futures) {
- future.get(100, TimeUnit.SECONDS);
- }
+ futures.forEach(future -> {
+ try {
+ future.get(maxWaitSeconds, TimeUnit.SECONDS);
+ } catch (Exception e) {
+ LOG.error("While getting futures", e);
+ }
+ });
service.shutdownNow();
}
protected NotificationTaskTO findNotificationTask(final String
notification, final int maxWaitSeconds) {
- int i = 0;
- int maxit = maxWaitSeconds;
-
- NotificationTaskTO notificationTask = null;
- do {
+ AtomicReference<NotificationTaskTO> notificationTask = new
AtomicReference<>();
+ await().atMost(maxWaitSeconds, TimeUnit.SECONDS).pollInterval(1,
TimeUnit.SECONDS).until(() -> {
try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- }
-
- PagedResult<NotificationTaskTO> tasks =
- taskService.search(new
TaskQuery.Builder(TaskType.NOTIFICATION).notification(notification).build());
- if (!tasks.getResult().isEmpty()) {
- notificationTask = tasks.getResult().get(0);
+ PagedResult<NotificationTaskTO> tasks = taskService.search(
+ new
TaskQuery.Builder(TaskType.NOTIFICATION).notification(notification).build());
+ if (!tasks.getResult().isEmpty()) {
+ notificationTask.set(tasks.getResult().get(0));
+ }
+ } catch (Exception e) {
+ // ignore
}
+ return notificationTask.get() != null;
+ });
- i++;
- } while (notificationTask == null && i < maxit);
- if (notificationTask == null) {
- fail("Timeout when looking for notification tasks from
notification " + notification);
- }
-
- return notificationTask;
+ return notificationTask.get();
}
}
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuditITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuditITCase.java
index a3362bf..31304d2 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuditITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuditITCase.java
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.fit.core;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -28,6 +29,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.lang3.SerializationUtils;
import org.apache.syncope.client.lib.SyncopeClient;
import org.apache.syncope.common.lib.SyncopeConstants;
@@ -59,17 +62,16 @@ public class AuditITCase extends AbstractITCase {
}
private static List<AuditEntry> query(final AuditQuery query, final int
maxWaitSeconds) {
- int i = 0;
- List<AuditEntry> results = List.of();
- do {
+ AtomicReference<List<AuditEntry>> holder = new AtomicReference<>();
+ await().atMost(maxWaitSeconds, TimeUnit.SECONDS).pollInterval(1,
TimeUnit.SECONDS).until(() -> {
try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
+ holder.set(loggerService.search(query).getResult());
+ return !holder.get().isEmpty();
+ } catch (Exception e) {
+ return false;
}
- results = loggerService.search(query).getResult();
- i++;
- } while (results.isEmpty() && i < maxWaitSeconds);
- return results;
+ });
+ return holder.get();
}
@Test
@@ -201,7 +203,7 @@ public class AuditITCase extends AbstractITCase {
event("update").
result(AuditElements.Result.SUCCESS).
build();
- List<AuditEntry> entries = query(query, 0);
+ List<AuditEntry> entries = loggerService.search(query).getResult();
int pre = entries.size();
ConnInstanceTO ldapConn = connectorService.read(connectorKey, null);
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/BatchITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/BatchITCase.java
index 097918e..8ba5538 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/BatchITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/BatchITCase.java
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.fit.core;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -34,6 +35,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
@@ -228,17 +231,16 @@ public class BatchITCase extends AbstractITCase {
header(HttpHeaders.AUTHORIZATION, "Bearer " +
adminClient.getJWT()).
type(RESTHeaders.multipartMixedWith(boundary.substring(2)));
- int i = 0;
- do {
+ AtomicReference<Response> holder = new AtomicReference<>();
+ await().atMost(MAX_WAIT_SECONDS, TimeUnit.SECONDS).pollInterval(1,
TimeUnit.SECONDS).until(() -> {
try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
+ holder.set(client.get());
+ return holder.get().getStatus() !=
Response.Status.ACCEPTED.getStatusCode();
+ } catch (Exception e) {
+ return false;
}
-
- response = client.get();
-
- i++;
- } while (response.getStatus() ==
Response.Status.ACCEPTED.getStatusCode() && i < MAX_WAIT_SECONDS);
+ });
+ response = holder.get();
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
assertTrue(response.getMediaType().toString().
startsWith(RESTHeaders.multipartMixedWith(boundary.substring(2))));
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java
index 4e3d47a..bceccc7 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/GroupITCase.java
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.fit.core;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -31,6 +32,8 @@ import java.security.AccessControlException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
@@ -74,7 +77,6 @@ import org.apache.syncope.common.lib.to.MembershipTO;
import org.apache.syncope.common.lib.to.PropagationStatus;
import org.apache.syncope.common.lib.to.ProvisionTO;
import org.apache.syncope.common.lib.to.ProvisioningResult;
-import org.apache.syncope.common.lib.to.SchedTaskTO;
import org.apache.syncope.common.lib.to.TypeExtensionTO;
import org.apache.syncope.common.lib.to.UserTO;
import org.apache.syncope.common.lib.types.AnyTypeKind;
@@ -963,22 +965,16 @@ public class GroupITCase extends AbstractITCase {
ExecTO exec = groupService.provisionMembers(groupTO.getKey(),
ProvisionAction.PROVISION);
assertNotNull(exec.getRefKey());
- int i = 0;
-
- // wait for task exec completion (executions incremented)
- SchedTaskTO taskTO;
- do {
- Thread.sleep(1000);
-
- taskTO = taskService.read(TaskType.SCHEDULED,
exec.getRefKey(), true);
-
- assertNotNull(taskTO);
- assertNotNull(taskTO.getExecutions());
- i++;
- } while (taskTO.getExecutions().isEmpty() && i < MAX_WAIT_SECONDS);
- assertFalse(taskTO.getExecutions().isEmpty());
-
- assertEquals(TaskJob.Status.SUCCESS.name(),
taskTO.getExecutions().get(0).getStatus());
+ AtomicReference<List<ExecTO>> execs = new AtomicReference<>();
+ await().atMost(MAX_WAIT_SECONDS, TimeUnit.SECONDS).pollInterval(1,
TimeUnit.SECONDS).until(() -> {
+ try {
+ execs.set(taskService.read(TaskType.SCHEDULED,
exec.getRefKey(), true).getExecutions());
+ return !execs.get().isEmpty();
+ } catch (Exception e) {
+ return false;
+ }
+ });
+ assertEquals(TaskJob.Status.SUCCESS.name(),
execs.get().get(0).getStatus());
// 6. verify that the user above is now fond on LDAP
ConnObjectTO userOnLdap =
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/KeymasterITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/KeymasterITCase.java
index 30c10fb..0deb7bd 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/KeymasterITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/KeymasterITCase.java
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.fit.core;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -33,6 +34,8 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
@@ -152,25 +155,16 @@ public class KeymasterITCase extends AbstractITCase {
final Function<List<NetworkService>, Boolean> check,
final int maxWaitSeconds) {
- int i = 0;
- int maxit = maxWaitSeconds;
-
- List<NetworkService> list = List.of();
- do {
+ AtomicReference<List<NetworkService>> holder = new AtomicReference<>();
+ await().atMost(maxWaitSeconds, TimeUnit.SECONDS).pollInterval(1,
TimeUnit.SECONDS).until(() -> {
try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
+ holder.set(serviceOps.list(type));
+ return !check.apply(holder.get());
+ } catch (Exception e) {
+ return false;
}
-
- list = serviceOps.list(type);
-
- i++;
- } while (check.apply(list) && i < maxit);
- if (check.apply(list)) {
- fail("Timeout when looking for network services of type " + type);
- }
-
- return list;
+ });
+ return holder.get();
}
@Test
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/LoggerITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/LoggerITCase.java
index 960da37..70171ff 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/LoggerITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/LoggerITCase.java
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.fit.core;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -38,6 +39,8 @@ import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
import javax.ws.rs.core.Response;
import javax.xml.ws.WebServiceException;
import org.apache.commons.lang3.StringUtils;
@@ -254,23 +257,19 @@ public class LoggerITCase extends AbstractITCase {
assertTrue(found);
}
- private static boolean logFileContains(final Path path, final String
message, final int maxWaitSeconds)
+ private static void checkLogFileFor(
+ final Path path,
+ final Function<String, Boolean> checker,
+ final int maxWaitSeconds)
throws IOException {
- int i = 0;
- boolean messagePresent = false;
- do {
+ await().atMost(maxWaitSeconds, TimeUnit.SECONDS).pollInterval(1,
TimeUnit.SECONDS).until(() -> {
try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
+ return checker.apply(Files.readString(path,
StandardCharsets.UTF_8));
+ } catch (Exception e) {
+ return false;
}
-
- String auditLog = Files.readString(path, StandardCharsets.UTF_8);
- messagePresent = auditLog.contains(message);
-
- i++;
- } while (!messagePresent && i < maxWaitSeconds);
- return messagePresent;
+ });
}
@Test
@@ -352,14 +351,20 @@ public class LoggerITCase extends AbstractITCase {
connectorService.update(connector);
// check audit_for_Master_file.log, it should contain only a
static message
- assertTrue(logFileContains(auditFilePath,
- "DEBUG
Master.syncope.audit.[LOGIC]:[ResourceLogic]:[]:[update]:[SUCCESS]"
- + " - This is a static test message", 10));
+ checkLogFileFor(
+ auditFilePath,
+ content -> content.contains(
+ "DEBUG
Master.syncope.audit.[LOGIC]:[ResourceLogic]:[]:[update]:[SUCCESS]"
+ + " - This is a static test message"),
+ 10);
// nothing expected in audit_for_Master_norewrite_file.log instead
- assertFalse(logFileContains(auditNoRewriteFilePath,
- "DEBUG
Master.syncope.audit.[LOGIC]:[ResourceLogic]:[]:[update]:[SUCCESS]"
- + " - This is a static test message", 10));
+ checkLogFileFor(
+ auditNoRewriteFilePath,
+ content -> !content.contains(
+ "DEBUG
Master.syncope.audit.[LOGIC]:[ResourceLogic]:[]:[update]:[SUCCESS]"
+ + " - This is a static test message"),
+ 10);
// clean audit_for_Master_file.log
Files.write(auditFilePath, new byte[0],
StandardOpenOption.TRUNCATE_EXISTING);
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskITCase.java
index 03d875f..5c7b501 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/NotificationTaskITCase.java
@@ -56,14 +56,13 @@ public class NotificationTaskITCase extends
AbstractNotificationTaskITCase {
String sender = "syncopetest-" + getUUIDString() +
"@syncope.apache.org";
String subject = "Test notification " + getUUIDString();
Pair<String, String> created = createNotificationTask(true, true,
TraceLevel.ALL, sender, subject);
- NotificationTaskTO taskTO = findNotificationTask(created.getLeft(),
50);
+ NotificationTaskTO taskTO = findNotificationTask(created.getLeft(),
MAX_WAIT_SECONDS);
assertNotNull(taskTO);
assertNotNull(taskTO.getNotification());
- assertTrue(taskTO.getExecutions().isEmpty());
- execNotificationTask(taskService, taskTO.getKey(), 50);
+ execNotificationTask(taskService, taskTO.getKey(), MAX_WAIT_SECONDS);
- assertTrue(verifyMail(sender, subject, created.getRight(), 50));
+ verifyMail(sender, subject, created.getRight(), MAX_WAIT_SECONDS);
// verify message body
taskTO = taskService.read(TaskType.NOTIFICATION, taskTO.getKey(),
true);
@@ -80,13 +79,12 @@ public class NotificationTaskITCase extends
AbstractNotificationTaskITCase {
String sender = "syncopetest-" + getUUIDString() +
"@syncope.apache.org";
String subject = "Test notification " + getUUIDString();
Pair<String, String> created = createNotificationTask(true, false,
TraceLevel.ALL, sender, subject);
- NotificationTaskTO taskTO = findNotificationTask(created.getLeft(),
50);
+ NotificationTaskTO taskTO = findNotificationTask(created.getLeft(),
MAX_WAIT_SECONDS);
assertNotNull(taskTO);
- assertTrue(taskTO.getExecutions().isEmpty());
- execNotificationTask(taskService, taskTO.getKey(), 50);
+ execNotificationTask(taskService, taskTO.getKey(), MAX_WAIT_SECONDS);
- assertTrue(verifyMail(sender, subject, created.getRight(), 50));
+ verifyMail(sender, subject, created.getRight(), MAX_WAIT_SECONDS);
}
@Test
@@ -105,7 +103,7 @@ public class NotificationTaskITCase extends
AbstractNotificationTaskITCase {
String sender = "syncopetest-" + getUUIDString() +
"@syncope.apache.org";
String subject = "Test notification " + getUUIDString();
Pair<String, String> created = createNotificationTask(true, true,
TraceLevel.ALL, sender, subject);
- NotificationTaskTO taskTO =
findNotificationTask(created.getLeft(), 50);
+ NotificationTaskTO taskTO =
findNotificationTask(created.getLeft(), MAX_WAIT_SECONDS);
assertNotNull(taskTO);
assertNotNull(taskTO.getNotification());
int preExecs = taskTO.getExecutions().size();
@@ -134,13 +132,13 @@ public class NotificationTaskITCase extends
AbstractNotificationTaskITCase {
public void issueSYNCOPE81() {
String sender = "[email protected]";
Pair<String, String> created = createNotificationTask(true, true,
TraceLevel.ALL, sender, "Test notification");
- NotificationTaskTO taskTO = findNotificationTask(created.getLeft(),
50);
+ NotificationTaskTO taskTO = findNotificationTask(created.getLeft(),
MAX_WAIT_SECONDS);
assertNotNull(taskTO);
assertNotNull(taskTO.getNotification());
assertTrue(taskTO.getExecutions().isEmpty());
// generate an execution in order to verify the deletion of a
notification task with one or more executions
- execNotificationTask(taskService, taskTO.getKey(), 50);
+ execNotificationTask(taskService, taskTO.getKey(), MAX_WAIT_SECONDS);
taskTO = taskService.read(TaskType.NOTIFICATION, taskTO.getKey(),
true);
assertTrue(taskTO.isExecuted());
@@ -156,14 +154,14 @@ public class NotificationTaskITCase extends
AbstractNotificationTaskITCase {
Pair<String, String> created = createNotificationTask(true, true,
TraceLevel.ALL, sender, "Test notification");
// 2. get NotificationTaskTO for user just created
- NotificationTaskTO taskTO = findNotificationTask(created.getLeft(),
50);
+ NotificationTaskTO taskTO = findNotificationTask(created.getLeft(),
MAX_WAIT_SECONDS);
assertNotNull(taskTO);
assertNotNull(taskTO.getNotification());
assertTrue(taskTO.getExecutions().isEmpty());
try {
// 3. execute the generated NotificationTask
- execNotificationTask(taskService, taskTO.getKey(), 50);
+ execNotificationTask(taskService, taskTO.getKey(),
MAX_WAIT_SECONDS);
// 4. verify
taskTO = taskService.read(TaskType.NOTIFICATION, taskTO.getKey(),
true);
@@ -183,7 +181,7 @@ public class NotificationTaskITCase extends
AbstractNotificationTaskITCase {
String sender = "syncopetest-" + getUUIDString() +
"@syncope.apache.org";
String subject = "Test notification " + getUUIDString();
Pair<String, String> created = createNotificationTask(true, true,
TraceLevel.NONE, sender, subject);
- NotificationTaskTO taskTO = findNotificationTask(created.getLeft(),
50);
+ NotificationTaskTO taskTO = findNotificationTask(created.getLeft(),
MAX_WAIT_SECONDS);
assertNotNull(taskTO);
assertNotNull(taskTO.getNotification());
assertTrue(taskTO.getExecutions().isEmpty());
@@ -195,7 +193,7 @@ public class NotificationTaskITCase extends
AbstractNotificationTaskITCase {
} catch (InterruptedException e) {
}
- assertTrue(verifyMail(sender, subject, created.getRight(), 50));
+ verifyMail(sender, subject, created.getRight(), MAX_WAIT_SECONDS);
// verify that last exec status was updated
taskTO = taskService.read(TaskType.NOTIFICATION, taskTO.getKey(),
true);
@@ -211,14 +209,14 @@ public class NotificationTaskITCase extends
AbstractNotificationTaskITCase {
String subject = "Test notification " + getUUIDString();
Pair<String, String> created = createNotificationTask(
true, true, TraceLevel.ALL, sender, subject,
"[email protected]");
- NotificationTaskTO taskTO = findNotificationTask(created.getLeft(),
50);
+ NotificationTaskTO taskTO = findNotificationTask(created.getLeft(),
MAX_WAIT_SECONDS);
assertNotNull(taskTO);
assertNotNull(taskTO.getNotification());
assertTrue(taskTO.getExecutions().isEmpty());
- execNotificationTask(taskService, taskTO.getKey(), 50);
+ execNotificationTask(taskService, taskTO.getKey(), MAX_WAIT_SECONDS);
- assertTrue(verifyMail(sender, subject, created.getRight(), 50));
+ verifyMail(sender, subject, created.getRight(), MAX_WAIT_SECONDS);
// verify task
taskTO = taskService.read(TaskType.NOTIFICATION, taskTO.getKey(),
true);
@@ -275,20 +273,15 @@ public class NotificationTaskITCase extends
AbstractNotificationTaskITCase {
assertNotNull(groupTO);
// 3. verify
- NotificationTaskTO taskTO =
findNotificationTask(notification.getKey(), 50);
+ NotificationTaskTO taskTO =
findNotificationTask(notification.getKey(), MAX_WAIT_SECONDS);
assertNotNull(taskTO);
assertNotNull(taskTO.getNotification());
assertTrue(taskTO.getRecipients().containsAll(
new
TestNotificationRecipientsProvider().provideRecipients(null)));
- NotificationTaskTO foundViaList =
taskService.<NotificationTaskTO>search(
- new
TaskQuery.Builder(TaskType.NOTIFICATION).notification(notification.getKey()).build()).
- getResult().get(0);
- assertEquals(taskTO, foundViaList);
+ execNotificationTask(taskService, taskTO.getKey(), MAX_WAIT_SECONDS);
- execNotificationTask(taskService, taskTO.getKey(), 50);
-
- assertTrue(verifyMail(sender, subject,
"[email protected]", 50));
+ verifyMail(sender, subject, "[email protected]",
MAX_WAIT_SECONDS);
}
@Test
@@ -303,5 +296,4 @@ public class NotificationTaskITCase extends
AbstractNotificationTaskITCase {
taskService.search(new
TaskQuery.Builder(TaskType.NOTIFICATION).notification(created.getLeft()).build());
assertEquals(0, tasks.getSize());
}
-
}
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java
index 8b053bf..f63272a 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PullTaskITCase.java
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.fit.core;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -35,13 +36,14 @@ import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Date;
-import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
import javax.ws.rs.core.Response;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.SerializationUtils;
@@ -71,7 +73,6 @@ import org.apache.syncope.common.lib.to.ItemTO;
import org.apache.syncope.common.lib.to.PullTaskTO;
import org.apache.syncope.common.lib.to.ExecTO;
import org.apache.syncope.common.lib.to.ImplementationTO;
-import org.apache.syncope.common.lib.to.PropagationTaskTO;
import org.apache.syncope.common.lib.to.ProvisioningResult;
import org.apache.syncope.common.lib.to.RemediationTO;
import org.apache.syncope.common.lib.to.UserTO;
@@ -305,9 +306,9 @@ public class PullTaskITCase extends AbstractTaskITCase {
assertNotNull(userTO);
assertEquals("active", userTO.getStatus());
- Set<String> otherPullTaskKeys = new HashSet<>();
- otherPullTaskKeys.add("feae4e57-15ca-40d9-b973-8b9015efca49");
- otherPullTaskKeys.add("55d5e74b-497e-4bc0-9156-73abef4b9adc");
+ Set<String> otherPullTaskKeys = Set.of(
+ "feae4e57-15ca-40d9-b973-8b9015efca49",
+ "55d5e74b-497e-4bc0-9156-73abef4b9adc");
execProvisioningTasks(taskService, TaskType.PULL,
otherPullTaskKeys, MAX_WAIT_SECONDS, false);
// Matching --> UNLINK
@@ -432,25 +433,20 @@ public class PullTaskITCase extends AbstractTaskITCase {
taskService, TaskType.PULL,
"1e419ca4-ea81-4493-a14f-28b90113686d", MAX_WAIT_SECONDS, false);
// 4. verify that LDAP group membership is pulled as Syncope membership
- int i = 0;
- PagedResult<UserTO> members;
- do {
+ AtomicReference<Integer> numMembers = new AtomicReference<>();
+ await().atMost(MAX_WAIT_SECONDS, TimeUnit.SECONDS).pollInterval(1,
TimeUnit.SECONDS).until(() -> {
try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
+ PagedResult<UserTO> members = userService.search(
+ new
AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
+
fiql(SyncopeClient.getUserSearchConditionBuilder().inGroups(groupTO.getKey()).query()).
+ build());
+ numMembers.set(members.getResult().size());
+ return !members.getResult().isEmpty();
+ } catch (Exception e) {
+ return false;
}
-
- members = userService.search(new
AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
-
fiql(SyncopeClient.getUserSearchConditionBuilder().inGroups(groupTO.getKey()).query()).
- build());
- assertNotNull(members);
-
- i++;
- } while (members.getResult().isEmpty() && i < MAX_WAIT_SECONDS);
- if (i == MAX_WAIT_SECONDS) {
- fail("Timeout while checking for memberships of " +
groupTO.getName());
- }
- assertEquals(1, members.getResult().size());
+ });
+ assertEquals(1, numMembers.get());
// SYNCOPE-1343, verify that the title attribute has been reset
matchingUsers = userService.search(
@@ -471,24 +467,16 @@ public class PullTaskITCase extends AbstractTaskITCase {
execProvisioningTask(
taskService, TaskType.PULL,
"1e419ca4-ea81-4493-a14f-28b90113686d", MAX_WAIT_SECONDS, false);
- i = 0;
- do {
+ await().atMost(MAX_WAIT_SECONDS, TimeUnit.SECONDS).pollInterval(1,
TimeUnit.SECONDS).until(() -> {
try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
+ return userService.search(
+ new
AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
+
fiql(SyncopeClient.getUserSearchConditionBuilder().inGroups(groupTO.getKey()).query()).
+ build()).getResult().isEmpty();
+ } catch (Exception e) {
+ return false;
}
-
- members = userService.search(new
AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
-
fiql(SyncopeClient.getUserSearchConditionBuilder().inGroups(groupTO.getKey()).query()).
- build());
- assertNotNull(members);
-
- i++;
- } while (!members.getResult().isEmpty() && i < MAX_WAIT_SECONDS);
- if (i == MAX_WAIT_SECONDS) {
- fail("Timeout while checking for memberships of " +
groupTO.getName());
- }
- assertEquals(0, members.getResult().size());
+ });
}
@Test
@@ -1059,14 +1047,11 @@ public class PullTaskITCase extends AbstractTaskITCase {
taskService.update(TaskType.PULL, task);
// exec task: one user from CSV will match the user created above and
template will be applied
- execProvisioningTask(taskService, TaskType.PULL, task.getKey(),
MAX_WAIT_SECONDS, false);
+ ExecTO exec = execProvisioningTask(taskService, TaskType.PULL,
task.getKey(), MAX_WAIT_SECONDS, false);
// check that template was successfully applied
// 1. propagation to db
- PagedResult<PropagationTaskTO> tasks = taskService.search(new
TaskQuery.Builder(TaskType.PROPAGATION).
-
anyTypeKind(AnyTypeKind.USER).entityKey(userTO.getKey()).resource(RESOURCE_NAME_DBVIRATTR).build());
- assertFalse(tasks.getResult().isEmpty());
- assertEquals(ExecStatus.SUCCESS.name(),
tasks.getResult().get(0).getLatestExecStatus());
+ assertEquals(ExecStatus.SUCCESS.name(), exec.getStatus());
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
String value = queryForObject(jdbcTemplate,
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PushTaskITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PushTaskITCase.java
index 5d9c879..5c4406d 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PushTaskITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PushTaskITCase.java
@@ -26,7 +26,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.ws.rs.core.Response;
@@ -157,11 +156,11 @@ public class PushTaskITCase extends AbstractTaskITCase {
getResources().contains(RESOURCE_NAME_TESTDB2));
// ------------------------------------------
- Set<String> pushTaskKeys = new HashSet<>();
- pushTaskKeys.add("af558be4-9d2f-4359-bf85-a554e6e90be1");
- pushTaskKeys.add("97f327b6-2eff-4d35-85e8-d581baaab855");
- pushTaskKeys.add("03aa2a04-4881-4573-9117-753f81b04865");
- pushTaskKeys.add("5e5f7c7e-9de7-4c6a-99f1-4df1af959807");
+ Set<String> pushTaskKeys = Set.of(
+ "af558be4-9d2f-4359-bf85-a554e6e90be1",
+ "97f327b6-2eff-4d35-85e8-d581baaab855",
+ "03aa2a04-4881-4573-9117-753f81b04865",
+ "5e5f7c7e-9de7-4c6a-99f1-4df1af959807");
execProvisioningTasks(taskService, TaskType.PUSH, pushTaskKeys,
MAX_WAIT_SECONDS, false);
// ------------------------------------------
@@ -220,11 +219,10 @@ public class PushTaskITCase extends AbstractTaskITCase {
assertEquals(1, jdbcTemplate.queryForList("SELECT ID FROM test2 WHERE
ID='rossini'").size());
// ------------------------------------------
- Set<String> pushTaskKeys = new HashSet<>();
- pushTaskKeys.add("ec674143-480a-4816-98ad-b61fa090821e");
- pushTaskKeys.add("c46edc3a-a18b-4af2-b707-f4a415507496");
- pushTaskKeys.add("5e5f7c7e-9de7-4c6a-99f1-4df1af959807");
-
+ Set<String> pushTaskKeys = Set.of(
+ "ec674143-480a-4816-98ad-b61fa090821e",
+ "c46edc3a-a18b-4af2-b707-f4a415507496",
+ "5e5f7c7e-9de7-4c6a-99f1-4df1af959807");
execProvisioningTasks(taskService, TaskType.PUSH, pushTaskKeys,
MAX_WAIT_SECONDS, false);
// ------------------------------------------
@@ -255,10 +253,9 @@ public class PushTaskITCase extends AbstractTaskITCase {
assertEquals(1, jdbcTemplate.queryForList("SELECT ID FROM test2 WHERE
ID='verdi'").size());
// ------------------------------------------
- pushTaskKeys.clear();
- pushTaskKeys.add("24b1be9c-7e3b-443a-86c9-798ebce5eaf2");
- pushTaskKeys.add("375c7b7f-9e3a-4833-88c9-b7787b0a69f2");
-
+ pushTaskKeys = Set.of(
+ "24b1be9c-7e3b-443a-86c9-798ebce5eaf2",
+ "375c7b7f-9e3a-4833-88c9-b7787b0a69f2");
execProvisioningTasks(taskService, TaskType.PUSH, pushTaskKeys,
MAX_WAIT_SECONDS, false);
// ------------------------------------------
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportITCase.java
index ab9e35e..6832e64 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReportITCase.java
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.fit.core;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -30,6 +31,8 @@ import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import org.apache.commons.io.IOUtils;
@@ -61,36 +64,20 @@ import org.junit.jupiter.api.Test;
public class ReportITCase extends AbstractITCase {
protected static String execReport(final String reportKey) {
- ReportTO reportTO = reportService.read(reportKey);
- assertNotNull(reportTO);
- assertNotNull(reportTO.getExecutions());
-
- int preExecSize = reportTO.getExecutions().size();
- ExecuteQuery query = new ExecuteQuery.Builder().key(reportKey).build();
- ExecTO exec = reportService.execute(query);
- assertNotNull(exec);
- assertNotNull(exec.getExecutor());
+ AtomicReference<ReportTO> reportTO = new
AtomicReference<>(reportService.read(reportKey));
+ int preExecSize = reportTO.get().getExecutions().size();
+ ExecTO execution = reportService.execute(new
ExecuteQuery.Builder().key(reportKey).build());
+ assertNotNull(execution.getExecutor());
- int i = 0;
-
- // wait for completion (executions incremented)
- do {
+ await().atMost(MAX_WAIT_SECONDS, TimeUnit.SECONDS).pollInterval(1,
TimeUnit.SECONDS).until(() -> {
try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
+ reportTO.set(reportService.read(reportKey));
+ return preExecSize < reportTO.get().getExecutions().size();
+ } catch (Exception e) {
+ return false;
}
-
- reportTO = reportService.read(reportKey);
-
- assertNotNull(reportTO);
- assertNotNull(reportTO.getExecutions());
-
- i++;
- } while (preExecSize == reportTO.getExecutions().size() && i <
MAX_WAIT_SECONDS);
- if (i == MAX_WAIT_SECONDS) {
- fail("Timeout when executing report " + reportKey);
- }
- exec = reportTO.getExecutions().get(reportTO.getExecutions().size() -
1);
+ });
+ ExecTO exec =
reportTO.get().getExecutions().get(reportTO.get().getExecutions().size() - 1);
assertEquals(ReportExecStatus.SUCCESS.name(), exec.getStatus());
return exec.getKey();
}
@@ -353,23 +340,10 @@ public class ReportITCase extends AbstractITCase {
reportTO.setActive(true);
reportTO.setTemplate("sample");
reportTO = createReport(reportTO);
- assertNotNull(reportTO);
-
- ExecTO execution = reportService.execute(new
ExecuteQuery.Builder().key(reportTO.getKey()).build());
- assertNotNull(execution);
-
- int maxit = MAX_WAIT_SECONDS;
- do {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- }
-
- reportTO = reportService.read(reportTO.getKey());
-
- maxit--;
- } while (reportTO.getExecutions().isEmpty() && maxit > 0);
+ assertNotNull(reportTO.getKey());
+ execReport(reportTO.getKey());
+ reportTO = reportService.read(reportTO.getKey());
assertEquals(1, reportTO.getExecutions().size());
}
@@ -379,26 +353,21 @@ public class ReportITCase extends AbstractITCase {
ReportTO reportTO =
reportService.read("0062ea9c-924d-4ecf-9961-4492a8cc6d1b");
reportTO.setName("issueSYNCOPE102" + getUUIDString());
reportTO = createReport(reportTO);
- assertNotNull(reportTO);
+ assertNotNull(reportTO.getKey());
+ String reportKey = reportTO.getKey();
// Execute (multiple requests)
for (int i = 0; i < 10; i++) {
- ExecTO execution = reportService.execute(new
ExecuteQuery.Builder().key(reportTO.getKey()).build());
- assertNotNull(execution);
+ assertNotNull(reportService.execute(new
ExecuteQuery.Builder().key(reportKey).build()));
}
// Wait for one execution
- int maxit = MAX_WAIT_SECONDS;
- do {
+ await().atMost(MAX_WAIT_SECONDS, TimeUnit.SECONDS).pollInterval(1,
TimeUnit.SECONDS).until(() -> {
try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
+ return
!reportService.read(reportKey).getExecutions().isEmpty();
+ } catch (Exception e) {
+ return false;
}
-
- reportTO = reportService.read(reportTO.getKey());
-
- maxit--;
- } while (reportTO.getExecutions().isEmpty() && maxit > 0);
- assertFalse(reportTO.getExecutions().isEmpty());
+ });
}
}
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SchedTaskITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SchedTaskITCase.java
index 3750c0b..deb2d64 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SchedTaskITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SchedTaskITCase.java
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.fit.core;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -28,6 +29,8 @@ import static org.junit.jupiter.api.Assertions.fail;
import java.util.Date;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.time.DateUtils;
@@ -38,6 +41,7 @@ import org.apache.syncope.common.lib.to.SchedTaskTO;
import org.apache.syncope.common.lib.to.PullTaskTO;
import org.apache.syncope.common.lib.to.ExecTO;
import org.apache.syncope.common.lib.to.ImplementationTO;
+import org.apache.syncope.common.lib.to.TaskTO;
import org.apache.syncope.common.lib.types.IdRepoImplementationType;
import org.apache.syncope.common.lib.types.JobAction;
import org.apache.syncope.common.lib.types.TaskType;
@@ -99,28 +103,25 @@ public class SchedTaskITCase extends AbstractTaskITCase {
Response response = taskService.create(TaskType.SCHEDULED, task);
task = getObject(response.getLocation(), TaskService.class,
SchedTaskTO.class);
assertNotNull(task);
+ String taskKey = task.getKey();
+ assertNotNull(task);
Date initial = new Date();
Date later = DateUtils.addSeconds(initial, 2);
- taskService.execute(new
ExecuteQuery.Builder().key(task.getKey()).startAt(later).build());
-
- int i = 0;
+ AtomicReference<TaskTO> taskTO = new AtomicReference<>(task);
+ int preSyncSize = taskTO.get().getExecutions().size();
+ ExecTO execution = taskService.execute(new
ExecuteQuery.Builder().key(task.getKey()).startAt(later).build());
+ assertNotNull(execution.getExecutor());
- // wait for completion (executions incremented)
- do {
+ await().atMost(MAX_WAIT_SECONDS, TimeUnit.SECONDS).pollInterval(1,
TimeUnit.SECONDS).until(() -> {
try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
+ taskTO.set(taskService.read(TaskType.SCHEDULED, taskKey,
true));
+ return preSyncSize < taskTO.get().getExecutions().size();
+ } catch (Exception e) {
+ return false;
}
-
- task = taskService.read(TaskType.SCHEDULED, task.getKey(), true);
-
- assertNotNull(task);
- assertNotNull(task.getExecutions());
-
- i++;
- } while (task.getExecutions().isEmpty() && i < MAX_WAIT_SECONDS);
+ });
PagedResult<ExecTO> execs =
taskService.listExecutions(new
ExecQuery.Builder().key(task.getKey()).build());
@@ -165,7 +166,7 @@ public class SchedTaskITCase extends AbstractTaskITCase {
@Test
public void issueSYNCOPE660() {
List<JobTO> jobs = taskService.listJobs();
- int old_size = jobs.size();
+ int oldSize = jobs.size();
ImplementationTO taskJobDelegate = implementationService.read(
IdRepoImplementationType.TASKJOB_DELEGATE,
TestSampleJobDelegate.class.getSimpleName());
@@ -180,41 +181,32 @@ public class SchedTaskITCase extends AbstractTaskITCase {
task = getObject(response.getLocation(), TaskService.class,
SchedTaskTO.class);
jobs = taskService.listJobs();
- assertEquals(old_size + 1, jobs.size());
+ assertEquals(oldSize + 1, jobs.size());
taskService.actionJob(task.getKey(), JobAction.START);
- int i = 0;
-
- do {
+ AtomicReference<List<JobTO>> run = new AtomicReference<>();
+ await().atMost(MAX_WAIT_SECONDS, TimeUnit.SECONDS).pollInterval(1,
TimeUnit.SECONDS).until(() -> {
try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // ignore
+
run.set(taskService.listJobs().stream().filter(JobTO::isRunning).collect(Collectors.toList()));
+ return !run.get().isEmpty();
+ } catch (Exception e) {
+ return false;
}
-
- jobs =
taskService.listJobs().stream().filter(JobTO::isRunning).collect(Collectors.toList());
- i++;
- } while (jobs.size() < 1 && i < MAX_WAIT_SECONDS);
-
- assertEquals(1, jobs.size());
- assertEquals(task.getKey(), jobs.get(0).getRefKey());
+ });
+ assertEquals(1, run.get().size());
+ assertEquals(task.getKey(), run.get().get(0).getRefKey());
taskService.actionJob(task.getKey(), JobAction.STOP);
- i = 0;
-
- do {
+ run.set(List.of());
+ await().atMost(MAX_WAIT_SECONDS, TimeUnit.SECONDS).pollInterval(1,
TimeUnit.SECONDS).until(() -> {
try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // ignore
+
run.set(taskService.listJobs().stream().filter(JobTO::isRunning).collect(Collectors.toList()));
+ return run.get().isEmpty();
+ } catch (Exception e) {
+ return false;
}
-
- jobs =
taskService.listJobs().stream().filter(JobTO::isRunning).collect(Collectors.toList());
- i++;
- } while (jobs.size() >= 1 && i < MAX_WAIT_SECONDS);
-
- assertTrue(jobs.isEmpty());
+ });
}
}