Search in sources :

Example 26 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableList in project buck by facebook.

the class CxxCompilationDatabase method getBuildSteps.

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    steps.add(new MkdirStep(getProjectFilesystem(), outputJsonFile.getParent()));
    steps.add(new GenerateCompilationCommandsJson(context.getSourcePathResolver(), context.getSourcePathResolver().getRelativePath(getSourcePathToOutput())));
    return steps.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) MkdirStep(com.facebook.buck.step.fs.MkdirStep) Step(com.facebook.buck.step.Step) MkdirStep(com.facebook.buck.step.fs.MkdirStep) AbstractExecutionStep(com.facebook.buck.step.AbstractExecutionStep)

Example 27 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.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 28 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.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 29 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.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 30 with ImmutableList

use of org.apache.beam.vendor.calcite.v1_28_0.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)1079 List (java.util.List)293 ArrayList (java.util.ArrayList)169 Test (org.junit.Test)161 Map (java.util.Map)152 Path (java.nio.file.Path)149 ImmutableMap (com.google.common.collect.ImmutableMap)127 IOException (java.io.IOException)112 Set (java.util.Set)99 ImmutableSet (com.google.common.collect.ImmutableSet)98 SourcePath (com.facebook.buck.rules.SourcePath)91 Optional (java.util.Optional)89 HashMap (java.util.HashMap)85 Step (com.facebook.buck.step.Step)76 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)71 Collectors (java.util.stream.Collectors)62 File (java.io.File)58 HashSet (java.util.HashSet)58 Nullable (javax.annotation.Nullable)54 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)52