Fix jackson property name for dropwizardemitterconfig (#8691)

Fix jackson property name and add test

Fix test
This commit is contained in:
Nishant Bangarwa 2019-10-23 03:10:19 +05:30 committed by Fangjin Yang
parent 42cfe679f1
commit 48486a4535
3 changed files with 28 additions and 2 deletions

View File

@ -47,6 +47,13 @@
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.druid</groupId>
<artifactId>druid-server</artifactId>
<type>test-jar</type>
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>

View File

@ -52,7 +52,7 @@ public class DropwizardEmitterConfig
@JsonProperty("includeHost") Boolean includeHost,
@JsonProperty("dimensionMapPath") String dimensionMapPath,
@JsonProperty("alertEmitters") List<String> alertEmitters,
@JsonProperty("metricsRegistrySize") Integer maxMetricsRegistrySize
@JsonProperty("maxMetricsRegistrySize") Integer maxMetricsRegistrySize
)
{
Preconditions.checkArgument(reporters != null && !reporters.isEmpty());

View File

@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import org.apache.druid.emitter.dropwizard.reporters.DropwizardConsoleReporter;
import org.apache.druid.emitter.dropwizard.reporters.DropwizardJMXReporter;
import org.apache.druid.guice.JsonConfigTesterBase;
import org.apache.druid.jackson.DefaultObjectMapper;
import org.junit.Assert;
import org.junit.Before;
@ -31,13 +32,16 @@ import org.junit.Test;
import java.io.IOException;
public class DropwizardEmitterConfigTest
public class DropwizardEmitterConfigTest extends JsonConfigTesterBase<DropwizardEmitterConfig>
{
private ObjectMapper mapper = new DefaultObjectMapper();
@Before
public void setUp()
{
testProperties.put(getPropertyKey("reporters"), "[{\"type\":\"jmx\", \"domain\" : \"mydomain\"}]");
propertyValues.put(getPropertyKey("reporters"), "[DropwizardJMXReporter{domain='mydomain'}]");
propertyValues.put(getPropertyKey("includeHost"), "true");
mapper.setInjectableValues(new InjectableValues.Std().addValue(
ObjectMapper.class,
new DefaultObjectMapper()
@ -62,6 +66,21 @@ public class DropwizardEmitterConfigTest
Assert.assertEquals(dropwizardEmitterConfigExpected, dropwizardEmitterConfig);
}
@Test
public void testSerde()
{
propertyValues.put(getPropertyKey("reporters"), "[{\"type\":\"jmx\"}]");
propertyValues.put(getPropertyKey("prefix"), "test-prefix");
propertyValues.put(getPropertyKey("includeHost"), "true");
testProperties.putAll(propertyValues);
configProvider.inject(testProperties, configurator);
DropwizardEmitterConfig config = configProvider.get().get();
Assert.assertTrue("IncludeHost", config.getIncludeHost());
Assert.assertEquals("test-prefix", config.getPrefix());
Assert.assertEquals(1, config.getReporters().size());
Assert.assertTrue("jmx reporter", config.getReporters().get(0) instanceof DropwizardJMXReporter);
}
}