ElasticSearchJsonBolt extends BaseBasicBolt implements Configurable { void configureBolt(Configuration conf) { esJsonField = conf.getString(ES_JSON_FIELD, ES_JSON_FIELD_DEFAULT); indexName = conf.getString(INDEX_NAME, INDEX_NAME_DEFAULT); indexField = conf.getString(INDEX_FIELD, INDEX_FIELD_DEFAULT); }  @Override void configure(Configuration conf); @Override void prepare(Map stormConf, TopologyContext context); @Override final void declareOutputFields(OutputFieldsDeclarer declarer); @Override final void execute(Tuple input, BasicOutputCollector collector); static final String ES_JSON; }
@Test public void testConfigureBolt() throws Exception { URL resource = getResource("configureBolt.xml"); XMLConfiguration conf = new XMLConfiguration(resource); bolt.configureBolt(conf); assertThat(bolt.esJsonField, is("custom_es_json_field")); assertThat(bolt.indexName, is("custom_index_name")); assertThat(bolt.indexField, is("custom_index_field")); }
@Test public void testConfigureBoltDefault() throws Exception { URL resource = getResource("configureDefault.xml"); XMLConfiguration conf = new XMLConfiguration(resource); bolt.configureBolt(conf); assertThat(bolt.esJsonField, is(ES_JSON_FIELD_DEFAULT)); assertThat(bolt.indexName, is(INDEX_NAME_DEFAULT)); assertThat(bolt.indexField, is(INDEX_FIELD_DEFAULT)); }