This is an automated email from the ASF dual-hosted git repository.

zhonghongsheng 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 dd44eb00aba Add unit test for PipelineJobCenter (#28879)
dd44eb00aba is described below

commit dd44eb00aba6f63efdba6feb8ddb5845fcc5152a
Author: HarshSawarkar <[email protected]>
AuthorDate: Thu Nov 2 12:51:56 2023 +0530

    Add unit test for PipelineJobCenter (#28879)
    
    * 28542-Add-unit-test-for-PipelineJobCenter
    
    * 28542-Add-unit-test-for-PipelineJobCenter
    
    * Made all the changes as mentioned in review comments.
    
    * Formatted the code as per code of conduct and made the changes as 
mentioned in the review comments.
    
    * Corrected the checkstyle errors
    
    * Updated method name
---
 .../pipeline/core/job/PipelineJobCenterTest.java   | 81 ++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git 
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/PipelineJobCenterTest.java
 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/PipelineJobCenterTest.java
new file mode 100644
index 00000000000..ab6e08941b3
--- /dev/null
+++ 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/PipelineJobCenterTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.job;
+
+import 
org.apache.shardingsphere.data.pipeline.common.context.PipelineJobItemContext;
+import org.apache.shardingsphere.data.pipeline.common.job.PipelineJob;
+import 
org.apache.shardingsphere.data.pipeline.core.task.runner.PipelineTasksRunner;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class PipelineJobCenterTest {
+    
+    @Test
+    void assertPipelineJobCenter() {
+        PipelineJob pipelineJob = mock(PipelineJob.class);
+        PipelineJobCenter.addJob("Job1", pipelineJob);
+        assertTrue(PipelineJobCenter.isJobExisting("Job1"));
+        assertFalse(PipelineJobCenter.isJobExisting("Job2"));
+        assertNotNull(PipelineJobCenter.getJob("Job1"));
+        assertEquals(pipelineJob, PipelineJobCenter.getJob("Job1"));
+        assertNull(PipelineJobCenter.getJob("Job2"));
+        PipelineJobCenter.stop("Job1");
+    }
+    
+    @Test
+    void assertGetJobItemContext() {
+        PipelineJob pipelineJob = mock(PipelineJob.class);
+        PipelineTasksRunner pipelineTasksRunner = 
mock(PipelineTasksRunner.class);
+        PipelineJobItemContext pipelineJobItemContext = 
mock(PipelineJobItemContext.class);
+        
when(pipelineJob.getTasksRunner(anyInt())).thenReturn(Optional.of(pipelineTasksRunner));
+        
when(pipelineTasksRunner.getJobItemContext()).thenReturn(pipelineJobItemContext);
+        PipelineJobCenter.addJob("Job1", pipelineJob);
+        Optional<PipelineJobItemContext> result = 
PipelineJobCenter.getJobItemContext("Job1", 1);
+        Optional<PipelineJobItemContext> optionalPipelineJobItemContext = 
Optional.ofNullable(pipelineJobItemContext);
+        assertTrue(result.isPresent());
+        assertEquals(Optional.empty(), 
PipelineJobCenter.getJobItemContext("Job2", 1));
+        assertEquals(optionalPipelineJobItemContext, result);
+        PipelineJobCenter.stop("Job1");
+    }
+    
+    @Test
+    void assertGetShardingItems() {
+        PipelineJob pipelineJob = mock(PipelineJob.class);
+        PipelineJobCenter.addJob("Job1", pipelineJob);
+        when(pipelineJob.getShardingItems()).thenReturn(Arrays.asList(1, 2, 
3));
+        Collection<Integer> shardingItems = pipelineJob.getShardingItems();
+        Assertions.assertFalse(shardingItems.isEmpty());
+        Assertions.assertEquals(Arrays.asList(1, 2, 3), 
PipelineJobCenter.getShardingItems("Job1"));
+        assertEquals(Collections.EMPTY_LIST, 
PipelineJobCenter.getShardingItems("Job2"));
+        PipelineJobCenter.stop("Job1");
+    }
+}

Reply via email to