Search in sources :

Example 11 with BusEvent

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);
}
Also used : InvoicePaymentErrorInternalEvent(org.killbill.billing.events.InvoicePaymentErrorInternalEvent) BusEvent(org.killbill.bus.api.BusEvent) InvoicePaymentMetadata(org.killbill.billing.notification.plugin.api.InvoicePaymentMetadata) Test(org.testng.annotations.Test)

Example 12 with BusEvent

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);
}
Also used : TenantConfigChangeInternalEvent(org.killbill.billing.events.TenantConfigChangeInternalEvent) BusEvent(org.killbill.bus.api.BusEvent) Test(org.testng.annotations.Test)

Example 13 with BusEvent

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);
}
Also used : OverdueChangeInternalEvent(org.killbill.billing.events.OverdueChangeInternalEvent) BusEvent(org.killbill.bus.api.BusEvent) Test(org.testng.annotations.Test)

Example 14 with BusEvent

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);
    }
}
Also used : EventBusException(org.killbill.bus.api.PersistentBus.EventBusException) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) BusEvent(org.killbill.bus.api.BusEvent) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Example 15 with BusEvent

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);
        }
    }
}
Also used : BlockingTransitionNotificationKey(org.killbill.billing.entitlement.engine.core.BlockingTransitionNotificationKey) DefaultBlockingTransitionInternalEvent(org.killbill.billing.entitlement.api.DefaultBlockingTransitionInternalEvent) NotificationEvent(org.killbill.notificationq.api.NotificationEvent) BusEvent(org.killbill.bus.api.BusEvent)

Aggregations

BusEvent (org.killbill.bus.api.BusEvent)27 Test (org.testng.annotations.Test)20 InvoicePaymentMetadata (org.killbill.billing.notification.plugin.api.InvoicePaymentMetadata)5 EventBusException (org.killbill.bus.api.PersistentBus.EventBusException)4 PaymentMetadata (org.killbill.billing.notification.plugin.api.PaymentMetadata)3 DefaultEffectiveSubscriptionEvent (org.killbill.billing.subscription.api.user.DefaultEffectiveSubscriptionEvent)3 SubscriptionBaseTransitionData (org.killbill.billing.subscription.api.user.SubscriptionBaseTransitionData)3 DefaultTagDefinition (org.killbill.billing.util.tag.DefaultTagDefinition)3 NotificationEvent (org.killbill.notificationq.api.NotificationEvent)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 OutputStream (java.io.OutputStream)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 StreamingOutput (javax.ws.rs.core.StreamingOutput)2 DateTime (org.joda.time.DateTime)2 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)2 InvoicePaymentErrorInternalEvent (org.killbill.billing.events.InvoicePaymentErrorInternalEvent)2