[ 
https://issues.apache.org/jira/browse/METRON-1849?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16710034#comment-16710034
 ] 

ASF GitHub Bot commented on METRON-1849:
----------------------------------------

Github user nickwallen commented on a diff in the pull request:

    https://github.com/apache/metron/pull/1254#discussion_r239054925
  
    --- Diff: 
metron-platform/metron-elasticsearch/src/test/java/org/apache/metron/elasticsearch/writer/ElasticsearchWriterTest.java
 ---
    @@ -18,170 +18,241 @@
     
     package org.apache.metron.elasticsearch.writer;
     
    -import static org.junit.Assert.assertEquals;
    -import static org.mockito.Mockito.mock;
    -import static org.mockito.Mockito.when;
    +import org.apache.metron.common.Constants;
    +import org.apache.metron.common.configuration.writer.WriterConfiguration;
    +import org.apache.metron.common.writer.BulkWriterResponse;
    +import org.apache.storm.task.TopologyContext;
    +import org.apache.storm.tuple.Tuple;
    +import org.json.simple.JSONObject;
    +import org.junit.Before;
    +import org.junit.Test;
     
    -import com.google.common.collect.ImmutableList;
    +import java.util.ArrayList;
     import java.util.Collection;
     import java.util.HashMap;
    +import java.util.List;
     import java.util.Map;
    -import org.apache.metron.common.writer.BulkWriterResponse;
    -import org.apache.storm.tuple.Tuple;
    -import org.elasticsearch.action.bulk.BulkItemResponse;
    -import org.elasticsearch.action.bulk.BulkResponse;
    -import org.junit.Test;
    +import java.util.UUID;
    +
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertFalse;
    +import static org.junit.Assert.assertNotNull;
    +import static org.junit.Assert.assertTrue;
    +import static org.junit.Assert.fail;
    +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);
    +    Map stormConf;
    +    TopologyContext topologyContext;
    +    WriterConfiguration writerConfiguration;
     
    -        BulkWriterResponse expected = new BulkWriterResponse();
    -        expected.addSuccess(tuple1);
    +    @Before
    +    public void setup() {
    +        topologyContext = mock(TopologyContext.class);
     
    -        ElasticsearchWriter esWriter = new ElasticsearchWriter();
    -        BulkWriterResponse actual = 
esWriter.buildWriteReponse(ImmutableList.of(tuple1), response);
    +        writerConfiguration = mock(WriterConfiguration.class);
    +        when(writerConfiguration.getGlobalConfig()).thenReturn(globals());
     
    -        assertEquals("Response should have no errors and single success", 
expected, actual);
    +        stormConf = new HashMap();
         }
     
         @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);
    +    public void shouldWriteSuccessfully() {
    +        // create a writer where all writes will be successful
    +        float probabilityOfSuccess = 1.0F;
    +        ElasticsearchWriter esWriter = new ElasticsearchWriter();
    +        esWriter.setDocumentWriter( new 
BulkDocumentWriterStub<>(probabilityOfSuccess));
    +        esWriter.init(stormConf, topologyContext, writerConfiguration);
     
    -        BulkWriterResponse expected = new BulkWriterResponse();
    -        expected.addSuccess(tuple1);
    -        expected.addSuccess(tuple2);
    +        // create a tuple and a message associated with that tuple
    +        List<Tuple> tuples = createTuples(1);
    +        List<JSONObject> messages = createMessages(1);
     
    -        ElasticsearchWriter esWriter = new ElasticsearchWriter();
    -        BulkWriterResponse actual = 
esWriter.buildWriteReponse(ImmutableList.of(tuple1, tuple2), response);
    +        BulkWriterResponse response = esWriter.write("bro", 
writerConfiguration, tuples, messages);
     
    -        assertEquals("Response should have no errors and two successes", 
expected, actual);
    +        // response should only contain successes
    +        assertFalse(response.hasErrors());
    +        assertTrue(response.getSuccesses().contains(tuples.get(0)));
         }
     
         @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());
    +    public void shouldWriteManySuccessfully() {
    +        // create a writer where all writes will be successful
    +        float probabilityOfSuccess = 1.0F;
    --- End diff --
    
    Right.  Just needed a way to test successes, failures, and partial 
successes.


> Elasticsearch Index Write Functionality Should be Shared
> --------------------------------------------------------
>
>                 Key: METRON-1849
>                 URL: https://issues.apache.org/jira/browse/METRON-1849
>             Project: Metron
>          Issue Type: Bug
>            Reporter: Nick Allen
>            Assignee: Nick Allen
>            Priority: Major
>
> The index write functionality is currently duplicated between the 
> ElasticsearchWriter and the ElasticsearchUpdateDao.  This functionality 
> should be de-duplicated and shared between the two.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to