killbill-memoizeit

Merge branch 'integration' of github.com:ning/killbill

3/9/2012 2:38:20 AM

Changes

Details

diff --git a/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java b/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java
index 62e2f96..c88d255 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java
@@ -208,6 +208,7 @@ public class TestAnalyticsService {
                 plan,
                 phase,
                 priceList,
+                1L,
                 true
         );
         expectedTransition = new BusinessSubscriptionTransition(
diff --git a/analytics/src/test/java/com/ning/billing/analytics/TestAnalyticsListener.java b/analytics/src/test/java/com/ning/billing/analytics/TestAnalyticsListener.java
index 79bea58..6d8e587 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/TestAnalyticsListener.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/TestAnalyticsListener.java
@@ -144,6 +144,7 @@ public class TestAnalyticsListener
             plan,
             phase,
             priceList,
+            1L,
             true
         );
     }
@@ -169,6 +170,7 @@ public class TestAnalyticsListener
             null,
             null,
             null,
+            1L,
             true
         );
     }
@@ -197,6 +199,7 @@ public class TestAnalyticsListener
             plan,
             phase,
             priceList,
+            1L,
             true
         );
     }
diff --git a/api/src/main/java/com/ning/billing/entitlement/api/billing/BillingEvent.java b/api/src/main/java/com/ning/billing/entitlement/api/billing/BillingEvent.java
index f11e5b4..21ac60f 100644
--- a/api/src/main/java/com/ning/billing/entitlement/api/billing/BillingEvent.java
+++ b/api/src/main/java/com/ning/billing/entitlement/api/billing/BillingEvent.java
@@ -82,13 +82,13 @@ public interface BillingEvent extends Comparable<BillingEvent> {
     public String getDescription();
 
     /**
-     * 
+     *
      * @return the fixed price for the phase
      */
     public BigDecimal getFixedPrice();
 
     /**
-     * 
+     *
      * @return the recurring price for the phase
      */
     public BigDecimal getRecurringPrice();
@@ -103,4 +103,10 @@ public interface BillingEvent extends Comparable<BillingEvent> {
 	 * @return the transition type of the underlying subscription event that triggered this
 	 */
 	public SubscriptionTransitionType getTransitionType();
+
+	/**
+	 * @return a unique long indicating the ordering on which events got inserted on disk-- used for sorting only
+	 */
+	public long getTotalOrdering();
+
 }
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBasic.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBasic.java
index 894f8d8..99a1d8b 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBasic.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBasic.java
@@ -242,25 +242,25 @@ public class TestBasic {
         assertTrue(ctd.compareTo(chargeThroughDate) == 0);
     }
 
-    @Test(groups = "fast", enabled = true)
+    @Test(groups = "slow", enabled = true)
     public void testBasePlanCompleteWithBillingDayInPast() throws Exception {
         DateTime startDate = new DateTime(2012, 2, 1, 0, 3, 42, 0);
         testBasePlanComplete(startDate, 31, false);
     }
 
-    @Test(groups = "fast", enabled = true)
+    @Test(groups = "slow", enabled = true)
     public void testBasePlanCompleteWithBillingDayPresent() throws Exception {
         DateTime startDate = new DateTime(2012, 2, 1, 0, 3, 42, 0);
         testBasePlanComplete(startDate, 1, false);
     }
 
-    @Test(groups = "fast", enabled = true)
+    @Test(groups = "slow", enabled = true)
     public void testBasePlanCompleteWithBillingDayAlignedWithTrial() throws Exception {
         DateTime startDate = new DateTime(2012, 2, 1, 0, 3, 42, 0);
         testBasePlanComplete(startDate, 2, false);
     }
 
-    @Test(groups = "fast", enabled = true)
+    @Test(groups = "slow", enabled = true)
     public void testBasePlanCompleteWithBillingDayInFuture() throws Exception {
         DateTime startDate = new DateTime(2012, 2, 1, 0, 3, 42, 0);
         testBasePlanComplete(startDate, 3, true);
@@ -270,7 +270,7 @@ public class TestBasic {
         Thread.sleep(600000);
     }
 
-    @Test(groups = "stress", enabled = true)
+    @Test(groups = "stress", enabled = false)
     public void stressTest() throws Exception {
         final int maxIterations = 7;
         for (int curIteration = 0; curIteration < maxIterations; curIteration++) {
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/api/billing/DefaultBillingEvent.java b/entitlement/src/main/java/com/ning/billing/entitlement/api/billing/DefaultBillingEvent.java
index 1186580..3d40c71 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/api/billing/DefaultBillingEvent.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/api/billing/DefaultBillingEvent.java
@@ -26,6 +26,7 @@ import com.ning.billing.catalog.api.PlanPhase;
 import com.ning.billing.entitlement.api.user.Subscription;
 import com.ning.billing.entitlement.api.user.SubscriptionTransition;
 import com.ning.billing.entitlement.api.user.SubscriptionTransition.SubscriptionTransitionType;
+import com.ning.billing.entitlement.api.user.SubscriptionTransitionData;
 
 import java.math.BigDecimal;
 
@@ -42,6 +43,7 @@ public class DefaultBillingEvent implements BillingEvent {
     final private BillingModeType billingModeType;
     final private BillingPeriod billingPeriod;
     final private SubscriptionTransitionType type;
+    final private long totalOrdering;
 
     public DefaultBillingEvent(SubscriptionTransition transition, Subscription subscription, int billCycleDay, Currency currency) throws CatalogApiException {
         this.billCycleDay = billCycleDay;
@@ -63,13 +65,14 @@ public class DefaultBillingEvent implements BillingEvent {
         billingPeriod =  (transition.getTransitionType() != SubscriptionTransitionType.CANCEL) ?
                 transition.getNextPhase().getBillingPeriod() : transition.getPreviousPhase().getBillingPeriod();
         type = transition.getTransitionType();
+        totalOrdering = ((SubscriptionTransitionData) transition).getTotalOrdering();
     }
 
     // Intended for test only
     public DefaultBillingEvent(Subscription subscription, DateTime effectiveDate, Plan plan, PlanPhase planPhase,
                                BigDecimal fixedPrice, BigDecimal recurringPrice, Currency currency,
                                BillingPeriod billingPeriod, int billCycleDay, BillingModeType billingModeType,
-                               String description, SubscriptionTransitionType type) {
+                               String description, long totalOrdering, SubscriptionTransitionType type) {
         this.subscription = subscription;
         this.effectiveDate = effectiveDate;
         this.plan = plan;
@@ -82,8 +85,10 @@ public class DefaultBillingEvent implements BillingEvent {
         this.billingModeType = billingModeType;
         this.description = description;
         this.type = type;
+        this.totalOrdering = totalOrdering;
     }
 
+
     @Override
     public int compareTo(BillingEvent e1) {
     	 if (!getSubscription().getId().equals(e1.getSubscription().getId())) { // First order by subscription
@@ -162,6 +167,11 @@ public class DefaultBillingEvent implements BillingEvent {
     }
 
     @Override
+    public long getTotalOrdering() {
+        return totalOrdering;
+    }
+
+    @Override
     public String toString() {
         StringBuilder sb = new StringBuilder();
         sb.append("BillingEvent {subscriptionId = ").append(subscription.getId().toString()).append(", ");
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionData.java b/entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionData.java
index 2efe1c5..138528d 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionData.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionData.java
@@ -100,22 +100,42 @@ public class SubscriptionData extends CustomizableEntityBase implements Subscrip
 
     @Override
     public void setFieldValue(String fieldName, String fieldValue) {
+        setFieldValueInternal(fieldName, fieldValue, true);
+    }
+
+    public void setFieldValueInternal(String fieldName, String fieldValue, boolean commit) {
         super.setFieldValue(fieldName, fieldValue);
-        apiService.commitCustomFields(this);
+        if (commit) {
+            apiService.commitCustomFields(this);
+        }
     }
 
+
     @Override
     public void addFields(List<CustomField> fields) {
+        addFieldsInternal(fields, true);
+    }
+
+    public void addFieldsInternal(List<CustomField> fields, boolean commit) {
         super.addFields(fields);
-        apiService.commitCustomFields(this);
+        if (commit) {
+            apiService.commitCustomFields(this);
+        }
     }
 
     @Override
     public void clearFields() {
+        clearFieldsInternal(true);
+    }
+
+    public void clearFieldsInternal(boolean commit) {
         super.clearFields();
-        apiService.commitCustomFields(this);
+        if (commit) {
+            apiService.commitCustomFields(this);
+        }
     }
 
+
     @Override
     public UUID getBundleId() {
         return bundleId;
@@ -455,6 +475,7 @@ public class SubscriptionData extends CustomizableEntityBase implements Subscrip
                         nextPlan,
                         nextPhase,
                         nextPriceList,
+                        cur.getTotalOrdering(),
                         isFromDisk);
             transitions.add(transition);
 
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionTransitionData.java b/entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionTransitionData.java
index fb8e2f2..f03193b 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionTransitionData.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/api/user/SubscriptionTransitionData.java
@@ -29,6 +29,7 @@ import java.util.UUID;
 public class SubscriptionTransitionData implements SubscriptionTransition {
 
 
+    private final long totalOrdering;
     private final UUID subscriptionId;
     private final UUID bundleId;
     private final UUID eventId;
@@ -49,7 +50,8 @@ public class SubscriptionTransitionData implements SubscriptionTransition {
     public SubscriptionTransitionData(UUID eventId, UUID subscriptionId, UUID bundleId, EventType eventType,
             ApiEventType apiEventType, DateTime requestedTransitionTime, DateTime effectiveTransitionTime,
             SubscriptionState previousState, Plan previousPlan, PlanPhase previousPhase, String previousPriceList,
-            SubscriptionState nextState, Plan nextPlan, PlanPhase nextPhase, String nextPriceList, boolean isFromDisk) {
+            SubscriptionState nextState, Plan nextPlan, PlanPhase nextPhase, String nextPriceList,
+            long totalOrdering, boolean isFromDisk) {
         super();
         this.eventId = eventId;
         this.subscriptionId = subscriptionId;
@@ -66,6 +68,7 @@ public class SubscriptionTransitionData implements SubscriptionTransition {
         this.nextPlan = nextPlan;
         this.nextPriceList = nextPriceList;
         this.nextPhase = nextPhase;
+        this.totalOrdering = totalOrdering;
         this.isFromDisk = isFromDisk;
     }
 
@@ -148,6 +151,10 @@ public class SubscriptionTransitionData implements SubscriptionTransition {
         return effectiveTransitionTime;
     }
 
+    public long getTotalOrdering() {
+        return totalOrdering;
+    }
+
     public boolean isFromDisk() {
         return isFromDisk;
     }
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/EntitlementSqlDao.java b/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/EntitlementSqlDao.java
index 15fe20c..cd4267e 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/EntitlementSqlDao.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/EntitlementSqlDao.java
@@ -511,7 +511,7 @@ public class EntitlementSqlDao implements EntitlementDao {
             default:
                 break;
             }
-            loadCustomFields(reloaded);
+            loadCustomFields((SubscriptionData) reloaded);
             result.add(reloaded);
         }
         return result;
@@ -618,12 +618,12 @@ public class EntitlementSqlDao implements EntitlementDao {
         });
     }
 
-    private void loadCustomFields(final Subscription subscription) {
+    private void loadCustomFields(final SubscriptionData subscription) {
         FieldStoreDao fieldStoreDao = subscriptionsDao.become(FieldStoreDao.class);
         List<CustomField> fields = fieldStoreDao.load(subscription.getId().toString(), subscription.getObjectName());
-        subscription.clearFields();
+        subscription.clearFieldsInternal(false);
         if (fields != null) {
-            subscription.addFields(fields);
+            subscription.addFieldsInternal(fields, false);
         }
     }
 }
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/EventSqlDao.java b/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/EventSqlDao.java
index 67c60c0..203877f 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/EventSqlDao.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/EventSqlDao.java
@@ -107,6 +107,7 @@ public interface EventSqlDao extends Transactional<EventSqlDao>, CloseMe, Transm
         public EntitlementEvent map(int index, ResultSet r, StatementContext ctx)
         throws SQLException {
 
+            long totalOrdering = r.getLong("id");
             UUID id = UUID.fromString(r.getString("event_id"));
             EventType eventType = EventType.valueOf(r.getString("event_type"));
             ApiEventType userType = (eventType == EventType.API_USER) ? ApiEventType.valueOf(r.getString("user_type")) : null;
@@ -123,6 +124,7 @@ public interface EventSqlDao extends Transactional<EventSqlDao>, CloseMe, Transm
             EventBaseBuilder<?> base = ((eventType == EventType.PHASE) ?
                     new PhaseEventBuilder() :
                         new ApiEventBuilder())
+                        .setTotalOrdering(totalOrdering)
                         .setUuid(id)
                         .setSubscriptionId(subscriptionId)
                         .setRequestedDate(requestedDate)
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/events/EntitlementEvent.java b/entitlement/src/main/java/com/ning/billing/entitlement/events/EntitlementEvent.java
index b7bfece..d3895c0 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/events/EntitlementEvent.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/events/EntitlementEvent.java
@@ -30,6 +30,8 @@ public interface EntitlementEvent extends Comparable<EntitlementEvent> {
 
     public EventType getType();
 
+    public long getTotalOrdering();
+
     public UUID getId();
 
     public long getActiveVersion();
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/events/EventBase.java b/entitlement/src/main/java/com/ning/billing/entitlement/events/EventBase.java
index 9420fbf..5861e5d 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/events/EventBase.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/events/EventBase.java
@@ -24,6 +24,7 @@ import java.util.UUID;
 
 public abstract class EventBase implements EntitlementEvent {
 
+    private final long totalOrdering;
     private final UUID uuid;
     private final UUID subscriptionId;
     private final DateTime requestedDate;
@@ -34,6 +35,7 @@ public abstract class EventBase implements EntitlementEvent {
     private boolean isActive;
 
     public EventBase(EventBaseBuilder<?> builder) {
+        this.totalOrdering = builder.getTotalOrdering();
         this.uuid = builder.getUuid();
         this.subscriptionId = builder.getSubscriptionId();
         this.requestedDate = builder.getRequestedDate();
@@ -43,7 +45,7 @@ public abstract class EventBase implements EntitlementEvent {
         this.activeVersion = builder.getActiveVersion();
         this.isActive = builder.isActive();
     }
-
+/*
     public EventBase(UUID subscriptionId, DateTime requestedDate,
             DateTime effectiveDate, DateTime processedDate,
             long activeVersion, boolean isActive) {
@@ -62,7 +64,7 @@ public abstract class EventBase implements EntitlementEvent {
         this.activeVersion = activeVersion;
         this.isActive = isActive;
     }
-
+*/
 
     @Override
     public DateTime getRequestedDate() {
@@ -85,11 +87,16 @@ public abstract class EventBase implements EntitlementEvent {
     }
 
     @Override
+    public long getTotalOrdering() {
+        return totalOrdering;
+    }
+
+
+    @Override
     public UUID getId() {
         return uuid;
     }
 
-
     @Override
     public long getActiveVersion() {
         return activeVersion;
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/events/EventBaseBuilder.java b/entitlement/src/main/java/com/ning/billing/entitlement/events/EventBaseBuilder.java
index 17f5e15..e74ea69 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/events/EventBaseBuilder.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/events/EventBaseBuilder.java
@@ -23,6 +23,7 @@ import java.util.UUID;
 @SuppressWarnings("unchecked")
 public class EventBaseBuilder<T extends EventBaseBuilder<T>> {
 
+    private long totalOrdering;
     private UUID uuid;
     private UUID subscriptionId;
     private DateTime requestedDate;
@@ -49,6 +50,11 @@ public class EventBaseBuilder<T extends EventBaseBuilder<T>> {
         this.isActive = copy.isActive;
     }
 
+    public T setTotalOrdering(long totalOrdering) {
+        this.totalOrdering = totalOrdering;
+        return (T) this;
+    }
+
     public T setUuid(UUID uuid) {
         this.uuid = uuid;
         return (T) this;
@@ -84,6 +90,10 @@ public class EventBaseBuilder<T extends EventBaseBuilder<T>> {
         return (T) this;
     }
 
+    public long getTotalOrdering() {
+        return totalOrdering;
+    }
+
     public UUID getUuid() {
         return uuid;
     }
diff --git a/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/EventSqlDao.sql.stg b/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/EventSqlDao.sql.stg
index 10f565d..b639dce 100644
--- a/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/EventSqlDao.sql.stg
+++ b/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/EventSqlDao.sql.stg
@@ -2,7 +2,8 @@ group EventSqlDao;
 
 getEventById(event_id) ::= <<
   select
-     event_id
+      id
+      , event_id
       , event_type
       , user_type
       , created_dt
@@ -82,7 +83,8 @@ reactiveEvent(event_id, now) ::= <<
 
 getFutureActiveEventForSubscription(subscription_id, now) ::= <<
     select 
-      event_id
+      id
+      , event_id
       , event_type
       , user_type
       , created_dt
@@ -110,7 +112,8 @@ getFutureActiveEventForSubscription(subscription_id, now) ::= <<
 
 getEventsForSubscription(subscription_id) ::= <<
     select
-      event_id
+       id
+      , event_id
       , event_type
       , user_type
       , created_dt
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/billing/TestDefaultBillingEvent.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/billing/TestDefaultBillingEvent.java
index 4766a08..df9e744 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/billing/TestDefaultBillingEvent.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/billing/TestDefaultBillingEvent.java
@@ -133,7 +133,7 @@ public class TestDefaultBillingEvent {
 		return new DefaultBillingEvent(sub , effectiveDate,
 				shotgun, shotgunMonthly,
 				BigDecimal.ZERO, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, billCycleDay,
-				BillingModeType.IN_ADVANCE, "Test Event 1", type);
+				BillingModeType.IN_ADVANCE, "Test Event 1", 1L, type);
 	}
 
 	private MockPlanPhase createMockMonthlyPlanPhase(@Nullable final BigDecimal recurringRate,
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/billing/TestDefaultEntitlementBillingApi.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/billing/TestDefaultEntitlementBillingApi.java
index 998e684..513a5ca 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/billing/TestDefaultEntitlementBillingApi.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/billing/TestDefaultEntitlementBillingApi.java
@@ -148,7 +148,7 @@ public class TestDefaultEntitlementBillingApi {
 		PlanPhase nextPhase = nextPlan.getAllPhases()[0]; // The trial has no billing period
 		String nextPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
 		SubscriptionTransition t = new SubscriptionTransitionData(
-				zeroId, oneId, twoId, EventType.API_USER, ApiEventType.CREATE, then, now, null, null, null, null, SubscriptionState.ACTIVE, nextPlan, nextPhase, nextPriceList, true);
+				zeroId, oneId, twoId, EventType.API_USER, ApiEventType.CREATE, then, now, null, null, null, null, SubscriptionState.ACTIVE, nextPlan, nextPhase, nextPriceList, 1, true);
 		transitions.add(t);
 
 		AccountUserApi accountApi = new BrainDeadAccountUserApi(){
@@ -180,7 +180,7 @@ public class TestDefaultEntitlementBillingApi {
 		PlanPhase nextPhase = nextPlan.getAllPhases()[1];
 		String nextPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
 		SubscriptionTransition t = new SubscriptionTransitionData(
-				zeroId, oneId, twoId, EventType.API_USER, ApiEventType.CREATE, then, now, null, null, null, null, SubscriptionState.ACTIVE, nextPlan, nextPhase, nextPriceList, true);
+				zeroId, oneId, twoId, EventType.API_USER, ApiEventType.CREATE, then, now, null, null, null, null, SubscriptionState.ACTIVE, nextPlan, nextPhase, nextPriceList, 1, true);
 		transitions.add(t);
 
 		Account account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
@@ -204,7 +204,7 @@ public class TestDefaultEntitlementBillingApi {
 		PlanPhase nextPhase = nextPlan.getAllPhases()[1];
 		String nextPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
 		SubscriptionTransition t = new SubscriptionTransitionData(
-				zeroId, oneId, twoId, EventType.API_USER, ApiEventType.CREATE, then, now, null, null, null, null, SubscriptionState.ACTIVE, nextPlan, nextPhase, nextPriceList, true);
+				zeroId, oneId, twoId, EventType.API_USER, ApiEventType.CREATE, then, now, null, null, null, null, SubscriptionState.ACTIVE, nextPlan, nextPhase, nextPriceList, 1, true);
 		transitions.add(t);
 
 		AccountUserApi accountApi = new BrainDeadAccountUserApi(){
@@ -236,7 +236,7 @@ public class TestDefaultEntitlementBillingApi {
 		PlanPhase nextPhase = nextPlan.getAllPhases()[0];
 		String nextPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
 		SubscriptionTransition t = new SubscriptionTransitionData(
-				zeroId, oneId, twoId, EventType.API_USER, ApiEventType.CREATE, then, now, null, null, null, null, SubscriptionState.ACTIVE, nextPlan, nextPhase, nextPriceList, true);
+				zeroId, oneId, twoId, EventType.API_USER, ApiEventType.CREATE, then, now, null, null, null, null, SubscriptionState.ACTIVE, nextPlan, nextPhase, nextPriceList, 1, true);
 		transitions.add(t);
 
 		Account account = BrainDeadProxyFactory.createBrainDeadProxyFor(Account.class);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTests.java b/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTests.java
index b4058e2..2289a78 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTests.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTests.java
@@ -517,7 +517,7 @@ public class InvoiceDaoTests extends InvoiceDaoTestBase {
         DateTime effectiveDate1 = new DateTime(2011, 2, 1, 0, 0, 0, 0);
         BillingEvent event1 = new DefaultBillingEvent(subscription, effectiveDate1, plan1, phase1, null,
                 recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 1, BillingModeType.IN_ADVANCE,
-                "testEvent1", SubscriptionTransitionType.CREATE);
+                "testEvent1", 1L, SubscriptionTransitionType.CREATE);
 
         BillingEventSet events = new BillingEventSet();
         events.add(event1);
@@ -535,7 +535,7 @@ public class InvoiceDaoTests extends InvoiceDaoTestBase {
         DateTime effectiveDate2 = new DateTime(2011, 2, 15, 0, 0, 0, 0);
         BillingEvent event2 = new DefaultBillingEvent(subscription, effectiveDate2, plan2, phase2, null,
                 recurringPrice2.getPrice(currency), currency, BillingPeriod.MONTHLY, 1, BillingModeType.IN_ADVANCE,
-                "testEvent2", SubscriptionTransitionType.CREATE);
+                "testEvent2", 2L, SubscriptionTransitionType.CREATE);
         events.add(event2);
 
         // second invoice should be for one half (14/28 days) the difference between the rate plans
@@ -568,7 +568,7 @@ public class InvoiceDaoTests extends InvoiceDaoTestBase {
 
         BillingEvent event = new DefaultBillingEvent(subscription, effectiveDate, plan, phase, null,
                 recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 15, BillingModeType.IN_ADVANCE,
-                "testEvent", SubscriptionTransitionType.CREATE);
+                "testEvent", 1L, SubscriptionTransitionType.CREATE);
         BillingEventSet events = new BillingEventSet();
         events.add(event);
 
@@ -601,7 +601,7 @@ public class InvoiceDaoTests extends InvoiceDaoTestBase {
 
         BillingEvent event1 = new DefaultBillingEvent(subscription, effectiveDate1, plan, phase1, fixedPrice.getPrice(currency),
                 null, currency, BillingPeriod.MONTHLY, 1, BillingModeType.IN_ADVANCE,
-                "testEvent1", SubscriptionTransitionType.CREATE);
+                "testEvent1", 1L, SubscriptionTransitionType.CREATE);
         BillingEventSet events = new BillingEventSet();
         events.add(event1);
 
@@ -616,7 +616,7 @@ public class InvoiceDaoTests extends InvoiceDaoTestBase {
         DateTime effectiveDate2 = effectiveDate1.plusDays(30);
         BillingEvent event2 = new DefaultBillingEvent(subscription, effectiveDate2, plan, phase2, null,
                 recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 31, BillingModeType.IN_ADVANCE,
-                "testEvent2", SubscriptionTransitionType.CHANGE);
+                "testEvent2", 2L, SubscriptionTransitionType.CHANGE);
         events.add(event2);
 
         Invoice invoice2 = generator.generateInvoice(UUID.randomUUID(), events, invoiceList, effectiveDate2, Currency.USD);
@@ -661,14 +661,14 @@ public class InvoiceDaoTests extends InvoiceDaoTestBase {
         BillingEvent event1 = new DefaultBillingEvent(subscription, effectiveDate1, plan, phase1,
                 fixedPrice.getPrice(currency), null, currency,
                 BillingPeriod.MONTHLY, 1, BillingModeType.IN_ADVANCE,
-                "testEvent1", SubscriptionTransitionType.CREATE);
+                "testEvent1", 1L, SubscriptionTransitionType.CREATE);
         BillingEventSet events = new BillingEventSet();
         events.add(event1);
 
         DateTime effectiveDate2 = effectiveDate1.plusDays(30);
         BillingEvent event2 = new DefaultBillingEvent(subscription, effectiveDate2, plan, phase2, null,
                 recurringPrice.getPrice(currency), currency, BillingPeriod.MONTHLY, 31, BillingModeType.IN_ADVANCE,
-                "testEvent2", SubscriptionTransitionType.CHANGE);
+                "testEvent2", 2L, SubscriptionTransitionType.CHANGE);
         events.add(event2);
 
         Invoice invoice = generator.generateInvoice(UUID.randomUUID(), events, null, effectiveDate2, Currency.USD);
@@ -708,7 +708,7 @@ public class InvoiceDaoTests extends InvoiceDaoTestBase {
         BillingEvent event1 = new DefaultBillingEvent(subscription, targetDate1, plan, phase1, null,
                                                       TEN, currency,
                                                       BillingPeriod.MONTHLY, 31, BillingModeType.IN_ADVANCE,
-                                                      "testEvent1", SubscriptionTransitionType.CHANGE);
+                                                      "testEvent1", 1L, SubscriptionTransitionType.CHANGE);
         events.add(event1);
 
         Invoice invoice1 = generator.generateInvoice(UUID.randomUUID(), events, invoices, targetDate1, Currency.USD);
@@ -720,7 +720,7 @@ public class InvoiceDaoTests extends InvoiceDaoTestBase {
         BillingEvent event2 = new DefaultBillingEvent(subscription, targetDate1, plan, phase2, null,
                                                       TWENTY, currency,
                                                       BillingPeriod.MONTHLY, 31, BillingModeType.IN_ADVANCE,
-                                                      "testEvent2", SubscriptionTransitionType.CHANGE);
+                                                      "testEvent2", 2L, SubscriptionTransitionType.CHANGE);
         events.add(event2);
         Invoice invoice2 = generator.generateInvoice(UUID.randomUUID(), events, invoices, targetDate2, Currency.USD);
         invoiceDao.create(invoice2);
diff --git a/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceDispatcher.java b/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceDispatcher.java
index 4546a8c..209d889 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceDispatcher.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceDispatcher.java
@@ -71,13 +71,13 @@ public class TestInvoiceDispatcher {
     private InvoiceDao invoiceDao;
     @Inject
     private GlobalLocker locker;
-    
+
     @Inject
     private MysqlTestingHelper helper;
-    
+
     @Inject
     NextBillingDateNotifier notifier;
-    
+
     @Inject
     private BusService busService;
 
@@ -103,7 +103,7 @@ public class TestInvoiceDispatcher {
         helper.initDb(utilDdl);
         notifier.initialize();
         notifier.start();
-        
+
         busService.getBus().start();
     }
 
@@ -118,7 +118,7 @@ public class TestInvoiceDispatcher {
 	    	((ZombieControl)accountUserApi).addResult("getAccountById", account);
 	    	((ZombieControl)account).addResult("getCurrency", Currency.USD);
 	    	((ZombieControl)account).addResult("getId", accountId);
-	    	
+
 	    	Subscription subscription =  BrainDeadProxyFactory.createBrainDeadProxyFor(Subscription.class);
 	    	((ZombieControl)subscription).addResult("getId", subscriptionId);
 	    	SortedSet<BillingEvent> events = new TreeSet<BillingEvent>();
@@ -129,34 +129,34 @@ public class TestInvoiceDispatcher {
 			BigDecimal fixedPrice = null;
 			events.add(new DefaultBillingEvent(subscription, effectiveDate,plan, planPhase,
                                                fixedPrice, BigDecimal.ONE, currency, BillingPeriod.MONTHLY, 1,
-                                               BillingModeType.IN_ADVANCE, "", SubscriptionTransitionType.CREATE));
+                                               BillingModeType.IN_ADVANCE, "", 1L, SubscriptionTransitionType.CREATE));
 
 	    	EntitlementBillingApi entitlementBillingApi = BrainDeadProxyFactory.createBrainDeadProxyFor(EntitlementBillingApi.class);
 	    	((ZombieControl)entitlementBillingApi).addResult("getBillingEventsForAccount", events);
 
 	    	DateTime target = new DateTime();
-	    	
+
 	    	InvoiceDispatcher dispatcher = new InvoiceDispatcher(generator, accountUserApi, entitlementBillingApi, invoiceDao, locker);
-	    	
+
 	    	Invoice invoice = dispatcher.processAccount(accountId, target, true);
 	    	Assert.assertNotNull(invoice);
-	    	
+
 	    	List<Invoice> invoices = invoiceDao.getInvoicesByAccount(accountId);
 	    	Assert.assertEquals(invoices.size(),0);
-	    	
+
 	    	// Try it again to double check
 	    	invoice = dispatcher.processAccount(accountId, target, true);
 	    	Assert.assertNotNull(invoice);
-	    	
+
 	    	invoices = invoiceDao.getInvoicesByAccount(accountId);
 	    	Assert.assertEquals(invoices.size(),0);
-	    	
+
 	    	// This time no dry run
 	    	invoice = dispatcher.processAccount(accountId, target, false);
 	    	Assert.assertNotNull(invoice);
-	    	
+
 	    	invoices = invoiceDao.getInvoicesByAccount(accountId);
 	    	Assert.assertEquals(invoices.size(),1);
-	    	
+
 	    }
 }
diff --git a/invoice/src/test/java/com/ning/billing/invoice/tests/DefaultInvoiceGeneratorTests.java b/invoice/src/test/java/com/ning/billing/invoice/tests/DefaultInvoiceGeneratorTests.java
index 30e3884..838375e 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/tests/DefaultInvoiceGeneratorTests.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/tests/DefaultInvoiceGeneratorTests.java
@@ -469,13 +469,13 @@ public class DefaultInvoiceGeneratorTests extends InvoicingTestBase {
         BillingEvent event1 = new DefaultBillingEvent(subscription, new DateTime("2012-01-1T00:00:00.000-08:00"),
                                                       plan, phase1,
                                                       ZERO, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 1,
-                                                      BillingModeType.IN_ADVANCE, "Test Event 1",
+                                                      BillingModeType.IN_ADVANCE, "Test Event 1", 1L,
                                                       SubscriptionTransitionType.CREATE);
 
         BillingEvent event2 = new DefaultBillingEvent(subscription, changeDate,
                                                       plan, phase2,
                                                       ZERO, null, Currency.USD, BillingPeriod.NO_BILLING_PERIOD, 1,
-                                                      BillingModeType.IN_ADVANCE, "Test Event 2",
+                                                      BillingModeType.IN_ADVANCE, "Test Event 2", 2L,
                                                       SubscriptionTransitionType.PHASE);
 
         events.add(event2);
@@ -668,7 +668,7 @@ public class DefaultInvoiceGeneratorTests extends InvoicingTestBase {
                                        planPhase.getFixedPrice() == null ? null : planPhase.getFixedPrice().getPrice(currency),
                                        planPhase.getRecurringPrice() == null ? null : planPhase.getRecurringPrice().getPrice(currency),
                                        currency, planPhase.getBillingPeriod(),
-                                       billCycleDay, BillingModeType.IN_ADVANCE,"Test", SubscriptionTransitionType.CREATE);
+                                       billCycleDay, BillingModeType.IN_ADVANCE, "Test", 1L, SubscriptionTransitionType.CREATE);
     }
 
     private void testInvoiceGeneration(final BillingEventSet events, final List<Invoice> existingInvoices,
diff --git a/payment/src/test/java/com/ning/billing/payment/TestRetryService.java b/payment/src/test/java/com/ning/billing/payment/TestRetryService.java
index 094d90d..cba51c9 100644
--- a/payment/src/test/java/com/ning/billing/payment/TestRetryService.java
+++ b/payment/src/test/java/com/ning/billing/payment/TestRetryService.java
@@ -139,52 +139,52 @@ public class TestRetryService {
         assertEquals(notification.getEffectiveDate(), expectedRetryDate);
     }
 
-    @Test
-    public void testRetries() throws Exception {
-        final DateTime now = new DateTime(DateTimeZone.UTC);
-        final Account account = testHelper.createTestCreditCardAccount();
-        final Invoice invoice = testHelper.createTestInvoice(account, now, Currency.USD);
-        final BigDecimal amount = new BigDecimal("10.00");
-        final UUID subscriptionId = UUID.randomUUID();
-
-        invoice.addInvoiceItem(new RecurringInvoiceItem(invoice.getId(),
-                                                       subscriptionId,
-                                                       "test plan", "test phase",
-                                                       now,
-                                                       now.plusMonths(1),
-                                                       amount,
-                                                       new BigDecimal("1.0"),
-                                                       Currency.USD,
-                                                       new DateTime(DateTimeZone.UTC)));
-
-        DateTime nextRetryDate = new DateTime(DateTimeZone.UTC).minusDays(1);
-        DateTime paymentAttemptDate = nextRetryDate.minusDays(paymentConfig.getPaymentRetryDays().get(0));
-        PaymentAttempt paymentAttempt = new PaymentAttempt(UUID.randomUUID(), invoice).cloner()
-                                                                                      .setRetryCount(1)
-                                                                                      .setPaymentAttemptDate(paymentAttemptDate)
-                                                                                      .build();
-
-        paymentDao.createPaymentAttempt(paymentAttempt);
-        retryService.scheduleRetry(paymentAttempt, nextRetryDate);
-
-        // wait a little to give the queue time to process
-        Thread.sleep(paymentConfig.getNotificationSleepTimeMs() * 10);
-
-        List<Notification> pendingNotifications = mockNotificationQueue.getPendingEvents();
-
-        assertEquals(pendingNotifications.size(), 0);
-
-        List<PaymentInfo> paymentInfos = paymentApi.getPaymentInfo(Arrays.asList(invoice.getId().toString()));
-
-        assertEquals(paymentInfos.size(), 1);
-
-        PaymentInfo paymentInfo = paymentInfos.get(0);
-
-        assertEquals(paymentInfo.getStatus(), PaymentStatus.Processed.toString());
-
-        PaymentAttempt updatedAttempt = paymentApi.getPaymentAttemptForInvoiceId(invoice.getId().toString());
-
-        assertEquals(paymentInfo.getPaymentId(), updatedAttempt.getPaymentId());
-
-    }
+//    @Test
+//    public void testRetries() throws Exception {
+//        final DateTime now = new DateTime(DateTimeZone.UTC);
+//        final Account account = testHelper.createTestCreditCardAccount();
+//        final Invoice invoice = testHelper.createTestInvoice(account, now, Currency.USD);
+//        final BigDecimal amount = new BigDecimal("10.00");
+//        final UUID subscriptionId = UUID.randomUUID();
+//
+//        invoice.addInvoiceItem(new RecurringInvoiceItem(invoice.getId(),
+//                                                       subscriptionId,
+//                                                       "test plan", "test phase",
+//                                                       now,
+//                                                       now.plusMonths(1),
+//                                                       amount,
+//                                                       new BigDecimal("1.0"),
+//                                                       Currency.USD,
+//                                                       new DateTime(DateTimeZone.UTC)));
+//
+//        DateTime nextRetryDate = new DateTime(DateTimeZone.UTC).minusDays(1);
+//        DateTime paymentAttemptDate = nextRetryDate.minusDays(paymentConfig.getPaymentRetryDays().get(0));
+//        PaymentAttempt paymentAttempt = new PaymentAttempt(UUID.randomUUID(), invoice).cloner()
+//                                                                                      .setRetryCount(1)
+//                                                                                      .setPaymentAttemptDate(paymentAttemptDate)
+//                                                                                      .build();
+//
+//        paymentDao.createPaymentAttempt(paymentAttempt);
+//        retryService.scheduleRetry(paymentAttempt, nextRetryDate);
+//
+//        // wait a little to give the queue time to process
+//        Thread.sleep(paymentConfig.getNotificationSleepTimeMs() * 10);
+//
+//        List<Notification> pendingNotifications = mockNotificationQueue.getPendingEvents();
+//
+//        assertEquals(pendingNotifications.size(), 0);
+//
+//        List<PaymentInfo> paymentInfos = paymentApi.getPaymentInfo(Arrays.asList(invoice.getId().toString()));
+//
+//        assertEquals(paymentInfos.size(), 1);
+//
+//        PaymentInfo paymentInfo = paymentInfos.get(0);
+//
+//        assertEquals(paymentInfo.getStatus(), PaymentStatus.Processed.toString());
+//
+//        PaymentAttempt updatedAttempt = paymentApi.getPaymentAttemptForInvoiceId(invoice.getId().toString());
+//
+//        assertEquals(paymentInfo.getPaymentId(), updatedAttempt.getPaymentId());
+//
+//    }
 }