Skip to content

Commit

Permalink
Merge 48c6d8a into 19655df
Browse files Browse the repository at this point in the history
  • Loading branch information
asgeirn committed May 27, 2018
2 parents 19655df + 48c6d8a commit 908ff09
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 40 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
apply from: 'https://raw.githubusercontent.com/FINTprosjektet/fint-buildscripts/v1.1.0/dependencies.gradle'
apply from: 'https://raw.githubusercontent.com/FINTprosjektet/fint-buildscripts/v1.3.0/dependencies.gradle'
ext {
springBootVersion = springBootVersion
}
Expand Down Expand Up @@ -44,9 +44,10 @@ repositories {


dependencies {
compile('no.fint:fint-audit-api:2.0.0-alpha-1')
compile('no.fint:fint-audit-mongo-plugin:1.1.1')
compile('no.fint:fint-events:2.1.0-rc-1')
compile('no.fint:fint-event-model:2.0.1')
compile('no.fint:fint-event-model:3.0.0-rc-2')
compile('no.fint:fint-springfox-extension:0.0.1')

compile('org.projectlombok:lombok')
Expand Down Expand Up @@ -111,4 +112,4 @@ jacocoTestReport {
}
}

apply from: 'https://raw.githubusercontent.com/FINTlibs/fint-buildscripts/v1.1.0/dependencyReport.gradle'
apply from: 'https://raw.githubusercontent.com/FINTlibs/fint-buildscripts/v1.3.0/dependencyReport.gradle'
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ public void init() {
}

public void add(Event event, int timeToLiveInMinutes) {
log.trace("Add {}, ttl={}", event, timeToLiveInMinutes);
eventStates.add(new EventState(event, timeToLiveInMinutes));
}

public Optional<EventState> get(Event event) {
return eventStates.stream().filter(eventState -> eventState.getCorrId().equals(event.getCorrId())).findAny();
Optional<EventState> result = eventStates.stream().filter(eventState -> eventState.getCorrId().equals(event.getCorrId())).findAny();
log.trace("Get {}: {}", event.getCorrId(), result);
return result;
}

public Optional<EventState> remove(Event event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import lombok.extern.slf4j.Slf4j;
import no.fint.audit.FintAuditService;
import no.fint.event.model.Event;
import no.fint.event.model.Status;
import no.fint.events.FintEvents;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
Expand All @@ -20,6 +22,9 @@ public class JanitorService {
@Autowired
private FintAuditService fintAuditService;

@Autowired
private FintEvents fintEvents;

@Scheduled(initialDelay = 20000L, fixedDelay = 5000L)
public void cleanUpEventStates() {
log.debug("Running janitor service");
Expand All @@ -30,8 +35,10 @@ public void cleanUpEventStates() {
log.info("EventState expired, removing from list: {}", eventState);
eventStateService.remove(event);

event.setStatus(Status.ADAPTER_NOT_CONFIRMED);
event.setMessage("Event expired");
fintAuditService.audit(event);
fintEvents.sendUpstream(event);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ public class ResponseService {
private FintEvents fintEvents;

public void handleAdapterResponse(Event event) {
log.info("Event received: {}, action: {}, orgId: {}", event.getCorrId(), event.getAction(), event.getOrgId());
log.info("Event received: {}", event);
if (event.isHealthCheck()) {
event.setStatus(Status.UPSTREAM_QUEUE);
fintEvents.sendUpstream(event);
} else {
Optional<EventState> state = eventStateService.get(event);
if (state.isPresent()) {
fintAuditService.audit(event);
fintAuditService.audit(event, Status.ADAPTER_RESPONSE);
event.setStatus(Status.UPSTREAM_QUEUE);
fintEvents.sendUpstream(event);
fintAuditService.audit(event);
fintAuditService.audit(event, Status.UPSTREAM_QUEUE);
eventStateService.remove(event);
} else {
log.error("EventState with corrId {} was not found. Either the Event has expired or the provider does not recognize the corrId. {}", event.getCorrId(), event);
Expand Down
9 changes: 8 additions & 1 deletion src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ fint:
queue-endpoint-enabled: true

springfox:
swagger-https: false
swagger-https: false

server:
port: 8081

logging:
level:
no.fint.provider.events.response: TRACE
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
package no.fint.provider.events.eventstate

import no.fint.audit.FintAuditService
import no.fint.event.model.Event
import spock.lang.Specification

class JanitorServiceSpec extends Specification {
private EventStateService eventStateService
private FintAuditService fintAuditService
private JanitorService janitorService

void setup() {
eventStateService = Mock(EventStateService)
fintAuditService = Mock(FintAuditService)
janitorService = new JanitorService(eventStateService: eventStateService, fintAuditService: fintAuditService)
}

def "Remove expired event states"() {
given:
def event = new Event(orgId: 'rogfk.no')
def expiredEventState = new EventState(event, -10)
def notExpiredEventState = new EventState(event, 5000)

when:
janitorService.cleanUpEventStates()

then:
1 * eventStateService.getEventStates() >> [expiredEventState, notExpiredEventState]
1 * eventStateService.remove(_ as Event)
1 * fintAuditService.audit(_ as Event)
}
}
package no.fint.provider.events.eventstate

import no.fint.audit.FintAuditService
import no.fint.event.model.Event
import no.fint.events.FintEvents
import spock.lang.Specification

class JanitorServiceSpec extends Specification {
private EventStateService eventStateService
private FintAuditService fintAuditService
private JanitorService janitorService
private FintEvents fintEvents

void setup() {
eventStateService = Mock(EventStateService)
fintAuditService = Mock(FintAuditService)
fintEvents = Mock(FintEvents)
janitorService = new JanitorService(eventStateService: eventStateService, fintAuditService: fintAuditService, fintEvents: fintEvents)
}

def "Remove expired event states"() {
given:
def event = new Event(orgId: 'rogfk.no')
def expiredEventState = new EventState(event, -10)
def notExpiredEventState = new EventState(event, 5000)

when:
janitorService.cleanUpEventStates()

then:
1 * eventStateService.getEventStates() >> [expiredEventState, notExpiredEventState]
1 * eventStateService.remove(_ as Event)
1 * fintAuditService.audit(_ as Event)
1 * fintEvents.sendUpstream(_ as Event)
}
}

0 comments on commit 908ff09

Please sign in to comment.