You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by sh...@apache.org on 2021/02/08 17:17:07 UTC
[unomi] 01/15: Fix bug in profile service it (#222)
This is an automated email from the ASF dual-hosted git repository.
shuber pushed a commit to branch unomi-1.5.x
in repository https://gitbox.apache.org/repos/asf/unomi.git
commit d4d6562b11630aa1f527f4d39bfd5c613f8a74ec
Author: liatiusim <62...@users.noreply.github.com>
AuthorDate: Fri Dec 4 11:18:49 2020 +0100
Fix bug in profile service it (#222)
(cherry picked from commit cc1306f6b6475ce557bea40ac17f602c8b15587e)
---
.../org/apache/unomi/itests/ProfileServiceIT.java | 25 +++++++++++++++++++
.../ElasticSearchPersistenceServiceImpl.java | 21 ++++++++++++++++
.../unomi/persistence/spi/PersistenceService.java | 28 ++++++++++++++++++++++
3 files changed, 74 insertions(+)
diff --git a/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java b/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
index db4e735..d75f608 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
@@ -24,6 +24,8 @@ import org.apache.unomi.api.services.DefinitionsService;
import org.apache.unomi.api.PartialList;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.Before;
@@ -112,4 +114,27 @@ public class ProfileServiceIT extends BaseIT {
assertEquals(0, profiles.getList().size());
}
+ // Relevant only when throwExceptions system property is true
+ @Test
+ public void testGetProfileWithWrongScrollerIdThrowException() throws InterruptedException, NoSuchFieldException, IllegalAccessException {
+ boolean throwExceptionCurrent = (boolean) persistenceService.getSetting("throwExceptions");
+ persistenceService.setSetting("throwExceptions", true);
+
+ Query query = new Query();
+ query.setLimit(2);
+ query.setScrollTimeValidity("10m");
+ query.setScrollIdentifier("dummyScrollId");
+
+ try {
+ profileService.search(query, Profile.class);
+ fail("search method didn't throw when expected");
+ } catch (RuntimeException ex) {
+ // Should get here since this scenario should throw exception
+ }
+ finally {
+ persistenceService.setSetting("throwExceptions", throwExceptionCurrent);
+ }
+ }
+
+
}
diff --git a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
index f51a5c0..62aaa81 100644
--- a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
+++ b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
@@ -112,6 +112,7 @@ import javax.net.ssl.X509TrustManager;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.lang.reflect.Field;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
@@ -694,6 +695,26 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService,
}
@Override
+ public void setSettings(Map<String, Object> settings) throws NoSuchFieldException, IllegalAccessException {
+ for (Map.Entry<String, Object> setting : settings.entrySet())
+ setSetting(setting.getKey(), setting.getValue());
+ }
+
+ @Override
+ public void setSetting(String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException {
+ Field field = this.getClass().getDeclaredField(fieldName);
+ field.set(getClass(), value);
+ }
+
+ @Override
+ public Object getSetting(String fieldName) throws NoSuchFieldException, IllegalAccessException {
+ Field field = this.getClass().getDeclaredField(fieldName);
+ return field.get(getClass());
+ }
+
+
+
+ @Override
public <T extends Item> T load(final String itemId, final Class<T> clazz) {
return load(itemId, null, clazz);
}
diff --git a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
index ce7d28e..d85059e 100644
--- a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
+++ b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
@@ -80,6 +80,34 @@ public interface PersistenceService {
<T extends Item> PartialList<T> getAllItems(final Class<T> clazz, int offset, int size, String sortBy, String scrollTimeValidity);
/**
+ * Set settings of the persistence service
+ *
+ * @param settings map of setting name and it's value
+ * @throws NoSuchFieldException if the field does not exist
+ * @throws IllegalAccessException field is not accessible to be changed
+ */
+ void setSettings(Map<String, Object> settings) throws NoSuchFieldException, IllegalAccessException;
+
+ /**
+ * Set settings of the persistence service
+ *
+ * @param fieldName name of the field to set
+ * @param value value of the field to set
+ * @throws NoSuchFieldException if the field does not exist
+ * @throws IllegalAccessException field is not accessible to be changed
+ */
+ void setSetting(String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException;
+
+ /**
+ * Set settings of the persistence service
+ *
+ * @param fieldName name of the field to get
+ * @throws NoSuchFieldException if the field does not exist
+ * @throws IllegalAccessException field is not accessible to be changed
+ */
+ Object getSetting(String fieldName) throws NoSuchFieldException, IllegalAccessException;
+
+ /**
* Persists the specified Item in the context server.
*
* @param item the item to persist