Search in sources :

Example 11 with ImmutableList

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");
                }
            };
        }
    }));
}
Also used : HashMap(java.util.HashMap) BitSet(java.util.BitSet) UOE(io.druid.java.util.common.UOE) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Nullable(javax.annotation.Nullable)

Example 12 with ImmutableList

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();
    }
}
Also used : Module(com.google.inject.Module) Properties(java.util.Properties) Inject(com.google.inject.Inject) Test(org.junit.Test) Random(java.util.Random) Names(com.google.inject.name.Names) UUID(java.util.UUID) Field(java.lang.reflect.Field) Ints(com.google.common.primitives.Ints) GuiceInjectors(io.druid.guice.GuiceInjectors) ManageLifecycle(io.druid.guice.ManageLifecycle) Lifecycle(io.druid.java.util.common.lifecycle.Lifecycle) Injector(com.google.inject.Injector) Initialization(io.druid.initialization.Initialization) JsonConfigurator(io.druid.guice.JsonConfigurator) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ForkJoinPool(java.util.concurrent.ForkJoinPool) JsonConfigProvider(io.druid.guice.JsonConfigProvider) Map(java.util.Map) Assert(org.junit.Assert) Method(java.lang.reflect.Method) Before(org.junit.Before) Injector(com.google.inject.Injector) ManageLifecycle(io.druid.guice.ManageLifecycle) Lifecycle(io.druid.java.util.common.lifecycle.Lifecycle) ManageLifecycle(io.druid.guice.ManageLifecycle) Test(org.junit.Test)

Example 13 with ImmutableList

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());
}
Also used : Module(com.google.inject.Module) Properties(java.util.Properties) Inject(com.google.inject.Inject) Test(org.junit.Test) Random(java.util.Random) Names(com.google.inject.name.Names) UUID(java.util.UUID) Field(java.lang.reflect.Field) Ints(com.google.common.primitives.Ints) GuiceInjectors(io.druid.guice.GuiceInjectors) ManageLifecycle(io.druid.guice.ManageLifecycle) Lifecycle(io.druid.java.util.common.lifecycle.Lifecycle) Injector(com.google.inject.Injector) Initialization(io.druid.initialization.Initialization) JsonConfigurator(io.druid.guice.JsonConfigurator) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ForkJoinPool(java.util.concurrent.ForkJoinPool) JsonConfigProvider(io.druid.guice.JsonConfigProvider) Map(java.util.Map) Assert(org.junit.Assert) Method(java.lang.reflect.Method) Before(org.junit.Before) Injector(com.google.inject.Injector) JsonConfigurator(io.druid.guice.JsonConfigurator) Properties(java.util.Properties) Test(org.junit.Test)

Example 14 with ImmutableList

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());
}
Also used : Module(com.google.inject.Module) Properties(java.util.Properties) Inject(com.google.inject.Inject) Test(org.junit.Test) Random(java.util.Random) Names(com.google.inject.name.Names) UUID(java.util.UUID) Field(java.lang.reflect.Field) Ints(com.google.common.primitives.Ints) GuiceInjectors(io.druid.guice.GuiceInjectors) ManageLifecycle(io.druid.guice.ManageLifecycle) Lifecycle(io.druid.java.util.common.lifecycle.Lifecycle) Injector(com.google.inject.Injector) Initialization(io.druid.initialization.Initialization) JsonConfigurator(io.druid.guice.JsonConfigurator) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ForkJoinPool(java.util.concurrent.ForkJoinPool) JsonConfigProvider(io.druid.guice.JsonConfigProvider) Map(java.util.Map) Assert(org.junit.Assert) Method(java.lang.reflect.Method) Before(org.junit.Before) Injector(com.google.inject.Injector) JsonConfigurator(io.druid.guice.JsonConfigurator) Properties(java.util.Properties) Test(org.junit.Test)

Example 15 with ImmutableList

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);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ImmutableList(com.google.common.collect.ImmutableList) Parameter(org.glassfish.jersey.server.model.Parameter) Default(javax.validation.groups.Default)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)523 Path (java.nio.file.Path)128 List (java.util.List)105 SourcePath (com.facebook.buck.rules.SourcePath)91 Test (org.junit.Test)77 Step (com.facebook.buck.step.Step)76 ImmutableMap (com.google.common.collect.ImmutableMap)65 IOException (java.io.IOException)62 ArrayList (java.util.ArrayList)60 Map (java.util.Map)59 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)52 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)52 BuildTarget (com.facebook.buck.model.BuildTarget)47 MkdirStep (com.facebook.buck.step.fs.MkdirStep)39 ImmutableSet (com.google.common.collect.ImmutableSet)39 Arguments (com.spectralogic.ds3autogen.api.models.Arguments)38 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)36 HumanReadableException (com.facebook.buck.util.HumanReadableException)36 Optional (java.util.Optional)36 BuildRule (com.facebook.buck.rules.BuildRule)34