Skip to content

Commit

Permalink
fix(new schema): fix logs to ignore ms component of timestamps (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsdonn authored Jan 18, 2023
1 parent 19071dc commit ea281ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public boolean equals(Object o) {
boolean primitiveEqualityCheck = this.key.equals(other.key)
// either both metadata fields are null or both are equal (will check non-null equality after)
&& ((this.metadata == null && other.metadata == null) || (this.metadata != null && other.metadata != null))
&& this.createdOn.equals(other.getCreatedOn())
&& Math.abs(this.createdOn.getTime() - other.getCreatedOn().getTime()) < 1000 // timestamps are considered equal if within 1s of each other
&& this.createdBy.equals(other.getCreatedBy())
// either both createdFor fields are null or both are equal (need to check this.createdFor != null to avoid NPE)
&& ((this.createdFor == null && other.getCreatedFor() == null) || (this.createdFor != null && this.createdFor.equals(other.getCreatedFor())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,18 @@ public void testCompareResultsListEbeanMetadataAspectSingleton() {
ema4.setMetadata("{\"field2\": \"value2\", \"field1\": \"value1\"}");
assertTrue(EBeanDAOUtils.compareResults(Collections.singletonList(ema4), Collections.singletonList(ema4Different), "testMethod"));

// different createdon
// different createdon, but within 1s of each other
EbeanMetadataAspect ema5 = new EbeanMetadataAspect();
ema5.setKey(new EbeanMetadataAspect.PrimaryKey("urn1", "aspect1", 0L));
ema5.setMetadata("{\"metadata\": \"value1\"}");
ema5.setCreatedBy("tester");
ema5.setCreatedFor("tester");
ema5.setCreatedOn(new Timestamp(987654321L));
ema5.setCreatedOn(new Timestamp(1234567000L)); // 890 ms different than Timestamp(1234567890L)

assertTrue(EBeanDAOUtils.compareResults(Collections.singletonList(ema1), Collections.singletonList(ema5), "testMethod"));

// different createdon
ema5.setCreatedOn(new Timestamp(1234560000L)); // 7890 ms different than Timestamp(1234567890L)
assertFalse(EBeanDAOUtils.compareResults(Collections.singletonList(ema1), Collections.singletonList(ema5), "testMethod"));

// createdFor is nullable, set one EbeanMetadataAspect's createdFor field to null
Expand Down

0 comments on commit ea281ea

Please sign in to comment.