You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metron.apache.org by merrimanr <gi...@git.apache.org> on 2016/04/19 00:12:07 UTC
[GitHub] incubator-metron pull request: METRON-103: Unit Tests for storm bo...
GitHub user merrimanr opened a pull request:
https://github.com/apache/incubator-metron/pull/81
METRON-103: Unit Tests for storm bolts
Unit tests for all bolts used in the parser and enrichment topologies. Tested with Integration tests, unit tests and single-node vagrant.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/merrimanr/incubator-metron METRON-103
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-metron/pull/81.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #81
----
commit 2713faf77ae27531f7a93c17ac4522b92f44eb02
Author: rmerriman <rm...@hortonworks.com>
Date: 2016-04-07T19:35:30Z
METRON-103: Unit Tests for storm bolts
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metron pull request: METRON-103: Unit Tests for storm bo...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/81#discussion_r60251394
--- Diff: metron-streaming/Metron-EnrichmentAdapters/src/test/java/org/apache/metron/enrichment/bolt/EnrichmentJoinBoltTest.java ---
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.metron.enrichment.bolt;
+
+import org.adrianwalker.multilinestring.Multiline;
+import org.apache.metron.bolt.BaseEnrichmentBoltTest;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+public class EnrichmentJoinBoltTest extends BaseEnrichmentBoltTest {
+
+ /**
+ * {
--- End diff --
I think those *'s are going to show up in your string, is that what you intended?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metron pull request: METRON-103: Unit Tests for storm bo...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/incubator-metron/pull/81
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metron pull request: METRON-103: Unit Tests for storm bo...
Posted by dlyle65535 <gi...@git.apache.org>.
Github user dlyle65535 commented on the pull request:
https://github.com/apache/incubator-metron/pull/81#issuecomment-211967271
+1 Great stuff, ship it! :)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metron pull request: METRON-103: Unit Tests for storm bo...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/81#discussion_r60251529
--- Diff: metron-streaming/Metron-EnrichmentAdapters/src/test/java/org/apache/metron/enrichment/bolt/EnrichmentJoinBoltTest.java ---
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.metron.enrichment.bolt;
+
+import org.adrianwalker.multilinestring.Multiline;
+import org.apache.metron.bolt.BaseEnrichmentBoltTest;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+public class EnrichmentJoinBoltTest extends BaseEnrichmentBoltTest {
+
+ /**
+ * {
--- End diff --
Nevermind, they don't. retracted
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metron pull request: METRON-103: Unit Tests for storm bo...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/81#discussion_r60249308
--- Diff: metron-streaming/Metron-Common/src/test/java/org/apache/metron/bolt/BulkMessageWriterTest.java ---
@@ -0,0 +1,147 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.metron.bolt;
+
+import backtype.storm.tuple.Tuple;
+import backtype.storm.tuple.Values;
+import org.adrianwalker.multilinestring.Multiline;
+import org.apache.metron.Constants;
+import org.apache.metron.domain.Configurations;
+import org.apache.metron.writer.interfaces.BulkMessageWriter;
+import org.hamcrest.Description;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentMatcher;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class BulkMessageWriterTest extends BaseEnrichmentBoltTest {
+
+ protected class MessageListMatcher extends ArgumentMatcher<List<JSONObject>> {
+
+ private List<JSONObject> expectedMessageList;
+
+ public MessageListMatcher(List<JSONObject> expectedMessageList) {
+ this.expectedMessageList = expectedMessageList;
+ }
+
+ @Override
+ public boolean matches(Object o) {
+ List<JSONObject> actualMessageList = (List<JSONObject>) o;
+ for(JSONObject message: actualMessageList) removeTimingFields(message);
+ return expectedMessageList.equals(actualMessageList);
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText(String.format("[%s]", expectedMessageList));
+ }
+
+ }
+
+ /**
+ * {
+ * "field": "value",
+ * "source.type": "yaf"
+ * }
+ */
+ @Multiline
+ private String sampleMessageString;
+
+ private JSONObject sampleMessage;
+ private List<JSONObject> messageList;
+ private List<Tuple> tupleList;
+
+ @Before
+ public void parseMessages() throws ParseException {
+ JSONParser parser = new JSONParser();
+ sampleMessage = (JSONObject) parser.parse(sampleMessageString);
+ sampleMessage.put("field", "value1");
+ messageList = new ArrayList<>();
+ messageList.add(((JSONObject) sampleMessage.clone()));
+ sampleMessage.put("field", "value2");
+ messageList.add(((JSONObject) sampleMessage.clone()));
+ sampleMessage.put("field", "value3");
+ messageList.add(((JSONObject) sampleMessage.clone()));
+ sampleMessage.put("field", "value4");
+ messageList.add(((JSONObject) sampleMessage.clone()));
+ sampleMessage.put("field", "value5");
+ messageList.add(((JSONObject) sampleMessage.clone()));
+ }
+
+ @Mock
+ private BulkMessageWriter<JSONObject> bulkMessageWriter;
+
+ @Test
+ public void test() throws Exception {
+ BulkMessageWriterBolt bulkMessageWriterBolt = new BulkMessageWriterBolt("zookeeperUrl").withBulkMessageWriter(bulkMessageWriter);
+ bulkMessageWriterBolt.setCuratorFramework(client);
+ bulkMessageWriterBolt.setTreeCache(cache);
+ bulkMessageWriterBolt.configurations.updateSensorEnrichmentConfig(sensorType, new FileInputStream(sampleSensorEnrichmentConfigPath));
+ bulkMessageWriterBolt.declareOutputFields(declarer);
+ verify(declarer, times(1)).declareStream(eq("error"), argThat(new FieldsMatcher("message")));
+ Map stormConf = new HashMap();
+ doThrow(new Exception()).when(bulkMessageWriter).init(eq(stormConf), any(Configurations.class));
+ try {
+ bulkMessageWriterBolt.prepare(stormConf, topologyContext, outputCollector);
+ fail("A runtime exception should be thrown when bulkMessageWriter.init throws an exception");
+ } catch(RuntimeException e) {}
+ reset(bulkMessageWriter);
+ bulkMessageWriterBolt.prepare(stormConf, topologyContext, outputCollector);
+ verify(bulkMessageWriter, times(1)).init(eq(stormConf), any(Configurations.class));
+ tupleList = new ArrayList<>();
+ for(int i = 0; i < 4; i++) {
+ when(tuple.getValueByField("message")).thenReturn(messageList.get(i));
+ tupleList.add(tuple);
+ bulkMessageWriterBolt.execute(tuple);
+ verify(bulkMessageWriter, times(0)).write(eq(sensorType), any(Configurations.class), eq(tupleList), eq(messageList));
+ }
+ when(tuple.getValueByField("message")).thenReturn(messageList.get(4));
+ tupleList.add(tuple);
+ bulkMessageWriterBolt.execute(tuple);
+ verify(bulkMessageWriter, times(1)).write(eq(sensorType), any(Configurations.class), eq(tupleList), argThat(new MessageListMatcher(messageList)));
+ verify(outputCollector, times(5)).ack(tuple);
+ reset(outputCollector);
+ doThrow(new Exception()).when(bulkMessageWriter).write(eq(sensorType), any(Configurations.class), Matchers.anyListOf(Tuple.class), Matchers.anyListOf(JSONObject.class));
+ when(tuple.getValueByField("message")).thenReturn(messageList.get(0));
+ for(int i = 0; i < 5; i++) bulkMessageWriterBolt.execute(tuple);
--- End diff --
This is a style thing, but can we please have braces? It's so easy to accidentally screw if's and for's up without explicit braces.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metron pull request: METRON-103: Unit Tests for storm bo...
Posted by dlyle65535 <gi...@git.apache.org>.
Github user dlyle65535 commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/81#discussion_r60152962
--- Diff: deployment/roles/metron_ui/tasks/main.yml ---
@@ -53,4 +53,4 @@
production: no
- name: Start Metron UI
- shell: "pm2 restart {{ metron_ui_directory }}/lib/metron-ui.js --name metron"
+ shell: "pm2 start {{ metron_ui_directory }}/lib/metron-ui.js --name metron"
--- End diff --
Oh, good call then. :)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metron pull request: METRON-103: Unit Tests for storm bo...
Posted by dlyle65535 <gi...@git.apache.org>.
Github user dlyle65535 commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/81#discussion_r60145331
--- Diff: deployment/roles/metron_ui/tasks/main.yml ---
@@ -53,4 +53,4 @@
production: no
- name: Start Metron UI
- shell: "pm2 restart {{ metron_ui_directory }}/lib/metron-ui.js --name metron"
+ shell: "pm2 start {{ metron_ui_directory }}/lib/metron-ui.js --name metron"
--- End diff --
Did you intend to revert this change?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metron pull request: METRON-103: Unit Tests for storm bo...
Posted by cestella <gi...@git.apache.org>.
Github user cestella commented on the pull request:
https://github.com/apache/incubator-metron/pull/81#issuecomment-211975900
+1, looks good
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metron pull request: METRON-103: Unit Tests for storm bo...
Posted by merrimanr <gi...@git.apache.org>.
Github user merrimanr commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/81#discussion_r60250609
--- Diff: metron-streaming/Metron-Common/src/test/java/org/apache/metron/bolt/BulkMessageWriterTest.java ---
@@ -0,0 +1,147 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.metron.bolt;
+
+import backtype.storm.tuple.Tuple;
+import backtype.storm.tuple.Values;
+import org.adrianwalker.multilinestring.Multiline;
+import org.apache.metron.Constants;
+import org.apache.metron.domain.Configurations;
+import org.apache.metron.writer.interfaces.BulkMessageWriter;
+import org.hamcrest.Description;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentMatcher;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class BulkMessageWriterTest extends BaseEnrichmentBoltTest {
+
+ protected class MessageListMatcher extends ArgumentMatcher<List<JSONObject>> {
+
+ private List<JSONObject> expectedMessageList;
+
+ public MessageListMatcher(List<JSONObject> expectedMessageList) {
+ this.expectedMessageList = expectedMessageList;
+ }
+
+ @Override
+ public boolean matches(Object o) {
+ List<JSONObject> actualMessageList = (List<JSONObject>) o;
+ for(JSONObject message: actualMessageList) removeTimingFields(message);
+ return expectedMessageList.equals(actualMessageList);
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText(String.format("[%s]", expectedMessageList));
+ }
+
+ }
+
+ /**
+ * {
+ * "field": "value",
+ * "source.type": "yaf"
+ * }
+ */
+ @Multiline
+ private String sampleMessageString;
+
+ private JSONObject sampleMessage;
+ private List<JSONObject> messageList;
+ private List<Tuple> tupleList;
+
+ @Before
+ public void parseMessages() throws ParseException {
+ JSONParser parser = new JSONParser();
+ sampleMessage = (JSONObject) parser.parse(sampleMessageString);
+ sampleMessage.put("field", "value1");
+ messageList = new ArrayList<>();
+ messageList.add(((JSONObject) sampleMessage.clone()));
+ sampleMessage.put("field", "value2");
+ messageList.add(((JSONObject) sampleMessage.clone()));
+ sampleMessage.put("field", "value3");
+ messageList.add(((JSONObject) sampleMessage.clone()));
+ sampleMessage.put("field", "value4");
+ messageList.add(((JSONObject) sampleMessage.clone()));
+ sampleMessage.put("field", "value5");
+ messageList.add(((JSONObject) sampleMessage.clone()));
+ }
+
+ @Mock
+ private BulkMessageWriter<JSONObject> bulkMessageWriter;
+
+ @Test
+ public void test() throws Exception {
+ BulkMessageWriterBolt bulkMessageWriterBolt = new BulkMessageWriterBolt("zookeeperUrl").withBulkMessageWriter(bulkMessageWriter);
+ bulkMessageWriterBolt.setCuratorFramework(client);
+ bulkMessageWriterBolt.setTreeCache(cache);
+ bulkMessageWriterBolt.configurations.updateSensorEnrichmentConfig(sensorType, new FileInputStream(sampleSensorEnrichmentConfigPath));
+ bulkMessageWriterBolt.declareOutputFields(declarer);
+ verify(declarer, times(1)).declareStream(eq("error"), argThat(new FieldsMatcher("message")));
+ Map stormConf = new HashMap();
+ doThrow(new Exception()).when(bulkMessageWriter).init(eq(stormConf), any(Configurations.class));
+ try {
+ bulkMessageWriterBolt.prepare(stormConf, topologyContext, outputCollector);
+ fail("A runtime exception should be thrown when bulkMessageWriter.init throws an exception");
+ } catch(RuntimeException e) {}
+ reset(bulkMessageWriter);
+ bulkMessageWriterBolt.prepare(stormConf, topologyContext, outputCollector);
+ verify(bulkMessageWriter, times(1)).init(eq(stormConf), any(Configurations.class));
+ tupleList = new ArrayList<>();
+ for(int i = 0; i < 4; i++) {
+ when(tuple.getValueByField("message")).thenReturn(messageList.get(i));
+ tupleList.add(tuple);
+ bulkMessageWriterBolt.execute(tuple);
+ verify(bulkMessageWriter, times(0)).write(eq(sensorType), any(Configurations.class), eq(tupleList), eq(messageList));
+ }
+ when(tuple.getValueByField("message")).thenReturn(messageList.get(4));
+ tupleList.add(tuple);
+ bulkMessageWriterBolt.execute(tuple);
+ verify(bulkMessageWriter, times(1)).write(eq(sensorType), any(Configurations.class), eq(tupleList), argThat(new MessageListMatcher(messageList)));
+ verify(outputCollector, times(5)).ack(tuple);
+ reset(outputCollector);
+ doThrow(new Exception()).when(bulkMessageWriter).write(eq(sensorType), any(Configurations.class), Matchers.anyListOf(Tuple.class), Matchers.anyListOf(JSONObject.class));
+ when(tuple.getValueByField("message")).thenReturn(messageList.get(0));
+ for(int i = 0; i < 5; i++) bulkMessageWriterBolt.execute(tuple);
--- End diff --
Fixed. Also realized I named the test wrong so I fixed that as well.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-metron pull request: METRON-103: Unit Tests for storm bo...
Posted by merrimanr <gi...@git.apache.org>.
Github user merrimanr commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/81#discussion_r60152303
--- Diff: deployment/roles/metron_ui/tasks/main.yml ---
@@ -53,4 +53,4 @@
production: no
- name: Start Metron UI
- shell: "pm2 restart {{ metron_ui_directory }}/lib/metron-ui.js --name metron"
+ shell: "pm2 start {{ metron_ui_directory }}/lib/metron-ui.js --name metron"
--- End diff --
Yes this was intentional. Turns out the previous commit only works on AWS so I reverted it to keep the single node vagrant deployment from breaking. @nickwallen reopened the pull request and will submit another fix. Sorry I should have called that out in the description.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---