entitlement: iteration on EventsStreamBuilder speedup optimizations

Explain the magic and add tests for eventsStreamBuilder.buildForAccount. Even though
all tests were passing, I still went ahead and updated buildForAccount to do the same
magic as buildForEntitlement. I didn't manage to write a failing test scenario for it
but it seems required.

This also fixes an NPE with standalone subscriptions.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
entitlement: optimize DefaultSubscriptionApi

Go through the getSubscriptionBundlesForAccountId API (which is
behind /1.0/kb/accounts/ACCOUNT_ID/bundles) and optimize the various
layers to limit the amount of DAO calls.

1.0 call timings for an account with 35 bundles and 67 subscriptions:

* Before changes: 8m40s
* After changes: 6.50s at startup, 4.20s after caches are warm

Since this call should be fast, change most APIs in DefaultSubscriptionApi
to always build all subscriptions for a given account first, and then do
further filtering in memory (per bundle, etc.). This simplifies the amount
of codepaths to optimize.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Merge branch 'master' of github.com:killbill/killbill
server: fix tests failures after recent changes

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
[maven-release-plugin] prepare release killbill-0.8.3
[maven-release-plugin] prepare for next development iteration
Revert "refactoring in invoice to extact the logic for interval calculation in one class and simplify the code"

This reverts commit bd4f6e704cbe2593d23fab5e65df0d85bd2bcbb7.
Perf optimization when retrieving events for accounts
Merge branch 'master' of github.com:killbill/killbill
junction: fix bug when computing blocking durations

This patch removes

  getBlockingAll(UUID blockableId, BlockingStateType blockingStateType, InternalTenantContext context);

from BlockingInternalApi: junction was calling it multiple times for different blockingStateType, which
was breaking the natural ordering of events and hence introducing bugs when computing blocking durations.

Instead, we introduce

  getBlockingAllForAccount(InternalTenantContext context);

Events are ordered correctly by junction and will return bundle, subscription and account level blocking
events (we were ignoring the subscription level ones before for some reason).

This also:

* fixes the ordering returned by the SQL statements (only really needed for getBlockingStateForService
as we re-order the other calls in ProxyBlockingStateDao).
* removes BillingEventSet#isLast which wasn't used.

This closes #123.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Merge remote-tracking branch 'origin/master' into junction-bug-fixes

Conflicts:
	entitlement/src/main/java/com/ning/billing/entitlement/dao/ProxyBlockingStateDao.java

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Fixes #132

(Also fixes the bug introduced during the perf optimization in subscription base where events are retrieved by account_record_id and where
ordering by effective_date, record_id must be enforced)
Code review integration for default sql ordering
beatrix: fix ClassCastException

Reported-by: Nitin Singh <nsiitk@gmail.com>
Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Merge branch 'junction-bug-fixes' of github.com:killbill/killbill into junction-bug-fixes
entitlement: fix regression in bundle timeline API

After the recent optimization iterations, the timeline
API was broken and didn't return blocking states for
non-entitlement services anymore.

This patch fixes it and optimizes the entitlement code a bit further
by limiting the amount of DAO calls in blocking states.

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
Merge remote-tracking branch 'origin/master' into junction-bug-fixes
NEWS: updates for 0.8.3 and 0.8.4

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
Fix flaky tests that were missing events
Fix flaky tests by hardcoding the UUID so when comparison defaults to ID level this is predictable