mirror of https://github.com/apache/druid.git
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.
This commit is contained in:
parent
0f0554f8fa
commit
4963a113dc
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.apache.druid.guice;
|
package org.apache.druid.guice;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.inject.Binder;
|
import com.google.inject.Binder;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
@ -42,7 +43,8 @@ public class JoinableFactoryModule implements Module
|
||||||
/**
|
/**
|
||||||
* Default mappings of datasources to factories.
|
* Default mappings of datasources to factories.
|
||||||
*/
|
*/
|
||||||
private static final Map<Class<? extends DataSource>, Class<? extends JoinableFactory>> FACTORY_MAPPINGS =
|
@VisibleForTesting
|
||||||
|
static final Map<Class<? extends DataSource>, Class<? extends JoinableFactory>> FACTORY_MAPPINGS =
|
||||||
ImmutableMap.of(
|
ImmutableMap.of(
|
||||||
InlineDataSource.class, InlineJoinableFactory.class,
|
InlineDataSource.class, InlineJoinableFactory.class,
|
||||||
LookupDataSource.class, LookupJoinableFactory.class
|
LookupDataSource.class, LookupJoinableFactory.class
|
||||||
|
|
|
@ -27,20 +27,20 @@ import com.google.inject.Module;
|
||||||
import com.google.inject.Scopes;
|
import com.google.inject.Scopes;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
import org.apache.druid.query.DataSource;
|
import org.apache.druid.query.DataSource;
|
||||||
import org.apache.druid.query.InlineDataSource;
|
|
||||||
import org.apache.druid.query.expression.LookupEnabledTestExprMacroTable;
|
import org.apache.druid.query.expression.LookupEnabledTestExprMacroTable;
|
||||||
import org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider;
|
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.JoinableFactory;
|
||||||
import org.apache.druid.segment.join.MapJoinableFactory;
|
import org.apache.druid.segment.join.MapJoinableFactory;
|
||||||
import org.apache.druid.segment.join.NoopDataSource;
|
import org.apache.druid.segment.join.NoopDataSource;
|
||||||
import org.apache.druid.segment.join.NoopJoinableFactory;
|
import org.apache.druid.segment.join.NoopJoinableFactory;
|
||||||
|
import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class JoinableFactoryModuleTest
|
public class JoinableFactoryModuleTest
|
||||||
{
|
{
|
||||||
|
@ -66,8 +66,14 @@ public class JoinableFactoryModuleTest
|
||||||
{
|
{
|
||||||
Map<Class<? extends DataSource>, JoinableFactory> joinableFactories =
|
Map<Class<? extends DataSource>, JoinableFactory> joinableFactories =
|
||||||
injector.getInstance(Key.get(new TypeLiteral<Map<Class<? extends DataSource>, JoinableFactory>>() {}));
|
injector.getInstance(Key.get(new TypeLiteral<Map<Class<? extends DataSource>, JoinableFactory>>() {}));
|
||||||
Assert.assertEquals(2, joinableFactories.size());
|
Assert.assertEquals(JoinableFactoryModule.FACTORY_MAPPINGS.size(), joinableFactories.size());
|
||||||
Assert.assertEquals(InlineJoinableFactory.class, joinableFactories.get(InlineDataSource.class).getClass());
|
|
||||||
|
final Set<Map.Entry<Class<? extends DataSource>, Class<? extends JoinableFactory>>> expectedEntries =
|
||||||
|
JoinableFactoryModule.FACTORY_MAPPINGS.entrySet();
|
||||||
|
|
||||||
|
for (Map.Entry<Class<? extends DataSource>, Class<? extends JoinableFactory>> entry : expectedEntries) {
|
||||||
|
Assert.assertThat(joinableFactories.get(entry.getKey()), CoreMatchers.instanceOf(entry.getValue()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -78,7 +84,7 @@ public class JoinableFactoryModuleTest
|
||||||
.joinableFactoryBinder(binder).addBinding(NoopDataSource.class).toInstance(NoopJoinableFactory.INSTANCE));
|
.joinableFactoryBinder(binder).addBinding(NoopDataSource.class).toInstance(NoopJoinableFactory.INSTANCE));
|
||||||
Map<Class<? extends DataSource>, JoinableFactory> joinableFactories =
|
Map<Class<? extends DataSource>, JoinableFactory> joinableFactories =
|
||||||
injector.getInstance(Key.get(new TypeLiteral<Map<Class<? extends DataSource>, JoinableFactory>>() {}));
|
injector.getInstance(Key.get(new TypeLiteral<Map<Class<? extends DataSource>, JoinableFactory>>() {}));
|
||||||
Assert.assertEquals(3, joinableFactories.size());
|
Assert.assertEquals(JoinableFactoryModule.FACTORY_MAPPINGS.size() + 1, joinableFactories.size());
|
||||||
Assert.assertEquals(NoopJoinableFactory.INSTANCE, joinableFactories.get(NoopDataSource.class));
|
Assert.assertEquals(NoopJoinableFactory.INSTANCE, joinableFactories.get(NoopDataSource.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue