@Before public void ensureOfflineCache() { final ExternalCacheSettings settings = new ExternalCacheSettingsBuilder() .entryGrowthRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(5) .defaultTtl(Duration.ofMinutes(5)) .dataChangeRateHint(ChangeRate.HIGH_CHANGE) .build(); offlineCache = createOfflineCache(CACHE_NAME, settings); }
@Before public void ensureCache() { final ExternalCacheSettings settings = new ExternalCacheSettingsBuilder() .entryGrowthRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(5) .defaultTtl(Duration.ofMinutes(5)) .dataChangeRateHint(ChangeRate.HIGH_CHANGE) .build(); cache = createCache(CACHE_NAME, settings); final CompletionStage<Void> rm = cache.removeAll(); assertThat(rm, successful()); }
@Before public void ensureOfflineCache() { final ExternalCacheSettings settings = new ExternalCacheSettingsBuilder() .entryGrowthRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(5) .defaultTtl(Duration.ofMinutes(5)) .dataChangeRateHint(ChangeRate.HIGH_CHANGE) .build(); offlineCache = createOfflineCache(CACHE_NAME, settings); }
@Test public void transactionalExternalCache_normal_marshalling() { final ExternalCacheSettings settings = new ExternalCacheSettingsBuilder() .defaultTtl(Duration.ofSeconds(60)) .entryGrowthRateHint(ChangeRate.LOW_CHANGE) .dataChangeRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(100) .build(); final TransactionalExternalCache<String> cache = vCacheFactory().getTransactionalExternalCache( "my-txn-cache", StringMarshalling.pair(), settings); assertThat(cache, notNullValue()); assertThat(cache.getName(), is("my-txn-cache")); assertThat(invocationsOfBegunTxns, is(0)); cache.removeAll(); assertThat(invocationsOfBegunTxns, is(1)); cache.put("three", "drei", PUT_ALWAYS); final CompletionStage<Optional<String>> get1 = cache.get("three"); assertThat(get1, successfulWith(is(Optional.of("drei")))); vCacheLifecycleManager().transactionSync(currentRequestContext()); assertThat(invocationsOfBegunTxns, is(1)); forceNewRequestContext(); final CompletionStage<Optional<String>> get2 = cache.get("three"); assertThat(invocationsOfBegunTxns, is(2)); unsafeJoin(get2.toCompletableFuture()).get(); assertThat(get2, successfulWith(is(Optional.of("drei")))); assertThat(invocationsOfBegunTxns, is(2)); }
@Test public void transactionalExternalCache_normal_marshaller() { final ExternalCacheSettings settings = new ExternalCacheSettingsBuilder() .defaultTtl(Duration.ofSeconds(60)) .entryGrowthRateHint(ChangeRate.LOW_CHANGE) .dataChangeRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(100) .build(); @SuppressWarnings("deprecation") final TransactionalExternalCache<String> cache = vCacheFactory().getTransactionalExternalCache( "my-txn-cache", MarshallerFactory.stringMarshaller(), settings); assertThat(cache, notNullValue()); assertThat(cache.getName(), is("my-txn-cache")); assertThat(invocationsOfBegunTxns, is(0)); cache.removeAll(); assertThat(invocationsOfBegunTxns, is(1)); cache.put("three", "drei", PUT_ALWAYS); final CompletionStage<Optional<String>> get1 = cache.get("three"); assertThat(get1, successfulWith(is(Optional.of("drei")))); vCacheLifecycleManager().transactionSync(currentRequestContext()); assertThat(invocationsOfBegunTxns, is(1)); forceNewRequestContext(); final CompletionStage<Optional<String>> get2 = cache.get("three"); assertThat(invocationsOfBegunTxns, is(2)); unsafeJoin(get2.toCompletableFuture()).get(); assertThat(get2, successfulWith(is(Optional.of("drei")))); assertThat(invocationsOfBegunTxns, is(2)); }
@Test public void directExternalCache_normal_marshalling() { final ExternalCacheSettings settings = new ExternalCacheSettingsBuilder() .defaultTtl(Duration.ofSeconds(60)) .entryGrowthRateHint(ChangeRate.LOW_CHANGE) .dataChangeRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(100) .build(); final DirectExternalCache<String> cache = vCacheFactory().getDirectExternalCache( "my-direct-cache", StringMarshalling.pair(), settings); assertThat(cache, notNullValue()); assertThat(cache.getName(), is("my-direct-cache")); final CompletionStage<Void> rmall = cache.removeAll(); assertThat(rmall, successful()); final CompletionStage<Boolean> put1 = cache.put("one", "eine", PUT_ALWAYS); assertThat(put1, successfulWith(is(true))); final CompletionStage<Optional<String>> get1 = cache.get("one"); assertThat(get1, successfulWith(is(Optional.of("eine")))); assertThat(vCacheManagement().allJvmCacheDetails().size(), is(0)); assertThat(vCacheManagement().allRequestCacheDetails().size(), is(0)); final Map<String, ExternalCacheDetails> allCacheDetails = vCacheManagement().allExternalCacheDetails(); assertThat(allCacheDetails, notNullValue()); assertThat(allCacheDetails.keySet(), containsInAnyOrder("my-direct-cache")); final ExternalCacheDetails cacheDetails = allCacheDetails.get("my-direct-cache"); assertThat(cacheDetails.getName(), is("my-direct-cache")); assertThat(cacheDetails.getSettings().getDefaultTtl(), is(Optional.of(MAX_TTL))); assertThat(cacheDetails.getSettings().getEntryCountHint(), is(Optional.of(MAX_ENTRIES))); assertThat(invocationsOfBegunTxns, is(0)); }
@Test public void directExternalCache_normal_marshaller() { final ExternalCacheSettings settings = new ExternalCacheSettingsBuilder() .defaultTtl(Duration.ofSeconds(60)) .entryGrowthRateHint(ChangeRate.LOW_CHANGE) .dataChangeRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(100) .build(); @SuppressWarnings("deprecation") final DirectExternalCache<String> cache = vCacheFactory().getDirectExternalCache( "my-direct-cache", MarshallerFactory.stringMarshaller(), settings); assertThat(cache, notNullValue()); assertThat(cache.getName(), is("my-direct-cache")); final CompletionStage<Void> rmall = cache.removeAll(); assertThat(rmall, successful()); final CompletionStage<Boolean> put1 = cache.put("one1", "eine", PUT_ALWAYS); assertThat(put1, successfulWith(is(true))); final CompletionStage<Optional<String>> get1 = cache.get("one1"); assertThat(get1, successfulWith(is(Optional.of("eine")))); assertThat(vCacheManagement().allJvmCacheDetails().size(), is(0)); assertThat(vCacheManagement().allRequestCacheDetails().size(), is(0)); }
@Test public void stableReadExternalCache_normal_marshalling() { final ExternalCacheSettings settings = new ExternalCacheSettingsBuilder() .defaultTtl(Duration.ofSeconds(60)) .entryGrowthRateHint(ChangeRate.LOW_CHANGE) .dataChangeRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(100) .build(); final StableReadExternalCache<String> cache = vCacheFactory().getStableReadExternalCache( "my-stable-read-cache", StringMarshalling.pair(), settings); assertThat(cache, notNullValue()); assertThat(cache.getName(), is("my-stable-read-cache")); final CompletionStage<Void> rmall = cache.removeAll(); assertThat(rmall, successful()); final CompletionStage<Boolean> put1 = cache.put("three", "drei", PUT_ALWAYS); assertThat(put1, successfulWith(is(true))); final CompletionStage<Optional<String>> get1 = cache.get("three"); assertThat(get1, successfulWith(is(Optional.of("drei")))); assertThat(invocationsOfBegunTxns, is(0)); }
@Test public void stableReadExternalCache_normal_marshaller() { final ExternalCacheSettings settings = new ExternalCacheSettingsBuilder() .defaultTtl(Duration.ofSeconds(60)) .entryGrowthRateHint(ChangeRate.LOW_CHANGE) .dataChangeRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(100) .build(); @SuppressWarnings("deprecation") final StableReadExternalCache<String> cache = vCacheFactory().getStableReadExternalCache( "my-stable-read-cache", MarshallerFactory.stringMarshaller(), settings); assertThat(cache, notNullValue()); assertThat(cache.getName(), is("my-stable-read-cache")); final CompletionStage<Void> rmall = cache.removeAll(); assertThat(rmall, successful()); final CompletionStage<Boolean> put1 = cache.put("three", "drei", PUT_ALWAYS); assertThat(put1, successfulWith(is(true))); final CompletionStage<Optional<String>> get1 = cache.get("three"); assertThat(get1, successfulWith(is(Optional.of("drei")))); assertThat(invocationsOfBegunTxns, is(0)); }
@Test public void handle_legal_recursive_get_supplier() { final ExternalCacheSettings settings = new ExternalCacheSettingsBuilder() .defaultTtl(Duration.ofSeconds(60)) .entryGrowthRateHint(ChangeRate.LOW_CHANGE) .dataChangeRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(100) .build(); final StableReadExternalCache<String> cache = vCacheFactory().getStableReadExternalCache( "my-stable-read-cache", StringMarshalling.pair(), settings); final CompletionStage<String> get1 = cache.get("recursive", () -> "ignored-" + unsafeJoin(cache.get("recursive", () -> "2"))); assertThat(get1, successfulWith(is("2"))); }
@Test public void handle_legal_recursive_get_supplier2() { final ExternalCacheSettings settings = new ExternalCacheSettingsBuilder() .defaultTtl(Duration.ofSeconds(60)) .entryGrowthRateHint(ChangeRate.LOW_CHANGE) .dataChangeRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(100) .build(); final StableReadExternalCache<String> cache = vCacheFactory().getStableReadExternalCache( "my-stable-read-cache", StringMarshalling.pair(), settings); final CompletionStage<String> get1 = cache.get("recursive", () -> unsafeJoin(cache.get("recursive2", () -> "pass"))); assertThat(get1, successfulWith(is("pass"))); } }
@Before public void ensureCache() { final ExternalCacheSettings settings = new ExternalCacheSettingsBuilder() .entryGrowthRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(5) .defaultTtl(Duration.ofMinutes(5)) .dataChangeRateHint(ChangeRate.HIGH_CHANGE) .build(); cache = createCache(CACHE_NAME, settings); directCache = obtainDirectCache(CACHE_NAME, settings); // Start from a clean slate final CompletionStage<Void> rm = directCache.removeAll(); assertThat(rm, successful()); }
.entryGrowthRateHint(ChangeRate.LOW_CHANGE) .dataChangeRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(100) .build();
.entryGrowthRateHint(ChangeRate.LOW_CHANGE) .dataChangeRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(100) .build();
.entryGrowthRateHint(ChangeRate.LOW_CHANGE) .dataChangeRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(100) .build();
.entryGrowthRateHint(ChangeRate.LOW_CHANGE) .dataChangeRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(100) .build();