@Test(groups = { "unit" }, timeOut = TIMEOUT)

public void getAsync() {
    AtomicInteger numberOfCacheRefreshes = new AtomicInteger(0);
    final Func1<Integer, Single<Integer>> refreshFunc = key -> {
        numberOfCacheRefreshes.incrementAndGet();
        return Single.just(key*2);
    };
    AsyncCache<Integer, Integer> cache = new AsyncCache<>();
    List<Single<Integer>> tasks = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            int key = j;
            tasks.add(cache.getAsync(key, -1, () -> refreshFunc.call(key)));
        }
    }
    Observable<Integer> o = Observable.merge(tasks.stream().map(s -> s.toObservable()).collect(Collectors.toList()));
    o.toList().toSingle().toBlocking().value();
    assertThat(numberOfCacheRefreshes.get()).isEqualTo(10);
    assertThat(cache.getAsync(2, -1, () -> refreshFunc.call(2)).toBlocking().value()).isEqualTo(4);
    Func1<Integer, Single<Integer>> refreshFunc1 = key -> {
        numberOfCacheRefreshes.incrementAndGet();
        return Single.just(key * 2 + 1);
    };
    List<Single<Integer>> tasks1 = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            int key = j;
            tasks1.add(cache.getAsync(key, key * 2, () -> refreshFunc1.call(key)));
        }
        for (int j = 0; j < 10; j++) {
            int key = j;
            tasks1.add(cache.getAsync(key, key * 2 , () -> refreshFunc1.call(key)));
        }
    }
    Observable<Integer> o1 = Observable.merge(tasks1.stream().map(s -> s.toObservable()).collect(Collectors.toList()));
    o1.toList().toSingle().toBlocking().value();
    assertThat(numberOfCacheRefreshes.get()).isEqualTo(20);
    assertThat(cache.getAsync(2, -1, () -> refreshFunc.call(2)).toBlocking().value()).isEqualTo(5);
}