Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kfaraz committed Dec 4, 2023
1 parent 011319e commit 0d88e64
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public class CoordinatorBasicAuthenticatorResourceTest
public void setUp()
{
req = EasyMock.createStrictMock(HttpServletRequest.class);
EasyMock.expect(req.getRemoteAddr()).andReturn("127.0.0.1").anyTimes();
EasyMock.replay(req);

objectMapper = new ObjectMapper(new SmileFactory());
TestDerbyConnector connector = derbyConnectorRule.getConnector();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,14 @@ public boolean equals(Object o)
&& Objects.equals(this.key, that.key)
&& Objects.equals(this.type, that.type)
&& Objects.equals(this.auditInfo, that.auditInfo)
&& Objects.equals(this.payload, that.payload)
&& Objects.equals(this.serializedPayload, that.serializedPayload);
}

@Override
public int hashCode()
{
return Objects.hash(key, type, auditInfo, serializedPayload, auditTime);
return Objects.hash(key, type, auditInfo, payload, serializedPayload, auditTime);
}

public static class Builder
Expand Down
23 changes: 14 additions & 9 deletions processing/src/test/java/org/apache/druid/audit/AuditInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@

package org.apache.druid.audit;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.druid.jackson.DefaultObjectMapper;
import org.apache.druid.java.util.common.DateTimes;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;

public class AuditInfoTest
{
@Test
Expand All @@ -39,9 +35,20 @@ public void testAuditInfoEquality()
}

@Test(timeout = 60_000L)
public void testAuditEntrySerde() throws IOException
public void testAuditEventEquality()
{
AuditEvent entry = new AuditEvent(
final AuditEvent event1 = new AuditEvent(
"testKey",
"testType",
new AuditInfo(
"testAuthor",
"testComment",
"127.0.0.1"
),
"testPayload",
DateTimes.of("2013-01-01T00:00:00Z")
);
final AuditEvent event2 = new AuditEvent(
"testKey",
"testType",
new AuditInfo(
Expand All @@ -52,9 +59,7 @@ public void testAuditEntrySerde() throws IOException
"testPayload",
DateTimes.of("2013-01-01T00:00:00Z")
);
ObjectMapper mapper = new DefaultObjectMapper();
AuditEvent serde = mapper.readValue(mapper.writeValueAsString(entry), AuditEvent.class);
Assert.assertEquals(entry, serde);
Assert.assertEquals(event1, event2);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,14 @@ private AuditEvent lookupAuditEntryForKey(String key) throws IOException
if (payload == null) {
return null;
} else {
return mapper.readValue(payload, AuditEvent.class);
AuditRecord record = mapper.readValue(payload, AuditRecord.class);
return new AuditEvent(
record.getKey(),
record.getType(),
record.getAuditInfo(),
record.getPayload(),
record.getAuditTime()
);
}
}

Expand Down

0 comments on commit 0d88e64

Please sign in to comment.