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());
}
}
}
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);
}
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();
}
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);
}
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());
}
Aggregations