Skip to content

Commit

Permalink
[#2745] fix(test): Extend sleep time in the testInternalCache unit …
Browse files Browse the repository at this point in the history
…test to fix flaky test (#2744)

### What changes were proposed in this pull request?

`Caffeine Cache`'s use of `RemoveListener` is not stable and may cause a
single test to fail in some cases. Therefore, the waiting time in the
single test is extended to ensure that the `Cache` is cleaned normally.


![image](https://github.com/datastrato/gravitino/assets/26177232/7ecb8a6b-28a0-4146-91bd-0e633f9fe53b)

### Why are the changes needed?

Fix: #2745

---------

Co-authored-by: xiaojiebao <[email protected]>
  • Loading branch information
xloya and xiaojiebao authored Apr 1, 2024
1 parent f72a48d commit c433f84
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions clients/filesystem-hadoop3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
implementation(project(":clients:client-java-runtime", configuration = "shadow"))
implementation(libs.caffeine)

testImplementation(libs.awaitility)
testImplementation(libs.hadoop3.common)
testImplementation(libs.junit.jupiter.api)
testImplementation(libs.junit.jupiter.params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -151,7 +153,7 @@ public void testFSCache() throws IOException {
}

@Test
public void testInternalCache() throws IOException, InterruptedException {
public void testInternalCache() throws IOException {
Configuration configuration = new Configuration(conf);
configuration.set(
GravitinoVirtualFileSystemConfiguration.FS_GRAVITINO_FILESET_CACHE_MAX_CAPACITY_KEY, "1");
Expand Down Expand Up @@ -187,15 +189,27 @@ public void testInternalCache() throws IOException, InterruptedException {
localPath2.toString());
FileSystemTestUtils.mkdirs(filesetPath2, fs);

Thread.sleep(1000);
assertNull(
((GravitinoVirtualFileSystem) fs)
.getFilesetCache()
.getIfPresent(NameIdentifier.of(metalakeName, catalogName, schemaName, "fileset1")));
Awaitility.await()
.atMost(5, TimeUnit.SECONDS)
.pollInterval(1, TimeUnit.SECONDS)
.untilAsserted(
() ->
assertNull(
((GravitinoVirtualFileSystem) fs)
.getFilesetCache()
.getIfPresent(
NameIdentifier.of(
metalakeName, catalogName, schemaName, "fileset1"))));

// expired by time
Thread.sleep(1000);
assertEquals(0, ((GravitinoVirtualFileSystem) fs).getFilesetCache().asMap().size());
Awaitility.await()
.atMost(5, TimeUnit.SECONDS)
.pollInterval(1, TimeUnit.SECONDS)
.untilAsserted(
() ->
assertEquals(
0, ((GravitinoVirtualFileSystem) fs).getFilesetCache().asMap().size()));

assertNull(
((GravitinoVirtualFileSystem) fs)
.getFilesetCache()
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ h2db = "1.4.200"
kyuubi = "1.8.0"
kafka = "3.4.0"
curator = "2.12.0"
awaitility = "4.2.1"

protobuf-plugin = "0.9.2"
spotless-plugin = '6.11.0'
Expand Down Expand Up @@ -162,6 +163,7 @@ selenium = { group = "org.seleniumhq.selenium", name = "selenium-java", version.
rauschig = { group = "org.rauschig", name = "jarchivelib", version.ref = "rauschig" }
mybatis = { group = "org.mybatis", name = "mybatis", version.ref = "mybatis"}
h2db = { group = "com.h2database", name = "h2", version.ref = "h2db"}
awaitility = { group = "org.awaitility", name = "awaitility", version.ref = "awaitility" }

[bundles]
log4j = ["slf4j-api", "log4j-slf4j2-impl", "log4j-api", "log4j-core", "log4j-12-api"]
Expand Down

0 comments on commit c433f84

Please sign in to comment.