Search in sources :

Example 6 with AuditEntry

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

the class RulesResourceTest method testGetAllDatasourcesRuleHistoryWithCount.

@Test
public void testGetAllDatasourcesRuleHistoryWithCount() {
    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("rules"), EasyMock.eq(2))).andReturn(ImmutableList.of(entry1, entry2)).once();
    EasyMock.replay(auditManager);
    RulesResource rulesResource = new RulesResource(databaseRuleManager, auditManager);
    Response response = rulesResource.getDatasourceRuleHistory(null, 2);
    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) Test(org.junit.Test)

Example 7 with AuditEntry

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

the class RulesResourceTest method testGetDatasourceRuleHistoryWithCount.

@Test
public void testGetDatasourceRuleHistoryWithCount() {
    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(2))).andReturn(ImmutableList.of(entry1, entry2)).once();
    EasyMock.replay(auditManager);
    RulesResource rulesResource = new RulesResource(databaseRuleManager, auditManager);
    Response response = rulesResource.getDatasourceRuleHistory("datasource1", null, 2);
    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) Test(org.junit.Test)

Example 8 with AuditEntry

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

the class SQLAuditManagerTest method testFetchAuditHistoryByTypeWithLimit.

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

Example 9 with AuditEntry

use of io.druid.audit.AuditEntry 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 10 with AuditEntry

use of io.druid.audit.AuditEntry 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)

Aggregations

AuditEntry (io.druid.audit.AuditEntry)11 AuditInfo (io.druid.audit.AuditInfo)11 Test (org.junit.Test)11 DateTime (org.joda.time.DateTime)9 Interval (org.joda.time.Interval)5 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 Response (javax.ws.rs.core.Response)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 IntervalLoadRule (io.druid.server.coordinator.rules.IntervalLoadRule)2 Rule (io.druid.server.coordinator.rules.Rule)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)1