Search in sources :

Example 6 with LookupsState

use of org.apache.druid.query.lookup.LookupsState in project druid by druid-io.

the class LookupCoordinatorManagerTest method testLookupManagementLoop.

@Test(timeout = 60_000L)
public void testLookupManagementLoop() throws Exception {
    Map<String, LookupExtractorFactoryMapContainer> lookup1 = ImmutableMap.of("lookup1", new LookupExtractorFactoryMapContainer("v1", ImmutableMap.of("k1", "v1")));
    Map<String, Map<String, LookupExtractorFactoryMapContainer>> configuredLookups = ImmutableMap.of("tier1", lookup1);
    EasyMock.reset(configManager);
    EasyMock.expect(configManager.watch(EasyMock.eq(LookupCoordinatorManager.LOOKUP_CONFIG_KEY), EasyMock.<TypeReference>anyObject(), EasyMock.<AtomicReference>isNull())).andReturn(new AtomicReference<>(configuredLookups)).once();
    EasyMock.replay(configManager);
    HostAndPortWithScheme host1 = HostAndPortWithScheme.fromParts("http", "host1", 1234);
    HostAndPortWithScheme host2 = HostAndPortWithScheme.fromParts("http", "host2", 3456);
    EasyMock.reset(lookupNodeDiscovery);
    EasyMock.expect(lookupNodeDiscovery.getAllTiers()).andReturn(ImmutableSet.of("tier1")).once();
    EasyMock.expect(lookupNodeDiscovery.getNodesInTier("tier1")).andReturn(ImmutableList.of(host1, host2)).anyTimes();
    EasyMock.replay(lookupNodeDiscovery);
    LookupCoordinatorManager.LookupsCommunicator lookupsCommunicator = EasyMock.createMock(LookupCoordinatorManager.LookupsCommunicator.class);
    EasyMock.expect(lookupsCommunicator.getLookupStateForNode(host1)).andReturn(new LookupsState<>(ImmutableMap.of("lookup0", new LookupExtractorFactoryMapContainer("v1", ImmutableMap.of("k0", "v0"))), null, null)).once();
    LookupsState<LookupExtractorFactoryMapContainer> host1UpdatedState = new LookupsState<>(lookup1, null, null);
    EasyMock.expect(lookupsCommunicator.updateNode(host1, new LookupsState<>(null, lookup1, ImmutableSet.of("lookup0")))).andReturn(host1UpdatedState).once();
    EasyMock.expect(lookupsCommunicator.getLookupStateForNode(host2)).andReturn(new LookupsState<>(ImmutableMap.of("lookup3", new LookupExtractorFactoryMapContainer("v1", ImmutableMap.of("k0", "v0")), "lookup1", new LookupExtractorFactoryMapContainer("v0", ImmutableMap.of("k0", "v0"))), null, null)).once();
    LookupsState<LookupExtractorFactoryMapContainer> host2UpdatedState = new LookupsState<>(null, lookup1, null);
    EasyMock.expect(lookupsCommunicator.updateNode(host2, new LookupsState<>(null, lookup1, ImmutableSet.of("lookup3")))).andReturn(host2UpdatedState).once();
    EasyMock.replay(lookupsCommunicator);
    LookupCoordinatorManagerConfig lookupCoordinatorManagerConfig = new LookupCoordinatorManagerConfig() {

        @Override
        public long getInitialDelay() {
            return 1;
        }

        @Override
        public int getThreadPoolSize() {
            return 2;
        }
    };
    final LookupCoordinatorManager manager = new LookupCoordinatorManager(druidNodeDiscoveryProvider, configManager, lookupCoordinatorManagerConfig, lookupsCommunicator, lookupNodeDiscovery);
    Assert.assertTrue(manager.knownOldState.get().isEmpty());
    manager.start();
    Map<HostAndPort, LookupsState<LookupExtractorFactoryMapContainer>> expectedKnownState = ImmutableMap.of(host1.getHostAndPort(), host1UpdatedState, host2.getHostAndPort(), host2UpdatedState);
    while (!expectedKnownState.equals(manager.knownOldState.get())) {
        Thread.sleep(100);
    }
    EasyMock.verify(lookupNodeDiscovery, configManager, lookupsCommunicator);
}
Also used : HostAndPortWithScheme(org.apache.druid.server.http.HostAndPortWithScheme) AtomicReference(java.util.concurrent.atomic.AtomicReference) HostAndPort(com.google.common.net.HostAndPort) LookupsState(org.apache.druid.query.lookup.LookupsState) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 7 with LookupsState

use of org.apache.druid.query.lookup.LookupsState in project druid by druid-io.

the class LookupCoordinatorResourceTest method testGetAllNodesStatusDetailedFalse.

@Test
public void testGetAllNodesStatusDetailedFalse() {
    final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
    EasyMock.expect(lookupCoordinatorManager.getKnownLookups()).andReturn(SINGLE_TIER_MAP);
    EasyMock.expect(lookupCoordinatorManager.getLastKnownLookupsStateOnNodes()).andReturn(NODES_LOOKUP_STATE);
    EasyMock.expect(lookupCoordinatorManager.discoverNodesInTier(LOOKUP_TIER)).andReturn(ImmutableList.of(LOOKUP_NODE));
    EasyMock.replay(lookupCoordinatorManager);
    final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(lookupCoordinatorManager, MAPPER, MAPPER);
    final Response response = lookupCoordinatorResource.getAllNodesStatus(false, false);
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals(ImmutableMap.of(LOOKUP_TIER, ImmutableMap.of(LOOKUP_NODE, new LookupsState(ImmutableMap.of(LOOKUP_NAME, SINGLE_LOOKUP.getVersion()), null, null))), response.getEntity());
    EasyMock.verify(lookupCoordinatorManager);
}
Also used : Response(javax.ws.rs.core.Response) LookupCoordinatorManager(org.apache.druid.server.lookup.cache.LookupCoordinatorManager) LookupsState(org.apache.druid.query.lookup.LookupsState) Test(org.junit.Test)

Aggregations

LookupsState (org.apache.druid.query.lookup.LookupsState)7 HostAndPort (com.google.common.net.HostAndPort)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 IOException (java.io.IOException)4 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 LookupExtractorFactoryMapContainer (org.apache.druid.server.lookup.cache.LookupExtractorFactoryMapContainer)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Response (javax.ws.rs.core.Response)2 LookupCoordinatorManager (org.apache.druid.server.lookup.cache.LookupCoordinatorManager)2 Test (org.junit.Test)2 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1