metron-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject [24/51] [abbrv] metron git commit: METRON-1771 Update REST endpoints to support eventually consistent UI updates (merrimanr) closes apache/metron#1190
Date Wed, 24 Oct 2018 15:04:13 GMT
http://git-wip-us.apache.org/repos/asf/metron/blob/de533063/metron-platform/metron-solr/src/main/java/org/apache/metron/solr/dao/SolrUpdateDao.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-solr/src/main/java/org/apache/metron/solr/dao/SolrUpdateDao.java
b/metron-platform/metron-solr/src/main/java/org/apache/metron/solr/dao/SolrUpdateDao.java
index 2f83921..54b5b64 100644
--- a/metron-platform/metron-solr/src/main/java/org/apache/metron/solr/dao/SolrUpdateDao.java
+++ b/metron-platform/metron-solr/src/main/java/org/apache/metron/solr/dao/SolrUpdateDao.java
@@ -56,7 +56,7 @@ public class SolrUpdateDao implements UpdateDao {
   }
 
   @Override
-  public void update(Document update, Optional<String> rawIndex) throws IOException
{
+  public Document update(Document update, Optional<String> rawIndex) throws IOException
{
     Document newVersion = update;
     // Handle any case where we're given comments in Map form, instead of raw String
     Object commentsObj = update.getDocument().get(COMMENTS_FIELD);
@@ -79,10 +79,11 @@ public class SolrUpdateDao implements UpdateDao {
     } catch (SolrServerException e) {
       throw new IOException(e);
     }
+    return newVersion;
   }
 
   @Override
-  public void batchUpdate(Map<Document, Optional<String>> updates) throws IOException
{
+  public Map<Document, Optional<String>> batchUpdate(Map<Document, Optional<String>>
updates) throws IOException {
     // updates with a collection specified
     Map<String, Collection<SolrInputDocument>> solrCollectionUpdates = new HashMap<>();
     Set<String> collectionsUpdated = new HashSet<>();
@@ -117,18 +118,20 @@ public class SolrUpdateDao implements UpdateDao {
     } catch (SolrServerException e) {
       throw new IOException(e);
     }
+    return updates;
   }
 
   @Override
-  public void addCommentToAlert(CommentAddRemoveRequest request) throws IOException {
+  public Document addCommentToAlert(CommentAddRemoveRequest request) throws IOException {
     Document latest = retrieveLatestDao.getLatest(request.getGuid(), request.getSensorType());
-    addCommentToAlert(request, latest);
+    return addCommentToAlert(request, latest);
   }
 
   @Override
-  public void addCommentToAlert(CommentAddRemoveRequest request, Document latest) throws
IOException {
-    if (latest == null) {
-      return;
+  public Document addCommentToAlert(CommentAddRemoveRequest request, Document latest) throws
IOException {
+    if (latest == null || latest.getDocument() == null) {
+      throw new IOException(String.format("Unable to add comment. Document with guid %s cannot
be found.",
+              request.getGuid()));
     }
 
     @SuppressWarnings("unchecked")
@@ -149,21 +152,22 @@ public class SolrUpdateDao implements UpdateDao {
 
     Document newVersion = new Document(latest);
     newVersion.getDocument().put(COMMENTS_FIELD, commentStrs);
-    update(newVersion, Optional.empty());
+    return update(newVersion, Optional.empty());
   }
 
   @Override
-  public void removeCommentFromAlert(CommentAddRemoveRequest request)
+  public Document removeCommentFromAlert(CommentAddRemoveRequest request)
       throws IOException {
     Document latest = retrieveLatestDao.getLatest(request.getGuid(), request.getSensorType());
-    removeCommentFromAlert(request, latest);
+    return removeCommentFromAlert(request, latest);
   }
 
   @Override
-  public void removeCommentFromAlert(CommentAddRemoveRequest request, Document latest)
+  public Document removeCommentFromAlert(CommentAddRemoveRequest request, Document latest)
       throws IOException {
-    if (latest == null) {
-      return;
+    if (latest == null || latest.getDocument() == null) {
+      throw new IOException(String.format("Unable to remove comment. Document with guid %s
cannot be found.",
+              request.getGuid()));
     }
 
     @SuppressWarnings("unchecked")
@@ -171,8 +175,8 @@ public class SolrUpdateDao implements UpdateDao {
         .get(COMMENTS_FIELD);
     // Can't remove anything if there's nothing there
     if (commentMap == null) {
-      LOG.debug("Provided alert had no comments to be able to remove from");
-      return;
+      throw new IOException(String.format("Unable to remove comment. Document with guid %s
has no comments.",
+              request.getGuid()));
     }
     List<Map<String, Object>> originalComments = new ArrayList<>(commentMap);
     List<AlertComment> comments = new ArrayList<>();
@@ -186,7 +190,7 @@ public class SolrUpdateDao implements UpdateDao {
         .collect(Collectors.toList());
     Document newVersion = new Document(latest);
     newVersion.getDocument().put(COMMENTS_FIELD, commentsAsJson);
-    update(newVersion, Optional.empty());
+    return update(newVersion, Optional.empty());
   }
 
   public void convertCommentsToRaw(Map<String,Object> source) {

http://git-wip-us.apache.org/repos/asf/metron/blob/de533063/metron-platform/metron-solr/src/test/java/org/apache/metron/solr/dao/SolrMetaAlertDaoTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-solr/src/test/java/org/apache/metron/solr/dao/SolrMetaAlertDaoTest.java
b/metron-platform/metron-solr/src/test/java/org/apache/metron/solr/dao/SolrMetaAlertDaoTest.java
index 43bf1b1..8920d5a 100644
--- a/metron-platform/metron-solr/src/test/java/org/apache/metron/solr/dao/SolrMetaAlertDaoTest.java
+++ b/metron-platform/metron-solr/src/test/java/org/apache/metron/solr/dao/SolrMetaAlertDaoTest.java
@@ -86,31 +86,38 @@ public class SolrMetaAlertDaoTest {
       }
 
       @Override
-      public void update(Document update, Optional<String> index) {
+      public Document update(Document update, Optional<String> index) {
+        return null;
       }
 
       @Override
-      public void batchUpdate(Map<Document, Optional<String>> updates) {
+      public Map<Document, Optional<String>> batchUpdate(Map<Document, Optional<String>>
updates) {
+        return null;
       }
 
       @Override
-      public void addCommentToAlert(CommentAddRemoveRequest request) {
+      public Document addCommentToAlert(CommentAddRemoveRequest request) {
+        return null;
       }
 
       @Override
-      public void removeCommentFromAlert(CommentAddRemoveRequest request) {
+      public Document removeCommentFromAlert(CommentAddRemoveRequest request) {
+        return null;
       }
 
       @Override
-      public void addCommentToAlert(CommentAddRemoveRequest request, Document latest) {
+      public Document addCommentToAlert(CommentAddRemoveRequest request, Document latest)
{
+        return null;
       }
 
       @Override
-      public void removeCommentFromAlert(CommentAddRemoveRequest request, Document latest)
{
+      public Document removeCommentFromAlert(CommentAddRemoveRequest request, Document latest)
{
+        return null;
       }
 
       @Override
-      public void patch(RetrieveLatestDao dao, PatchRequest request, Optional<Long>
timestamp) {
+      public Document patch(RetrieveLatestDao dao, PatchRequest request, Optional<Long>
timestamp) {
+        return null;
       }
 
       @Override

http://git-wip-us.apache.org/repos/asf/metron/blob/de533063/metron-platform/metron-solr/src/test/java/org/apache/metron/solr/dao/SolrUpdateDaoTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-solr/src/test/java/org/apache/metron/solr/dao/SolrUpdateDaoTest.java
b/metron-platform/metron-solr/src/test/java/org/apache/metron/solr/dao/SolrUpdateDaoTest.java
index bed43ae..21fc79b 100644
--- a/metron-platform/metron-solr/src/test/java/org/apache/metron/solr/dao/SolrUpdateDaoTest.java
+++ b/metron-platform/metron-solr/src/test/java/org/apache/metron/solr/dao/SolrUpdateDaoTest.java
@@ -39,10 +39,12 @@ import org.apache.metron.common.Constants;
 import org.apache.metron.common.configuration.IndexingConfigurations;
 import org.apache.metron.common.zookeeper.ConfigurationsCache;
 import org.apache.metron.indexing.dao.AccessConfig;
+import org.apache.metron.indexing.dao.UpdateDaoTest;
 import org.apache.metron.indexing.dao.search.AlertComment;
 import org.apache.metron.indexing.dao.update.Document;
 import org.apache.metron.indexing.dao.update.OriginalNotFoundException;
 import org.apache.metron.indexing.dao.update.PatchRequest;
+import org.apache.metron.indexing.dao.update.UpdateDao;
 import org.apache.metron.indexing.util.IndexingCacheUtil;
 import org.apache.metron.solr.matcher.SolrInputDocumentListMatcher;
 import org.apache.metron.solr.matcher.SolrInputDocumentMatcher;
@@ -51,19 +53,19 @@ import org.apache.solr.client.solrj.request.CollectionAdminRequest;
 import org.apache.solr.common.SolrInputDocument;
 import org.junit.Before;
 import org.junit.BeforeClass;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.junit.runner.RunWith;
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
 
+/**
+ * This class contains tests specific to the SolrUpdateDao implementation.  It also returns
the SolrUpdateDao
+ * implementation to be used in UpdateDaoTest.  UpdateDaoTest contains a common set of tests
that all Dao
+ * implementations must pass.
+ */
 @RunWith(PowerMockRunner.class)
 @PrepareForTest({CollectionAdminRequest.class})
-public class SolrUpdateDaoTest {
-
-  @Rule
-  public final ExpectedException exception = ExpectedException.none();
+public class SolrUpdateDaoTest extends UpdateDaoTest {
 
   private SolrClient client;
   private SolrRetrieveLatestDao solrRetrieveLatestDao;
@@ -238,4 +240,9 @@ public class SolrUpdateDaoTest {
     latest.getDocument().put("project", "metron");
     assertEquals(actual, latest);
   }
+
+  @Override
+  public UpdateDao getUpdateDao() {
+    return solrUpdateDao;
+  }
 }


Mime
View raw message