-
Notifications
You must be signed in to change notification settings - Fork 505
METRON-2172 Solr Updates Not Tested in Integration Test #1454
Conversation
metron-platform/metron-elasticsearch/metron-elasticsearch-common/pom.xml
Outdated
Show resolved
Hide resolved
…d HBase. They can all share the same implementation
|
These changes look good to me. Thank you for fixing this. +1 by inspection |
|
I found a problem with this change. The Alerts UI does not properly display comments when indexing into Elasticsearch. See screenshot. The problem is that we serialize comments into Elasticsearch differently than we do Solr. For Elasticsearch we write the comments as a list of maps. For Solr, we write a list of JSON strings. I do not understand why we serialize these differently, but I definitely don't want to change that behavior in this PR. With this change, it wrote the comments as a list of JSON strings for both Solr and Elasticsearch. When running against Elasticsearch, the Alerts UI is then passed a raw JSON string that it does not know how to handle; hence the"Invalid Date" error in the Alerts UI. To really fix this, I would need to refactor deeper into the Elasticsearch side of the DAOs and have them also use the As mentioned in the PR description we (de)serialize comments in many different places and this should ultimately be cleaned up and more thoroughly tested. I am going to shelve this refactor for later. Until then, the minimal necessary fixes to test current behavior is in #1456 . Its less than ideal, but it gets the job done. |

The
SolrUpdateIntegrationTestis not testing that theSolrDaocan update and retrieve values.What?
This gap in the integration test is hiding a few existing bugs in the
SolrUpdateIntegrationTest. This fix is similar to what was done for Elasticsearch in #1451.Why?
These problems arise because of the way the test is setup. Instead of directly testing a
SolrDaothis test runs against aMultiIndexDaoinitialized with both aSolrDaoand anHBaseDao. On retrievals theMultIndexDaowill return the document from whichever index responds first.With the current test setup, the underlying
SolrDaowill never retrieve the document that the test case is expecting. In all cases where the test passes, the document is actually being returned from theHBaseDaowhich is actually just interacting with a mock backend. The test needs to actually test that we can update and retrieve documents from Elasticsearch.Bugs?
After correcting the test setup in
SolrUpdateIntegrationTestthe following bugs were found.Changes
The
SolrUpdateIntegrationTestwas changed so that it specifically tests aSolrDao.The logic to serialize and deserialize a document to/from Solr was moved into a new abstraction called a
DocumentBuilder. The Solr DAOs now all use aSolrDocumentBuilderto do this. Most of the existing logic fromSolrUtilitieswas moved toSolrDocumentBuilder, except for portions that needed corrected.This allowed me to add unit tests for this logic in
SolrDocumentBuilderTests. Specifically, I was able to add a test to ensure that the document's timestamp is being set correctly and that a missing sensor type does not cause a NullPointerException.Duplicate logic to add, remove, and (de)serialize comments existed in
UpdateIntegrationTest,SolrUpdateDao,SolrUtilities,HBaseUpdateDao, andElasticsearchUpdateDao. This logic was also not covered by unit tests.The comment logic was moved to
Documentso that it could be reused. This made it so that no additional "reformatting" logic was needed for the comments. This also made it easy to add unit tests to test this functionality inDocumentTest.After the previous change the logic for adding and removing comments is exactly the same for Solr, HBase, and Elasticsearch. So there is no need for custom
addCommentToAlertandremoveCommentFromAlertinHBaseUpdateDao,SolrUpdateDao, andElasticsearchUpdateDao. The shared implementation for these was moved up to theUpdateDaointerface as default methods.Acceptance Testing
Validate against Elasticsearch.
Validate against Solr.
Pull Request Checklist