LineRegexReplaceInRegionBolt extends AbstractLogRecordBolt { void configureRegexRegions(Configuration conf) throws ConfigurationException { List<String> regexRegionGroupList = conf.getList(REGEX_REGION_GROUP).stream().map(o -> o.toString()).collect(Collectors.toList()); List<String> regexRegionSearchList = conf.getList(REGEX_REGION_SEARCH).stream().map(o -> o.toString()).collect(Collectors.toList()); List<String> regexRegionReplaceList = conf.getList(REGEX_REGION_REPLACE).stream().map(o -> o.toString()).collect(Collectors.toList()); int groupListSize = regexRegionGroupList.size(); int searchListSize = regexRegionSearchList.size(); int replaceListSize = regexRegionReplaceList.size(); if (!(groupListSize == searchListSize && searchListSize == replaceListSize)) { throw new ConfigurationException("Error initializing class. All regexRegion lists must be the same size"); } groupSearchReplaceList = new ArrayList<>(groupListSize); for (int index = 0; index < regexRegionGroupList.size(); index++) { Pattern pattern = Pattern.compile(regexRegionGroupList.get(index)); String regex = regexRegionSearchList.get(index); String replacement = regexRegionReplaceList.get(index); ImmutableTriple<Pattern, String, String> triple = new ImmutableTriple<>(pattern, regex, replacement); groupSearchReplaceList.add(triple); } }  @Override void configure(Configuration conf);  }
@Test public void testConfigureRegexRegions() throws Exception { XMLConfiguration conf = new XMLConfiguration(getResource(this.getClass(), "regexRegions.xml")); bolt.configureRegexRegions(conf); assertThat(bolt.groupSearchReplaceList.size(), is(2)); Triple<Pattern, String, String> entry0 = bolt.groupSearchReplaceList.get(0); Triple<Pattern, String, String> entry1 = bolt.groupSearchReplaceList.get(1); assertNotNull(entry0.getLeft()); assertThat(entry0.getMiddle(), is("regex0")); assertThat(entry0.getRight(), is("replacement0")); assertNotNull(entry1.getLeft()); assertThat(entry1.getMiddle(), is("regex1")); assertThat(entry1.getRight(), is("replacement1")); }