@Test public void putOperation() { final boolean result = fold(offlineCache.put("key", "value", PutPolicy.PUT_ALWAYS), t -> t, err -> false); assertThat(result, is(equalTo(false))); }
@SuppressWarnings("ConstantConditions") @Test public void check_null_key() { final CompletionStage<Boolean> put1 = cache.put(null, "value", PutPolicy.PUT_ALWAYS); assertThat(put1, not(successful())); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_PUT_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_REMOVE_ALL_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_FAILED_PUT, is(1L), is(1L))); assertThat(cacheMetrics, hasSize(is(3))); }
@Test public void simple_get_add() throws ExecutionException, InterruptedException { final CompletionStage<Optional<String>> eldestGet = cache.get("claira"); assertThat(eldestGet, successfulWith(is(Optional.empty()))); final CompletionStage<Boolean> eldestAdd = cache.put("claira", "dancing", PutPolicy.ADD_ONLY); assertThat(eldestAdd, successfulWith(is(true))); final CompletionStage<Optional<String>> eldestGet2 = cache.get("claira"); assertThat(eldestGet2, successfulWith(is(Optional.of("dancing")))); final CompletionStage<Boolean> eldestAdd2 = cache.put("claira", "singing", PutPolicy.ADD_ONLY); assertThat(eldestAdd2, successfulWith(is(false))); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_GET_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_PUT_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_REMOVE_ALL_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_HITS, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_MISSES, is(1L), is(1L))); assertThat(cacheMetrics, hasSize(is(5))); }
@Test public void simple_get_set() throws ExecutionException, InterruptedException { final CompletionStage<Optional<String>> eldestGet = cache.get("claira"); assertThat(eldestGet, successfulWith(is(Optional.empty()))); final CompletionStage<Boolean> eldestAdd = cache.put("claira", "dancing", PutPolicy.PUT_ALWAYS); assertThat(eldestAdd, successfulWith(is(true))); final CompletionStage<Optional<String>> eldestGet2 = cache.get("claira"); assertThat(eldestGet2, successfulWith(is(Optional.of("dancing")))); final CompletionStage<Boolean> eldestAdd2 = cache.put("claira", "singing", PutPolicy.PUT_ALWAYS); assertThat(eldestAdd2, successfulWith(is(true))); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_GET_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_PUT_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_REMOVE_ALL_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_HITS, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_MISSES, is(1L), is(1L))); assertThat(cacheMetrics, hasSize(is(5))); }
@SuppressWarnings("unchecked") @Test public void simple_getBulk() throws ExecutionException, InterruptedException { final CompletionStage<Map<String, Optional<String>>> get1 = cache.getBulk("claira", "jasmin", "josie", "josie"); assertThat(get1, successful()); assertThat(unsafeJoin(get1).keySet(), containsInAnyOrder("claira", "jasmin", "josie")); assertThat(unsafeJoin(get1).values(), containsInAnyOrder(Optional.empty(), Optional.empty(), Optional.empty())); final CompletionStage<Boolean> put1 = cache.put("claira", "youtube", PutPolicy.PUT_ALWAYS); assertThat(put1, successfulWith(is(true))); final CompletionStage<Map<String, Optional<String>>> get2 = cache.getBulk("jasmin", "claira", "josie", "claira"); assertThat(get2, successful()); assertThat(unsafeJoin(get2).keySet(), containsInAnyOrder("claira", "jasmin", "josie")); assertThat(unsafeJoin(get2).values(), containsInAnyOrder(Optional.of("youtube"), Optional.empty(), Optional.empty())); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_GET_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_PUT_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_REMOVE_ALL_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_HITS, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_MISSES, is(2L), is(5L))); assertThat(cacheMetrics, hasSize(is(5))); }
@Test public void simple_removeAll() throws ExecutionException, InterruptedException { final CompletionStage<Boolean> put1 = cache.put("claira", "", PutPolicy.PUT_ALWAYS); assertThat(put1, successfulWith(is(true))); final CompletionStage<Optional<String>> get1 = cache.get("claira"); assertThat(get1, successfulWith(is(Optional.of("")))); final CompletionStage<Void> rm1 = cache.removeAll(); assertThat(rm1, successful()); final CompletionStage<Optional<String>> get2 = cache.get("claira"); assertThat(get2, successfulWith(is(Optional.empty()))); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_GET_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_PUT_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_REMOVE_ALL_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_HITS, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_MISSES, is(1L), is(1L))); assertThat(cacheMetrics, hasSize(is(5))); }
/** * Tests where the cas id is genuinely unique, and not just a copy of the original value. */ @Test public void exact_getIdentified_removeIf() throws ExecutionException, InterruptedException { final CompletionStage<Boolean> putFirst = cache.put("josie", "football", PutPolicy.PUT_ALWAYS); assertThat(putFirst, successfulWith(is(true))); final CompletionStage<Optional<IdentifiedValue<String>>> getFirst = cache.getIdentified("josie"); assertThat(getFirst, successful()); final IdentifiedValue<String> ivFirst = unsafeJoin(getFirst).get(); assertThat(ivFirst.identifier(), notNullValue()); assertThat(ivFirst.value(), is("football")); final CompletionStage<Boolean> putSecond = cache.put("josie", "football", PutPolicy.PUT_ALWAYS); assertThat(putSecond, successfulWith(is(true))); final CompletionStage<Boolean> rm1 = cache.removeIf("josie", ivFirst.identifier()); assertThat(rm1, successfulWith(is(false))); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_IDENTIFIED_GET_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_IDENTIFIED_REMOVE_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_PUT_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_REMOVE_ALL_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_HITS, is(1L), is(1L))); assertThat(cacheMetrics, hasSize(is(5))); }
/** * Tests where the cas id is genuinely unique, and not just a copy of the original value. */ @Test public void exact_getIdentified_replaceIf() throws ExecutionException, InterruptedException { final CompletionStage<Boolean> putFirst = cache.put("josie", "football", PutPolicy.PUT_ALWAYS); assertThat(putFirst, successfulWith(is(true))); final CompletionStage<Optional<IdentifiedValue<String>>> getFirst = cache.getIdentified("josie"); assertThat(getFirst, successful()); final IdentifiedValue<String> ivFirst = unsafeJoin(getFirst).get(); assertThat(ivFirst.identifier(), notNullValue()); assertThat(ivFirst.value(), is("football")); final CompletionStage<Boolean> putSecond = cache.put("josie", "football", PutPolicy.PUT_ALWAYS); assertThat(putSecond, successfulWith(is(true))); final CompletionStage<Boolean> rm1 = cache.replaceIf("josie", ivFirst.identifier(), "afl"); assertThat(rm1, successfulWith(is(false))); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_IDENTIFIED_GET_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_IDENTIFIED_REPLACE_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_PUT_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_REMOVE_ALL_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_HITS, is(1L), is(1L))); assertThat(cacheMetrics, hasSize(is(5))); }
@Test public void dual_cache_get_with_supplier_take2() throws ExecutionException, InterruptedException { final CompletionStage<Optional<String>> get1 = cache.get("claira"); assertThat(get1, successfulWith(is(Optional.empty()))); final CompletionStage<Boolean> dput1 = directCache.put("claira", "singing", PutPolicy.PUT_ALWAYS); assertThat(dput1, successfulWith(is(true))); final CompletionStage<String> get2 = cache.get("claira", () -> "riding"); assertThat(get2, successfulWith(is("singing"))); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_GET_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_SUPPLIER_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_MISSES, is(2L), is(2L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_REMOTE_GET, is(3L), is(3L))); assertThat(cacheMetrics, hasSize(is(4))); }
@Test public void existing_removeAll_get() { directCache().put("key", "existing", PutPolicy.PUT_ALWAYS); final CompletionStage<Optional<String>> get1 = cache().get("key"); assertThat(get1, successfulWith(is(Optional.of("existing")))); cache().removeAll(); final CompletionStage<Optional<String>> get2 = cache().get("key"); assertThat(get2, successfulWith(is(Optional.empty()))); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_GET_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_REMOVE_ALL_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_HITS, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_MISSES, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_REMOTE_GET, is(1L), is(1L))); assertThat(cacheMetrics, hasSize(is(5))); }
@Test public void existing_getSupplier_getSupplier() { final CompletionStage<Boolean> put = directCache().put("josie", "football", PutPolicy.PUT_ALWAYS); assertThat(put, successfulWith(is(true))); final CompletionStage<String> get1 = cache().get("josie", () -> "soccer"); assertThat(get1, successfulWith(is("football"))); final CompletionStage<String> get2 = cache().get("josie", () -> "soccer"); assertThat(get2, successfulWith(is("football"))); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_GET_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_HITS, is(2L), is(2L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_REMOTE_GET, is(1L), is(1L))); assertThat(cacheMetrics, hasSize(is(3))); }
@Test public void existing_remove_getSupplier() { directCache().put("key", "existing", PutPolicy.PUT_ALWAYS); final CompletionStage<Optional<String>> get1 = cache().get("key"); assertThat(get1, successfulWith(is(Optional.of("existing")))); cache().remove("key"); final CompletionStage<String> get2 = cache().get("key", () -> "new"); assertThat(get2, successfulWith(is("new"))); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_GET_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_REMOVE_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_SUPPLIER_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_HITS, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_MISSES, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_REMOTE_GET, is(1L), is(1L))); assertThat(cacheMetrics, hasSize(is(6))); }
@Test public void existing_remove_get() { directCache().put("key", "existing", PutPolicy.PUT_ALWAYS); final CompletionStage<Optional<String>> get1 = cache().get("key"); assertThat(get1, successfulWith(is(Optional.of("existing")))); cache().remove("key"); final CompletionStage<Optional<String>> get2 = cache().get("key"); assertThat(get2, successfulWith(is(Optional.empty()))); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_GET_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_REMOVE_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_HITS, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_MISSES, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_REMOTE_GET, is(1L), is(1L))); assertThat(cacheMetrics, hasSize(is(5))); }
@Test public void dual_cache_get_set() throws ExecutionException, InterruptedException { final CompletionStage<Optional<String>> get1 = cache.get("claira"); assertThat(get1, successfulWith(is(Optional.empty()))); // Change will not be visible to main cache final CompletionStage<Boolean> dput1 = directCache.put("claira", "dancing", PutPolicy.PUT_ALWAYS); assertThat(dput1, successfulWith(is(true))); final CompletionStage<Optional<String>> get2 = cache.get("claira"); assertThat(get2, successfulWith(is(Optional.empty()))); // Add will fail as value exists from the other cache. However, we will now be able to see the // value added by the other cache. final CompletionStage<Boolean> put1 = cache.put("claira", "singing", PutPolicy.ADD_ONLY); assertThat(put1, successfulWith(is(false))); final CompletionStage<Optional<String>> get3 = cache.get("claira"); assertThat(get3, successfulWith(is(Optional.of("dancing")))); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_GET_CALL, is(3L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_PUT_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_HITS, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_MISSES, is(2L), is(2L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_REMOTE_GET, is(2L), is(2L))); assertThat(cacheMetrics, hasSize(is(5))); }
@Test public void existing_removeAll_getSupplier() { directCache().put("key", "existing", PutPolicy.PUT_ALWAYS); final CompletionStage<Optional<String>> get1 = cache().get("key"); assertThat(get1, successfulWith(is(Optional.of("existing")))); cache().removeAll(); final CompletionStage<String> get2 = cache().get("key", () -> "new"); assertThat(get2, successfulWith(is("new"))); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_GET_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_REMOVE_ALL_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_SUPPLIER_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_HITS, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_MISSES, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_REMOTE_GET, is(1L), is(1L))); assertThat(cacheMetrics, hasSize(is(6))); }
@Test public void existing_removeAll_getBulk() { directCache().put("key", "existing", PutPolicy.PUT_ALWAYS); final CompletionStage<Optional<String>> get1 = cache().get("key"); assertThat(get1, successfulWith(is(Optional.of("existing")))); cache().removeAll(); final CompletionStage<Map<String, String>> get2 = cache().getBulk( strings -> strings.stream().collect(Collectors.toMap(k -> k, k -> k + "-new")), "key"); assertThat(get2, successful()); assertThat(unsafeJoin(get2).keySet(), containsInAnyOrder("key")); assertThat(unsafeJoin(get2).values(), containsInAnyOrder("key-new")); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_GET_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_FACTORY_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_REMOVE_ALL_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_FACTORY_KEYS, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_HITS, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_MISSES, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_REMOTE_GET, is(1L), is(1L))); assertThat(cacheMetrics, hasSize(is(7))); }
@Test public void existing_remove_getBulk() { directCache().put("key", "existing", PutPolicy.PUT_ALWAYS); final CompletionStage<Optional<String>> get1 = cache().get("key"); assertThat(get1, successfulWith(is(Optional.of("existing")))); cache().remove("key"); final CompletionStage<Map<String, String>> get2 = cache().getBulk( strings -> strings.stream().collect(Collectors.toMap(k -> k, k -> k + "-new")), "key", "extra"); assertThat(get2, successful()); assertThat(unsafeJoin(get2).keySet(), containsInAnyOrder("key", "extra")); assertThat(unsafeJoin(get2).values(), containsInAnyOrder("key-new", "extra-new")); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_GET_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_FACTORY_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_REMOVE_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_FACTORY_KEYS, is(1L), is(2L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_HITS, is(1L), is(1L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_MISSES, is(1L), is(2L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_REMOTE_GET, is(2L), is(2L))); assertThat(cacheMetrics, hasSize(is(7))); }
@Test public void dual_cache_get_with_supplier() throws ExecutionException, InterruptedException { final CompletionStage<Optional<String>> get1 = cache.get("claira"); assertThat(get1, successfulWith(is(Optional.empty()))); final CompletionStage<String> get2 = cache.get("claira", () -> "dancing"); assertThat(get2, successfulWith(is("dancing"))); final CompletionStage<Optional<String>> get3 = cache.get("claira"); assertThat(get3, successfulWith(is(Optional.of("dancing")))); // Change will not be visible to main cache final CompletionStage<Boolean> dput1 = directCache.put("claira", "singing", PutPolicy.PUT_ALWAYS); assertThat(dput1, successfulWith(is(true))); final CompletionStage<Optional<String>> get4 = cache.get("claira"); assertThat(get4, successfulWith(is(Optional.of("dancing")))); final CompletionStage<String> get5 = cache.get("claira", () -> "riding"); assertThat(get5, successfulWith(is("dancing"))); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_GET_CALL, is(5L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_SUPPLIER_CALL, is(1L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_HITS, is(3L), is(3L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_MISSES, is(2L), is(2L))); assertThat(cacheMetrics, hasMetric(MetricLabel.NUMBER_OF_REMOTE_GET, is(2L), is(2L))); assertThat(cacheMetrics, hasSize(is(5))); }
@Test public void directexternalcache_duplicate_obtain() { final DirectExternalCache<String> firstTime = vCacheFactory().getDirectExternalCache( "duplicate", dodgyPair("first"), new ExternalCacheSettingsBuilder().build()); final CompletionStage<Boolean> put1 = firstTime.put("key", "ignored", PUT_ALWAYS); assertThat(VCacheUtils.unsafeJoin(put1), is(true)); final CompletionStage<Optional<String>> get1 = firstTime.get("key"); assertThat(VCacheUtils.unsafeJoin(get1), is(Optional.of("first"))); final DirectExternalCache<String> secondTime = vCacheFactory().getDirectExternalCache( "duplicate", dodgyPair("second"), new ExternalCacheSettingsBuilder().build()); final CompletionStage<Optional<String>> get2 = secondTime.get("key"); assertThat(VCacheUtils.unsafeJoin(get2), is(Optional.of("second"))); }
@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)); }