@Programmatic @SuppressWarnings("unchecked") public <T> T execute(final Callable<T> callable, final Key cacheKey) { if(control.isFixturesInstalling()) { try { return callable.call(); } catch (Exception e) { throw new RuntimeException(e); } } return executeWithCaching(callable, cacheKey); }
@Test public void cachingDisabled() { // given fixtures installing, hence caching disabled control.on(new FixturesInstallingEvent(new FixtureScriptsDefault())); final int[] i = new int[]{0}; Callable<String> callable = new Callable<String>(){ @Override public String call() throws Exception { i[0]++; return "foo"; } }; // when, then (a cache miss) assertThat(i[0], is(0)); assertThat(queryResultsCache.execute(callable, QueryResultsCacheTest.class, "caching", "a","b",1,2), is("foo")); assertThat(i[0], is(1)); // when, then should also be a cache miss - would've been a hit previously assertThat(queryResultsCache.execute(callable, QueryResultsCacheTest.class, "caching", "a","b",1,2), is("foo")); assertThat(i[0], is(2)); }
@Before public void setUp() throws Exception { queryResultsCache = new QueryResultsCache(); control = new QueryResultsCache.Control(); queryResultsCache.control = control; }
@Programmatic public <T> T execute(final Callable<T> callable, final Class<?> callingClass, final String methodName, final Object... keys) { if(control.isFixturesInstalling()) { try { return callable.call(); } catch (Exception e) { throw new RuntimeException(e); } } final Key cacheKey = new Key(callingClass, methodName, keys); return executeWithCaching(callable, cacheKey); }