From cc18bdeb0d157f3cffdb223236d22488cc323a33 Mon Sep 17 00:00:00 2001 From: fjy Date: Sun, 19 Oct 2014 16:14:26 -0700 Subject: [PATCH] another test for defaults --- .../JacksonifiedConnectionFactory.java | 4 +- .../rabbitmq/RabbitMQFirehoseFactoryTest.java | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/rabbitmq/src/main/java/io/druid/firehose/rabbitmq/JacksonifiedConnectionFactory.java b/rabbitmq/src/main/java/io/druid/firehose/rabbitmq/JacksonifiedConnectionFactory.java index 56cb040f89f..a4a39bcc9cd 100644 --- a/rabbitmq/src/main/java/io/druid/firehose/rabbitmq/JacksonifiedConnectionFactory.java +++ b/rabbitmq/src/main/java/io/druid/firehose/rabbitmq/JacksonifiedConnectionFactory.java @@ -65,7 +65,7 @@ public class JacksonifiedConnectionFactory extends ConnectionFactory ) throws Exception { super(); - + this.host = host == null ? super.getHost() : host; this.port = port == 0 ? super.getPort() : port; this.username = username == null ? super.getUsername() : username; @@ -206,7 +206,7 @@ public class JacksonifiedConnectionFactory extends ConnectionFactory if (requestedHeartbeat != that.requestedHeartbeat) { return false; } - if (clientProperties != null ? !clientProperties.equals(that.clientProperties) : that.clientProperties != null) { + if (clientProperties != null ? Maps.difference(clientProperties, that.clientProperties).areEqual() : that.clientProperties != null) { return false; } if (host != null ? !host.equals(that.host) : that.host != null) { diff --git a/rabbitmq/src/test/java/io/druid/examples/rabbitmq/RabbitMQFirehoseFactoryTest.java b/rabbitmq/src/test/java/io/druid/examples/rabbitmq/RabbitMQFirehoseFactoryTest.java index 09bd205df25..eca04717fc2 100644 --- a/rabbitmq/src/test/java/io/druid/examples/rabbitmq/RabbitMQFirehoseFactoryTest.java +++ b/rabbitmq/src/test/java/io/druid/examples/rabbitmq/RabbitMQFirehoseFactoryTest.java @@ -22,6 +22,7 @@ package io.druid.examples.rabbitmq; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; +import com.rabbitmq.client.ConnectionFactory; import io.druid.data.input.impl.DimensionsSpec; import io.druid.data.input.impl.JSONParseSpec; import io.druid.data.input.impl.SpatialDimensionSchema; @@ -96,4 +97,43 @@ public class RabbitMQFirehoseFactoryTest Assert.assertEquals(factory.getConfig(), factory2.getConfig()); Assert.assertEquals(factory.getConnectionFactory(), factory2.getConnectionFactory()); } + + @Test + public void testDefaultSerde() throws Exception + { + RabbitMQFirehoseConfig config = RabbitMQFirehoseConfig.makeDefaultConfig(); + + JacksonifiedConnectionFactory connectionFactory = JacksonifiedConnectionFactory.makeDefaultConnectionFactory(); + + RabbitMQFirehoseFactory factory = new RabbitMQFirehoseFactory( + connectionFactory, + config, + new StringInputRowParser( + new JSONParseSpec( + new TimestampSpec("timestamp", "auto"), + new DimensionsSpec( + Arrays.asList("dim"), + Lists.newArrayList(), + Lists.newArrayList() + ) + ), + null, null, null, null + ) + ); + + byte[] bytes = mapper.writeValueAsBytes(factory); + RabbitMQFirehoseFactory factory2 = mapper.readValue(bytes, RabbitMQFirehoseFactory.class); + byte[] bytes2 = mapper.writeValueAsBytes(factory2); + + Assert.assertArrayEquals(bytes, bytes2); + + Assert.assertEquals(factory.getConfig(), factory2.getConfig()); + Assert.assertEquals(factory.getConnectionFactory(), factory2.getConnectionFactory()); + + Assert.assertEquals(300, factory2.getConfig().getMaxDurationSeconds()); + + Assert.assertEquals(ConnectionFactory.DEFAULT_HOST, factory2.getConnectionFactory().getHost()); + Assert.assertEquals(ConnectionFactory.DEFAULT_USER, factory2.getConnectionFactory().getUsername()); + Assert.assertEquals(ConnectionFactory.DEFAULT_AMQP_PORT, factory2.getConnectionFactory().getPort()); + } }