use of com.google.common.collect.ImmutableList in project druid by druid-io.
the class IndexIOTest method constructionFeeder.
@Parameterized.Parameters
public static Iterable<Object[]> constructionFeeder() {
final Map<String, Object> map = ImmutableMap.<String, Object>of();
final Map<String, Object> map00 = ImmutableMap.<String, Object>of("dim0", ImmutableList.<String>of("dim00", "dim01"));
final Map<String, Object> map10 = ImmutableMap.<String, Object>of("dim1", "dim10");
final Map<String, Object> map0null = new HashMap<>();
map0null.put("dim0", null);
final Map<String, Object> map1null = new HashMap<>();
map1null.put("dim1", null);
final Map<String, Object> mapAll = ImmutableMap.<String, Object>of("dim0", ImmutableList.<String>of("dim00", "dim01"), "dim1", "dim10");
final List<Map<String, Object>> maps = ImmutableList.of(map, map00, map10, map0null, map1null, mapAll);
return Iterables.<Object[]>concat(// First iterable tests permutations of the maps which are expected to be equal
Iterables.<Object[]>concat(new Iterable<Iterable<Object[]>>() {
@Override
public Iterator<Iterable<Object[]>> iterator() {
return new Iterator<Iterable<Object[]>>() {
long nextBitset = 1L;
@Override
public boolean hasNext() {
return nextBitset < (1L << maps.size());
}
@Override
public Iterable<Object[]> next() {
final BitSet bitset = BitSet.valueOf(new long[] { nextBitset++ });
final List<Map<String, Object>> myMaps = filterByBitset(maps, bitset);
return Collections2.transform(Collections2.permutations(myMaps), new Function<List<Map<String, Object>>, Object[]>() {
@Nullable
@Override
public Object[] apply(List<Map<String, Object>> input) {
return new Object[] { input, input, null };
}
});
}
@Override
public void remove() {
throw new UOE("Remove not suported");
}
};
}
}), // Second iterable tests combinations of the maps which may or may not be equal
Iterables.<Object[]>concat(new Iterable<Iterable<Object[]>>() {
@Override
public Iterator<Iterable<Object[]>> iterator() {
return new Iterator<Iterable<Object[]>>() {
long nextMap1Bits = 1L;
@Override
public boolean hasNext() {
return nextMap1Bits < (1L << maps.size());
}
@Override
public Iterable<Object[]> next() {
final BitSet bitset1 = BitSet.valueOf(new long[] { nextMap1Bits++ });
final List<Map<String, Object>> maplist1 = filterByBitset(maps, bitset1);
return new Iterable<Object[]>() {
@Override
public Iterator<Object[]> iterator() {
return new Iterator<Object[]>() {
long nextMap2Bits = 1L;
@Override
public boolean hasNext() {
return nextMap2Bits < (1L << maps.size());
}
@Override
public Object[] next() {
final List<Map<String, Object>> maplist2 = filterByBitset(maps, BitSet.valueOf(new long[] { nextMap2Bits++ }));
return new Object[] { maplist1, maplist2, filterNullValues(maplist1).equals(filterNullValues(maplist2)) ? null : SegmentValidationException.class };
}
@Override
public void remove() {
throw new UOE("remove not supported");
}
};
}
};
}
@Override
public void remove() {
throw new UOE("Remove not supported");
}
};
}
}));
}
use of com.google.common.collect.ImmutableList in project druid by druid-io.
the class CaffeineCacheProviderWithConfig method testBasicInjection.
@Test
public void testBasicInjection() throws Exception {
final CaffeineCacheConfig config = new CaffeineCacheConfig();
Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.<Module>of(binder -> {
binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test/redis");
binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
binder.bind(CaffeineCacheConfig.class).toInstance(config);
binder.bind(Cache.class).toProvider(CaffeineCacheProviderWithConfig.class).in(ManageLifecycle.class);
}));
final Lifecycle lifecycle = injector.getInstance(Lifecycle.class);
lifecycle.start();
try {
Cache cache = injector.getInstance(Cache.class);
Assert.assertEquals(CaffeineCache.class, cache.getClass());
} finally {
lifecycle.stop();
}
}
use of com.google.common.collect.ImmutableList in project druid by druid-io.
the class CaffeineCacheProviderWithConfig method testDefaultFromProperties.
@Test
public void testDefaultFromProperties() {
final String keyPrefix = "cache.config.prefix";
final Properties properties = new Properties();
final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.<Module>of(binder -> {
binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test");
binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
JsonConfigProvider.bind(binder, keyPrefix, CaffeineCacheConfig.class);
}));
final JsonConfigurator configurator = injector.getInstance(JsonConfigurator.class);
final JsonConfigProvider<CaffeineCacheConfig> caffeineCacheConfigJsonConfigProvider = JsonConfigProvider.of(keyPrefix, CaffeineCacheConfig.class);
caffeineCacheConfigJsonConfigProvider.inject(properties, configurator);
final CaffeineCacheConfig config = caffeineCacheConfigJsonConfigProvider.get().get();
Assert.assertEquals(-1, config.getExpireAfter());
Assert.assertEquals(-1, config.getSizeInBytes());
Assert.assertEquals(ForkJoinPool.commonPool(), config.createExecutor());
}
use of com.google.common.collect.ImmutableList in project druid by druid-io.
the class CaffeineCacheProviderWithConfig method testFromProperties.
@Test
public void testFromProperties() {
final String keyPrefix = "cache.config.prefix";
final Properties properties = new Properties();
properties.put(keyPrefix + ".expireAfter", "10");
properties.put(keyPrefix + ".sizeInBytes", "100");
properties.put(keyPrefix + ".cacheExecutorFactory", "single_thread");
final Injector injector = Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.<Module>of(binder -> {
binder.bindConstant().annotatedWith(Names.named("serviceName")).to("druid/test");
binder.bindConstant().annotatedWith(Names.named("servicePort")).to(0);
JsonConfigProvider.bind(binder, keyPrefix, CaffeineCacheConfig.class);
}));
final JsonConfigurator configurator = injector.getInstance(JsonConfigurator.class);
final JsonConfigProvider<CaffeineCacheConfig> caffeineCacheConfigJsonConfigProvider = JsonConfigProvider.of(keyPrefix, CaffeineCacheConfig.class);
caffeineCacheConfigJsonConfigProvider.inject(properties, configurator);
final CaffeineCacheConfig config = caffeineCacheConfigJsonConfigProvider.get().get();
Assert.assertEquals(10, config.getExpireAfter());
Assert.assertEquals(100, config.getSizeInBytes());
Assert.assertNotNull(config.createExecutor());
}
use of com.google.common.collect.ImmutableList in project dropwizard by dropwizard.
the class DropwizardConfiguredValidator method getGroup.
/**
* If the request entity is annotated with {@link Validated} then run
* validations in the specified constraint group else validate with the
* {@link Default} group
*/
private Class<?>[] getGroup(Invocable invocable) {
final ImmutableList.Builder<Class<?>[]> builder = ImmutableList.builder();
for (Parameter parameter : invocable.getParameters()) {
if (parameter.isAnnotationPresent(Validated.class)) {
builder.add(parameter.getAnnotation(Validated.class).value());
}
}
final ImmutableList<Class<?>[]> groups = builder.build();
switch(groups.size()) {
// No parameters were annotated with Validated, so validate under the default group
case 0:
return new Class<?>[] { Default.class };
// A single parameter was annotated with Validated, so use their group
case 1:
return groups.get(0);
// group.
default:
for (int i = 0; i < groups.size(); i++) {
for (int j = i; j < groups.size(); j++) {
if (!Arrays.deepEquals(groups.get(i), groups.get(j))) {
throw new WebApplicationException("Parameters must have the same validation groups in " + invocable.getHandlingMethod().getName(), 500);
}
}
}
return groups.get(0);
}
}
Aggregations