Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error datetime in exceptionless-client 0.1.0 #68 #69

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ class ExampleApp {
client.submitEvent(
EventPluginContext.from(
client.createLog("test-log").referenceId("test-reference-id").build()));

// Submit async events using submitXXXAsync methods
client.submitLogAsync("Test log");
Copy link
Collaborator

@pc9795 pc9795 Jan 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the cleanup 👍

}
}
```
Expand Down Expand Up @@ -98,7 +95,7 @@ client uses v4. In that case you have to explicitly declare v4 of the library in
<dependency>
<groupId>com.exceptionless</groupId>
<artifactId>exceptionless-client</artifactId>
<version>1.0-beta1</version>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -176,7 +177,7 @@ public Event.EventBuilder createSessionStart() {
}

public Event.EventBuilder createEvent() {
return Event.builder().dataExclusions(configuration.getDataExclusions()).date(LocalDate.now());
return Event.builder().dataExclusions(configuration.getDataExclusions()).date(OffsetDateTime.now());
}

public void submitEvent(Event event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import lombok.EqualsAndHashCode;

import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.*;
import java.util.stream.Collectors;

Expand All @@ -24,7 +25,7 @@ public class Event extends Model {

private String type;
private String source;
private LocalDate date;
private OffsetDateTime date;
private Set<String> tags;
private String message;
private String geo;
Expand All @@ -36,7 +37,7 @@ public class Event extends Model {
public Event(
String type,
String source,
LocalDate date,
OffsetDateTime date,
Set<String> tags,
String message,
String geo,
Expand All @@ -47,7 +48,7 @@ public Event(
Set<String> dataExclusions) {
this.type = type;
this.source = source;
this.date = date == null ? LocalDate.now() : date;
this.date = date == null ? OffsetDateTime.now() : date;
this.tags = tags == null ? new HashSet<>() : tags;
this.message = message;
this.geo = geo;
Expand Down Expand Up @@ -167,7 +168,7 @@ public EventBuilder source(String source) {
}

@Override
public EventBuilder date(LocalDate date) {
public EventBuilder date(OffsetDateTime date) {
super.date(date);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Data;

import java.time.LocalDate;
import java.time.OffsetDateTime;

@Data
public class MergedEvent {
Expand All @@ -24,7 +25,7 @@ public void incrementCount(long count) {
event.setCount(event.getCount() + count);
}

public void updateDate(LocalDate date) {
public void updateDate(OffsetDateTime date) {
if (date.isAfter(event.getDate())) {
event.setDate(date);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Value;

import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.Map;
import java.util.Set;

Expand All @@ -12,7 +13,7 @@
public class EventRequest {
String type;
String source;
LocalDate date;
OffsetDateTime date;
Set<String> tags;
String message;
String geo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

import java.time.LocalDate;
import java.time.OffsetDateTime;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -72,7 +73,7 @@ public void itCanSubmitAnExceptionEvent() {
argThat(
event ->
event.getType().equals(EventType.ERROR.value())
&& event.getDate().equals(LocalDate.now())
&& event.getDate().toLocalDate().equals(OffsetDateTime.now().toLocalDate())
&& event.getReferenceId() != null
&& event.getError().isPresent()
&& event.getEnvironmentInfo().isPresent()
Expand Down Expand Up @@ -101,7 +102,7 @@ public void itCanSubmitUnhandledExceptionEvent() {
argThat(
event ->
event.getType().equals(EventType.ERROR.value())
&& event.getDate().equals(LocalDate.now())
&& event.getDate().toLocalDate().equals(OffsetDateTime.now().toLocalDate())
&& event.getReferenceId() != null
&& event.getError().isPresent()
&& event.getEnvironmentInfo().isPresent()
Expand All @@ -123,7 +124,7 @@ public void itCanSubmitFeatureUsageEvent() {
event ->
event.getType().equals(EventType.USAGE.value())
&& event.getSource().equals("test-feature")
&& event.getDate().equals(LocalDate.now())
&& event.getDate().toLocalDate().equals(OffsetDateTime.now().toLocalDate())
&& event.getReferenceId() != null
&& event.getEnvironmentInfo().isPresent()));
assertThat(configuration.getLastReferenceIdManager().getLast()).isNotNull();
Expand Down Expand Up @@ -153,7 +154,7 @@ public void itCanSubmitALogEvent() {
event.getType().equals(EventType.LOG.value())
&& event.getSource().equals("test-log-source")
&& event.getMessage().equals("test-log-message")
&& event.getDate().equals(LocalDate.now())
&& event.getDate().toLocalDate().equals(OffsetDateTime.now().toLocalDate())
&& event.getReferenceId() != null
&& event.getEnvironmentInfo().isPresent()
&& event.getData().containsKey(EventPropertyKey.LOG_LEVEL.value())));
Expand Down Expand Up @@ -226,7 +227,7 @@ public void itCanSubmitANotFoundEvent() {
event ->
event.getType().equals(EventType.NOT_FOUND.value())
&& event.getSource().equals("test-resource")
&& event.getDate().equals(LocalDate.now())
&& event.getDate().toLocalDate().equals(OffsetDateTime.now().toLocalDate())
&& event.getReferenceId() != null
&& event.getEnvironmentInfo().isPresent()));
assertThat(configuration.getLastReferenceIdManager().getLast()).isNotNull();
Expand Down Expand Up @@ -254,7 +255,7 @@ public void itCanSubmitASessionStartEvent() {
argThat(
event ->
event.getType().equals(EventType.SESSION.value())
&& event.getDate().equals(LocalDate.now())
&& event.getDate().toLocalDate().equals(OffsetDateTime.now().toLocalDate())
&& event.getReferenceId() != null
&& event.getEnvironmentInfo().isPresent()));
assertThat(configuration.getLastReferenceIdManager().getLast()).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

import java.time.LocalDate;
import java.time.OffsetDateTime;

import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.times;
Expand All @@ -23,7 +24,7 @@ public class MergedEventTest {
public void setup() {
mergedEvent =
MergedEvent.builder()
.event(Event.builder().date(LocalDate.now()).build())
.event(Event.builder().date(OffsetDateTime.now()).build())
.eventQueue(eventQueue)
.build();
}
Expand All @@ -38,7 +39,7 @@ public void itCanIncrementCount() {

@Test
public void itCanUpdateDate() {
LocalDate tomorrow = LocalDate.now().plusDays(1);
OffsetDateTime tomorrow = OffsetDateTime.now().plusDays(1);
mergedEvent.updateDate(tomorrow);
mergedEvent.resubmit();

Expand All @@ -47,18 +48,19 @@ public void itCanUpdateDate() {

@Test
public void itShouldNotUpdateDateIfSameAsTheEvent() {
mergedEvent.updateDate(LocalDate.now());
OffsetDateTime now = OffsetDateTime.now();
mergedEvent.updateDate(now);
mergedEvent.resubmit();

verify(eventQueue, times(1)).enqueue(argThat(event -> event.getDate().equals(LocalDate.now())));
verify(eventQueue, times(1)).enqueue(argThat(event -> event.getDate().equals(now)));
}

@Test
public void itShouldNotUpdateDateIfBeforeAsTheEvent() {
LocalDate yesterday = LocalDate.now().minusDays(1);
OffsetDateTime yesterday = OffsetDateTime.now().minusDays(1);
mergedEvent.updateDate(yesterday);
mergedEvent.resubmit();

verify(eventQueue, times(1)).enqueue(argThat(event -> event.getDate().equals(LocalDate.now())));
verify(eventQueue, times(1)).enqueue(argThat(event -> event.getDate().toLocalDate().equals(OffsetDateTime.now().toLocalDate())));
}
}