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 2022/01/28 16:07:47 UTC

[unomi] branch addTestsOnScoringRecalculationMaxEventCount created (now 8fb5672)

This is an automated email from the ASF dual-hosted git repository.

jkevan pushed a change to branch addTestsOnScoringRecalculationMaxEventCount
in repository https://gitbox.apache.org/repos/asf/unomi.git.


      at 8fb5672  UNOMI-530: add itest on scoring recalculation when there is maximum event count in a past event condition

This branch includes the following new commits:

     new 8fb5672  UNOMI-530: add itest on scoring recalculation when there is maximum event count in a past event condition

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[unomi] 01/01: UNOMI-530: add itest on scoring recalculation when there is maximum event count in a past event condition

Posted by jk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jkevan pushed a commit to branch addTestsOnScoringRecalculationMaxEventCount
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit 8fb56727cbe067a802fbf5253a77f544b1d5beec
Author: Kevan <ke...@jahia.com>
AuthorDate: Fri Jan 28 17:07:34 2022 +0100

    UNOMI-530: add itest on scoring recalculation when there is maximum event count in a past event condition
---
 .../java/org/apache/unomi/itests/SegmentIT.java    | 66 ++++++++++++++++++++++
 1 file changed, 66 insertions(+)

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 55f3ce9..5180421 100644
--- a/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
@@ -359,6 +359,72 @@ public class SegmentIT extends BaseIT {
                 1000, 20);
     }
 
+    @Test
+    public void testScoringPastEventRecalculationMaximumEventCount() throws Exception {
+        // create Profile
+        Profile profile = new Profile();
+        profile.setItemId("test_profile_id");
+        profileService.save(profile);
+        persistenceService.refreshIndex(Profile.class, null); // wait for profile to be full persisted and index
+
+        // create the past event condition
+        Condition pastEventCondition = new Condition(definitionsService.getConditionType("pastEventCondition"));
+        pastEventCondition.setParameter("numberOfDays", 10);
+        Condition pastEventEventCondition = new Condition(definitionsService.getConditionType("eventTypeCondition"));
+        pastEventEventCondition.setParameter("eventTypeId", "test-event-type-max");
+        pastEventCondition.setParameter("eventCondition", pastEventEventCondition);
+        pastEventCondition.setParameter("maximumEventCount", 1);
+
+        // create the scoring
+        Metadata scoringMetadata = new Metadata("past-event-scoring-test-max");
+        Scoring scoring = new Scoring(scoringMetadata);
+        List<ScoringElement> scoringElements = new ArrayList<>();
+        ScoringElement scoringElement = new ScoringElement();
+        scoringElement.setCondition(pastEventCondition);
+        scoringElement.setValue(50);
+        scoringElements.add(scoringElement);
+        scoring.setElements(scoringElements);
+        segmentService.setScoringDefinition(scoring);
+        Thread.sleep(5000);
+
+        // Persist the event (do not send it into the system so that it will not be processed by the rules)
+        ZoneId defaultZoneId = ZoneId.systemDefault();
+        LocalDate localDate = LocalDate.now().minusDays(3);
+        Event testEvent = new Event("test-event-type-max", null, profile, null, null, profile, Date.from(localDate.atStartOfDay(defaultZoneId).toInstant()));
+        testEvent.setPersistent(true);
+        persistenceService.save(testEvent, null, true);
+        persistenceService.refreshIndex(Event.class, testEvent.getTimeStamp()); // wait for event to be fully persisted and indexed
+
+        // insure the profile is not yet engaged since we directly saved the event in ES
+        profile = profileService.load("test_profile_id");
+        Assert.assertTrue("Profile should not be engaged in the scoring", profile.getScores() == null || !profile.getScores().containsKey("past-event-scoring-test-max"));
+
+        // now recalculate the past event conditions
+        segmentService.recalculatePastEventConditions();
+        persistenceService.refreshIndex(Profile.class, null);
+        keepTrying("Profile should be engaged in the scoring with a score of 50",
+                () -> profileService.load("test_profile_id"),
+                updatedProfile -> updatedProfile.getScores() != null &&
+                        updatedProfile.getScores().containsKey("past-event-scoring-test-max") &&
+                        updatedProfile.getScores().get("past-event-scoring-test-max") == 50,
+                1000, 20);
+
+        // Persist the 2 event (do not send it into the system so that it will not be processed by the rules)
+        defaultZoneId = ZoneId.systemDefault();
+        localDate = LocalDate.now().minusDays(3);
+        testEvent = new Event("test-event-type-max", null, profile, null, null, profile, Date.from(localDate.atStartOfDay(defaultZoneId).toInstant()));
+        testEvent.setPersistent(true);
+        persistenceService.save(testEvent, null, true);
+        persistenceService.refreshIndex(Event.class, testEvent.getTimeStamp()); // wait for event to be fully persisted and indexed
+
+        // now recalculate the past event conditions
+        segmentService.recalculatePastEventConditions();
+        persistenceService.refreshIndex(Profile.class, null);
+        keepTrying("Profile should not be engaged in the scoring anymore",
+                () -> profileService.load("test_profile_id"),
+                updatedProfile -> !updatedProfile.getScores().containsKey("past-event-scoring-test-max"),
+                1000, 20);
+    }
 
     @Test
     public void testScoringRecalculation() throws Exception {