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