use of uk.gov.pay.connector.events.model.charge.PaymentCreated in project pay-connector by alphagov.
the class StateTransitionEmitterProcessTest method shouldPutPaymentTransitionBackOnQueueIfEventEmitFails.
@Test
public void shouldPutPaymentTransitionBackOnQueueIfEventEmitFails() throws Exception {
PaymentStateTransition paymentStateTransition = new PaymentStateTransition(100L, PaymentEvent.class);
ChargeEventEntity chargeEvent = mock(ChargeEventEntity.class);
when(stateTransitionQueue.poll(anyLong(), any(TimeUnit.class))).thenReturn(paymentStateTransition);
when(eventFactory.createEvents(any(PaymentStateTransition.class))).thenReturn(List.of(new PaymentCreated("service-id", true, "id", mock(PaymentCreatedEventDetails.class), ZonedDateTime.now())));
doThrow(QueueException.class).when(mockEventService).emitAndMarkEventAsEmitted(any());
stateTransitionEmitterProcess.handleStateTransitionMessages();
verify(stateTransitionQueue).offer(any(PaymentStateTransition.class));
}
use of uk.gov.pay.connector.events.model.charge.PaymentCreated in project pay-connector by alphagov.
the class EmittedEventDaoIT method findNotEmittedEventsOlderThan_shouldReturnEventsWithEmptyEmittedDate.
@Test
public void findNotEmittedEventsOlderThan_shouldReturnEventsWithEmptyEmittedDate() {
final PaymentCreated paymentCreatedEvent = aPaymentCreatedEvent();
emittedEventDao.recordEmission(paymentCreatedEvent.getResourceType(), paymentCreatedEvent.getResourceExternalId(), paymentCreatedEvent.getEventType(), paymentCreatedEvent.getTimestamp(), null);
Optional<Long> maxId = emittedEventDao.findNotEmittedEventMaxIdOlderThan(ZonedDateTime.parse("2019-01-01T14:00:01Z"), ZonedDateTime.now(UTC));
assertThat(maxId.isPresent(), is(true));
List<EmittedEventEntity> notEmittedEvents = emittedEventDao.findNotEmittedEventsOlderThan(ZonedDateTime.parse("2019-01-01T14:00:01Z"), 1, 0L, Long.MAX_VALUE, ZonedDateTime.now(UTC));
assertThat(notEmittedEvents.size(), is(1));
assertThat(notEmittedEvents.get(0).getEmittedDate(), nullValue());
assertThat(notEmittedEvents.get(0).getEventType(), is(paymentCreatedEvent.getEventType()));
assertThat(notEmittedEvents.get(0).getResourceExternalId(), is(paymentCreatedEvent.getResourceExternalId()));
assertThat(notEmittedEvents.get(0).getResourceType(), is(paymentCreatedEvent.getResourceType().getLowercase()));
}
use of uk.gov.pay.connector.events.model.charge.PaymentCreated in project pay-connector by alphagov.
the class EmittedEventDaoIT method hasBeenEmittedBefore_shouldReturnTrueIfRecordedBefore.
@Test
public void hasBeenEmittedBefore_shouldReturnTrueIfRecordedBefore() {
final PaymentCreated paymentCreatedEvent = aPaymentCreatedEvent();
emittedEventDao.recordEmission(paymentCreatedEvent, null);
assertThat(emittedEventDao.hasBeenEmittedBefore(paymentCreatedEvent), is(true));
}
use of uk.gov.pay.connector.events.model.charge.PaymentCreated in project pay-connector by alphagov.
the class EmittedEventDaoIT method recordEmissionWithParameters_shouldRecordEmission.
@Test
public void recordEmissionWithParameters_shouldRecordEmission() {
final PaymentCreated eventToRecord = aPaymentCreatedEvent();
ZonedDateTime doNotRetryEmitUntilDate = ZonedDateTime.parse("2019-01-02T13:00:00Z");
emittedEventDao.recordEmission(eventToRecord.getResourceType(), eventToRecord.getResourceExternalId(), eventToRecord.getEventType(), eventToRecord.getTimestamp(), doNotRetryEmitUntilDate);
final List<Map<String, Object>> events = databaseTestHelper.readEmittedEvents();
assertThat(events.size(), is(1));
final Map<String, Object> event = events.get(0);
assertThat(event.get("resource_external_id"), is(eventToRecord.getResourceExternalId()));
assertThat(event.get("resource_type"), is(eventToRecord.getResourceType().getLowercase()));
assertThat(event.get("event_type"), is(eventToRecord.getEventType()));
assertThat(event.get("emitted_date"), is(nullValue()));
assertThat(event.get("do_not_retry_emit_until"), is(Timestamp.from(doNotRetryEmitUntilDate.toInstant())));
}
use of uk.gov.pay.connector.events.model.charge.PaymentCreated in project pay-connector by alphagov.
the class EmittedEventDaoIT method findNotEmittedEventsOlderThan_shouldNotReturnRecordsWithDoNotRetryEmitUntilValueInFuture.
@Test
public void findNotEmittedEventsOlderThan_shouldNotReturnRecordsWithDoNotRetryEmitUntilValueInFuture() {
final PaymentCreated paymentCreatedEvent = aPaymentCreatedEvent();
final RefundSubmitted refundSubmittedEvent = aRefundSubmittedEvent(ZonedDateTime.parse("2019-01-01T14:00:00Z"));
emittedEventDao.recordEmission(paymentCreatedEvent.getResourceType(), paymentCreatedEvent.getResourceExternalId(), paymentCreatedEvent.getEventType(), paymentCreatedEvent.getTimestamp(), null);
ZonedDateTime doNotRetryEmitUntil = ZonedDateTime.now(UTC).minusSeconds(120);
emittedEventDao.recordEmission(refundSubmittedEvent.getResourceType(), refundSubmittedEvent.getResourceExternalId(), refundSubmittedEvent.getEventType(), refundSubmittedEvent.getTimestamp(), doNotRetryEmitUntil);
emittedEventDao.recordEmission(paymentCreatedEvent.getResourceType(), paymentCreatedEvent.getResourceExternalId(), paymentCreatedEvent.getEventType(), paymentCreatedEvent.getTimestamp(), ZonedDateTime.now(UTC).plusSeconds(120));
Optional<Long> maxId = emittedEventDao.findNotEmittedEventMaxIdOlderThan(ZonedDateTime.parse("2019-01-01T14:00:01Z"), ZonedDateTime.now(UTC));
assertThat(maxId.isPresent(), is(true));
List<EmittedEventEntity> notEmittedEvents = emittedEventDao.findNotEmittedEventsOlderThan(ZonedDateTime.parse("2019-01-01T14:00:01Z"), 2, 0L, Long.MAX_VALUE, ZonedDateTime.now(UTC));
assertThat(notEmittedEvents.size(), is(2));
assertThat(notEmittedEvents.get(0).getEmittedDate(), nullValue());
assertThat(notEmittedEvents.get(0).getEventType(), is(paymentCreatedEvent.getEventType()));
assertThat(notEmittedEvents.get(0).getResourceExternalId(), is(paymentCreatedEvent.getResourceExternalId()));
assertThat(notEmittedEvents.get(0).getResourceType(), is(paymentCreatedEvent.getResourceType().getLowercase()));
assertThat(notEmittedEvents.get(0).getDoNotRetryEmitUntil(), is(nullValue()));
assertThat(notEmittedEvents.get(1).getEmittedDate(), nullValue());
assertThat(notEmittedEvents.get(1).getEventType(), is(refundSubmittedEvent.getEventType()));
assertThat(notEmittedEvents.get(1).getResourceExternalId(), is(refundSubmittedEvent.getResourceExternalId()));
assertThat(notEmittedEvents.get(1).getResourceType(), is(refundSubmittedEvent.getResourceType().getLowercase()));
assertThat(Timestamp.from(notEmittedEvents.get(1).getDoNotRetryEmitUntil().toInstant()), is(Timestamp.from(doNotRetryEmitUntil.toInstant())));
}
Aggregations