Exemplo n.º 1
0
 @Test
 public void testNullValue() throws Exception {
   // mocks have their methods returning null by default
   PersistentCacheLoader<byte[]> c = mock(PersistentCacheLoader.class);
   assertThat(cache.get(URI, c)).isNull();
   verify(c).get();
   assertCacheHit(false);
 }
  @Test
  public void errorSave() throws IOException {
    when(cache.getDirectory()).thenReturn(tmp.getRoot().toPath().resolve("unexistent_folder"));
    cacheStatus = new DefaultProjectCacheStatus(cache);

    exception.expect(IllegalStateException.class);
    exception.expectMessage("Failed to write cache sync status");
    cacheStatus.save();
  }
Exemplo n.º 3
0
 public WSLoader provide(
     AnalysisProperties props, AnalysisMode mode, PersistentCache cache, ServerClient client) {
   if (wsLoader == null) {
     // recreate cache directory if needed for this analysis
     cache.reconfigure();
     wsLoader = new WSLoader(isCacheEnabled(props.properties(), mode.isPreview()), cache, client);
     wsLoader.setStrategy(getStrategy(mode));
   }
   return wsLoader;
 }
Exemplo n.º 4
0
  @Test
  public void testReconfigure() throws Exception {
    cache = new PersistentCache(tmp.getRoot().toPath(), Long.MAX_VALUE, mock(Logger.class));
    assertCacheHit(false);
    assertCacheHit(true);

    File root = tmp.getRoot();
    FileUtils.deleteQuietly(root);

    // should re-create cache directory and start using the cache
    cache.reconfigure();
    assertThat(root).exists();

    assertCacheHit(false);
    assertCacheHit(true);
  }
 @Before
 public void setUp() {
   when(cache.getDirectory()).thenReturn(tmp.getRoot().toPath());
   cacheStatus = new DefaultProjectCacheStatus(cache);
 }
Exemplo n.º 6
0
 @Test
 public void testClean() throws Exception {
   assertCacheHit(false);
   cache.clear();
   assertCacheHit(false);
 }
Exemplo n.º 7
0
 @Test
 public void testNullLoader() throws Exception {
   assertThat(cache.get(URI, null)).isNull();
   assertCacheHit(false);
 }
Exemplo n.º 8
0
 /**
  * WSCache should be transparent regarding exceptions: if an exception is thrown by the value
  * loader, it should pass through the cache to the original caller using the cache.
  *
  * @throws Exception
  */
 @Test(expected = ArithmeticException.class)
 public void testExceptions() throws Exception {
   PersistentCacheLoader<byte[]> c = mock(PersistentCacheLoader.class);
   when(c.get()).thenThrow(ArithmeticException.class);
   cache.get(URI, c);
 }
Exemplo n.º 9
0
 private void assertCacheHit(boolean hit) throws Exception {
   CacheFillerString c = new CacheFillerString();
   assertThat(cache.getString(URI, c)).isEqualTo(VALUE);
   assertThat(c.wasCalled).isEqualTo(!hit);
 }