You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2023/05/25 05:35:50 UTC
[shardingsphere] branch master updated: Refactor GovernanceRepositoryAPIImplTest.watch test (#25878)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new cdd9453332c Refactor GovernanceRepositoryAPIImplTest.watch test (#25878)
cdd9453332c is described below
commit cdd9453332c59b6ba5a67e35d47d922d29f57695
Author: zhaojinchao <zh...@apache.org>
AuthorDate: Thu May 25 13:35:34 2023 +0800
Refactor GovernanceRepositoryAPIImplTest.watch test (#25878)
* Refactor GovernanceRepositoryAPIImplTest.watch test
* Fix ci
* Fix ci
---
.../api/impl/GovernanceRepositoryAPIImplTest.java | 26 +++++++++++++---------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/api/impl/GovernanceRepositoryAPIImplTest.java b/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/api/impl/GovernanceRepositoryAPIImplTest.java
index d3e3274bcc3..e1b6c31d9d9 100644
--- a/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/api/impl/GovernanceRepositoryAPIImplTest.java
+++ b/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/api/impl/GovernanceRepositoryAPIImplTest.java
@@ -63,10 +63,24 @@ class GovernanceRepositoryAPIImplTest {
private static GovernanceRepositoryAPI governanceRepositoryAPI;
+ private static final AtomicReference<DataChangedEvent> EVENT_ATOMIC_REFERENCE = new AtomicReference<>();
+
+ private static final CountDownLatch COUNT_DOWN_LATCH = new CountDownLatch(1);
+
@BeforeAll
static void beforeClass() {
PipelineContextUtils.mockModeConfigAndContextManager();
governanceRepositoryAPI = PipelineAPIFactory.getGovernanceRepositoryAPI(PipelineContextUtils.getContextKey());
+ watch();
+ }
+
+ private static void watch() {
+ governanceRepositoryAPI.watch(DataPipelineConstants.DATA_PIPELINE_ROOT, event -> {
+ if ((DataPipelineConstants.DATA_PIPELINE_ROOT + "/1").equals(event.getKey())) {
+ EVENT_ATOMIC_REFERENCE.set(event);
+ COUNT_DOWN_LATCH.countDown();
+ }
+ });
}
@Test
@@ -107,19 +121,11 @@ class GovernanceRepositoryAPIImplTest {
@Test
void assertWatch() throws InterruptedException {
- AtomicReference<DataChangedEvent> eventReference = new AtomicReference<>();
- CountDownLatch countDownLatch = new CountDownLatch(1);
String key = DataPipelineConstants.DATA_PIPELINE_ROOT + "/1";
- governanceRepositoryAPI.watch(DataPipelineConstants.DATA_PIPELINE_ROOT, event -> {
- if (event.getKey().equals(key)) {
- eventReference.set(event);
- countDownLatch.countDown();
- }
- });
governanceRepositoryAPI.persist(key, "");
- boolean awaitResult = countDownLatch.await(10, TimeUnit.SECONDS);
+ boolean awaitResult = COUNT_DOWN_LATCH.await(10, TimeUnit.SECONDS);
assertTrue(awaitResult);
- DataChangedEvent event = eventReference.get();
+ DataChangedEvent event = EVENT_ATOMIC_REFERENCE.get();
assertNotNull(event);
assertThat(event.getType(), anyOf(is(Type.ADDED), is(Type.UPDATED)));
}