1) It's good when unit tests actually pass...

This commit is contained in:
cheddar 2013-08-31 17:27:15 -05:00
parent 3c39f90c89
commit 740c70ed06
9 changed files with 118 additions and 13 deletions

View File

@ -42,6 +42,7 @@ public class DefaultObjectMapper extends ObjectMapper
registerModule(new GuavaModule());
registerModule(new QueryGranularityModule());
registerModule(new AggregatorsModule());
registerModule(new SegmentsModule());
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
configure(MapperFeature.AUTO_DETECT_GETTERS, false);

View File

@ -0,0 +1,45 @@
/*
* Druid - a distributed column store.
* Copyright (C) 2012, 2013 Metamarkets Group Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.druid.jackson;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.module.SimpleModule;
import io.druid.timeline.partition.NoneShardSpec;
import io.druid.timeline.partition.ShardSpec;
/**
*/
public class SegmentsModule extends SimpleModule
{
public SegmentsModule()
{
super("SegmentsModule");
setMixInAnnotation(ShardSpec.class, ShardSpecMixin.class);
}
@JsonTypeInfo(use= JsonTypeInfo.Id.NAME, property="type")
@JsonSubTypes({
@JsonSubTypes.Type(name="none", value=NoneShardSpec.class),
})
public static interface ShardSpecMixin
{}
}

View File

@ -19,19 +19,27 @@
package io.druid.guice;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.metamx.common.concurrent.ScheduledExecutorFactory;
import com.metamx.common.concurrent.ScheduledExecutors;
import com.metamx.common.lifecycle.Lifecycle;
import io.druid.guice.annotations.Self;
import io.druid.initialization.DruidModule;
import io.druid.server.DruidNode;
import io.druid.server.initialization.initialization.ZkPathsConfig;
import io.druid.timeline.partition.LinearShardSpec;
import io.druid.timeline.partition.NumberedShardSpec;
import io.druid.timeline.partition.SingleDimensionShardSpec;
import java.util.Arrays;
import java.util.List;
/**
*/
public class ServerModule implements Module
public class ServerModule implements DruidModule
{
@Override
public void configure(Binder binder)
@ -46,4 +54,17 @@ public class ServerModule implements Module
{
return ScheduledExecutors.createFactory(lifecycle);
}
@Override
public List<? extends com.fasterxml.jackson.databind.Module> getJacksonModules()
{
return Arrays.asList(
new SimpleModule()
.registerSubtypes(
new NamedType(SingleDimensionShardSpec.class, "single"),
new NamedType(LinearShardSpec.class, "linear"),
new NamedType(NumberedShardSpec.class, "numbered")
)
);
}
}

View File

@ -0,0 +1,41 @@
/*
* Druid - a distributed column store.
* Copyright (C) 2012, 2013 Metamarkets Group Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.druid;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.druid.guice.ServerModule;
import io.druid.jackson.DefaultObjectMapper;
import java.util.List;
/**
*/
public class TestUtil
{
public static final ObjectMapper MAPPER = new DefaultObjectMapper();
static {
final List<? extends Module> list = new ServerModule().getJacksonModules();
for (Module module : list) {
MAPPER.registerModule(module);
}
}
}

View File

@ -19,11 +19,10 @@
package io.druid.server.shard;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import io.druid.jackson.DefaultObjectMapper;
import io.druid.TestUtil;
import io.druid.timeline.partition.NumberedShardSpec;
import io.druid.timeline.partition.PartitionChunk;
import io.druid.timeline.partition.ShardSpec;
@ -37,9 +36,8 @@ public class NumberedShardSpecTest
@Test
public void testSerdeRoundTrip() throws Exception
{
final ObjectMapper jsonMapper = new DefaultObjectMapper();
final ShardSpec spec = jsonMapper.readValue(
jsonMapper.writeValueAsBytes(new NumberedShardSpec(1, 2)),
final ShardSpec spec = TestUtil.MAPPER.readValue(
TestUtil.MAPPER.writeValueAsBytes(new NumberedShardSpec(1, 2)),
ShardSpec.class
);
Assert.assertEquals(1, spec.getPartitionNum());
@ -49,8 +47,7 @@ public class NumberedShardSpecTest
@Test
public void testSerdeBackwardsCompat() throws Exception
{
final ObjectMapper jsonMapper = new DefaultObjectMapper();
final ShardSpec spec = jsonMapper.readValue(
final ShardSpec spec = TestUtil.MAPPER.readValue(
"{\"type\": \"numbered\", \"partitions\": 2, \"partitionNum\": 1}",
ShardSpec.class
);

View File

@ -63,7 +63,7 @@ public class CliBroker extends ServerRunnable
HttpClientModule.global(),
CuratorModule.class,
new MetricsModule().register(CacheMonitor.class),
ServerModule.class,
new ServerModule(),
new JettyServerModule(new QueryJettyServerInitializer())
.addResource(StatusResource.class),
new QueryableModule(ClientQuerySegmentWalker.class),

View File

@ -82,7 +82,7 @@ public class CliCoordinator extends ServerRunnable
CuratorModule.class,
new MetricsModule(),
new DiscoveryModule().register(Self.class),
ServerModule.class,
new ServerModule(),
new JettyServerModule(new CoordinatorJettyServerInitializer())
.addResource(InfoResource.class)
.addResource(MasterResource.class)

View File

@ -71,7 +71,7 @@ public class CliMiddleManager extends ServerRunnable
HttpClientModule.global(),
CuratorModule.class,
new MetricsModule(),
ServerModule.class,
new ServerModule(),
new JettyServerModule(new MiddleManagerJettyServerInitializer())
.addResource(StatusResource.class)
.addResource(WorkerResource.class),

View File

@ -78,7 +78,7 @@ public class CliOverlord extends ServerRunnable
HttpClientModule.global(),
CuratorModule.class,
new MetricsModule(),
ServerModule.class,
new ServerModule(),
new AWSModule(),
new DbConnectorModule(),
new JacksonConfigManagerModule(),