Search in sources :

Example 6 with MapMaker

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);
}
Also used : MapMaker(com.google.common.collect.MapMaker) DateTime(org.joda.time.DateTime) Result(io.druid.query.Result) Test(org.junit.Test)

Example 7 with MapMaker

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;
}
Also used : MapMaker(com.google.common.collect.MapMaker)

Example 8 with 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");
}
Also used : MapMaker(com.google.common.collect.MapMaker) Pointer(org.directmemory.memory.Pointer) Test(org.junit.Test)

Example 9 with MapMaker

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();
    }
}
Also used : MapMaker(com.google.common.collect.MapMaker) ByteBuffer(java.nio.ByteBuffer)

Example 10 with MapMaker

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;
            }
        }
    });
}
Also used : ComputeFunction(com.alibaba.otter.shared.common.utils.cache.RefreshMemoryMirror.ComputeFunction) Function(com.google.common.base.Function) ComputeFunction(com.alibaba.otter.shared.common.utils.cache.RefreshMemoryMirror.ComputeFunction) Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) Node(com.alibaba.otter.shared.common.model.config.node.Node) MapMaker(com.google.common.collect.MapMaker) ConfigException(com.alibaba.otter.shared.common.model.config.ConfigException)

Aggregations

MapMaker (com.google.common.collect.MapMaker)32 EventData (com.alibaba.otter.shared.etl.model.EventData)9 Test (org.junit.Test)9 BaseDbTest (com.alibaba.otter.node.etl.BaseDbTest)8 RowKey (com.alibaba.otter.node.etl.load.loader.db.DbLoadMerger.RowKey)8 EventColumn (com.alibaba.otter.shared.etl.model.EventColumn)8 Test (org.testng.annotations.Test)8 List (java.util.List)7 DateTime (org.joda.time.DateTime)7 Sequence (io.druid.java.util.common.guava.Sequence)6 TimeseriesQueryQueryToolChest (io.druid.query.timeseries.TimeseriesQueryQueryToolChest)5 TimeseriesResultValue (io.druid.query.timeseries.TimeseriesResultValue)5 Interval (org.joda.time.Interval)5 Function (com.google.common.base.Function)4 Result (io.druid.query.Result)3 ByteBuffer (java.nio.ByteBuffer)3 ConfigException (com.alibaba.otter.shared.common.model.config.ConfigException)2 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)2 Node (com.alibaba.otter.shared.common.model.config.node.Node)2 ComputeFunction (com.alibaba.otter.shared.common.utils.cache.RefreshMemoryMirror.ComputeFunction)2