Search in sources :

Example 96 with TreeMap

use of java.util.TreeMap in project druid by druid-io.

the class IntervalsResourceTest method testGetIntervals.

@Test
public void testGetIntervals() {
    EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).atLeastOnce();
    EasyMock.replay(inventoryView);
    List<Interval> expectedIntervals = new ArrayList<>();
    expectedIntervals.add(new Interval("2010-01-01T00:00:00.000Z/2010-01-02T00:00:00.000Z"));
    expectedIntervals.add(new Interval("2010-01-22T00:00:00.000Z/2010-01-23T00:00:00.000Z"));
    IntervalsResource intervalsResource = new IntervalsResource(inventoryView, new AuthConfig());
    Response response = intervalsResource.getIntervals(request);
    TreeMap<Interval, Map<String, Map<String, Object>>> actualIntervals = (TreeMap) response.getEntity();
    Assert.assertEquals(2, actualIntervals.size());
    Assert.assertEquals(expectedIntervals.get(1), actualIntervals.firstKey());
    Assert.assertEquals(10L, actualIntervals.get(expectedIntervals.get(1)).get("datasource1").get("size"));
    Assert.assertEquals(1, actualIntervals.get(expectedIntervals.get(1)).get("datasource1").get("count"));
    Assert.assertEquals(expectedIntervals.get(0), actualIntervals.lastKey());
    Assert.assertEquals(20L, actualIntervals.get(expectedIntervals.get(0)).get("datasource1").get("size"));
    Assert.assertEquals(1, actualIntervals.get(expectedIntervals.get(0)).get("datasource1").get("count"));
    Assert.assertEquals(5L, actualIntervals.get(expectedIntervals.get(0)).get("datasource2").get("size"));
    Assert.assertEquals(1, actualIntervals.get(expectedIntervals.get(0)).get("datasource2").get("count"));
}
Also used : Response(javax.ws.rs.core.Response) ArrayList(java.util.ArrayList) AuthConfig(io.druid.server.security.AuthConfig) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 97 with TreeMap

use of java.util.TreeMap in project druid by druid-io.

the class DatasourcesResourceTest method testGetSegmentDataSourceIntervals.

@Test
public void testGetSegmentDataSourceIntervals() {
    server = new DruidServer("who", "host", 1234, "historical", "tier1", 0);
    server.addDataSegment(dataSegmentList.get(0).getIdentifier(), dataSegmentList.get(0));
    server.addDataSegment(dataSegmentList.get(1).getIdentifier(), dataSegmentList.get(1));
    server.addDataSegment(dataSegmentList.get(2).getIdentifier(), dataSegmentList.get(2));
    EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).atLeastOnce();
    EasyMock.replay(inventoryView);
    List<Interval> expectedIntervals = new ArrayList<>();
    expectedIntervals.add(new Interval("2010-01-22T00:00:00.000Z/2010-01-23T00:00:00.000Z"));
    expectedIntervals.add(new Interval("2010-01-01T00:00:00.000Z/2010-01-02T00:00:00.000Z"));
    DatasourcesResource datasourcesResource = new DatasourcesResource(inventoryView, null, null, new AuthConfig());
    Response response = datasourcesResource.getSegmentDataSourceIntervals("invalidDataSource", null, null);
    Assert.assertEquals(response.getEntity(), null);
    response = datasourcesResource.getSegmentDataSourceIntervals("datasource1", null, null);
    TreeSet<Interval> actualIntervals = (TreeSet) response.getEntity();
    Assert.assertEquals(2, actualIntervals.size());
    Assert.assertEquals(expectedIntervals.get(0), actualIntervals.first());
    Assert.assertEquals(expectedIntervals.get(1), actualIntervals.last());
    response = datasourcesResource.getSegmentDataSourceIntervals("datasource1", "simple", null);
    TreeMap<Interval, Map<String, Object>> results = (TreeMap) response.getEntity();
    Assert.assertEquals(2, results.size());
    Assert.assertEquals(expectedIntervals.get(0), results.firstKey());
    Assert.assertEquals(expectedIntervals.get(1), results.lastKey());
    Assert.assertEquals(1, results.firstEntry().getValue().get("count"));
    Assert.assertEquals(1, results.lastEntry().getValue().get("count"));
    response = datasourcesResource.getSegmentDataSourceIntervals("datasource1", null, "full");
    results = ((TreeMap<Interval, Map<String, Object>>) response.getEntity());
    int i = 1;
    for (Map.Entry<Interval, Map<String, Object>> entry : results.entrySet()) {
        Assert.assertEquals(dataSegmentList.get(i).getInterval(), entry.getKey());
        Assert.assertEquals(dataSegmentList.get(i), ((Map<String, Object>) entry.getValue().get(dataSegmentList.get(i).getIdentifier())).get("metadata"));
        i--;
    }
    EasyMock.verify(inventoryView);
}
Also used : ArrayList(java.util.ArrayList) DruidServer(io.druid.client.DruidServer) AuthConfig(io.druid.server.security.AuthConfig) TreeMap(java.util.TreeMap) Response(javax.ws.rs.core.Response) TreeSet(java.util.TreeSet) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 98 with TreeMap

