use of org.killbill.bus.api.BusEvent in project killbill by killbill.
the class TestBeatrixListener method testInvoicePaymentError.
@Test(groups = "fast")
public void testInvoicePaymentError() throws Exception {
InvoicePaymentErrorInternalEvent event = mock(InvoicePaymentErrorInternalEvent.class);
provideCommonBusEventInfo(event);
when(event.getBusEventType()).thenReturn(BusInternalEventType.INVOICE_PAYMENT_ERROR);
when(event.getInvoiceId()).thenReturn(OBJECT_ID);
provideCommonInvoicePaymentInfo(event);
ArgumentCaptor<InvoicePaymentMetadata> metadataCaptor = ArgumentCaptor.forClass(InvoicePaymentMetadata.class);
when(objectMapper.writeValueAsString(metadataCaptor.capture())).thenReturn(METADATA);
when(internalCallContextFactory.getAccountId(OBJECT_ID, ObjectType.INVOICE, tenantContext)).thenReturn(ACCOUNT_ID);
ArgumentCaptor<BusEvent> eventCaptor = ArgumentCaptor.forClass(BusEvent.class);
beatrixListener.handleAllInternalKillbillEvents(event);
verify(externalBus).post(eventCaptor.capture());
DefaultBusExternalEvent postedEvent = (DefaultBusExternalEvent) eventCaptor.getValue();
assertEquals(postedEvent.getObjectId(), OBJECT_ID);
assertEquals(postedEvent.getObjectType(), ObjectType.INVOICE);
assertEquals(postedEvent.getEventType(), ExtBusEventType.INVOICE_PAYMENT_FAILED);
assertEquals(postedEvent.getMetaData(), METADATA);
assertCommonFieldsWithAccountId(postedEvent);
InvoicePaymentMetadata invoicePaymentMetadata = metadataCaptor.getValue();
assertInvoicePaymentMetadataFields(invoicePaymentMetadata);
}
use of org.killbill.bus.api.BusEvent in project killbill by killbill.
the class TestBeatrixListener method testTenantConfigChange.
@Test(groups = "fast")
public void testTenantConfigChange() throws Exception {
TenantConfigChangeInternalEvent event = mock(TenantConfigChangeInternalEvent.class);
provideCommonBusEventInfo(event);
when(event.getBusEventType()).thenReturn(BusInternalEventType.TENANT_CONFIG_CHANGE);
when(event.getId()).thenReturn(OBJECT_ID);
when(event.getKey()).thenReturn(METADATA);
ArgumentCaptor<BusEvent> eventCaptor = ArgumentCaptor.forClass(BusEvent.class);
beatrixListener.handleAllInternalKillbillEvents(event);
verify(externalBus).post(eventCaptor.capture());
DefaultBusExternalEvent postedEvent = (DefaultBusExternalEvent) eventCaptor.getValue();
assertEquals(postedEvent.getObjectId(), OBJECT_ID);
assertEquals(postedEvent.getObjectType(), ObjectType.TENANT_KVS);
assertEquals(postedEvent.getEventType(), ExtBusEventType.TENANT_CONFIG_CHANGE);
assertEquals(postedEvent.getMetaData(), METADATA);
assertCommonFieldsWithNoAccountId(postedEvent);
}
use of org.killbill.bus.api.BusEvent in project killbill by killbill.
the class TestBeatrixListener method testOverdueChange.
@Test(groups = "fast")
public void testOverdueChange() throws Exception {
OverdueChangeInternalEvent event = mock(OverdueChangeInternalEvent.class);
provideCommonBusEventInfo(event);
when(event.getBusEventType()).thenReturn(BusInternalEventType.OVERDUE_CHANGE);
when(event.getOverdueObjectId()).thenReturn(OBJECT_ID);
when(internalCallContextFactory.getAccountId(OBJECT_ID, ObjectType.ACCOUNT, tenantContext)).thenReturn(ACCOUNT_ID);
ArgumentCaptor<BusEvent> eventCaptor = ArgumentCaptor.forClass(BusEvent.class);
beatrixListener.handleAllInternalKillbillEvents(event);
verify(externalBus).post(eventCaptor.capture());
DefaultBusExternalEvent postedEvent = (DefaultBusExternalEvent) eventCaptor.getValue();
assertEquals(postedEvent.getObjectId(), OBJECT_ID);
assertEquals(postedEvent.getObjectType(), ObjectType.ACCOUNT);
assertEquals(postedEvent.getEventType(), ExtBusEventType.OVERDUE_CHANGE);
assertNull(postedEvent.getMetaData());
assertCommonFieldsWithAccountId(postedEvent);
}
use of org.killbill.bus.api.BusEvent in project killbill by killbill.
the class BeatrixListener method handleAllInternalKillbillEvents.
@AllowConcurrentEvents
@Subscribe
public void handleAllInternalKillbillEvents(final BusInternalEvent event) {
// No BusDispatcherOptimizer logic on purpose
final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContext(event.getSearchKey2(), event.getSearchKey1(), "BeatrixListener", CallOrigin.INTERNAL, UserType.SYSTEM, event.getUserToken());
try {
final BusEvent externalEvent = computeExtBusEventEntryFromBusInternalEvent(event, internalContext);
if (externalEvent != null) {
log.info("Sending extBusEvent='{}' from busEvent='{}'", externalEvent, event);
externalBus.post(externalEvent);
}
} catch (final EventBusException e) {
//
// When using PersistentBus this should never be reached, because errors are caught at the 'ext' bus level and retried until either success or event row is moved to FAILED status.
// However when using InMemoryBus, this can happen as there is no retry logic (at the 'ext' bus level) and so we should re-throw at this level to kick-in the retry logic from the 'main' bus
// (The use of RuntimeException is somewhat arbitrary)
//
log.warn("Failed to post event {}", event, e);
throw new RuntimeException(e);
} catch (JsonProcessingException e) {
log.warn("Failed to post event {}", event, e);
}
}
use of org.killbill.bus.api.BusEvent in project killbill by killbill.
the class DefaultBlockingStateDao method recordBusOrFutureNotificationFromTransaction.
private void recordBusOrFutureNotificationFromTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final UUID blockingStateId, final DateTime effectiveDate, final UUID blockableId, final BlockingStateType type, final String stateName, final String serviceName, final boolean blockingStateInserted, final BlockingAggregator previousState, final BlockingAggregator currentState, final InternalCallContext context) {
final boolean isTransitionToBlockedBilling = !previousState.isBlockBilling() && currentState.isBlockBilling();
final boolean isTransitionToUnblockedBilling = previousState.isBlockBilling() && !currentState.isBlockBilling();
final boolean isTransitionToBlockedEntitlement = !previousState.isBlockEntitlement() && currentState.isBlockEntitlement();
final boolean isTransitionToUnblockedEntitlement = previousState.isBlockEntitlement() && !currentState.isBlockEntitlement();
if (effectiveDate.compareTo(context.getCreatedDate()) > 0) {
// Add notification entry to send the bus event at the effective date
final NotificationEvent notificationEvent = new BlockingTransitionNotificationKey(blockingStateId, blockableId, stateName, serviceName, effectiveDate, type, isTransitionToBlockedBilling, isTransitionToUnblockedBilling, isTransitionToBlockedEntitlement, isTransitionToUnblockedEntitlement);
recordFutureNotificationFromTransaction(entitySqlDaoWrapperFactory, effectiveDate, notificationEvent, context);
} else {
if (blockingStateInserted) {
final BusEvent event = new DefaultBlockingTransitionInternalEvent(blockableId, stateName, serviceName, effectiveDate, type, isTransitionToBlockedBilling, isTransitionToUnblockedBilling, isTransitionToBlockedEntitlement, isTransitionToUnblockedEntitlement, context.getAccountRecordId(), context.getTenantRecordId(), context.getUserToken());
notifyBusFromTransaction(entitySqlDaoWrapperFactory, event);
} else {
log.debug("Skipping event for service {} and blockableId {} (previousState={}, currentState={})", serviceName, blockableId, previousState, currentState);
}
}
}
Aggregations