Fix tests flakiness and adopt code to Java 11
Feature: Issue 13487
Change-Id: I2b0b6864f2fbdf4b5949d887a9800b30d19698ef
diff --git a/src/test/java/com/googlesource/gerrit/modules/cache/chroniclemap/ChronicleMapCacheConfigTest.java b/src/test/java/com/googlesource/gerrit/modules/cache/chroniclemap/ChronicleMapCacheConfigTest.java
index 395b25c..735d23b 100644
--- a/src/test/java/com/googlesource/gerrit/modules/cache/chroniclemap/ChronicleMapCacheConfigTest.java
+++ b/src/test/java/com/googlesource/gerrit/modules/cache/chroniclemap/ChronicleMapCacheConfigTest.java
@@ -22,6 +22,7 @@
import com.google.gerrit.server.config.SitePaths;
import java.io.IOException;
+import java.nio.file.FileSystemException;
import java.nio.file.Files;
import java.time.Duration;
import org.eclipse.jgit.lib.StoredConfig;
@@ -178,8 +179,7 @@
gerritConfig.setString("cache", null, "directory", "/var/bar/foobar");
gerritConfig.save();
- IOException thrown = assertThrows(IOException.class, () -> configUnderTest(gerritConfig));
- assertThat(thrown).hasMessageThat().contains("Operation not permitted");
+ assertThrows(FileSystemException.class, () -> configUnderTest(gerritConfig));
}
@Test
diff --git a/src/test/java/com/googlesource/gerrit/modules/cache/chroniclemap/ChronicleMapCacheTest.java b/src/test/java/com/googlesource/gerrit/modules/cache/chroniclemap/ChronicleMapCacheTest.java
index 43205c0..6abf49d 100644
--- a/src/test/java/com/googlesource/gerrit/modules/cache/chroniclemap/ChronicleMapCacheTest.java
+++ b/src/test/java/com/googlesource/gerrit/modules/cache/chroniclemap/ChronicleMapCacheTest.java
@@ -166,7 +166,7 @@
public void getIfPresentShouldReturnNullWhenValueIsExpired() throws Exception {
ChronicleMapCacheImpl<String, String> cache = newCache(true, null, Duration.ofSeconds(1), null);
cache.put("foo", "some-stale-value");
- Thread.sleep(1000); // Allow cache entry to expire
+ Thread.sleep(1010); // Allow cache entry to expire
assertThat(cache.getIfPresent("foo")).isNull();
}
@@ -176,7 +176,7 @@
ChronicleMapCacheImpl<String, String> cache =
newCache(true, newCachedValue, null, Duration.ofSeconds(1));
cache.put("foo", "some-stale-value");
- Thread.sleep(1000); // Allow cache to be flagged as needing refresh
+ Thread.sleep(1010); // Allow cache to be flagged as needing refresh
assertThat(cache.get("foo")).isEqualTo(newCachedValue);
}
@@ -185,7 +185,7 @@
ChronicleMapCacheImpl<String, String> cache = newCache(true, null, Duration.ofSeconds(1), null);
cache.put("foo1", "some-stale-value1");
cache.put("foo2", "some-stale-value1");
- Thread.sleep(1000); // Allow cache entries to expire
+ Thread.sleep(1010); // Allow cache entries to expire
cache.put("foo3", "some-fresh-value3");
cache.prune();