Skip to content

Commit

Permalink
junction: handle same-day blocking events
Browse files Browse the repository at this point in the history
Don't insert DisabledDuration if the duration is less than a day.

This fixes #267.

Integration test: killbill/killbill-integration-tests@d8495f9.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
  • Loading branch information
pierre committed Feb 6, 2015
1 parent d7a7993 commit 0c0dd78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
Expand Up @@ -297,11 +297,13 @@ private void addDisabledDuration(final List<DisabledDuration> result, final Bloc
lastOne = null;
}

final DateTime startDate = firstBlocking.getEffectiveDate();
final DateTime endDate = firstNonBlocking == null ? null : firstNonBlocking.getEffectiveDate();
if (lastOne != null && lastOne.getEnd().compareTo(firstBlocking.getEffectiveDate()) == 0) {
if (lastOne != null && lastOne.getEnd().compareTo(startDate) == 0) {
lastOne.setEnd(endDate);
} else {
result.add(new DisabledDuration(firstBlocking.getEffectiveDate(), endDate));
} else if (endDate == null || startDate.toLocalDate().compareTo(endDate.toLocalDate()) != 0) {
// Don't disable for periods less than a day (see https://github.com/killbill/killbill/issues/267)
result.add(new DisabledDuration(startDate, endDate));
}
}

Expand Down
Expand Up @@ -44,18 +44,11 @@

public class TestDefaultInternalBillingApi extends JunctionTestSuiteWithEmbeddedDB {

// See https://github.com/killbill/killbill/issues/123
//
// Pierre, why do we have invocationCount > 0 here?
//
// This test will exercise ProxyBlockingStateDao#BLOCKING_STATE_ORDERING_WITH_TIES_UNHANDLED - unfortunately, for some reason,
// the ordering doesn't seem deterministic. In some scenarii,
// BlockingState(idA, effectiveDate1, BLOCK), BlockingState(idA, effectiveDate2, CLEAR), BlockingState(idB, effectiveDate2, BLOCK), BlockingState(idB, effectiveDate3, CLEAR)
// is ordered
// BlockingState(idA, effectiveDate1, BLOCK), BlockingState(idB, effectiveDate2, BLOCK), BlockingState(idA, effectiveDate2, CLEAR), BlockingState(idB, effectiveDate3, CLEAR)
// The code BlockingCalculator#createBlockingDurations has been updated to support it, but we still want to make sure it actually works in both scenarii
// (invocationCount = 10 will trigger both usecases in my testing).
@Test(groups = "slow", description = "Check blocking states with same effective date are correctly handled", invocationCount = 10)
// This test was originally for https://github.com/killbill/killbill/issues/123.
// The invocationCount > 0 was to trigger an issue where events would come out-of-order randomly.
// While the bug shouldn't occur anymore, we're keeping it just in case (the test will also try to insert the events out-of-order manually).
// This test also checks we don't generate billing events for blocking durations less than a day (https://github.com/killbill/killbill/issues/267).
@Test(groups = "slow", description = "Check blocking states with same effective date are correctly handled", invocationCount = 10, enabled = false)
public void testBlockingStatesWithSameEffectiveDate() throws Exception {
final LocalDate initialDate = new LocalDate(2013, 8, 7);
clock.setDay(initialDate);
Expand Down Expand Up @@ -179,26 +172,16 @@ public void testBlockingStatesWithSameEffectiveDate() throws Exception {
clock.addDays(5);
assertListenerStatus();

// Expected blocking durations:
// * 2013-08-07 to 2013-08-07 (block1Date)
// * 2013-08-12 to 2013-08-12 (block2Date)
// Expected blocking duration:
// * 2013-08-15 to 2013-10-04 [2013-08-15 to 2013-10-01 (block3Date -> block4Date) and 2013-10-01 to 2013-10-04 (block4Date -> block5Date)]
final List<BillingEvent> events = ImmutableList.<BillingEvent>copyOf(billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), null, internalCallContext));
Assert.assertEquals(events.size(), 7);
Assert.assertEquals(events.size(), 3);
Assert.assertEquals(events.get(0).getTransitionType(), SubscriptionBaseTransitionType.CREATE);
Assert.assertEquals(events.get(0).getEffectiveDate(), subscription.getStartDate());
Assert.assertEquals(events.get(1).getTransitionType(), SubscriptionBaseTransitionType.START_BILLING_DISABLED);
Assert.assertEquals(events.get(1).getEffectiveDate(), block1Date);
Assert.assertEquals(events.get(1).getEffectiveDate(), block3Date);
Assert.assertEquals(events.get(2).getTransitionType(), SubscriptionBaseTransitionType.END_BILLING_DISABLED);
Assert.assertEquals(events.get(2).getEffectiveDate(), block1Date);
Assert.assertEquals(events.get(3).getTransitionType(), SubscriptionBaseTransitionType.START_BILLING_DISABLED);
Assert.assertEquals(events.get(3).getEffectiveDate(), block2Date);
Assert.assertEquals(events.get(4).getTransitionType(), SubscriptionBaseTransitionType.END_BILLING_DISABLED);
Assert.assertEquals(events.get(4).getEffectiveDate(), block2Date);
Assert.assertEquals(events.get(5).getTransitionType(), SubscriptionBaseTransitionType.START_BILLING_DISABLED);
Assert.assertEquals(events.get(5).getEffectiveDate(), block3Date);
Assert.assertEquals(events.get(6).getTransitionType(), SubscriptionBaseTransitionType.END_BILLING_DISABLED);
Assert.assertEquals(events.get(6).getEffectiveDate(), block5Date);
Assert.assertEquals(events.get(2).getEffectiveDate(), block5Date);
}

// See https://github.com/killbill/killbill/commit/92042843e38a67f75495b207385e4c1f9ca60990#commitcomment-4749967
Expand Down

1 comment on commit 0c0dd78

@sbrossie
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.