Skip to content

Commit

Permalink
Fix Megabus Topic POJO throws Jackson deserialization exception when … (
Browse files Browse the repository at this point in the history
#291)

* Fix Megabus Topic POJO throws Jackson deserialization exception when reading config yaml

* Add config tests for Kafka configuration and Megabus configuration
  • Loading branch information
Jona Fenocchi authored Dec 18, 2019
1 parent 49597ce commit 4479b62
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 10 deletions.
15 changes: 5 additions & 10 deletions kafka/src/main/java/com/bazaarvoice/emodb/kafka/Topic.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bazaarvoice.emodb.kafka;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.annotations.VisibleForTesting;

Expand All @@ -8,23 +9,17 @@

public class Topic {

@Valid
@NotNull
@JsonProperty("name")
private String _name;

@Valid
@NotNull
@JsonProperty("partitions")
private int _partitions;

@Valid
@NotNull
@JsonProperty("replicationFactor")
private short _replicationFactor;

@JsonCreator
@VisibleForTesting
public Topic(String name, int partitions, short replicationFactor) {
public Topic(@Valid @NotNull @JsonProperty("name") String name,
@Valid @NotNull @JsonProperty("partitions") int partitions,
@Valid @NotNull @JsonProperty("replicationFactor") short replicationFactor) {
this._name = name;
this._partitions = partitions;
this._replicationFactor = replicationFactor;
Expand Down
11 changes: 11 additions & 0 deletions kafka/src/main/resources/emodb-kafka-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
bootstrapServers: kafka:9092
producer:
bufferMemory: 12356789
batchSize: 100
lingerMs: 5
ssl:
trustStoreLocation: /abc/123
trustStorePassword: banana
keyStoreLocation: /def/456
keyStorePassword: apple
keyPassword: orange
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.bazaarvoice.emodb.kafka;

import com.bazaarvoice.emodb.common.json.CustomJsonObjectMapperFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.dropwizard.configuration.ConfigurationException;
import io.dropwizard.configuration.ConfigurationFactory;
import org.testng.annotations.Test;

import javax.validation.Validation;
import javax.validation.Validator;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;

public class KafkaConfigTest {
@Test
public void ensureKafkaDefaultConfigDeserialization()
throws IOException, URISyntaxException, ConfigurationException {
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
ObjectMapper mapper = CustomJsonObjectMapperFactory.build(new YAMLFactory());
ConfigurationFactory configurationFactory = new ConfigurationFactory(KafkaConfiguration.class, validator, mapper, "dw");
// Make sure that our config files are up to date
configurationFactory.build(
new File(KafkaConfiguration.class.getResource("/emodb-kafka-config.yaml").toURI()));
}
}
28 changes: 28 additions & 0 deletions megabus/src/main/resources/emodb-megabus-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
applicationId: megabus-local
refResolverConsumerGroupName: emodb.megabus.resolver
delayProcessorConsumerGroupName: emodb.megabus.delay
megabusRefTopic:
name: emodb.internal.megabus.ref
partitions: 8
replicationFactor: 1
megabusTopic:
name: emodb.megabus
partitions: 8
replicationFactor: 1
missingRefTopic:
name: emodb.internal.megabus.missing
partitions: 8
replicationFactor: 1
retryRefTopic:
name: emodb.internal.megabus.retry
partitions: 8
replicationFactor: 1
boot:
queueServiceApiKey: local_admin
scanStatusTable: __system_megabus_boot
pendingScanRangeQueueName: megabus-boot-pending-scan-ranges
completeScanRangeQueueName: megabus-boot-complete-scan-ranges
refProducer:
batchSize: 400
skipWaitThreshold: 250
pollIntervalMs: 100
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.bazaarvoice.megabus;

import com.bazaarvoice.emodb.common.json.CustomJsonObjectMapperFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.dropwizard.configuration.ConfigurationException;
import io.dropwizard.configuration.ConfigurationFactory;
import org.testng.annotations.Test;

import javax.validation.Validation;
import javax.validation.Validator;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;

public class MegabusConfigTest {
@Test
public void ensureMegabusDefaultConfigDeserialization()
throws IOException, URISyntaxException, ConfigurationException {
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
ObjectMapper mapper = CustomJsonObjectMapperFactory.build(new YAMLFactory());
ConfigurationFactory configurationFactory = new ConfigurationFactory(MegabusConfiguration.class, validator, mapper, "dw");
// Make sure that our config files are up to date
configurationFactory.build(
new File(MegabusConfiguration.class.getResource("/emodb-megabus-config.yaml").toURI()));
}
}

0 comments on commit 4479b62

Please sign in to comment.