Search in sources :

Example 1 with ConfigurationsCache

use of org.apache.metron.common.zookeeper.ConfigurationsCache in project metron by apache.

the class SolrUpdateDaoTest method setupBefore.

@BeforeAll
public static void setupBefore() {
    accessConfig.setGlobalConfigSupplier(() -> new HashMap<String, Object>() {

        {
            put(SOLR_ZOOKEEPER, "zookeeper:2181");
        }
    });
    IndexingConfigurations indexingConfigs = mock(IndexingConfigurations.class);
    ConfigurationsCache cache = mock(ConfigurationsCache.class);
    Map<String, Object> broIndexingConfig = new HashMap<String, Object>() {

        {
            put("solr", new HashMap<String, Object>() {

                {
                }
            });
        }
    };
    when(indexingConfigs.getSensorIndexingConfig("bro")).thenReturn(broIndexingConfig);
    when(cache.get(IndexingConfigurations.class)).thenReturn(indexingConfigs);
    accessConfig.setIndexSupplier(IndexingCacheUtil.getIndexLookupFunction(cache, "solr"));
}
Also used : IndexingConfigurations(org.apache.metron.common.configuration.IndexingConfigurations) ConfigurationsCache(org.apache.metron.common.zookeeper.ConfigurationsCache) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with ConfigurationsCache

use of org.apache.metron.common.zookeeper.ConfigurationsCache in project metron by apache.

the class IndexingCacheUtilTest method getIndexLookupFunctionShouldDefaultToSensorType.

@Test
public void getIndexLookupFunctionShouldDefaultToSensorType() {
    IndexingConfigurations indexingConfigs = mock(IndexingConfigurations.class);
    ConfigurationsCache cache = mock(ConfigurationsCache.class);
    Map<String, Object> broIndexingConfig = new HashMap<String, Object>() {

        {
            put("writer", new HashMap<String, Object>() {

                {
                    put("index", "bro_index");
                }
            });
        }
    };
    when(indexingConfigs.getSensorIndexingConfig("bro")).thenReturn(broIndexingConfig);
    when(cache.get(IndexingConfigurations.class)).thenReturn(indexingConfigs);
    assertEquals("snort", IndexingCacheUtil.getIndexLookupFunction(cache, "writer").apply("snort"), "Should default to sensor type on missing sensor config");
    assertEquals("bro", IndexingCacheUtil.getIndexLookupFunction(cache, "someWriter").apply("bro"), "Should default to sensor type on missing writer config");
}
Also used : HashMap(java.util.HashMap) IndexingConfigurations(org.apache.metron.common.configuration.IndexingConfigurations) ConfigurationsCache(org.apache.metron.common.zookeeper.ConfigurationsCache) Test(org.junit.jupiter.api.Test)

Example 3 with ConfigurationsCache

use of org.apache.metron.common.zookeeper.ConfigurationsCache in project metron by apache.

the class IndexingCacheUtilTest method getIndexLookupFunctionShouldReturnConfiguredIndex.

@Test
public void getIndexLookupFunctionShouldReturnConfiguredIndex() {
    IndexingConfigurations indexingConfigs = mock(IndexingConfigurations.class);
    ConfigurationsCache cache = mock(ConfigurationsCache.class);
    Map<String, Object> broIndexingConfig = new HashMap<String, Object>() {

        {
            put("writer", new HashMap<String, Object>() {

                {
                    put("index", "bro_index");
                }
            });
        }
    };
    when(indexingConfigs.getSensorIndexingConfig("bro")).thenReturn(broIndexingConfig);
    when(cache.get(IndexingConfigurations.class)).thenReturn(indexingConfigs);
    assertEquals("bro_index", IndexingCacheUtil.getIndexLookupFunction(cache, "writer").apply("bro"));
}
Also used : HashMap(java.util.HashMap) IndexingConfigurations(org.apache.metron.common.configuration.IndexingConfigurations) ConfigurationsCache(org.apache.metron.common.zookeeper.ConfigurationsCache) Test(org.junit.jupiter.api.Test)

Aggregations

IndexingConfigurations (org.apache.metron.common.configuration.IndexingConfigurations)3 ConfigurationsCache (org.apache.metron.common.zookeeper.ConfigurationsCache)3 HashMap (java.util.HashMap)2 Test (org.junit.jupiter.api.Test)2 BeforeAll (org.junit.jupiter.api.BeforeAll)1