healchow commented on code in PR #5512:
URL: https://github.com/apache/inlong/pull/5512#discussion_r944315040


##########
inlong-sdk/sort-sdk/src/test/java/org/apache/inlong/sdk/sort/manager/InlongSingleTopicManagerTest.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.inlong.sdk.sort.manager;
+
+import org.apache.inlong.sdk.sort.api.ClientContext;
+import org.apache.inlong.sdk.sort.api.InLongTopicFetcher;
+import org.apache.inlong.sdk.sort.api.InlongTopicManager;
+import org.apache.inlong.sdk.sort.api.QueryConsumeConfig;
+import org.apache.inlong.sdk.sort.api.SortClientConfig;
+import org.apache.inlong.sdk.sort.entity.CacheZoneCluster;
+import org.apache.inlong.sdk.sort.entity.InLongTopic;
+import org.apache.inlong.sdk.sort.impl.ClientContextImpl;
+import org.apache.inlong.sdk.sort.impl.InlongTopicManagerImpl;
+import org.apache.inlong.sdk.sort.impl.QueryConsumeConfigImpl;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import static org.powermock.api.mockito.PowerMockito.when;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ClientContext.class})
+public class InlongSingleTopicManagerTest {
+
+    private InLongTopic inLongTopic;
+    private ClientContext clientContext;
+    private QueryConsumeConfig queryConsumeConfig;
+    private InlongTopicManager inLongTopicManager;
+
+    {
+        System.setProperty("log4j2.disable.jmx", Boolean.TRUE.toString());
+
+        inLongTopic = new InLongTopic();
+        inLongTopic.setTopic("testTopic");
+        inLongTopic.setPartitionId(0);
+        inLongTopic.setTopicType("pulsar");
+        inLongTopic.setProperties(new HashMap<>());
+
+        CacheZoneCluster cacheZoneCluster = new CacheZoneCluster("clusterId", 
"bootstraps", "token");
+        inLongTopic.setInLongCluster(cacheZoneCluster);
+
+        clientContext = PowerMockito.mock(ClientContextImpl.class);
+
+        SortClientConfig sortClientConfig = 
PowerMockito.mock(SortClientConfig.class);
+        when(clientContext.getConfig()).thenReturn(sortClientConfig);
+        when(sortClientConfig.getSortTaskId()).thenReturn("test");
+        when(sortClientConfig.getUpdateMetaDataIntervalSec()).thenReturn(60);
+        queryConsumeConfig = PowerMockito.mock(QueryConsumeConfigImpl.class);
+        inLongTopicManager = new InlongTopicManagerImpl(clientContext, 
queryConsumeConfig);
+    }
+
+    @Test
+    public void testAddFetcher() {
+        InlongTopicManager inLongTopicManager = new 
InlongTopicManagerImpl(clientContext, queryConsumeConfig);
+
+        InLongTopicFetcher inLongTopicFetcher = 
inLongTopicManager.addFetcher(inLongTopic);
+        Assert.assertNull(inLongTopicFetcher);
+    }
+
+    @Test
+    public void testRemoveFetcher() {
+
+        InLongTopicFetcher inLongTopicFetcher = 
inLongTopicManager.removeFetcher(inLongTopic, true);
+        Assert.assertNull(inLongTopicFetcher);
+
+        ConcurrentHashMap<String, InLongTopicFetcher> fetchers = new 
ConcurrentHashMap<>();
+        InLongTopicFetcher inLongTopicFetcherRmMock = 
PowerMockito.mock(InLongTopicFetcher.class);
+        fetchers.put(inLongTopic.getTopicKey(), inLongTopicFetcherRmMock);
+
+        Whitebox.setInternalState(inLongTopicManager, "fetchers", fetchers);
+
+        inLongTopicFetcher = inLongTopicManager.removeFetcher(inLongTopic, 
true);
+        Assert.assertNotNull(inLongTopicFetcher);
+
+    }
+
+    @Test
+    public void testGetFetcher() {
+        InLongTopicFetcher fetcher = 
inLongTopicManager.getFetcher(inLongTopic.getTopicKey());
+        Assert.assertNull(fetcher);
+        ConcurrentHashMap<String, InLongTopicFetcher> fetchers = new 
ConcurrentHashMap<>();
+        InLongTopicFetcher inLongTopicFetcherRmMock = 
PowerMockito.mock(InLongTopicFetcher.class);
+        fetchers.put(inLongTopic.getTopicKey(), inLongTopicFetcherRmMock);
+
+        Whitebox.setInternalState(inLongTopicManager, "fetchers", fetchers);
+
+        fetcher = inLongTopicManager.getFetcher(inLongTopic.getTopicKey());
+        Assert.assertNotNull(fetcher);
+
+    }
+
+    @Test
+    public void testGetManagedInLongTopics() {
+        Set<String> managedInLongTopics = 
inLongTopicManager.getManagedInLongTopics();
+        Assert.assertEquals(0, managedInLongTopics.size());
+
+        ConcurrentHashMap<String, InLongTopicFetcher> fetchers = new 
ConcurrentHashMap<>();
+        InLongTopicFetcher inLongTopicFetcherRmMock = 
PowerMockito.mock(InLongTopicFetcher.class);
+        fetchers.put(inLongTopic.getTopicKey(), inLongTopicFetcherRmMock);
+        Whitebox.setInternalState(inLongTopicManager, "fetchers", fetchers);
+        managedInLongTopics = inLongTopicManager.getManagedInLongTopics();
+        Assert.assertEquals(1, managedInLongTopics.size());
+
+    }
+
+    @Test
+    public void testGetAllFetchers() {
+        Collection<InLongTopicFetcher> allFetchers = 
inLongTopicManager.getAllFetchers();
+        Assert.assertEquals(0, allFetchers.size());
+
+        ConcurrentHashMap<String, InLongTopicFetcher> fetchers = new 
ConcurrentHashMap<>();
+        InLongTopicFetcher inLongTopicFetcherRmMock = 
PowerMockito.mock(InLongTopicFetcher.class);
+        fetchers.put(inLongTopic.getTopicKey(), inLongTopicFetcherRmMock);
+        Whitebox.setInternalState(inLongTopicManager, "fetchers", fetchers);
+        allFetchers = inLongTopicManager.getAllFetchers();
+        Assert.assertEquals(1, allFetchers.size());
+    }
+
+    @Test
+    public void testOfflineAllTp() {

Review Comment:
   What does the `Tp` mean? 
   If it is `topic`, then using the `Topics` is better.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@inlong.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to