Search in sources :

Example 31 with AuditInfo

use of io.druid.audit.AuditInfo in project druid by druid-io.

the class LookupCoordinatorManagerTest method testUpdateLookupsAddsNewLookup.

@Test
public void testUpdateLookupsAddsNewLookup() throws Exception {
    final Map<String, Object> ignore = ImmutableMap.<String, Object>of("prop", "old");
    final AuditInfo auditInfo = new AuditInfo("author", "comment", "localhost");
    final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig) {

        @Override
        public Map<String, Map<String, Map<String, Object>>> getKnownLookups() {
            return ImmutableMap.<String, Map<String, Map<String, Object>>>of(LOOKUP_TIER + "1", ImmutableMap.<String, Map<String, Object>>of("foo1", ImmutableMap.<String, Object>of("prop", "old")), LOOKUP_TIER + "2", ImmutableMap.of("ignore", ignore));
        }
    };
    final Map<String, Object> newSpec = ImmutableMap.<String, Object>of("prop", "new");
    EasyMock.reset(configManager);
    EasyMock.expect(configManager.set(EasyMock.eq(LookupCoordinatorManager.LOOKUP_CONFIG_KEY), EasyMock.eq(ImmutableMap.<String, Map<String, Map<String, Object>>>of(LOOKUP_TIER + "1", ImmutableMap.of("foo1", ImmutableMap.<String, Object>of("prop", "old"), "foo2", newSpec), LOOKUP_TIER + "2", ImmutableMap.of("ignore", ignore))), EasyMock.eq(auditInfo))).andReturn(true).once();
    EasyMock.replay(configManager);
    Assert.assertTrue(manager.updateLookups(ImmutableMap.<String, Map<String, Map<String, Object>>>of(LOOKUP_TIER + "1", ImmutableMap.<String, Map<String, Object>>of("foo2", newSpec)), auditInfo));
    EasyMock.verify(configManager);
}
Also used : AuditInfo(io.druid.audit.AuditInfo) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 32 with AuditInfo

use of io.druid.audit.AuditInfo in project druid by druid-io.

the class LookupCoordinatorManagerTest method testDeleteLookup.

@Test
public void testDeleteLookup() throws Exception {
    final Map<String, Object> ignore = ImmutableMap.<String, Object>of("lookup", "ignore");
    final Map<String, Object> lookup = ImmutableMap.<String, Object>of("lookup", "foo");
    final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig) {

        @Override
        public Map<String, Map<String, Map<String, Object>>> getKnownLookups() {
            return ImmutableMap.<String, Map<String, Map<String, Object>>>of(LOOKUP_TIER, ImmutableMap.of("foo", lookup, "ignore", ignore));
        }
    };
    final AuditInfo auditInfo = new AuditInfo("author", "comment", "localhost");
    EasyMock.reset(configManager);
    EasyMock.expect(configManager.set(EasyMock.eq(LookupCoordinatorManager.LOOKUP_CONFIG_KEY), EasyMock.eq(ImmutableMap.of(LOOKUP_TIER, ImmutableMap.of("ignore", ignore))), EasyMock.eq(auditInfo))).andReturn(true).once();
    EasyMock.replay(configManager);
    Assert.assertTrue(manager.deleteLookup(LOOKUP_TIER, "foo", auditInfo));
    EasyMock.verify(configManager);
}
Also used : AuditInfo(io.druid.audit.AuditInfo) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 33 with AuditInfo

use of io.druid.audit.AuditInfo in project druid by druid-io.

the class RulesResourceTest method testGetDatasourceRuleHistoryWithInterval.

@Test
public void testGetDatasourceRuleHistoryWithInterval() {
    String interval = "P2D/2013-01-02T00:00:00Z";
    Interval theInterval = new Interval(interval);
    AuditEntry entry1 = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", new DateTime("2013-01-02T00:00:00Z"));
    AuditEntry entry2 = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", new DateTime("2013-01-01T00:00:00Z"));
    EasyMock.expect(auditManager.fetchAuditHistory(EasyMock.eq("datasource1"), EasyMock.eq("rules"), EasyMock.eq(theInterval))).andReturn(ImmutableList.of(entry1, entry2)).once();
    EasyMock.replay(auditManager);
    RulesResource rulesResource = new RulesResource(databaseRuleManager, auditManager);
    Response response = rulesResource.getDatasourceRuleHistory("datasource1", interval, null);
    List<AuditEntry> rulesHistory = (List) response.getEntity();
    Assert.assertEquals(2, rulesHistory.size());
    Assert.assertEquals(entry1, rulesHistory.get(0));
    Assert.assertEquals(entry2, rulesHistory.get(1));
    EasyMock.verify(auditManager);
}
Also used : Response(javax.ws.rs.core.Response) AuditInfo(io.druid.audit.AuditInfo) AuditEntry(io.druid.audit.AuditEntry) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

AuditInfo (io.druid.audit.AuditInfo)33 Test (org.junit.Test)31 Response (javax.ws.rs.core.Response)13 AuditEntry (io.druid.audit.AuditEntry)11 Map (java.util.Map)11 ImmutableMap (com.google.common.collect.ImmutableMap)10 LookupCoordinatorManager (io.druid.server.lookup.cache.LookupCoordinatorManager)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 DateTime (org.joda.time.DateTime)9 Interval (org.joda.time.Interval)6 List (java.util.List)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 ImmutableList (com.google.common.collect.ImmutableList)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 IntervalLoadRule (io.druid.server.coordinator.rules.IntervalLoadRule)3 Rule (io.druid.server.coordinator.rules.Rule)3 IOException (java.io.IOException)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)1