mmiklavc commented on a change in pull request #1465: METRON-2172 Solr Updates 
Not Tested in Integration Test
URL: https://github.com/apache/metron/pull/1465#discussion_r305117740
 
 

 ##########
 File path: 
metron-platform/metron-indexing/metron-indexing-common/src/test/java/org/apache/metron/indexing/dao/UpdateIntegrationTest.java
 ##########
 @@ -272,29 +273,81 @@ protected Document createDocument(String guid, Long 
timestamp) {
     return new Document(message1, guid, SENSOR_NAME, timestamp);
   }
 
-  private List<AlertComment> getComments(Document withComment) {
-    List<Map<String, Object>> commentsField = 
List.class.cast(withComment.getDocument().get(COMMENTS_FIELD));
+  private static List<AlertComment> getComments(Document withComment) throws 
ParseException {
+    return getComments(withComment.getDocument());
+  }
+
+  private static List<AlertComment> getComments(Map<String, Object> fields) 
throws ParseException {
     List<AlertComment> comments = new ArrayList<>();
-    if(commentsField != null) {
-      comments = commentsField
-              .stream()
-              .map(map -> new AlertComment(map))
-              .collect(Collectors.toList());
+    boolean hasComments = fields.containsKey(COMMENTS_FIELD);
+    if(hasComments) {
+      List<Object> commentsField = List.class.cast(fields.get(COMMENTS_FIELD));
+      for (Object commentObject: commentsField) {
+        if (commentObject instanceof Map) {
+          // comments are stored as maps in Elasticsearch
+          Map<String, Object> commentAsMap = (Map<String, Object>) 
commentObject;
+          comments.add(new AlertComment(commentAsMap));
+
+        } else if (commentObject instanceof String) {
+          // comments are stored as json strings in Solr
+          String commentAsString = (String) commentObject;
+          comments.add(new AlertComment(commentAsString));
+
+        } else {
+          throw new IllegalArgumentException(String.format("Unexpected comment 
value; %s", commentObject));
+        }
+      }
     }
 
     return comments;
   }
 
-  protected Document findUpdatedDoc(Map<String, Object> message0, String guid, 
String sensorType)
+  /**
+   * Reformats the format of stored comments.
+   *
+   * <p>Comments are serialized differently when stored in Elasticsearch and 
Solr.  Comments
+   * are stored as maps in Elasticsearch and JSON strings in Solr.  This 
reformats all comments
+   * as maps, so they look the same when validation occurs in the integration 
tests.
+   * @param fields
+   */
+  protected static void reformatComments(Map<String, Object> fields) {
 
 Review comment:
   How about `normalizeCommentsAsMap` for a name?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to