use of org.apache.metron.common.configuration.IndexingConfigurations in project metron by apache.
the class SensorIndexingConfigServiceImplTest method getAllIndicesWithOnlyIndexing.
@Test
public void getAllIndicesWithOnlyIndexing() throws RestException {
ParserConfigurations parserConfiguration = mock(ParserConfigurations.class);
when(parserConfiguration.getTypes()).thenReturn(Collections.emptyList());
IndexingConfigurations indexingConfiguration = mock(IndexingConfigurations.class);
// rename bro, include snort by default configs, and disable yaf
when(indexingConfiguration.getTypes()).thenReturn(ImmutableList.of("bro", "snort", "yaf"));
when(indexingConfiguration.getIndex(eq("bro"), eq("elasticsearch"))).thenReturn("renamed_bro");
when(indexingConfiguration.getIndex(eq("snort"), eq("elasticsearch"))).thenReturn(null);
when(indexingConfiguration.isEnabled(eq("snort"), eq("elasticsearch"))).thenReturn(true);
when(indexingConfiguration.isEnabled(eq("bro"), eq("elasticsearch"))).thenReturn(true);
when(indexingConfiguration.isEnabled(eq("yaf"), eq("elasticsearch"))).thenReturn(false);
when(cache.get(eq(ParserConfigurations.class))).thenReturn(parserConfiguration);
when(cache.get(eq(IndexingConfigurations.class))).thenReturn(indexingConfiguration);
List<String> indices = new ArrayList<String>();
Iterables.addAll(indices, sensorIndexingConfigService.getAllIndices("elasticsearch"));
assertEquals(2, indices.size());
assertTrue(indices.contains("renamed_bro"));
assertTrue(indices.contains("snort"));
}
use of org.apache.metron.common.configuration.IndexingConfigurations in project metron by apache.
the class SensorIndexingConfigServiceImplTest method getAllTypesShouldProperlyReturnTypes.
@Test
public void getAllTypesShouldProperlyReturnTypes() throws Exception {
IndexingConfigurations configs = new IndexingConfigurations() {
@Override
public Map<String, Object> getConfigurations() {
return ImmutableMap.of(IndexingConfigurations.getKey("bro"), new HashMap<>(), IndexingConfigurations.getKey("squid"), new HashMap<>());
}
};
when(cache.get(eq(IndexingConfigurations.class))).thenReturn(configs);
assertEquals(new ArrayList() {
{
add("bro");
add("squid");
}
}, sensorIndexingConfigService.getAllTypes());
}
use of org.apache.metron.common.configuration.IndexingConfigurations in project metron by apache.
the class SolrWriterTest method testWriter.
@Test
public void testWriter() throws Exception {
IndexingConfigurations configurations = SampleUtil.getSampleIndexingConfigs();
JSONObject message1 = new JSONObject();
message1.put(Constants.GUID, "guid-1");
message1.put(Constants.SENSOR_TYPE, "test");
message1.put("intField", 100);
message1.put("doubleField", 100.0);
JSONObject message2 = new JSONObject();
message2.put(Constants.GUID, "guid-2");
message2.put(Constants.SENSOR_TYPE, "test");
message2.put("intField", 200);
message2.put("doubleField", 200.0);
List<BulkMessage<JSONObject>> messages = new ArrayList<>();
messages.add(new BulkMessage<>("message1", message1));
messages.add(new BulkMessage<>("message2", message2));
String collection = "metron";
MetronSolrClient solr = Mockito.mock(MetronSolrClient.class);
SolrWriter writer = new SolrWriter().withMetronSolrClient(solr);
writer.init(null, new IndexingWriterConfiguration("solr", configurations));
verify(solr, times(1)).setDefaultCollection(collection);
collection = "metron2";
Map<String, Object> globalConfig = configurations.getGlobalConfig();
globalConfig.put("solr.collection", collection);
configurations.updateGlobalConfig(globalConfig);
writer = new SolrWriter().withMetronSolrClient(solr);
writer.init(null, new IndexingWriterConfiguration("solr", configurations));
verify(solr, times(1)).setDefaultCollection(collection);
writer.write("test", new IndexingWriterConfiguration("solr", configurations), messages);
verify(solr, times(1)).add(eq("yaf"), argThat(new SolrInputDocumentMatcher(ImmutableList.of(message1, message2))));
verify(solr, times(1)).commit("yaf", (boolean) SolrWriter.SolrProperties.COMMIT_WAIT_FLUSH.defaultValue.get(), (boolean) SolrWriter.SolrProperties.COMMIT_WAIT_SEARCHER.defaultValue.get(), (boolean) SolrWriter.SolrProperties.COMMIT_SOFT.defaultValue.get());
}
Aggregations