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

    https://github.com/apache/incubator-metron/pull/481#discussion_r107765415
  
    --- Diff: 
metron-platform/metron-writer/src/main/java/org/apache/metron/writer/bolt/BulkMessageWriterBolt.java
 ---
    @@ -92,22 +177,51 @@ public void prepare(Map stormConf, TopologyContext 
context, OutputCollector coll
           configurationTransformation = x -> x;
         }
         try {
    -      bulkMessageWriter.init(stormConf
    -                            , configurationTransformation.apply(new 
IndexingWriterConfiguration(bulkMessageWriter.getName(), getConfigurations()))
    -                            );
    +      WriterConfiguration writerconf = configurationTransformation.apply(
    +              new IndexingWriterConfiguration(bulkMessageWriter.getName(), 
getConfigurations()));
    +      if (defaultBatchTimeout == 0) {
    +        //This means getComponentConfiguration was never called to 
initialize defaultBatchTimeout,
    +        //probably because we are in a unit test scenario.  So calculate 
it here.
    +        BatchTimeoutHelper timeoutHelper = new 
BatchTimeoutHelper(writerconf::getAllConfiguredTimeouts, batchTimeoutDivisor);
    +        defaultBatchTimeout = timeoutHelper.getDefaultBatchTimeout();
    +      }
    +      writerComponent.setDefaultBatchTimeout(defaultBatchTimeout);
    +      bulkMessageWriter.init(stormConf, writerconf);
         } catch (Exception e) {
           throw new RuntimeException(e);
         }
       }
     
    +  /**
    +   * Used only for unit testing.
    +   */
    +  public void prepare(Map stormConf, TopologyContext context, 
OutputCollector collector, Clock clock) {
    +    prepare(stormConf, context, collector);
    +    writerComponent.withClock(clock);
    +  }
    +
       @SuppressWarnings("unchecked")
       @Override
       public void execute(Tuple tuple) {
    -    JSONObject message = (JSONObject) messageGetStrategy.get(tuple);
    -    String sensorType = MessageUtils.getSensorType(message);
         try
         {
    -      WriterConfiguration writerConfiguration = 
configurationTransformation.apply(new 
IndexingWriterConfiguration(bulkMessageWriter.getName(), getConfigurations()));
    +      if (isTick(tuple)) {
    +        if (!(bulkMessageWriter instanceof WriterToBulkWriter)) {
    +          //WriterToBulkWriter doesn't allow batching, so no need to flush 
on Tick.
    +          LOG.debug("Flushing message queues older than their 
batchTimeouts");
    +          writerComponent.flushTimeouts(bulkMessageWriter, 
configurationTransformation.apply(
    +                  new 
IndexingWriterConfiguration(bulkMessageWriter.getName(), getConfigurations()))
    +                  , messageGetStrategy);
    +        }
    +        collector.ack(tuple);
    --- End diff --
    
    Should this be in a finally?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to