Github user mmiklavc commented on a diff in the pull request:
https://github.com/apache/incubator-metron/pull/286#discussion_r81365456
--- Diff:
metron-platform/metron-elasticsearch/src/test/java/org/apache/metron/elasticsearch/writer/ElasticsearchWriterTest.java
---
@@ -0,0 +1,190 @@
+/*
+ * 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.elasticsearch.writer;
+
+import backtype.storm.tuple.Tuple;
+import com.google.common.collect.ImmutableList;
+import org.apache.metron.writer.BulkWriterResponse;
+import org.elasticsearch.action.bulk.BulkItemResponse;
+import org.elasticsearch.action.bulk.BulkResponse;
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ElasticsearchWriterTest {
+ @Test
+ public void testSingleSuccesses() throws Exception {
+ Tuple tuple1 = mock(Tuple.class);
+
+ BulkResponse response = mock(BulkResponse.class);
+ when(response.hasFailures()).thenReturn(false);
+
+ BulkWriterResponse expected = new BulkWriterResponse();
+ expected.addSuccess(tuple1);
+
+ ElasticsearchWriter esWriter = new ElasticsearchWriter();
+ BulkWriterResponse actual =
esWriter.buildWriteReponse(ImmutableList.of(tuple1), response);
+
+ assertEquals("Response should have no errors and single success",
expected, actual);
+ }
+
+ @Test
+ public void testMultipleSuccesses() throws Exception {
+ Tuple tuple1 = mock(Tuple.class);
+ Tuple tuple2 = mock(Tuple.class);
+
+ BulkResponse response = mock(BulkResponse.class);
+ when(response.hasFailures()).thenReturn(false);
+
+ BulkWriterResponse expected = new BulkWriterResponse();
+ expected.addSuccess(tuple1);
+ expected.addSuccess(tuple2);
+
+ ElasticsearchWriter esWriter = new ElasticsearchWriter();
+ BulkWriterResponse actual =
esWriter.buildWriteReponse(ImmutableList.of(tuple1, tuple2), response);
+
+ assertEquals("Response should have no errors and two successes",
expected, actual);
+ }
+
+ @Test
+ public void testSingleFailure() throws Exception {
+ Tuple tuple1 = mock(Tuple.class);
+
+ BulkResponse response = mock(BulkResponse.class);
+ when(response.hasFailures()).thenReturn(true);
+
+ Exception e = new IllegalStateException();
+ BulkItemResponse itemResponse = buildBulkItemFailure(e);
+
when(response.iterator()).thenReturn(ImmutableList.of(itemResponse).iterator());
+
+ BulkWriterResponse expected = new BulkWriterResponse();
+ expected.addError(e, tuple1);
+
+ ElasticsearchWriter esWriter = new ElasticsearchWriter();
+ BulkWriterResponse actual =
esWriter.buildWriteReponse(ImmutableList.of(tuple1), response);
+
+ assertEquals("Response should have no errors and two successes",
expected, actual);
--- End diff --
I believe this assert message should read "Response should have one error
and zero successes"
---
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 [email protected] or file a JIRA ticket
with INFRA.
---