use of com.google.common.collect.MapMaker in project druid by druid-io.
the class TimeBoundaryQueryRunnerTest method testTimeBoundaryMin.
@Test
@SuppressWarnings("unchecked")
public void testTimeBoundaryMin() {
TimeBoundaryQuery timeBoundaryQuery = Druids.newTimeBoundaryQueryBuilder().dataSource("testing").bound(TimeBoundaryQuery.MIN_TIME).build();
Map<String, Object> context = new MapMaker().makeMap();
context.put(Result.MISSING_SEGMENTS_KEY, Lists.newArrayList());
Iterable<Result<TimeBoundaryResultValue>> results = Sequences.toList(runner.run(timeBoundaryQuery, context), Lists.<Result<TimeBoundaryResultValue>>newArrayList());
TimeBoundaryResultValue val = results.iterator().next().getValue();
DateTime minTime = val.getMinTime();
DateTime maxTime = val.getMaxTime();
Assert.assertEquals(new DateTime("2011-01-12T00:00:00.000Z"), minTime);
Assert.assertNull(maxTime);
}
use of com.google.common.collect.MapMaker in project pinpoint by naver.
the class Maps method createWeakMapMaker.
private static MapMaker createWeakMapMaker() {
final MapMaker mapMaker = new MapMaker();
mapMaker.weakKeys();
return mapMaker;
}
use of com.google.common.collect.MapMaker in project DirectMemory by raffaeleguidi.
the class MallocTests method withMap.
@Test
public void withMap() {
ConcurrentMap<Long, Pointer> map = new MapMaker().concurrencyLevel(4).initialCapacity(500000).makeMap();
String str = "This is the string to store into the off-heap memory";
int size = str.length();
int howMany = 1000000;
byte[] payload = str.getBytes();
logger.info("adding " + howMany + " strings of " + size + " bytes...");
for (long i = 0; i < howMany; i++) {
Pointer p = mem.store(payload);
map.put(i, p);
}
logger.info("...done");
}
use of com.google.common.collect.MapMaker in project DirectMemory by raffaeleguidi.
the class PreliminarBenchmarks method pump.
private void pump(int ops) {
ConcurrentMap<String, ByteBuffer> test = new MapMaker().concurrencyLevel(4).maximumSize(ops).expireAfterWrite(10, TimeUnit.MINUTES).makeMap();
logger.info(Ram.inMb(ops * payload.length) + " to store");
double started = System.currentTimeMillis();
for (int i = 0; i < ops; i++) {
ByteBuffer buf = ByteBuffer.allocateDirect(payload.length);
buf.put(payload);
test.put("test-" + i, buf);
}
double finished = System.currentTimeMillis();
logger.info("done in " + (finished - started) / 1000 + " seconds");
for (ByteBuffer buf : test.values()) {
buf.clear();
}
}
use of com.google.common.collect.MapMaker in project otter by alibaba.
the class ArbitrateConfigImpl method afterPropertiesSet.
public void afterPropertiesSet() throws Exception {
// 获取一下nid变量
channelMapping = new MapMaker().makeComputingMap(new Function<Long, Long>() {
public Long apply(Long pipelineId) {
// 处理下pipline -> channel映射关系不存在的情况
Channel channel = channelService.findByPipelineId(pipelineId);
if (channel == null) {
throw new ConfigException("No Such Channel by pipelineId[" + pipelineId + "]");
}
// 排除下自己
updateMapping(channel, pipelineId);
// 更新下channelCache
channelCache.put(channel.getId(), channel);
return channel.getId();
}
});
channelCache = new RefreshMemoryMirror<Long, Channel>(timeout, new ComputeFunction<Long, Channel>() {
public Channel apply(Long key, Channel oldValue) {
Channel channel = channelService.findById(key);
if (channel == null) {
// 其他情况直接返回内存中的旧值
return oldValue;
} else {
// 排除下自己
updateMapping(channel, null);
return channel;
}
}
});
nodeCache = new RefreshMemoryMirror<Long, Node>(timeout, new ComputeFunction<Long, Node>() {
public Node apply(Long key, Node oldValue) {
Node node = nodeService.findById(key);
if (node == null) {
return oldValue;
} else {
return node;
}
}
});
}
Aggregations