@Test public void whenNotifiedOfLogInThenTopUpResultStatusShouldBeRemovedFromCache() { Element element = new Element( PLAYER_ID, new TopUpResultService.TopUpStatusCacheEntry(ACKNOWLEDGED, new DateTime())); topUpStatusCache.put(element); assertNotNull(topUpStatusCache.get(PLAYER_ID)); underTest.clearTopUpStatus(PLAYER_ID); assertNull(topUpStatusCache.get(PLAYER_ID)); }
@Test public void acknowledgeTopUpResultShouldPutAcknowledgedResultIntoCache() { final TopUpAcknowledgeRequest topUpAcknowledgeRequest = new TopUpAcknowledgeRequest(PLAYER_ID, new DateTime()); underTest.acknowledgeTopUpResult(topUpAcknowledgeRequest); assertThat(topUpStatusCache.getStatistics().getMemoryStoreObjectCount(), is(1L)); TopUpResultService.TopUpStatusCacheEntry entry = (TopUpResultService.TopUpStatusCacheEntry) topUpStatusCache.get(PLAYER_ID).getObjectValue(); assertThat(entry.getTopUpStatus(), is(ACKNOWLEDGED)); assertThat(entry.getLastTopUpDate(), is(topUpAcknowledgeRequest.getTopUpDate())); }
@Test public void getTopUpResultShouldDelegateToTopUpServiceAndNotCacheResultWhenPlayerHasNoCachedResultAndHasBeenToppedUpButNotAcknowledgedTopUp() { final TopUpResult topUpResult = new TopUpResult(PLAYER_ID, CREDITED, new DateTime()); when(dailyAwardPromotionService.getTopUpResult(PLAYER_ID, WEB)).thenReturn(topUpResult); final TopUpResult actualTopUpResult = underTest.getTopUpResult(PLAYER_ID, WEB); // check that result wasn't cached before assertThat(topUpStatusCache.getStatistics().getCacheHits(), is(0L)); // check that result wasn't cached after assertThat(topUpStatusCache.getStatistics().getMemoryStoreObjectCount(), is(0L)); assertThat(actualTopUpResult, is(topUpResult)); }
@Test public void getTopUpResultShouldReturnCachedResultIfPlayerHasCacheEntry() { topUpStatusCache.setStatisticsEnabled(true); long cacheHitsPreRequest = topUpStatusCache.getStatistics().getCacheHits(); final TopUpResult expectedTopUpResult = new TopUpResult(PLAYER_ID, ACKNOWLEDGED, new DateTime()); Element element = new Element( PLAYER_ID, new TopUpResultService.TopUpStatusCacheEntry( ACKNOWLEDGED, expectedTopUpResult.getLastTopUpDate())); topUpStatusCache.put(element); final TopUpResult actualTopUpResult = underTest.getTopUpResult(PLAYER_ID, WEB); assertThat(topUpStatusCache.getStatistics().getCacheHits(), is(cacheHitsPreRequest + 1)); assertThat(actualTopUpResult, is(expectedTopUpResult)); verify(dailyAwardPromotionService, never()).getTopUpResult(PLAYER_ID, WEB); }
@Test public void getTopUpResultShouldCacheResultWhenPlayerHasNoCachedResultAndLastTopUpIsAcknowledged() { final TopUpResult topUpResult = new TopUpResult(PLAYER_ID, ACKNOWLEDGED, new DateTime()); when(dailyAwardPromotionService.getTopUpResult(PLAYER_ID, WEB)).thenReturn(topUpResult); final TopUpResult actualTopUpResult = underTest.getTopUpResult(PLAYER_ID, WEB); // check that result wasn't cached before assertThat(topUpStatusCache.getStatistics().getCacheHits(), is(0L)); // check that result was cached after assertThat(topUpStatusCache.getStatistics().getMemoryStoreObjectCount(), is(1L)); // check cache entry TopUpResultService.TopUpStatusCacheEntry entry = (TopUpResultService.TopUpStatusCacheEntry) topUpStatusCache.get(PLAYER_ID).getObjectValue(); assertThat(entry.getTopUpStatus(), is(ACKNOWLEDGED)); assertThat(entry.getLastTopUpDate(), is(topUpResult.getLastTopUpDate())); assertThat(actualTopUpResult, is(topUpResult)); }
@Test public void acknowledgeTopUpResultShouldNotSendAcknowledgeRequestIfAlreadyCached() { final TopUpAcknowledgeRequest topUpAcknowledgeRequest = new TopUpAcknowledgeRequest(PLAYER_ID, new DateTime()); Element element = new Element( PLAYER_ID, new TopUpResultService.TopUpStatusCacheEntry( ACKNOWLEDGED, topUpAcknowledgeRequest.getTopUpDate())); topUpStatusCache.put(element); underTest.acknowledgeTopUpResult(topUpAcknowledgeRequest); assertThat(topUpStatusCache.getStatistics().getMemoryStoreObjectCount(), is(1L)); TopUpResultService.TopUpStatusCacheEntry entry = (TopUpResultService.TopUpStatusCacheEntry) topUpStatusCache.get(PLAYER_ID).getObjectValue(); assertThat(entry.getTopUpStatus(), is(ACKNOWLEDGED)); assertThat(entry.getLastTopUpDate(), is(topUpAcknowledgeRequest.getTopUpDate())); verify(queuePublishingService, never()).send(topUpAcknowledgeRequest); }