/** * 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))); }
@Test public void simple_getIdentifiedSupplier_removeIf() throws ExecutionException, InterruptedException { final CompletionStage<IdentifiedValue<String>> get1 = cache.getIdentified("josie", () -> "football"); assertThat(get1, successful()); final IdentifiedValue<String> iv1 = unsafeJoin(get1); assertThat(iv1.identifier(), notNullValue()); assertThat(iv1.value(), is("football")); final CompletionStage<Boolean> rm1 = cache.removeIf("josie", iv1.identifier()); assertThat(rm1, successfulWith(is(true))); final CompletionStage<Boolean> put1 = cache.put("josie", "football", PutPolicy.PUT_ALWAYS); assertThat(put1, successfulWith(is(true))); final CompletionStage<IdentifiedValue<String>> get2 = cache.getIdentified("josie", () -> "swimming"); assertThat(get2, successful()); final IdentifiedValue<String> iv2 = unsafeJoin(get2); assertThat(iv2.identifier(), notNullValue()); assertThat(iv2.value(), is("football")); final CompletionStage<Boolean> rm2 = cache.removeIf("josie", iv2.identifier()); assertThat(rm2, successfulWith(is(true))); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_IDENTIFIED_GET_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_IDENTIFIED_REMOVE_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.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, hasSize(is(7))); }
@Test public void simple_getIdentified_replaceIf() throws ExecutionException, InterruptedException { final CompletionStage<Boolean> put1 = cache.put("josie", "football", PutPolicy.PUT_ALWAYS); assertThat(put1, successfulWith(is(true))); final CompletionStage<Optional<IdentifiedValue<String>>> get1 = cache.getIdentified("josie"); assertThat(get1, successful()); final IdentifiedValue<String> iv1 = unsafeJoin(get1).get(); assertThat(iv1.identifier(), notNullValue()); assertThat(iv1.value(), is("football")); final CompletionStage<Boolean> rm1 = cache.replaceIf("josie", iv1.identifier(), "soccer"); assertThat(rm1, successfulWith(is(true))); final CompletionStage<Boolean> put2 = cache.put("josie", "football", PutPolicy.PUT_ALWAYS); assertThat(put2, successfulWith(is(true))); final CompletionStage<Optional<IdentifiedValue<String>>> get3 = cache.getIdentified("josie"); assertThat(get3, successful()); final IdentifiedValue<String> iv3 = unsafeJoin(get3).get(); assertThat(iv3.identifier(), notNullValue()); assertThat(iv3.value(), is("football")); final CompletionStage<Boolean> rm3 = cache.removeIf("josie", iv3.identifier()); assertThat(rm3, successfulWith(is(true))); final Map<MetricLabel, ? extends LongMetric> cacheMetrics = requestMetrics().allExternalCacheLongMetrics().get(CACHE_NAME); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_IDENTIFIED_GET_CALL, is(2L), greaterThan(0L))); assertThat(cacheMetrics, hasMetric(MetricLabel.TIMED_IDENTIFIED_REPLACE_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(2L), is(2L))); assertThat(cacheMetrics, hasSize(is(6))); }
return fold(vcache.removeIf(key, identifiedValue.get().identifier()),