Search in sources :

Example 26 with AuditInfo

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

the class SQLAuditManagerTest method testAuditEntrySerde.

@Test(timeout = 10_000L)
public void testAuditEntrySerde() throws IOException {
    AuditEntry entry = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", new DateTime("2013-01-01T00:00:00Z"));
    ObjectMapper mapper = new DefaultObjectMapper();
    AuditEntry serde = mapper.readValue(mapper.writeValueAsString(entry), AuditEntry.class);
    Assert.assertEquals(entry, serde);
}
Also used : AuditInfo(io.druid.audit.AuditInfo) AuditEntry(io.druid.audit.AuditEntry) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DateTime(org.joda.time.DateTime) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 27 with AuditInfo

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

the class SQLAuditManagerTest method testFetchAuditHistory.

@Test(timeout = 10_000L)
public void testFetchAuditHistory() throws IOException {
    AuditEntry entry = new AuditEntry("testKey", "testType", new AuditInfo("testAuthor", "testComment", "127.0.0.1"), "testPayload", new DateTime("2013-01-01T00:00:00Z"));
    auditManager.doAudit(entry);
    auditManager.doAudit(entry);
    List<AuditEntry> auditEntries = auditManager.fetchAuditHistory("testKey", "testType", new Interval("2012-01-01T00:00:00Z/2013-01-03T00:00:00Z"));
    Assert.assertEquals(2, auditEntries.size());
    Assert.assertEquals(entry, auditEntries.get(0));
    Assert.assertEquals(entry, auditEntries.get(1));
}
Also used : AuditInfo(io.druid.audit.AuditInfo) AuditEntry(io.druid.audit.AuditEntry) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 28 with AuditInfo

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

the class LookupCoordinatorManagerTest method testUpdateLookupsOnlyAddsToTier.

@Test
public void testUpdateLookupsOnlyAddsToTier() 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("foo", 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("foo", 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("foo", 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 29 with AuditInfo

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

the class LookupCoordinatorManagerTest method testDeleteLookupIgnoresNotReady.

@Test
public void testDeleteLookupIgnoresNotReady() throws Exception {
    final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig) {

        @Override
        public Map<String, Map<String, Map<String, Object>>> getKnownLookups() {
            return null;
        }
    };
    final AuditInfo auditInfo = new AuditInfo("author", "comment", "localhost");
    Assert.assertFalse(manager.deleteLookup(LOOKUP_TIER, "foo", auditInfo));
}
Also used : AuditInfo(io.druid.audit.AuditInfo) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 30 with AuditInfo

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

the class LookupCoordinatorManagerTest method testUpdateLookupFailsBadUpdates.

@Test
public void testUpdateLookupFailsBadUpdates() throws Exception {
    final Map<String, Object> ignore = ImmutableMap.<String, Object>of("prop", "old");
    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", ImmutableMap.<String, Object>of("prop", "old"), "ignore", ignore));
        }
    };
    final Map<String, Object> newSpec = ImmutableMap.<String, Object>of("prop", "new");
    final Map<String, Map<String, Object>> lookup = ImmutableMap.<String, Map<String, Object>>of("foo", newSpec, "ignore", ignore);
    final Map<String, Map<String, Map<String, Object>>> tier = ImmutableMap.of(LOOKUP_TIER, lookup);
    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("foo", newSpec, "ignore", ignore))), EasyMock.eq(auditInfo))).andReturn(false).once();
    EasyMock.replay(configManager);
    Assert.assertFalse(manager.updateLookups(tier, 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)

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