diff --git a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/SearchableSnapshotsPersistentCacheIntegTests.java b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/SearchableSnapshotsPersistentCacheIntegTests.java index 7cf678cda3977..5ffeb66ba1ce8 100644 --- a/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/SearchableSnapshotsPersistentCacheIntegTests.java +++ b/x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/cache/SearchableSnapshotsPersistentCacheIntegTests.java @@ -112,10 +112,10 @@ public void testCacheSurviveRestart() throws Exception { } assertFalse("no cache files found", cacheFiles.isEmpty()); - CacheService cacheService = internalCluster().getInstance(CacheService.class, dataNode); + final CacheService cacheService = internalCluster().getInstance(CacheService.class, dataNode); cacheService.synchronizeCache(); - PersistentCache persistentCache = cacheService.getPersistentCache(); + final PersistentCache persistentCache = cacheService.getPersistentCache(); assertThat(persistentCache.getNumDocs(), equalTo((long) cacheFiles.size())); internalCluster().restartNode(dataNode, new InternalTestCluster.RestartCallback() { @@ -142,21 +142,19 @@ public Settings onNodeStopped(String nodeName) { } }); - cacheService = internalCluster().getInstance(CacheService.class, dataNode); - persistentCache = cacheService.getPersistentCache(); + final CacheService cacheServiceAfterRestart = internalCluster().getInstance(CacheService.class, dataNode); + final PersistentCache persistentCacheAfterRestart = cacheServiceAfterRestart.getPersistentCache(); ensureGreen(restoredIndexName); cacheFiles.forEach(cacheFile -> assertTrue(cacheFile + " should have survived node restart", Files.exists(cacheFile))); - assertThat("Cache files should be repopulated in cache", persistentCache.getNumDocs(), equalTo((long) cacheFiles.size())); + assertThat("Cache files should be loaded in cache", persistentCacheAfterRestart.getNumDocs(), equalTo((long) cacheFiles.size())); assertAcked(client().admin().indices().prepareDelete(restoredIndexName)); assertBusy(() -> { cacheFiles.forEach(cacheFile -> assertFalse(cacheFile + " should have been cleaned up", Files.exists(cacheFile))); - assertTrue(internalCluster().getInstance(CacheService.class, dataNode).getPersistentCache().hasDeletions()); + cacheServiceAfterRestart.synchronizeCache(); + assertThat(persistentCacheAfterRestart.getNumDocs(), equalTo(0L)); }); - cacheService.synchronizeCache(); - - assertThat(persistentCache.getNumDocs(), equalTo(0L)); } }