From 4963a113dc4b48d6dfcac2eb12f39b0973095fc7 Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Fri, 31 Jan 2020 17:15:38 -0800 Subject: [PATCH] Make JoinableFactoryModule tests look at all the actual mappings. (#9295) By depending on JoinableFactoryModule.FACTORY_MAPPINGS, we verify that the bound JoinableFactory can actually handle and create all default classes. --- .../druid/guice/JoinableFactoryModule.java | 4 +++- .../druid/guice/JoinableFactoryModuleTest.java | 16 +++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/apache/druid/guice/JoinableFactoryModule.java b/server/src/main/java/org/apache/druid/guice/JoinableFactoryModule.java index fb4dbdc3dd9..73e5610d847 100644 --- a/server/src/main/java/org/apache/druid/guice/JoinableFactoryModule.java +++ b/server/src/main/java/org/apache/druid/guice/JoinableFactoryModule.java @@ -19,6 +19,7 @@ package org.apache.druid.guice; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; import com.google.inject.Binder; import com.google.inject.Module; @@ -42,7 +43,8 @@ public class JoinableFactoryModule implements Module /** * Default mappings of datasources to factories. */ - private static final Map, Class> FACTORY_MAPPINGS = + @VisibleForTesting + static final Map, Class> FACTORY_MAPPINGS = ImmutableMap.of( InlineDataSource.class, InlineJoinableFactory.class, LookupDataSource.class, LookupJoinableFactory.class diff --git a/server/src/test/java/org/apache/druid/guice/JoinableFactoryModuleTest.java b/server/src/test/java/org/apache/druid/guice/JoinableFactoryModuleTest.java index 47c34fd9cef..5478a62deb9 100644 --- a/server/src/test/java/org/apache/druid/guice/JoinableFactoryModuleTest.java +++ b/server/src/test/java/org/apache/druid/guice/JoinableFactoryModuleTest.java @@ -27,20 +27,20 @@ import com.google.inject.Module; import com.google.inject.Scopes; import com.google.inject.TypeLiteral; import org.apache.druid.query.DataSource; -import org.apache.druid.query.InlineDataSource; import org.apache.druid.query.expression.LookupEnabledTestExprMacroTable; import org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider; -import org.apache.druid.segment.join.InlineJoinableFactory; import org.apache.druid.segment.join.JoinableFactory; import org.apache.druid.segment.join.MapJoinableFactory; import org.apache.druid.segment.join.NoopDataSource; import org.apache.druid.segment.join.NoopJoinableFactory; +import org.hamcrest.CoreMatchers; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import java.util.Collections; import java.util.Map; +import java.util.Set; public class JoinableFactoryModuleTest { @@ -66,8 +66,14 @@ public class JoinableFactoryModuleTest { Map, JoinableFactory> joinableFactories = injector.getInstance(Key.get(new TypeLiteral, JoinableFactory>>() {})); - Assert.assertEquals(2, joinableFactories.size()); - Assert.assertEquals(InlineJoinableFactory.class, joinableFactories.get(InlineDataSource.class).getClass()); + Assert.assertEquals(JoinableFactoryModule.FACTORY_MAPPINGS.size(), joinableFactories.size()); + + final Set, Class>> expectedEntries = + JoinableFactoryModule.FACTORY_MAPPINGS.entrySet(); + + for (Map.Entry, Class> entry : expectedEntries) { + Assert.assertThat(joinableFactories.get(entry.getKey()), CoreMatchers.instanceOf(entry.getValue())); + } } @Test @@ -78,7 +84,7 @@ public class JoinableFactoryModuleTest .joinableFactoryBinder(binder).addBinding(NoopDataSource.class).toInstance(NoopJoinableFactory.INSTANCE)); Map, JoinableFactory> joinableFactories = injector.getInstance(Key.get(new TypeLiteral, JoinableFactory>>() {})); - Assert.assertEquals(3, joinableFactories.size()); + Assert.assertEquals(JoinableFactoryModule.FACTORY_MAPPINGS.size() + 1, joinableFactories.size()); Assert.assertEquals(NoopJoinableFactory.INSTANCE, joinableFactories.get(NoopDataSource.class)); }