@Test public void testCall() { List<Context> contextList = Arrays.asList( Context.create().with("cacheManagerName", "myCM1").with("cacheName", "aCache1"), Context.create().with("cacheManagerName", "myCM1").with("cacheName", "aCache4"), Context.create().with("cacheManagerName", "myCM2").with("cacheName", "aCache2"), Context.create().with("cacheManagerName", "myCM55").with("cacheName", "aCache55")); cacheManager1.getCache("aCache1", Long.class, String.class).put(1L, "1"); cacheManager2.getCache("aCache2", Long.class, String.class).put(2L, "2"); assertThat(cacheManager1.getCache("aCache1", Long.class, String.class).get(1L), equalTo("1")); assertThat(cacheManager2.getCache("aCache2", Long.class, String.class).get(2L), equalTo("2")); CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder() .withResourcePools( ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES).build()) .buildConfig(Long.class, String.class); cacheManager1.createCache("aCache4", cacheConfiguration); cacheManager1.getCache("aCache4", Long.class, String.class).put(4L, "4"); assertThat(cacheManager1.getCache("aCache4", Long.class, String.class).get(4L), equalTo("4")); ResultSet<ContextualReturn<Void>> results = service.withCapability("ActionsCapability").call("clear").on(contextList).build().execute(); assertThat(results.size(), Matchers.equalTo(4)); assertThat(results.getResult(contextList.get(0)).hasValue(), is(true)); assertThat(results.getResult(contextList.get(1)).hasValue(), is(true)); assertThat(results.getResult(contextList.get(2)).hasValue(), is(true)); assertThat(results.getResult(contextList.get(3)).hasValue(), is(false)); assertThat(results.getResult(contextList.get(0)).getValue(), is(nullValue())); assertThat(results.getResult(contextList.get(1)).getValue(), is(nullValue())); assertThat(results.getResult(contextList.get(2)).getValue(), is(nullValue())); try { results.getResult(contextList.get(3)).getValue(); fail(); } catch (Exception e) { assertThat(e, instanceOf(NoSuchElementException.class)); } assertThat( cacheManager1.getCache("aCache1", Long.class, String.class).get(1L), is(Matchers.nullValue())); assertThat( cacheManager2.getCache("aCache2", Long.class, String.class).get(2L), is(Matchers.nullValue())); assertThat( cacheManager1.getCache("aCache4", Long.class, String.class).get(4L), is(Matchers.nullValue())); }
@Test public void testStats() { List<Context> contextList = Arrays.asList( Context.create().with("cacheManagerName", "myCM1").with("cacheName", "aCache1"), Context.create().with("cacheManagerName", "myCM2").with("cacheName", "aCache2"), Context.create().with("cacheManagerName", "myCM2").with("cacheName", "aCache3")); cacheManager1.getCache("aCache1", Long.class, String.class).put(1L, "1"); cacheManager2.getCache("aCache2", Long.class, String.class).put(2L, "2"); cacheManager2.getCache("aCache3", Long.class, String.class).put(3L, "3"); ResultSet<ContextualStatistics> allCounters = service .withCapability("StatisticsCapability") .queryStatistic("PutCounter") .on(contextList) .build() .execute(); assertThat(allCounters.size(), equalTo(3)); assertThat(allCounters.getResult(contextList.get(0)).size(), equalTo(1)); assertThat(allCounters.getResult(contextList.get(1)).size(), equalTo(1)); assertThat(allCounters.getResult(contextList.get(2)).size(), equalTo(1)); assertThat( allCounters.getResult(contextList.get(0)).getStatistic(Counter.class).getValue(), equalTo(1L)); assertThat( allCounters.getResult(contextList.get(1)).getStatistic(Counter.class).getValue(), equalTo(1L)); assertThat( allCounters.getResult(contextList.get(2)).getStatistic(Counter.class).getValue(), equalTo(1L)); }