コード例 #1
0
  @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);
  }
コード例 #2
0
  @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));
  }