Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve][test] Add unit test for metadata cache #20363 #20436

Merged
merged 1 commit into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ public Object[][] implementations() {
};
}

@DataProvider(name = "distributedImpl")
public Object[][] distributedImplementations() {
return new Object[][]{
{"ZooKeeper", stringSupplier(() -> zks.getConnectionString())},
{"Etcd", stringSupplier(() -> "etcd:" + getEtcdClusterConnectString())},
};
}

private synchronized String getEtcdClusterConnectString() {
if (etcdCluster == null) {
etcdCluster = EtcdClusterExtension.builder().withClusterName("test").withNodes(1).withSsl(false).build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,4 +593,56 @@ public void testClosedMetadataStore(String provider, Supplier<String> urlSupplie
assertTrue(e.getCause() instanceof MetadataStoreException.AlreadyClosedException);
}
}

@Test(dataProvider = "distributedImpl")
public void testGetChildrenDistributed(String provider, Supplier<String> urlSupplier) throws Exception {
@Cleanup
MetadataStore store1 = MetadataStoreFactory.create(urlSupplier.get(),
MetadataStoreConfig.builder().fsyncEnable(false).build());
@Cleanup
MetadataStore store2 = MetadataStoreFactory.create(urlSupplier.get(),
MetadataStoreConfig.builder().fsyncEnable(false).build());

String parent = newKey();
byte[] value = "value1".getBytes(StandardCharsets.UTF_8);
store1.put(parent, value, Optional.empty()).get();
store1.put(parent + "/a", value, Optional.empty()).get();
assertEquals(store1.getChildren(parent).get(), List.of("a"));
store1.delete(parent + "/a", Optional.empty()).get();
assertEquals(store1.getChildren(parent).get(), Collections.emptyList());
store1.delete(parent, Optional.empty()).get();
assertEquals(store1.getChildren(parent).get(), Collections.emptyList());
store2.put(parent + "/b", value, Optional.empty()).get();
// There is a chance watcher event is not triggered before the store1.getChildren() call.
Awaitility.await().atMost(3, TimeUnit.SECONDS)
.pollInterval(100, TimeUnit.MILLISECONDS)
.untilAsserted(() -> assertEquals(store1.getChildren(parent).get(), List.of("b")));
store2.put(parent + "/c", value, Optional.empty()).get();
Awaitility.await().atMost(3, TimeUnit.SECONDS)
.pollInterval(100, TimeUnit.MILLISECONDS)
.untilAsserted(() -> assertEquals(store1.getChildren(parent).get(), List.of("b", "c")));
}

@Test(dataProvider = "distributedImpl")
public void testExistsDistributed(String provider, Supplier<String> urlSupplier) throws Exception {
@Cleanup
MetadataStore store1 = MetadataStoreFactory.create(urlSupplier.get(),
MetadataStoreConfig.builder().fsyncEnable(false).build());
@Cleanup
MetadataStore store2 = MetadataStoreFactory.create(urlSupplier.get(),
MetadataStoreConfig.builder().fsyncEnable(false).build());

String parent = newKey();
byte[] value = "value1".getBytes(StandardCharsets.UTF_8);
assertFalse(store1.exists(parent).get());
store1.put(parent, value, Optional.empty()).get();
assertTrue(store1.exists(parent).get());
assertFalse(store1.exists(parent + "/a").get());
store2.put(parent + "/a", value, Optional.empty()).get();
assertTrue(store1.exists(parent + "/a").get());
// There is a chance watcher event is not triggered before the store1.exists() call.
Awaitility.await().atMost(3, TimeUnit.SECONDS)
.pollInterval(100, TimeUnit.MILLISECONDS)
.untilAsserted(() -> assertFalse(store1.exists(parent + "/b").get()));
}
}