You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by jk...@apache.org on 2021/09/15 15:49:25 UTC
[unomi] branch UNOMI-462-past-events updated: remove unecessary
retry classe and use the existing keepRetry function that already exists
This is an automated email from the ASF dual-hosted git repository.
jkevan pushed a commit to branch UNOMI-462-past-events
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to refs/heads/UNOMI-462-past-events by this push:
new 001475c remove unecessary retry classe and use the existing keepRetry function that already exists
001475c is described below
commit 001475c7c25a3067e0fafa7f4a9684214c72a0e4
Author: Kevan <ke...@jahia.com>
AuthorDate: Wed Sep 15 17:49:16 2021 +0200
remove unecessary retry classe and use the existing keepRetry function that already exists
---
.../java/org/apache/unomi/itests/SegmentIT.java | 24 +++-----
.../apache/unomi/itests/tools/RetriableHelper.java | 66 ----------------------
2 files changed, 8 insertions(+), 82 deletions(-)
diff --git a/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java b/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
index 87ca3fd..8241dc3 100644
--- a/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
@@ -26,7 +26,6 @@ import org.apache.unomi.api.services.EventService;
import org.apache.unomi.api.services.ProfileService;
import org.apache.unomi.api.services.SegmentService;
import org.apache.unomi.api.exceptions.BadSegmentConditionException;
-import org.apache.unomi.itests.tools.RetriableHelper;
import org.apache.unomi.persistence.spi.PersistenceService;
import org.junit.After;
import org.junit.Assert;
@@ -45,7 +44,6 @@ import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
-import java.util.concurrent.Callable;
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerSuite.class)
@@ -218,13 +216,10 @@ public class SegmentIT extends BaseIT {
// now recalculate the past event conditions
segmentService.recalculatePastEventConditions();
persistenceService.refreshIndex(Profile.class, null);
- new RetriableHelper<>("testSegmentPastEventRecalculation profile engaged", 20, 1000, () -> {
- Profile updatedProfile = profileService.load("test_profile_id");
- if (!updatedProfile.getSegments().contains("past-event-segment-test")) {
- throw new RuntimeException("Profile should be engaged in the segment, will retry or fail if retry reach the limit");
- }
- return updatedProfile;
- }).call();
+ keepTrying("Profile should be engaged in the segment",
+ () -> profileService.load("test_profile_id"),
+ updatedProfile -> updatedProfile.getSegments().contains("past-event-segment-test"),
+ 1000, 20);
// update the event to a date out of the past event condition
removeItems(Event.class);
@@ -236,12 +231,9 @@ public class SegmentIT extends BaseIT {
// now recalculate the past event conditions
segmentService.recalculatePastEventConditions();
persistenceService.refreshIndex(Profile.class, null);
- new RetriableHelper<>("testSegmentPastEventRecalculation profile not engaged anymore", 20, 1000, () -> {
- Profile updatedProfile = profileService.load("test_profile_id");
- if (updatedProfile.getSegments().contains("past-event-segment-test")) {
- throw new RuntimeException("Profile should not be engaged in the segment anymore, will retry or fail if retry reach the limit");
- }
- return updatedProfile;
- }).call();
+ keepTrying("Profile should not be engaged in the segment anymore",
+ () -> profileService.load("test_profile_id"),
+ updatedProfile -> !updatedProfile.getSegments().contains("past-event-segment-test"),
+ 1000, 20);
}
}
diff --git a/itests/src/test/java/org/apache/unomi/itests/tools/RetriableHelper.java b/itests/src/test/java/org/apache/unomi/itests/tools/RetriableHelper.java
deleted file mode 100644
index 540a7db..0000000
--- a/itests/src/test/java/org/apache/unomi/itests/tools/RetriableHelper.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package org.apache.unomi.itests.tools;
-
-import org.junit.Assert;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.CancellationException;
-
-/**
- * Just an utility class to do some retriable stuff in ITests
- * Useful when you are waiting for something to be indexed in ES for exemple, you just retry until your object is available
- * @param <T> The type of object you are expecting to return from this retry instance
- */
-public class RetriableHelper<T> implements Callable<T> {
-
- private final static Logger LOGGER = LoggerFactory.getLogger(RetriableHelper.class);
-
- private final Callable<T> task;
- private final long timeToWait;
- private final String key;
-
- private int numberOfTriesLeft;
-
-
- public RetriableHelper(String key, int numberOfRetries, long timeToWait, Callable<T> task) {
- this.key = key;
- this.numberOfTriesLeft = numberOfRetries;
- this.timeToWait = timeToWait;
- this.task = task;
- }
-
- public T call() throws Exception {
- while (true) {
- try {
- return task.call();
- } catch (InterruptedException | CancellationException e) {
- throw e;
- } catch (Exception e) {
- numberOfTriesLeft--;
- LOGGER.warn("RETRY: {} failed, number of tries left: {}, will wait {}ms before next try", key, numberOfTriesLeft, timeToWait);
- if (numberOfTriesLeft == 0) {
- Assert.fail("RETRY LIMIT REACH: " + e.getMessage());
- }
- Thread.sleep(timeToWait);
- }
- }
- }
-}
\ No newline at end of file