Search in sources :

Example 26 with ImmutableMap

use of com.google.common.collect.ImmutableMap in project buck by facebook.

the class ProjectGeneratorTest method assertHasSingletonSourcesPhaseWithSourcesAndFlags.

private void assertHasSingletonSourcesPhaseWithSourcesAndFlags(PBXTarget target, ImmutableMap<String, Optional<String>> sourcesAndFlags) {
    PBXSourcesBuildPhase sourcesBuildPhase = ProjectGeneratorTestUtils.getSingletonPhaseByType(target, PBXSourcesBuildPhase.class);
    assertEquals("Sources build phase should have correct number of sources", sourcesAndFlags.size(), sourcesBuildPhase.getFiles().size());
    // map keys to absolute paths
    ImmutableMap.Builder<String, Optional<String>> absolutePathFlagMapBuilder = ImmutableMap.builder();
    for (Map.Entry<String, Optional<String>> name : sourcesAndFlags.entrySet()) {
        absolutePathFlagMapBuilder.put(projectFilesystem.getRootPath().resolve(name.getKey()).toAbsolutePath().normalize().toString(), name.getValue());
    }
    ImmutableMap<String, Optional<String>> absolutePathFlagMap = absolutePathFlagMapBuilder.build();
    for (PBXBuildFile file : sourcesBuildPhase.getFiles()) {
        String filePath = assertFileRefIsRelativeAndResolvePath(file.getFileRef());
        Optional<String> flags = absolutePathFlagMap.get(filePath);
        assertNotNull(String.format("Unexpected file ref '%s' found", filePath), flags);
        if (flags.isPresent()) {
            assertTrue("Build file should have settings dictionary", file.getSettings().isPresent());
            NSDictionary buildFileSettings = file.getSettings().get();
            NSString compilerFlags = (NSString) buildFileSettings.get("COMPILER_FLAGS");
            assertNotNull("Build file settings should have COMPILER_FLAGS entry", compilerFlags);
            assertEquals("Build file settings should be expected value", flags.get(), compilerFlags.getContent());
        } else {
            assertFalse("Build file should not have settings dictionary", file.getSettings().isPresent());
        }
    }
}
Also used : Optional(java.util.Optional) NSDictionary(com.dd.plist.NSDictionary) PBXBuildFile(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildFile) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) NSString(com.dd.plist.NSString) ImmutableMap(com.google.common.collect.ImmutableMap) PBXSourcesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXSourcesBuildPhase)

Example 27 with ImmutableMap

use of com.google.common.collect.ImmutableMap in project druid by druid-io.

the class FillCapacityWithAffinityWorkerSelectStrategy method findWorkerForTask.

