killbill-uncached

junction: Additional cleanup (Remove impl hack where we store

3/8/2019 4:58:28 PM

Details

diff --git a/junction/src/main/java/org/killbill/billing/junction/plumbing/billing/BlockingCalculator.java b/junction/src/main/java/org/killbill/billing/junction/plumbing/billing/BlockingCalculator.java
index 391dbfe..4f130dc 100644
--- a/junction/src/main/java/org/killbill/billing/junction/plumbing/billing/BlockingCalculator.java
+++ b/junction/src/main/java/org/killbill/billing/junction/plumbing/billing/BlockingCalculator.java
@@ -74,14 +74,11 @@ public class BlockingCalculator {
      *
      * @param billingEvents the original list of billing events to update (without overdue events)
      */
-    public boolean insertBlockingEvents(final SortedSet<BillingEvent> billingEvents, final Set<UUID> skippedSubscriptions, final Catalog catalog, final InternalTenantContext context) throws CatalogApiException {
+    public boolean insertBlockingEvents(final SortedSet<BillingEvent> billingEvents, final Set<UUID> skippedSubscriptions, final Map<UUID, List<SubscriptionBase>> subscriptionsForAccount, final Catalog catalog, final InternalTenantContext context) throws CatalogApiException {
         if (billingEvents.size() <= 0) {
             return false;
         }
 
-
-        final Hashtable<UUID, List<SubscriptionBase>> bundleMap = createBundleSubscriptionMap(billingEvents);
-
         final SortedSet<BillingEvent> billingEventsToAdd = new TreeSet<BillingEvent>();
         final SortedSet<BillingEvent> billingEventsToRemove = new TreeSet<BillingEvent>();
 
@@ -97,11 +94,11 @@ public class BlockingCalculator {
         final Map<UUID, List<BlockingState>> perBundleBlockingEvents = getPerTypeBlockingEvents(BlockingStateType.SUBSCRIPTION_BUNDLE, blockingEvents);
         final Map<UUID, List<BlockingState>> perSubscriptionBlockingEvents = getPerTypeBlockingEvents(BlockingStateType.SUBSCRIPTION, blockingEvents);
 
-        for (final UUID bundleId : bundleMap.keySet()) {
+        for (final UUID bundleId : subscriptionsForAccount.keySet()) {
 
             final List<BlockingState> bundleBlockingEvents = perBundleBlockingEvents.get(bundleId) != null ? perBundleBlockingEvents.get(bundleId) : ImmutableList.<BlockingState>of();
 
-            for (final SubscriptionBase subscription : bundleMap.get(bundleId)) {
+            for (final SubscriptionBase subscription : subscriptionsForAccount.get(bundleId)) {
                 // Avoid inserting additional events for subscriptions that don't even have a START event
                 if (skippedSubscriptions.contains(subscription.getId())) {
                     continue;
@@ -254,10 +251,20 @@ public class BlockingCalculator {
         final SubscriptionBaseTransitionType type = SubscriptionBaseTransitionType.START_BILLING_DISABLED;
         final Long totalOrdering = globaltotalOrder.getAndIncrement();
 
-        return new DefaultBillingEvent(((DefaultBillingEvent) previousEvent).getSubscription(), effectiveDate, plan, planPhase, fixedPrice, recurringPrice,
+        return new DefaultBillingEvent(previousEvent.getSubscriptionId(),
+                                       previousEvent.getBundleId(),
+                                       effectiveDate,
+                                       plan,
+                                       planPhase,
+                                       fixedPrice,
+                                       recurringPrice,
                                        currency,
-                                       billingPeriod, billCycleDay,
-                                       description, totalOrdering, type, true);
+                                       billingPeriod,
+                                       billCycleDay,
+                                       description,
+                                       totalOrdering,
+                                       type,
+                                       true);
     }
 
     protected BillingEvent createNewReenableEvent(final DateTime odEventTime, final BillingEvent previousEvent, final Catalog catalog, final InternalTenantContext context) throws CatalogApiException {
@@ -274,26 +281,20 @@ public class BlockingCalculator {
         final SubscriptionBaseTransitionType type = SubscriptionBaseTransitionType.END_BILLING_DISABLED;
         final Long totalOrdering = globaltotalOrder.getAndIncrement();
 
-        return new DefaultBillingEvent(((DefaultBillingEvent) previousEvent).getSubscription(), effectiveDate, plan, planPhase, fixedPrice, recurringPrice,
+        return new DefaultBillingEvent(previousEvent.getSubscriptionId(),
+                                       previousEvent.getBundleId(),
+                                       effectiveDate,
+                                       plan,
+                                       planPhase,
+                                       fixedPrice,
+                                       recurringPrice,
                                        currency,
-                                       billingPeriod, billCycleDay,
-                                       description, totalOrdering, type, false);
-    }
-
-    protected Hashtable<UUID, List<SubscriptionBase>> createBundleSubscriptionMap(final SortedSet<BillingEvent> billingEvents) {
-        final Hashtable<UUID, List<SubscriptionBase>> result = new Hashtable<UUID, List<SubscriptionBase>>();
-        for (final BillingEvent event : billingEvents) {
-            final UUID bundleId = event.getBundleId();
-            List<SubscriptionBase> subs = result.get(bundleId);
-            if (subs == null) {
-                subs = new ArrayList<SubscriptionBase>();
-                result.put(bundleId, subs);
-            }
-            if (!result.get(bundleId).contains(((DefaultBillingEvent)event).getSubscription())) {
-                subs.add(((DefaultBillingEvent)event).getSubscription());
-            }
-        }
-        return result;
+                                       billingPeriod,
+                                       billCycleDay,
+                                       description,
+                                       totalOrdering,
+                                       type,
+                                       false);
     }
 
     // In ascending order
diff --git a/junction/src/main/java/org/killbill/billing/junction/plumbing/billing/DefaultBillingEvent.java b/junction/src/main/java/org/killbill/billing/junction/plumbing/billing/DefaultBillingEvent.java
index bd977db..048f703 100644
--- a/junction/src/main/java/org/killbill/billing/junction/plumbing/billing/DefaultBillingEvent.java
+++ b/junction/src/main/java/org/killbill/billing/junction/plumbing/billing/DefaultBillingEvent.java
@@ -36,7 +36,6 @@ import org.killbill.billing.subscription.api.SubscriptionBase;
 import org.killbill.billing.subscription.api.SubscriptionBaseTransitionType;
 import org.killbill.billing.subscription.api.user.SubscriptionBillingEvent;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 
@@ -67,19 +66,12 @@ public class DefaultBillingEvent implements BillingEvent {
 
     private final DateTime catalogEffectiveDate;
 
-
-    // TODO Ugly, can that go completely ?
-    private final SubscriptionBase subscription;
-
     public DefaultBillingEvent(final SubscriptionBillingEvent inputEvent,
                                final SubscriptionBase subscription,
                                final int billCycleDayLocal,
                                final BillingAlignment billingAlignment,
                                final Currency currency,
                                final Catalog catalog) throws CatalogApiException {
-
-        this.subscription = subscription;
-
         this.subscriptionId = subscription.getId();
         this.bundleId = subscription.getBundleId();
 
@@ -99,12 +91,13 @@ public class DefaultBillingEvent implements BillingEvent {
         this.totalOrdering = inputEvent.getTotalOrdering();
 
         this.billingPeriod = computeRecurringBillingPeriod();
-        this.fixedPrice =  computeFixedPrice();
+        this.fixedPrice = computeFixedPrice();
         this.recurringPrice = computeRecurringPrice();
         this.usages = computeUsages();
     }
 
-    public DefaultBillingEvent(final SubscriptionBase subscription,
+    public DefaultBillingEvent(final UUID subscriptionId,
+                               final UUID bundleId,
                                final DateTime effectiveDate,
                                final Plan plan,
                                final PlanPhase planPhase,
@@ -117,12 +110,8 @@ public class DefaultBillingEvent implements BillingEvent {
                                final long totalOrdering,
                                final SubscriptionBaseTransitionType type,
                                final boolean isDisableEvent) throws CatalogApiException {
-
-        this.subscription = subscription;
-
-
-        this.subscriptionId = subscription.getId();
-        this.bundleId = subscription.getBundleId();
+        this.subscriptionId = subscriptionId;
+        this.bundleId = bundleId;
         this.effectiveDate = effectiveDate;
 
         this.isCancelledOrBlocked = isDisableEvent;
@@ -142,10 +131,42 @@ public class DefaultBillingEvent implements BillingEvent {
         this.billingAlignment = null;
     }
 
-    SubscriptionBase getSubscription() {
-        return subscription;
+
+
+    private BigDecimal computeFixedPrice() throws CatalogApiException {
+        if (isCancelledOrBlocked ||
+            type == SubscriptionBaseTransitionType.BCD_CHANGE /* We don't want to bill twice for the same fixed price */) {
+            return null;
+        }
+        return (planPhase.getFixed() != null && planPhase.getFixed().getPrice() != null) ? planPhase.getFixed().getPrice().getPrice(currency) : null;
     }
 
+    private BigDecimal computeRecurringPrice() throws CatalogApiException {
+        if (isCancelledOrBlocked) {
+            return null;
+        }
+        return (planPhase.getRecurring() != null && planPhase.getRecurring().getRecurringPrice() != null) ? planPhase.getRecurring().getRecurringPrice().getPrice(currency) : null;
+    }
+
+    private BillingPeriod computeRecurringBillingPeriod() {
+        return planPhase.getRecurring() != null ? planPhase.getRecurring().getBillingPeriod() : BillingPeriod.NO_BILLING_PERIOD;
+    }
+
+    private List<Usage> computeUsages() {
+        List<Usage> result = ImmutableList.<Usage>of();
+        if (isCancelledOrBlocked) {
+            return result;
+        }
+        if (planPhase.getUsages().length > 0) {
+            result = Lists.newArrayList();
+            for (Usage usage : planPhase.getUsages()) {
+                result.add(usage);
+            }
+        }
+        return result;
+    }
+
+
     @Override
     public int compareTo(final BillingEvent e1) {
         if (!subscriptionId.equals(e1.getSubscriptionId())) { // First order by subscription
@@ -212,7 +233,6 @@ public class DefaultBillingEvent implements BillingEvent {
         return billingAlignment;
     }
 
-
     @Override
     public DateTime getEffectiveDate() {
         return effectiveDate;
@@ -351,39 +371,6 @@ public class DefaultBillingEvent implements BillingEvent {
         return result;
     }
 
-    private BigDecimal computeFixedPrice() throws CatalogApiException {
-        if (isCancelledOrBlocked ||
-            type == SubscriptionBaseTransitionType.BCD_CHANGE /* We don't want to bill twice for the same fixed price */) {
-            return null;
-        }
-        return (planPhase.getFixed() != null && planPhase.getFixed().getPrice() != null) ? planPhase.getFixed().getPrice().getPrice(currency) : null;
-    }
-
-    private BigDecimal computeRecurringPrice() throws CatalogApiException {
-        if (isCancelledOrBlocked) {
-            return null;
-        }
-        return (planPhase.getRecurring() != null && planPhase.getRecurring().getRecurringPrice() != null) ? planPhase.getRecurring().getRecurringPrice().getPrice(currency) : null;
-    }
-
-    private BillingPeriod computeRecurringBillingPeriod() {
-        return planPhase.getRecurring() != null ? planPhase.getRecurring().getBillingPeriod() : BillingPeriod.NO_BILLING_PERIOD;
-    }
-
-    private List<Usage> computeUsages() {
-        List<Usage> result = ImmutableList.<Usage>of();
-        if (isCancelledOrBlocked) {
-            return result;
-        }
-        if (planPhase.getUsages().length > 0) {
-            result = Lists.newArrayList();
-            for (Usage usage : planPhase.getUsages()) {
-                result.add(usage);
-            }
-        }
-        return result;
-    }
-
     @Override
     public DateTime getCatalogEffectiveDate() {
         // TODO Can that go ?
diff --git a/junction/src/main/java/org/killbill/billing/junction/plumbing/billing/DefaultInternalBillingApi.java b/junction/src/main/java/org/killbill/billing/junction/plumbing/billing/DefaultInternalBillingApi.java
index 641173d..bb8f477 100644
--- a/junction/src/main/java/org/killbill/billing/junction/plumbing/billing/DefaultInternalBillingApi.java
+++ b/junction/src/main/java/org/killbill/billing/junction/plumbing/billing/DefaultInternalBillingApi.java
@@ -21,6 +21,7 @@ package org.killbill.billing.junction.plumbing.billing;
 import java.math.BigDecimal;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -50,9 +51,9 @@ import org.killbill.billing.junction.BillingInternalApi;
 import org.killbill.billing.subscription.api.SubscriptionBase;
 import org.killbill.billing.subscription.api.SubscriptionBaseInternalApi;
 import org.killbill.billing.subscription.api.SubscriptionBaseTransitionType;
-import org.killbill.billing.subscription.api.user.SubscriptionBillingEvent;
 import org.killbill.billing.subscription.api.user.SubscriptionBaseApiException;
 import org.killbill.billing.subscription.api.user.SubscriptionBaseBundle;
+import org.killbill.billing.subscription.api.user.SubscriptionBillingEvent;
 import org.killbill.billing.tag.TagInternalApi;
 import org.killbill.billing.util.UUIDs;
 import org.killbill.billing.util.bcd.BillCycleDayCalculator;
@@ -107,24 +108,28 @@ public class DefaultInternalBillingApi implements BillingInternalApi {
 
         if (found_AUTO_INVOICING_OFF) {
             result = new DefaultBillingEventSet(true, found_INVOICING_DRAFT, found_INVOICING_REUSE_DRAFT); // billing is off, we are done
-        } else {
-            final List<SubscriptionBaseBundle> bundles = subscriptionApi.getBundlesForAccount(accountId, context);
-
-            final ImmutableAccountData account = accountApi.getImmutableAccountDataById(accountId, context);
-            result = new DefaultBillingEventSet(false, found_INVOICING_DRAFT, found_INVOICING_REUSE_DRAFT);
-            addBillingEventsForBundles(bundles, account, dryRunArguments, context, result, skippedSubscriptions, fullCatalog, tagsForAccount);
+            log.info("Account is AUTO_INVOICING_OFF: no billing event for accountId='{}'", accountId);
+            return result;
         }
 
+        final Map<UUID, List<SubscriptionBase>> subscriptionsForAccount = subscriptionApi.getSubscriptionsForAccount(fullCatalog, context);
+
+
+        final List<SubscriptionBaseBundle> bundles = subscriptionApi.getBundlesForAccount(accountId, context);
+        final ImmutableAccountData account = accountApi.getImmutableAccountDataById(accountId, context);
+        result = new DefaultBillingEventSet(false, found_INVOICING_DRAFT, found_INVOICING_REUSE_DRAFT);
+        addBillingEventsForBundles(bundles, account, dryRunArguments, context, result, skippedSubscriptions, subscriptionsForAccount, fullCatalog, tagsForAccount);
         if (result.isEmpty()) {
             log.info("No billing event for accountId='{}'", accountId);
             return result;
         }
 
 
+
         // Pretty-print the events, before and after the blocking calculator does its magic
         final StringBuilder logStringBuilder = new StringBuilder("Computed billing events for accountId='").append(accountId).append("'");
         eventsToString(logStringBuilder, result);
-        if (blockCalculator.insertBlockingEvents(result, skippedSubscriptions, fullCatalog, context)) {
+        if (blockCalculator.insertBlockingEvents(result, skippedSubscriptions, subscriptionsForAccount, fullCatalog, context)) {
             logStringBuilder.append("\nBilling Events After Blocking");
             eventsToString(logStringBuilder, result);
         }
@@ -145,6 +150,7 @@ public class DefaultInternalBillingApi implements BillingInternalApi {
                                             final InternalCallContext context,
                                             final DefaultBillingEventSet result,
                                             final Set<UUID> skipSubscriptionsSet,
+                                            final Map<UUID, List<SubscriptionBase>> subscriptionsForAccount,
                                             final Catalog catalog,
                                             final List<Tag> tagsForAccount) throws AccountApiException, CatalogApiException, SubscriptionBaseApiException {
         final int currentAccountBCD = accountApi.getBCD(context);
@@ -154,6 +160,7 @@ public class DefaultInternalBillingApi implements BillingInternalApi {
                                    context,
                                    result,
                                    skipSubscriptionsSet,
+                                   subscriptionsForAccount,
                                    catalog,
                                    tagsForAccount,
                                    currentAccountBCD);
@@ -165,6 +172,7 @@ public class DefaultInternalBillingApi implements BillingInternalApi {
                                             final InternalCallContext context,
                                             final DefaultBillingEventSet result,
                                             final Set<UUID> skipSubscriptionsSet,
+                                            final Map<UUID, List<SubscriptionBase>> subscriptionsForAccount,
                                             final Catalog catalog,
                                             final List<Tag> tagsForAccount,
                                             final int currentAccountBCD) throws AccountApiException, CatalogApiException, SubscriptionBaseApiException {
@@ -179,8 +187,6 @@ public class DefaultInternalBillingApi implements BillingInternalApi {
             addBillingEventsForSubscription(account, subscriptions, null, currentAccountBCD, context, result, skipSubscriptionsSet, catalog);
         }
 
-        final Map<UUID, List<SubscriptionBase>> subscriptionsForAccount = subscriptionApi.getSubscriptionsForAccount(catalog, context);
-
         for (final SubscriptionBaseBundle bundle : bundles) {
             final DryRunArguments dryRunArgumentsForBundle = (dryRunArguments != null &&
                                                               dryRunArguments.getBundleId() != null &&
@@ -217,7 +223,7 @@ public class DefaultInternalBillingApi implements BillingInternalApi {
             // Because we now have computed the real BCD, we need to re-compute the BillingEvents BCD for ACCOUNT alignments (see BillCycleDayCalculator#calculateBcdForAlignment).
             // The code could maybe be optimized (no need to re-run the full function?), but since it's run once per account, it's probably not worth it.
             result.clear();
-            addBillingEventsForBundles(bundles, account, dryRunArguments, context, result, skipSubscriptionsSet, catalog, tagsForAccount, accountBCDCandidate);
+            addBillingEventsForBundles(bundles, account, dryRunArguments, context, result, skipSubscriptionsSet, subscriptionsForAccount, catalog, tagsForAccount, accountBCDCandidate);
 
             final boolean dryRunMode = dryRunArguments != null;
             if (!dryRunMode) {
diff --git a/junction/src/test/java/org/killbill/billing/junction/plumbing/billing/TestBlockingCalculator.java b/junction/src/test/java/org/killbill/billing/junction/plumbing/billing/TestBlockingCalculator.java
index a583d92..a2331ce 100644
--- a/junction/src/test/java/org/killbill/billing/junction/plumbing/billing/TestBlockingCalculator.java
+++ b/junction/src/test/java/org/killbill/billing/junction/plumbing/billing/TestBlockingCalculator.java
@@ -20,10 +20,12 @@ package org.killbill.billing.junction.plumbing.billing;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.SortedSet;
 import java.util.TreeSet;
 import java.util.UUID;
@@ -74,6 +76,7 @@ public class TestBlockingCalculator extends JunctionTestSuiteNoDB {
     private SubscriptionBase subscription2;
     private SubscriptionBase subscription3;
     private SubscriptionBase subscription4;
+    private Map<UUID, List<SubscriptionBase>> subscriptionsForAccount;
 
     @BeforeMethod(groups = "fast")
     public void beforeMethod() throws Exception {
@@ -83,6 +86,9 @@ public class TestBlockingCalculator extends JunctionTestSuiteNoDB {
 
         super.beforeMethod();
         account = Mockito.mock(Account.class);
+
+        subscriptionsForAccount = new HashMap<>();
+
         subscription1 = Mockito.mock(SubscriptionBase.class);
         subscription2 = Mockito.mock(SubscriptionBase.class);
         subscription3 = Mockito.mock(SubscriptionBase.class);
@@ -91,12 +97,25 @@ public class TestBlockingCalculator extends JunctionTestSuiteNoDB {
         Mockito.when(subscription1.getBundleId()).thenReturn(bundleId1);
         Mockito.when(subscription2.getBundleId()).thenReturn(bundleId1);
         Mockito.when(subscription3.getBundleId()).thenReturn(bundleId1);
+        final List<SubscriptionBase> bundleSubscriptions1 = new ArrayList<>();
+        bundleSubscriptions1.add(subscription1);
+        bundleSubscriptions1.add(subscription2);
+        bundleSubscriptions1.add(subscription3);
+        subscriptionsForAccount.put(bundleId1, bundleSubscriptions1);
+
         Mockito.when(subscription4.getBundleId()).thenReturn(bundleId2);
+        final List<SubscriptionBase> bundleSubscriptions2 = new ArrayList<>();
+        bundleSubscriptions1.add(subscription4);
+        subscriptionsForAccount.put(bundleId2, bundleSubscriptions2);
+
+
         Mockito.when(subscription1.getId()).thenReturn(UUID.randomUUID());
         Mockito.when(subscription2.getId()).thenReturn(UUID.randomUUID());
         Mockito.when(subscription3.getId()).thenReturn(UUID.randomUUID());
         Mockito.when(subscription4.getId()).thenReturn(UUID.randomUUID());
 
+
+
         ((MockBlockingStateDao) blockingStateDao).clear();
     }
 
@@ -131,7 +150,7 @@ public class TestBlockingCalculator extends JunctionTestSuiteNoDB {
                                                                                                                         blockingState2, Optional.<UUID>absent()),
                                                                          internalCallContext);
 
-        blockingCalculator.insertBlockingEvents(billingEvents, new HashSet<UUID>(), catalogInternalApi.getFullCatalog(true, true, internalCallContext), internalCallContext);
+        blockingCalculator.insertBlockingEvents(billingEvents, new HashSet<UUID>(), subscriptionsForAccount, catalogInternalApi.getFullCatalog(true, true, internalCallContext), internalCallContext);
 
         assertEquals(billingEvents.size(), 7);
 
@@ -580,10 +599,7 @@ public class TestBlockingCalculator extends JunctionTestSuiteNoDB {
         final SortedSet<BillingEvent> result3 = blockingCalculator.filter(events, subscription3);
 
         assertEquals(result1.size(), 3);
-        assertEquals(((DefaultBillingEvent)(result1.first())).getSubscription(), subscription1);
-        assertEquals(((DefaultBillingEvent)(result1.last())).getSubscription(), subscription1);
         assertEquals(result2.size(), 1);
-        assertEquals(((DefaultBillingEvent)(result2.first())).getSubscription(), subscription2);
         assertEquals(result3.size(), 0);
     }
 
@@ -629,25 +645,6 @@ public class TestBlockingCalculator extends JunctionTestSuiteNoDB {
     }
 
     @Test(groups = "fast")
-    public void testCreateBundleSubscriptionMap() {
-        final SortedSet<BillingEvent> events = new TreeSet<BillingEvent>();
-        events.add(createBillingEvent(subscription1, 1L));
-        events.add(createBillingEvent(subscription2, 2L));
-        events.add(createBillingEvent(subscription3, 3L));
-        events.add(createBillingEvent(subscription4, 4L));
-
-        final Hashtable<UUID, List<SubscriptionBase>> map = blockingCalculator.createBundleSubscriptionMap(events);
-
-        assertNotNull(map);
-        assertEquals(map.keySet().size(), 2);
-        assertEquals(map.get(bundleId1).size(), 3);
-        assertEquals(map.get(bundleId2).size(), 1);
-
-    }
-
-
-
-    @Test(groups = "fast")
     public void testCreateDisablePairs() {
         List<BlockingState> blockingEvents;
         final UUID ovdId = UUID.randomUUID();
@@ -801,7 +798,8 @@ public class TestBlockingCalculator extends JunctionTestSuiteNoDB {
                                                                                                                         blockingState4, Optional.<UUID>absent()),
                                                                          internalCallContext);
 
-        blockingCalculator.insertBlockingEvents(billingEvents, new HashSet<UUID>(), catalogInternalApi.getFullCatalog(true, true, internalCallContext), internalCallContext);
+
+        blockingCalculator.insertBlockingEvents(billingEvents, new HashSet<UUID>(), subscriptionsForAccount, catalogInternalApi.getFullCatalog(true, true, internalCallContext), internalCallContext);
 
         assertEquals(billingEvents.size(), 5);
         final List<BillingEvent> events = new ArrayList<BillingEvent>(billingEvents);
@@ -850,7 +848,8 @@ public class TestBlockingCalculator extends JunctionTestSuiteNoDB {
 
             final BigDecimal fixedPrice = BigDecimal.TEN;
 
-            return new DefaultBillingEvent(subscription,
+            return new DefaultBillingEvent(subscription.getId(),
+                                           subscription.getBundleId(),
                                            effectiveDate,
                                            plan,
                                            planPhase,
diff --git a/junction/src/test/java/org/killbill/billing/junction/plumbing/billing/TestDefaultBillingEvent.java b/junction/src/test/java/org/killbill/billing/junction/plumbing/billing/TestDefaultBillingEvent.java
index 9ae56ef..6b30758 100644
--- a/junction/src/test/java/org/killbill/billing/junction/plumbing/billing/TestDefaultBillingEvent.java
+++ b/junction/src/test/java/org/killbill/billing/junction/plumbing/billing/TestDefaultBillingEvent.java
@@ -184,7 +184,7 @@ public class TestDefaultBillingEvent extends JunctionTestSuiteNoDB {
         final Plan shotgun = new MockPlan();
         final PlanPhase shotgunMonthly = createMockMonthlyPlanPhase(null, BigDecimal.ZERO, PhaseType.TRIAL);
 
-        return new DefaultBillingEvent(sub, effectiveDate,
+        return new DefaultBillingEvent(sub.getId(), sub.getBundleId(), effectiveDate,
                                        shotgun, shotgunMonthly, BigDecimal.ZERO, BigDecimal.ZERO,
                                        Currency.USD, BillingPeriod.NO_BILLING_PERIOD, billCycleDay,
                                        "Test Event 1", totalOrdering, type, false);