public static Emitter create( Properties props, AsyncHttpClient httpClient, ObjectMapper jsonMapper, Lifecycle lifecycle ) { Map<String, Object> jsonified; if (props.getProperty(LOG_EMITTER_PROP) != null) { jsonified = makeLoggingMap(props); jsonified.put("type", "logging"); } else if (props.getProperty(HTTP_EMITTER_PROP) != null) { jsonified = makeHttpMap(props); jsonified.put("type", "http"); } else if (props.getProperty(CUSTOM_EMITTER_TYPE_PROP) != null) { jsonified = makeCustomFactoryMap(props); } else { throw new ISE( "Unknown type of emitter. Please set [%s], [%s] or provide registered subtype of org.apache.druid.java.util.emitter.core.factory.EmitterFactory via [%s]", LOG_EMITTER_PROP, HTTP_EMITTER_PROP, CUSTOM_EMITTER_TYPE_PROP ); } return jsonMapper.convertValue(jsonified, EmitterFactory.class).makeEmitter(jsonMapper, httpClient, lifecycle); }
@Test public void testSettingEverythingLegacy() { final Properties props = new Properties(); props.setProperty("org.apache.druid.java.util.emitter.flushMillis", "1"); props.setProperty("org.apache.druid.java.util.emitter.flushCount", "2"); props.setProperty("org.apache.druid.java.util.emitter.http.url", "http://example.com/"); props.setProperty("org.apache.druid.java.util.emitter.http.basicAuthentication", "a:b"); props.setProperty("org.apache.druid.java.util.emitter.http.batchingStrategy", "newlines"); props.setProperty("org.apache.druid.java.util.emitter.http.maxBatchSize", "4"); props.setProperty("org.apache.druid.java.util.emitter.http.flushTimeOut", "1000"); props.setProperty("org.apache.druid.java.util.emitter.http.batchQueueSizeLimit", "2500"); props.setProperty("org.apache.druid.java.util.emitter.http.httpTimeoutAllowanceFactor", "3.0"); props.setProperty("org.apache.druid.java.util.emitter.http.minHttpTimeoutMillis", "100"); final ObjectMapper objectMapper = new ObjectMapper(); final HttpEmitterConfig config = objectMapper.convertValue(Emitters.makeHttpMap(props), HttpEmitterConfig.class); Assert.assertEquals(1, config.getFlushMillis()); Assert.assertEquals(2, config.getFlushCount()); Assert.assertEquals("http://example.com/", config.getRecipientBaseUrl()); Assert.assertEquals("a:b", config.getBasicAuthentication()); Assert.assertEquals(BatchingStrategy.NEWLINES, config.getBatchingStrategy()); Assert.assertEquals(4, config.getMaxBatchSize()); Assert.assertEquals(1000, config.getFlushTimeOut()); Assert.assertEquals(2500, config.getBatchQueueSizeLimit()); Assert.assertEquals(3.0f, config.getHttpTimeoutAllowanceFactor(), 0.0f); Assert.assertEquals(100, config.getMinHttpTimeoutMillis()); }
@Test public void testDefaultsLegacy() { final Properties props = new Properties(); props.put("org.apache.druid.java.util.emitter.http.url", "http://example.com/"); final ObjectMapper objectMapper = new ObjectMapper(); final HttpEmitterConfig config = objectMapper.convertValue(Emitters.makeHttpMap(props), HttpEmitterConfig.class); Assert.assertEquals(60000, config.getFlushMillis()); Assert.assertEquals(300, config.getFlushCount()); Assert.assertEquals("http://example.com/", config.getRecipientBaseUrl()); Assert.assertEquals(null, config.getBasicAuthentication()); Assert.assertEquals(BatchingStrategy.ARRAY, config.getBatchingStrategy()); Pair<Integer, Integer> batchConfigPair = BaseHttpEmittingConfig.getDefaultBatchSizeAndLimit( Runtime.getRuntime().maxMemory() ); Assert.assertEquals(batchConfigPair.lhs.intValue(), config.getMaxBatchSize()); Assert.assertEquals(batchConfigPair.rhs.intValue(), config.getBatchQueueSizeLimit()); Assert.assertEquals(Long.MAX_VALUE, config.getFlushTimeOut()); Assert.assertEquals(2.0f, config.getHttpTimeoutAllowanceFactor(), 0.0f); Assert.assertEquals(0, config.getMinHttpTimeoutMillis()); }
public static Emitter create( Properties props, AsyncHttpClient httpClient, ObjectMapper jsonMapper, Lifecycle lifecycle ) { Map<String, Object> jsonified = Maps.newHashMap(); if (props.getProperty(LOG_EMITTER_PROP) != null) { jsonified = makeLoggingMap(props); jsonified.put("type", "logging"); } else if (props.getProperty(HTTP_EMITTER_PROP) != null) { jsonified = makeHttpMap(props); jsonified.put("type", "http"); } else if (props.getProperty(CUSTOM_EMITTER_TYPE_PROP) != null) { jsonified = makeCustomFactoryMap(props); } else { throw new ISE( "Unknown type of emitter. Please set [%s], [%s] or provide registered subtype of org.apache.druid.java.util.emitter.core.factory.EmitterFactory via [%s]", LOG_EMITTER_PROP, HTTP_EMITTER_PROP, CUSTOM_EMITTER_TYPE_PROP ); } return jsonMapper.convertValue(jsonified, EmitterFactory.class).makeEmitter(jsonMapper, httpClient, lifecycle); }