Search in sources :

Example 16 with LookupCoordinatorManager

use of io.druid.server.lookup.cache.LookupCoordinatorManager in project druid by druid-io.

the class LookupCoordinatorResourceTest method testExceptionalGetTier.

@Test
public void testExceptionalGetTier() {
    final String tier = "some tier";
    final String errMsg = "some error";
    final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
    EasyMock.expect(lookupCoordinatorManager.getKnownLookups()).andThrow(new RuntimeException(errMsg)).once();
    EasyMock.replay(lookupCoordinatorManager);
    final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(lookupCoordinatorManager, mapper, mapper);
    final Response response = lookupCoordinatorResource.getSpecificTier(tier);
    Assert.assertEquals(500, response.getStatus());
    Assert.assertEquals(ImmutableMap.of("error", errMsg), response.getEntity());
    EasyMock.verify(lookupCoordinatorManager);
}
Also used : Response(javax.ws.rs.core.Response) LookupCoordinatorManager(io.druid.server.lookup.cache.LookupCoordinatorManager) Test(org.junit.Test)

Example 17 with LookupCoordinatorManager

use of io.druid.server.lookup.cache.LookupCoordinatorManager in project druid by druid-io.

the class LookupCoordinatorResourceTest method testDBErrNewLookup.

@Test
public void testDBErrNewLookup() throws Exception {
    final String author = "some author";
    final String comment = "some comment";
    final String ip = "127.0.0.1";
    final HttpServletRequest request = EasyMock.createStrictMock(HttpServletRequest.class);
    EasyMock.expect(request.getContentType()).andReturn(MediaType.APPLICATION_JSON).once();
    EasyMock.expect(request.getRemoteAddr()).andReturn(ip).once();
    final Capture<AuditInfo> auditInfoCapture = Capture.newInstance();
    final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
    EasyMock.expect(lookupCoordinatorManager.updateLookup(EasyMock.eq(LOOKUP_TIER), EasyMock.eq(LOOKUP_NAME), EasyMock.eq(ImmutableMap.<String, Object>of()), EasyMock.capture(auditInfoCapture))).andReturn(false).once();
    EasyMock.replay(lookupCoordinatorManager, request);
    final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(lookupCoordinatorManager, mapper, mapper);
    final Response response = lookupCoordinatorResource.createOrUpdateLookup(LOOKUP_TIER, LOOKUP_NAME, author, comment, EMPTY_MAP_SOURCE.openStream(), request);
    Assert.assertEquals(500, response.getStatus());
    Assert.assertEquals(ImmutableMap.of("error", "Unknown error updating configuration"), response.getEntity());
    Assert.assertTrue(auditInfoCapture.hasCaptured());
    final AuditInfo auditInfo = auditInfoCapture.getValue();
    Assert.assertEquals(author, auditInfo.getAuthor());
    Assert.assertEquals(comment, auditInfo.getComment());
    Assert.assertEquals(ip, auditInfo.getIp());
    EasyMock.verify(lookupCoordinatorManager, request);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(javax.ws.rs.core.Response) LookupCoordinatorManager(io.druid.server.lookup.cache.LookupCoordinatorManager) AuditInfo(io.druid.audit.AuditInfo) Test(org.junit.Test)

Example 18 with LookupCoordinatorManager

use of io.druid.server.lookup.cache.LookupCoordinatorManager in project druid by druid-io.

the class LookupCoordinatorResourceTest method testSimpleGet.

@Test
public void testSimpleGet() {
    final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
    final Map<String, Map<String, Map<String, Object>>> retVal = new HashMap<>();
    EasyMock.expect(lookupCoordinatorManager.getKnownLookups()).andReturn(retVal).once();
    EasyMock.replay(lookupCoordinatorManager);
    final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(lookupCoordinatorManager, mapper, mapper);
    final Response response = lookupCoordinatorResource.getTiers(false);
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals(retVal.keySet(), response.getEntity());
    EasyMock.verify(lookupCoordinatorManager);
}
Also used : Response(javax.ws.rs.core.Response) LookupCoordinatorManager(io.druid.server.lookup.cache.LookupCoordinatorManager) HashMap(java.util.HashMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 19 with LookupCoordinatorManager

use of io.druid.server.lookup.cache.LookupCoordinatorManager in project druid by druid-io.

the class LookupCoordinatorResourceTest method testNullGetTier.

@Test
public void testNullGetTier() {
    final String tier = null;
    final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
    EasyMock.replay(lookupCoordinatorManager);
    final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(lookupCoordinatorManager, mapper, mapper);
    final Response response = lookupCoordinatorResource.getSpecificTier(tier);
    Assert.assertEquals(400, response.getStatus());
    Assert.assertEquals(ImmutableMap.of("error", "`tier` required"), response.getEntity());
    EasyMock.verify(lookupCoordinatorManager);
}
Also used : Response(javax.ws.rs.core.Response) LookupCoordinatorManager(io.druid.server.lookup.cache.LookupCoordinatorManager) Test(org.junit.Test)

Example 20 with LookupCoordinatorManager

use of io.druid.server.lookup.cache.LookupCoordinatorManager in project druid by druid-io.

the class LookupCoordinatorResourceTest method testDiscoveryExceptionalGet.

@Test
public void testDiscoveryExceptionalGet() {
    final List<String> tiers = ImmutableList.of();
    final String errMsg = "some error";
    final RuntimeException ex = new RuntimeException(errMsg);
    final LookupCoordinatorManager lookupCoordinatorManager = EasyMock.createStrictMock(LookupCoordinatorManager.class);
    EasyMock.expect(lookupCoordinatorManager.discoverTiers()).andThrow(ex).once();
    EasyMock.replay(lookupCoordinatorManager);
    final LookupCoordinatorResource lookupCoordinatorResource = new LookupCoordinatorResource(lookupCoordinatorManager, mapper, mapper);
    final Response response = lookupCoordinatorResource.getTiers(true);
    Assert.assertEquals(500, response.getStatus());
    Assert.assertEquals(ImmutableMap.of("error", errMsg), response.getEntity());
    EasyMock.verify(lookupCoordinatorManager);
}
Also used : Response(javax.ws.rs.core.Response) LookupCoordinatorManager(io.druid.server.lookup.cache.LookupCoordinatorManager) Test(org.junit.Test)

Aggregations

LookupCoordinatorManager (io.druid.server.lookup.cache.LookupCoordinatorManager)25 Test (org.junit.Test)25 Response (javax.ws.rs.core.Response)22 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 AuditInfo (io.druid.audit.AuditInfo)9 HashMap (java.util.HashMap)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Map (java.util.Map)3