@Override
public Optional<ImmutableWorkerInfo> findWorkerForTask(final WorkerTaskRunnerConfig config, final ImmutableMap<String, ImmutableWorkerInfo> zkWorkers, final Task task) {
    // don't run other datasources on affinity workers; we only want our configured datasources to run on them
    ImmutableMap.Builder<String, ImmutableWorkerInfo> builder = new ImmutableMap.Builder<>();
    for (String workerHost : zkWorkers.keySet()) {
        if (!affinityWorkerHosts.contains(workerHost)) {
            builder.put(workerHost, zkWorkers.get(workerHost));
        }
    }
    ImmutableMap<String, ImmutableWorkerInfo> eligibleWorkers = builder.build();
    List<String> workerHosts = affinityConfig.getAffinity().get(task.getDataSource());
    if (workerHosts == null) {
        return super.findWorkerForTask(config, eligibleWorkers, task);
    }
    ImmutableMap.Builder<String, ImmutableWorkerInfo> affinityBuilder = new ImmutableMap.Builder<>();
    for (String workerHost : workerHosts) {
        ImmutableWorkerInfo zkWorker = zkWorkers.get(workerHost);
        if (zkWorker != null) {
            affinityBuilder.put(workerHost, zkWorker);
        }
    }
    ImmutableMap<String, ImmutableWorkerInfo> affinityWorkers = affinityBuilder.build();
    if (!affinityWorkers.isEmpty()) {
        Optional<ImmutableWorkerInfo> retVal = super.findWorkerForTask(config, affinityWorkers, task);
        if (retVal.isPresent()) {
            return retVal;
        }
    }
    return super.findWorkerForTask(config, eligibleWorkers, task);
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableWorkerInfo(io.druid.indexing.overlord.ImmutableWorkerInfo)

Example 28 with ImmutableMap

use of com.google.common.collect.ImmutableMap in project druid by druid-io.

the class AsyncQueryRunnerTest method testQueryTimeoutHonored.

@Test(timeout = TEST_TIMEOUT)
public void testQueryTimeoutHonored() {
    QueryRunner baseRunner = new QueryRunner() {

        @Override
        public Sequence run(Query query, Map responseContext) {
            try {
                Thread.sleep(Long.MAX_VALUE);
                throw new RuntimeException("query should not have completed");
            } catch (InterruptedException ex) {
                throw Throwables.propagate(ex);
            }
        }
    };
    AsyncQueryRunner asyncRunner = new AsyncQueryRunner<>(baseRunner, executor, QueryRunnerTestHelper.NOOP_QUERYWATCHER);
    Sequence lazy = asyncRunner.run(query.withOverriddenContext(ImmutableMap.<String, Object>of(QueryContextKeys.TIMEOUT, 1)), Collections.EMPTY_MAP);
    try {
        Sequences.toList(lazy, Lists.newArrayList());
    } catch (RuntimeException ex) {
        Assert.assertTrue(ex.getCause() instanceof TimeoutException);
        return;
    }
    Assert.fail();
}
Also used : Sequence(io.druid.java.util.common.guava.Sequence) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 29 with ImmutableMap

use of com.google.common.collect.ImmutableMap in project druid by druid-io.

the class DataSourceMetadataQueryTest method testResultSerialization.

@Test
public void testResultSerialization() {
    final DataSourceMetadataResultValue resultValue = new DataSourceMetadataResultValue(new DateTime("2000-01-01T00Z"));
    final Map<String, Object> resultValueMap = new DefaultObjectMapper().convertValue(resultValue, new TypeReference<Map<String, Object>>() {
    });
    Assert.assertEquals(ImmutableMap.<String, Object>of("maxIngestedEventTime", "2000-01-01T00:00:00.000Z"), resultValueMap);
}
Also used : DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 30 with ImmutableMap

use of com.google.common.collect.ImmutableMap in project druid by druid-io.

the class QuerySegmentSpecTest method testSerializationSegments.

@Test
public void testSerializationSegments() throws Exception {
    QuerySegmentSpec spec = jsonMapper.convertValue(ImmutableMap.<String, Object>of("type", "segments", "segments", ImmutableList.<Map<String, Object>>of(ImmutableMap.<String, Object>of("itvl", "2011-07-01/2011-10-10", "ver", "1", "part", 0), ImmutableMap.<String, Object>of("itvl", "2011-07-01/2011-10-10", "ver", "1", "part", 1), ImmutableMap.<String, Object>of("itvl", "2011-11-01/2011-11-10", "ver", "2", "part", 10))), QuerySegmentSpec.class);
    Assert.assertTrue(spec instanceof MultipleSpecificSegmentSpec);
    Assert.assertEquals(ImmutableList.of(new Interval("2011-07-01/2011-10-10"), new Interval("2011-11-01/2011-11-10")), spec.getIntervals());
    Assert.assertEquals(ImmutableList.of(new SegmentDescriptor(new Interval("2011-07-01/2011-10-10"), "1", 0), new SegmentDescriptor(new Interval("2011-07-01/2011-10-10"), "1", 1), new SegmentDescriptor(new Interval("2011-11-01/2011-11-10"), "2", 10)), ((MultipleSpecificSegmentSpec) spec).getDescriptors());
}
Also used : SegmentDescriptor(io.druid.query.SegmentDescriptor) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)702 Map (java.util.Map)346 Test (org.junit.Test)195 HashMap (java.util.HashMap)144 ImmutableList (com.google.common.collect.ImmutableList)126 Path (java.nio.file.Path)104 List (java.util.List)100 ImmutableSet (com.google.common.collect.ImmutableSet)89 IOException (java.io.IOException)84 ArrayList (java.util.ArrayList)74 Set (java.util.Set)69 Optional (java.util.Optional)61 BuildTarget (com.facebook.buck.model.BuildTarget)57 File (java.io.File)57 Collectors (java.util.stream.Collectors)45 HashSet (java.util.HashSet)44 SourcePath (com.facebook.buck.rules.SourcePath)41 VisibleForTesting (com.google.common.annotations.VisibleForTesting)39 Nullable (javax.annotation.Nullable)39 LinkedHashMap (java.util.LinkedHashMap)36