use of java.util.TreeMap in project druid by druid-io.

the class ServerSelector method getCandidates.

public List<DruidServerMetadata> getCandidates(final int numCandidates) {
    List<DruidServerMetadata> result = Lists.newArrayList();
    synchronized (this) {
        final DataSegment target = segment.get();
        for (Map.Entry<Integer, Set<QueryableDruidServer>> entry : toPrioritizedServers().entrySet()) {
            Set<QueryableDruidServer> servers = entry.getValue();
            TreeMap<Integer, Set<QueryableDruidServer>> tieredMap = Maps.newTreeMap();
            while (!servers.isEmpty()) {
                // strategy.pick() removes entry
                tieredMap.put(entry.getKey(), servers);
                QueryableDruidServer server = strategy.pick(tieredMap, target);
                if (server == null) {
                    // regard this as any server in tieredMap is not appropriate
                    break;
                }
                result.add(server.getServer().getMetadata());
                if (numCandidates > 0 && result.size() >= numCandidates) {
                    return result;
                }
                servers.remove(server);
            }
        }
    }
    return result;
}
Also used : Set(java.util.Set) DruidServerMetadata(io.druid.server.coordination.DruidServerMetadata) DataSegment(io.druid.timeline.DataSegment) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 99 with TreeMap

use of java.util.TreeMap in project druid by druid-io.

the class CachingClusteredClientTest method populateTimeline.

private List<Map<DruidServer, ServerExpectations>> populateTimeline(List<Interval> queryIntervals, List<List<Iterable<Result<Object>>>> expectedResults, int numQueryIntervals, List<Object> mocks) {
    timeline = new VersionedIntervalTimeline<>(Ordering.natural());
    final List<Map<DruidServer, ServerExpectations>> serverExpectationList = Lists.newArrayList();
    for (int k = 0; k < numQueryIntervals + 1; ++k) {
        final int numChunks = expectedResults.get(k).size();
        final TreeMap<DruidServer, ServerExpectations> serverExpectations = Maps.newTreeMap();
        serverExpectationList.add(serverExpectations);
        for (int j = 0; j < numChunks; ++j) {
            DruidServer lastServer = servers[random.nextInt(servers.length)];
            if (!serverExpectations.containsKey(lastServer)) {
                serverExpectations.put(lastServer, new ServerExpectations(lastServer, makeMock(mocks, QueryRunner.class)));
            }
            DataSegment mockSegment = makeMock(mocks, DataSegment.class);
            ServerExpectation expectation = new ServerExpectation(// interval/chunk
            String.format("%s_%s", k, j), queryIntervals.get(k), mockSegment, expectedResults.get(k).get(j));
            serverExpectations.get(lastServer).addExpectation(expectation);
            ServerSelector selector = new ServerSelector(expectation.getSegment(), new HighestPriorityTierSelectorStrategy(new RandomServerSelectorStrategy()));
            selector.addServerAndUpdateSegment(new QueryableDruidServer(lastServer, null), selector.getSegment());
            final ShardSpec shardSpec;
            if (numChunks == 1) {
                shardSpec = new SingleDimensionShardSpec("dimAll", null, null, 0);
            } else {
                String start = null;
                String end = null;
                if (j > 0) {
                    start = String.valueOf(j);
                }
                if (j + 1 < numChunks) {
                    end = String.valueOf(j + 1);
                }
                shardSpec = new SingleDimensionShardSpec("dim" + k, start, end, j);
            }
            EasyMock.expect(mockSegment.getShardSpec()).andReturn(shardSpec).anyTimes();
            timeline.add(queryIntervals.get(k), String.valueOf(k), shardSpec.createChunk(selector));
        }
    }
    return serverExpectationList;
}
Also used : QueryableDruidServer(io.druid.client.selector.QueryableDruidServer) DataSegment(io.druid.timeline.DataSegment) SingleDimensionShardSpec(io.druid.timeline.partition.SingleDimensionShardSpec) ShardSpec(io.druid.timeline.partition.ShardSpec) NoneShardSpec(io.druid.timeline.partition.NoneShardSpec) QueryableDruidServer(io.druid.client.selector.QueryableDruidServer) ServerSelector(io.druid.client.selector.ServerSelector) HighestPriorityTierSelectorStrategy(io.druid.client.selector.HighestPriorityTierSelectorStrategy) Map(java.util.Map) TreeMap(java.util.TreeMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) SingleDimensionShardSpec(io.druid.timeline.partition.SingleDimensionShardSpec) RandomServerSelectorStrategy(io.druid.client.selector.RandomServerSelectorStrategy)

