This is an automated email from the ASF dual-hosted git repository.
shuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to refs/heads/master by this push:
new acfe957 Attempting to fix issues in integration tests.
acfe957 is described below
commit acfe957e872b289edb0efc16a317dbd8ed5aeed0
Author: Serge Huber <[email protected]>
AuthorDate: Wed Nov 27 11:44:43 2019 +0100
Attempting to fix issues in integration tests.
Signed-off-by: Serge Huber <[email protected]>
---
.../unomi/api/services/DefinitionsService.java | 6 +++++
.../apache/unomi/api/services/ProfileService.java | 7 +++++-
.../test/java/org/apache/unomi/itests/BasicIT.java | 1 +
.../test/java/org/apache/unomi/itests/PatchIT.java | 15 ++++++++----
.../org/apache/unomi/itests/ProfileExportIT.java | 4 ++--
.../apache/unomi/itests/ProfileImportActorsIT.java | 2 +-
.../apache/unomi/itests/ProfileImportBasicIT.java | 2 +-
.../unomi/itests/ProfileImportRankingIT.java | 2 +-
.../unomi/itests/ProfileImportSurfersIT.java | 6 ++---
.../impl/definitions/DefinitionsServiceImpl.java | 28 +++++++++++++++-------
.../services/impl/profiles/ProfileServiceImpl.java | 21 ++++++++++++----
11 files changed, 67 insertions(+), 27 deletions(-)
diff --git
a/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java
b/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java
index 25ec40b..816f883 100644
--- a/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java
+++ b/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java
@@ -204,4 +204,10 @@ public interface DefinitionsService {
* @return {@code true}
*/
boolean resolveConditionType(Condition rootCondition);
+
+ /**
+ * Forces a refresh of the definitions from the persistence service.
Warning: this may seriously impact performance
+ * so it is recommended to use this in specific cases such as for example
in integration tests.
+ */
+ void refresh();
}
\ No newline at end of file
diff --git
a/api/src/main/java/org/apache/unomi/api/services/ProfileService.java
b/api/src/main/java/org/apache/unomi/api/services/ProfileService.java
index bc86c70..35ebfd1 100644
--- a/api/src/main/java/org/apache/unomi/api/services/ProfileService.java
+++ b/api/src/main/java/org/apache/unomi/api/services/ProfileService.java
@@ -354,5 +354,10 @@ public interface ProfileService {
*/
Set<PropertyType> getExistingProperties(String tag, String itemType,
boolean systemTag);
-
+ /**
+ * Forces a refresh of the profile service, to load data from persistence
immediately instead of waiting for
+ * scheduled tasks to execute. Warning : this may have serious impacts on
performance so it should only be used
+ * in specific scenarios such as integration tests.
+ */
+ void refresh();
}
diff --git a/itests/src/test/java/org/apache/unomi/itests/BasicIT.java
b/itests/src/test/java/org/apache/unomi/itests/BasicIT.java
index ab6a914..fa46b75 100644
--- a/itests/src/test/java/org/apache/unomi/itests/BasicIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/BasicIT.java
@@ -99,6 +99,7 @@ public class BasicIT extends BaseIT {
@Before
public void setUp() throws InterruptedException {
while (!bundleWatcher.isStartupComplete()) {
+ LOGGER.info("Waiting for startup to complete...");
Thread.sleep(1000);
}
}
diff --git a/itests/src/test/java/org/apache/unomi/itests/PatchIT.java
b/itests/src/test/java/org/apache/unomi/itests/PatchIT.java
index 0ba26c5..679e87b 100644
--- a/itests/src/test/java/org/apache/unomi/itests/PatchIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/PatchIT.java
@@ -24,6 +24,7 @@ import org.apache.unomi.api.services.DefinitionsService;
import org.apache.unomi.api.services.PatchService;
import org.apache.unomi.api.services.ProfileService;
import org.apache.unomi.persistence.spi.CustomObjectMapper;
+import org.apache.unomi.persistence.spi.PersistenceService;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -56,6 +57,10 @@ public class PatchIT extends BaseIT {
protected DefinitionsService definitionsService;
@Inject
+ @Filter(timeout = 600000)
+ protected PersistenceService persistenceService;
+
+ @Inject
protected BundleContext bundleContext;
@Test
@@ -68,7 +73,7 @@ public class PatchIT extends BaseIT {
Assert.assertEquals("foo", newCompany.getDefaultValue());
- Thread.sleep(10000);
+ profileService.refresh();
newCompany = profileService.getPropertyType("company");
Assert.assertEquals("foo", newCompany.getDefaultValue());
@@ -87,7 +92,7 @@ public class PatchIT extends BaseIT {
Assert.assertEquals("foo", newGender.getDefaultValue());
- Thread.sleep(10000);
+ profileService.refresh();
newGender = profileService.getPropertyType("gender");
Assert.assertEquals("foo", newGender.getDefaultValue());
@@ -105,7 +110,7 @@ public class PatchIT extends BaseIT {
patchService.patch(patch);
- Thread.sleep(10000);
+ profileService.refresh();
PropertyType newIncome = profileService.getPropertyType("income");
Assert.assertNull(newIncome);
@@ -124,7 +129,7 @@ public class PatchIT extends BaseIT {
patchService.patch(patch);
- Thread.sleep(10000);
+ definitionsService.refresh();
ConditionType newFormCondition =
definitionsService.getConditionType("formEventCondition");
Assert.assertFalse(newFormCondition.getMetadata().getSystemTags().contains("usableInPastEventCondition"));
@@ -143,7 +148,7 @@ public class PatchIT extends BaseIT {
patchService.patch(patch);
- Thread.sleep(10000);
+ definitionsService.refresh();
ActionType newMailAction =
definitionsService.getActionType("sendMailAction");
Assert.assertFalse(newMailAction.getMetadata().getSystemTags().contains("availableToEndUser"));
diff --git a/itests/src/test/java/org/apache/unomi/itests/ProfileExportIT.java
b/itests/src/test/java/org/apache/unomi/itests/ProfileExportIT.java
index df15438..ef2ad7e 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileExportIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileExportIT.java
@@ -79,7 +79,7 @@ public class ProfileExportIT extends BaseIT {
profile3.setSegments(segments);
profileService.save(profile3);
- keepTrying(()->
profileService.findProfilesByPropertyValue("segments", "exportItSeg", 0, 10,
null), (p)->p.getTotalSize() == 3, 1000, 20);
+ keepTrying(()->
profileService.findProfilesByPropertyValue("segments", "exportItSeg", 0, 10,
null), (p)->p.getTotalSize() == 3, 1000, 40);
/*** Export Test ***/
String itemId = "export-test";
@@ -105,7 +105,7 @@ public class ProfileExportIT extends BaseIT {
exportConfigurationService.save(exportConfiguration, true);
final File exportResult = new File("data/tmp/profiles-export.csv");
- keepTrying(()-> exportResult, File::exists, 1000, 20);
+ keepTrying(()-> exportResult, File::exists, 1000, 40);
logger.info("PATH : {}", exportResult.getAbsolutePath());
Assert.assertTrue(exportResult.exists());
diff --git
a/itests/src/test/java/org/apache/unomi/itests/ProfileImportActorsIT.java
b/itests/src/test/java/org/apache/unomi/itests/ProfileImportActorsIT.java
index f95cca5..9960b68 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileImportActorsIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileImportActorsIT.java
@@ -101,7 +101,7 @@ public class ProfileImportActorsIT extends BaseIT {
importConfigurationService.save(importConfigActors, true);
//Wait for data to be processed
- keepTrying(()->
profileService.findProfilesByPropertyValue("properties.city", "hollywood", 0,
10, null), (p)->p.getTotalSize() == 6, 1000, 100);
+ keepTrying(()->
profileService.findProfilesByPropertyValue("properties.city", "hollywood", 0,
10, null), (p)->p.getTotalSize() == 6, 1000, 200);
List<ImportConfiguration> importConfigurations =
importConfigurationService.getAll();
Assert.assertEquals(1, importConfigurations.size());
diff --git
a/itests/src/test/java/org/apache/unomi/itests/ProfileImportBasicIT.java
b/itests/src/test/java/org/apache/unomi/itests/ProfileImportBasicIT.java
index e1b273d..0fe8287 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileImportBasicIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileImportBasicIT.java
@@ -88,7 +88,7 @@ public class ProfileImportBasicIT extends BaseIT {
Files.copy(basicFile.toPath(), new
File("data/tmp/unomi_oneshot_import_configs/1-basic-test.csv").toPath(),
StandardCopyOption.REPLACE_EXISTING);
//Wait for the csv to be processed
- PartialList<Profile> profiles =
keepTrying(()->profileService.findProfilesByPropertyValue("properties.city",
"oneShotImportCity", 0, 10, null), (p)->p.getTotalSize() == 3, 1000, 100);
+ PartialList<Profile> profiles =
keepTrying(()->profileService.findProfilesByPropertyValue("properties.city",
"oneShotImportCity", 0, 10, null), (p)->p.getTotalSize() == 3, 1000, 200);
Assert.assertEquals(3, profiles.getList().size());
checkProfiles(1);
diff --git
a/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java
b/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java
index 23c2e72..acae796 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileImportRankingIT.java
@@ -106,7 +106,7 @@ public class ProfileImportRankingIT extends BaseIT {
//Wait for data to be processed
-
keepTrying(()->profileService.findProfilesByPropertyValue("properties.city",
"rankingCity", 0, 50, null), (p)->p.getTotalSize() == 25, 1000, 100);
+
keepTrying(()->profileService.findProfilesByPropertyValue("properties.city",
"rankingCity", 0, 50, null), (p)->p.getTotalSize() == 25, 1000, 200);
List<ImportConfiguration> importConfigurations =
importConfigurationService.getAll();
Assert.assertEquals(1, importConfigurations.size());
diff --git
a/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersIT.java
b/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersIT.java
index a7de91e..91f58c9 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileImportSurfersIT.java
@@ -105,7 +105,7 @@ public class ProfileImportSurfersIT extends BaseIT {
logger.info("ProfileImportSurfersIT setup successfully.");
//Wait for data to be processed
-
keepTrying(()->profileService.findProfilesByPropertyValue("properties.city",
"surfersCity", 0, 50, null), (p)->p.getTotalSize() == 34, 1000, 20);
+
keepTrying(()->profileService.findProfilesByPropertyValue("properties.city",
"surfersCity", 0, 50, null), (p)->p.getTotalSize() == 34, 1000, 40);
List<ImportConfiguration> importConfigurations =
importConfigurationService.getAll();
Assert.assertEquals(1, importConfigurations.size());
@@ -150,7 +150,7 @@ public class ProfileImportSurfersIT extends BaseIT {
logger.info("ProfileImportSurfersOverwriteIT setup successfully.");
//Wait for data to be processed
-
keepTrying(()->profileService.findProfilesByPropertyValue("properties.city",
"surfersCity", 0, 50, null), (p)->p.getTotalSize() == 36, 1000, 20);
+
keepTrying(()->profileService.findProfilesByPropertyValue("properties.city",
"surfersCity", 0, 50, null), (p)->p.getTotalSize() == 36, 1000, 40);
importConfigurations = importConfigurationService.getAll();
Assert.assertEquals(1, importConfigurations.size());
@@ -189,7 +189,7 @@ public class ProfileImportSurfersIT extends BaseIT {
logger.info("ProfileImportSurfersDeleteIT setup successfully.");
//Wait for data to be processed
-
keepTrying(()->profileService.findProfilesByPropertyValue("properties.city",
"surfersCity", 0, 50, null), (p)->p.getTotalSize() == 0, 1000, 20);
+
keepTrying(()->profileService.findProfilesByPropertyValue("properties.city",
"surfersCity", 0, 50, null), (p)->p.getTotalSize() == 0, 1000, 40);
importConfigurations = importConfigurationService.getAll();
Assert.assertEquals(1, importConfigurations.size());
diff --git
a/services/src/main/java/org/apache/unomi/services/impl/definitions/DefinitionsServiceImpl.java
b/services/src/main/java/org/apache/unomi/services/impl/definitions/DefinitionsServiceImpl.java
index 0b42cd5..ff42612 100644
---
a/services/src/main/java/org/apache/unomi/services/impl/definitions/DefinitionsServiceImpl.java
+++
b/services/src/main/java/org/apache/unomi/services/impl/definitions/DefinitionsServiceImpl.java
@@ -91,26 +91,33 @@ public class DefinitionsServiceImpl implements
DefinitionsService, SynchronousBu
}
bundleContext.addBundleListener(this);
- scheduleConditionTypeLoad();
+ scheduleTypeReloads();
logger.info("Definitions service initialized.");
}
- private void scheduleConditionTypeLoad() {
+ private void scheduleTypeReloads() {
TimerTask task = new TimerTask() {
@Override
public void run() {
- try {
- loadConditionTypesFromPersistence();
- loadActionTypesFromPersistence();
- } catch (Throwable t) {
- logger.error("Error loading definitions from persistence
back-end", t);
- }
+ reloadTypes(false);
}
};
schedulerService.getScheduleExecutorService().scheduleAtFixedRate(task, 10000,
definitionsRefreshInterval, TimeUnit.MILLISECONDS);
logger.info("Scheduled task for condition type loading each 10s");
}
+ public void reloadTypes(boolean refresh) {
+ try {
+ if (refresh) {
+ persistenceService.refresh();
+ }
+ loadConditionTypesFromPersistence();
+ loadActionTypesFromPersistence();
+ } catch (Throwable t) {
+ logger.error("Error loading definitions from persistence
back-end", t);
+ }
+ }
+
private void loadConditionTypesFromPersistence() {
try {
Map<String, ConditionType> newConditionTypesById = new
ConcurrentHashMap<>();
@@ -511,4 +518,9 @@ public class DefinitionsServiceImpl implements
DefinitionsService, SynchronousBu
public boolean resolveConditionType(Condition rootCondition) {
return ParserHelper.resolveConditionType(this, rootCondition);
}
+
+ @Override
+ public void refresh() {
+ reloadTypes(true);
+ }
}
diff --git
a/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java
b/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java
index a27d23e..02f2526 100644
---
a/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java
+++
b/services/src/main/java/org/apache/unomi/services/impl/profiles/ProfileServiceImpl.java
@@ -259,17 +259,24 @@ public class ProfileServiceImpl implements
ProfileService, SynchronousBundleList
TimerTask task = new TimerTask() {
@Override
public void run() {
- try {
- loadPropertyTypesFromPersistence();
- } catch (Throwable t) {
- logger.error("Error loading property types from
persistence back-end", t);
- }
+ reloadPropertyTypes(false);
}
};
schedulerService.getScheduleExecutorService().scheduleAtFixedRate(task, 10000,
propertiesRefreshInterval, TimeUnit.MILLISECONDS);
logger.info("Scheduled task for property type loading each 10s");
}
+ public void reloadPropertyTypes(boolean refresh) {
+ try {
+ if (refresh) {
+ persistenceService.refresh();
+ }
+ loadPropertyTypesFromPersistence();
+ } catch (Throwable t) {
+ logger.error("Error loading property types from persistence
back-end", t);
+ }
+ }
+
private void loadPropertyTypesFromPersistence() {
try {
this.propertyTypes = new
PropertyTypes(persistenceService.getAllItems(PropertyType.class, 0, -1,
"rank").getList());
@@ -1079,4 +1086,8 @@ public class ProfileServiceImpl implements
ProfileService, SynchronousBundleList
return changed;
}
+
+ public void refresh() {
+ reloadPropertyTypes(true);
+ }
}