This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 9e4bfc5e01a Add test cases on IncrementalTaskAckCallback (#33394)
9e4bfc5e01a is described below
commit 9e4bfc5e01a572fabbb4a21a3552d09bc3622632
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Oct 24 23:15:58 2024 +0800
Add test cases on IncrementalTaskAckCallback (#33394)
* Refactor IncrementalTask
* Add test cases on IncrementalTaskAckCallback
---
.../data/pipeline/core/task/IncrementalTask.java | 5 +-
.../core/task/IncrementalTaskAckCallbackTest.java | 67 ++++++++++++++++++++++
2 files changed, 69 insertions(+), 3 deletions(-)
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/task/IncrementalTask.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/task/IncrementalTask.java
index 8635391b28b..2d736760f22 100644
---
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/task/IncrementalTask.java
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/task/IncrementalTask.java
@@ -21,6 +21,7 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import
org.apache.shardingsphere.data.pipeline.core.execute.PipelineExecuteEngine;
+import
org.apache.shardingsphere.data.pipeline.core.execute.PipelineLifecycleRunnable;
import org.apache.shardingsphere.data.pipeline.core.importer.Importer;
import org.apache.shardingsphere.data.pipeline.core.ingest.dumper.Dumper;
import
org.apache.shardingsphere.data.pipeline.core.task.progress.IncrementalTaskProgress;
@@ -62,8 +63,6 @@ public final class IncrementalTask implements PipelineTask {
@Override
public void stop() {
dumper.stop();
- for (Importer each : importers) {
- each.stop();
- }
+ importers.forEach(PipelineLifecycleRunnable::stop);
}
}
diff --git
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/task/IncrementalTaskAckCallbackTest.java
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/task/IncrementalTaskAckCallbackTest.java
new file mode 100644
index 00000000000..6d6f391c645
--- /dev/null
+++
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/task/IncrementalTaskAckCallbackTest.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.data.pipeline.core.task;
+
+import
org.apache.shardingsphere.data.pipeline.core.ingest.position.IngestPosition;
+import
org.apache.shardingsphere.data.pipeline.core.ingest.position.type.finished.IngestFinishedPosition;
+import
org.apache.shardingsphere.data.pipeline.core.ingest.position.type.placeholder.IngestPlaceholderPosition;
+import
org.apache.shardingsphere.data.pipeline.core.ingest.record.FinishedRecord;
+import
org.apache.shardingsphere.data.pipeline.core.ingest.record.PlaceholderRecord;
+import
org.apache.shardingsphere.data.pipeline.core.task.progress.IncrementalTaskProgress;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.lessThan;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+@ExtendWith(MockitoExtension.class)
+class IncrementalTaskAckCallbackTest {
+
+ @Mock
+ private IngestPosition position;
+
+ private final IncrementalTaskProgress taskProgress = new
IncrementalTaskProgress(position);
+
+ private final IncrementalTaskAckCallback callback = new
IncrementalTaskAckCallback(taskProgress);
+
+ @Test
+ void assertOnAckWithIngestPlaceholderPosition() {
+ PlaceholderRecord record = new PlaceholderRecord(new
IngestPlaceholderPosition());
+ callback.onAck(Collections.singletonList(record));
+ assertNull(taskProgress.getPosition());
+
assertThat(taskProgress.getIncrementalTaskDelay().getLastEventTimestamps(),
is(0L));
+ assertThat(System.currentTimeMillis() -
taskProgress.getIncrementalTaskDelay().getLatestActiveTimeMillis(),
lessThan(10000L));
+ }
+
+ @Test
+ void assertOnAckWithNotIngestPlaceholderPosition() {
+ IngestFinishedPosition position = new IngestFinishedPosition();
+ FinishedRecord record = new FinishedRecord(position);
+ record.setCommitTime(1L);
+ callback.onAck(Collections.singletonList(record));
+ assertThat(taskProgress.getPosition(), is(position));
+
assertThat(taskProgress.getIncrementalTaskDelay().getLastEventTimestamps(),
is(1L));
+ assertThat(System.currentTimeMillis() -
taskProgress.getIncrementalTaskDelay().getLatestActiveTimeMillis(),
lessThan(10000L));
+ }
+}