Example 100 with TreeMap

use of java.util.TreeMap in project hbase by apache.

the class BalancerTestBase method assertRegionReplicaPlacement.

/**
   * Checks whether region replicas are not hosted on the same host.
   */
public void assertRegionReplicaPlacement(Map<ServerName, List<HRegionInfo>> serverMap, RackManager rackManager) {
    TreeMap<String, Set<HRegionInfo>> regionsPerHost = new TreeMap<>();
    TreeMap<String, Set<HRegionInfo>> regionsPerRack = new TreeMap<>();
    for (Entry<ServerName, List<HRegionInfo>> entry : serverMap.entrySet()) {
        String hostname = entry.getKey().getHostname();
        Set<HRegionInfo> infos = regionsPerHost.get(hostname);
        if (infos == null) {
            infos = new HashSet<>();
            regionsPerHost.put(hostname, infos);
        }
        for (HRegionInfo info : entry.getValue()) {
            HRegionInfo primaryInfo = RegionReplicaUtil.getRegionInfoForDefaultReplica(info);
            if (!infos.add(primaryInfo)) {
                Assert.fail("Two or more region replicas are hosted on the same host after balance");
            }
        }
    }
    if (rackManager == null) {
        return;
    }
    for (Entry<ServerName, List<HRegionInfo>> entry : serverMap.entrySet()) {
        String rack = rackManager.getRack(entry.getKey());
        Set<HRegionInfo> infos = regionsPerRack.get(rack);
        if (infos == null) {
            infos = new HashSet<>();
            regionsPerRack.put(rack, infos);
        }
        for (HRegionInfo info : entry.getValue()) {
            HRegionInfo primaryInfo = RegionReplicaUtil.getRegionInfoForDefaultReplica(info);
            if (!infos.add(primaryInfo)) {
                Assert.fail("Two or more region replicas are hosted on the same rack after balance");
            }
        }
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) SortedSet(java.util.SortedSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) ServerName(org.apache.hadoop.hbase.ServerName) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TreeMap(java.util.TreeMap)

Aggregations

TreeMap (java.util.TreeMap)4400 Map (java.util.Map)1245 ArrayList (java.util.ArrayList)930 HashMap (java.util.HashMap)871 Test (org.junit.Test)614 List (java.util.List)542 Before (org.junit.Before)505 IOException (java.io.IOException)402 HashSet (java.util.HashSet)301 Set (java.util.Set)268 File (java.io.File)267 SortedMap (java.util.SortedMap)240 TreeSet (java.util.TreeSet)213 LinkedHashMap (java.util.LinkedHashMap)196 Key (org.apache.accumulo.core.data.Key)156 Value (org.apache.accumulo.core.data.Value)156 Iterator (java.util.Iterator)149 NavigableMap (java.util.NavigableMap)124 Collection (java.util.Collection)115 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)111