chengjianyun commented on a change in pull request #4079:
URL: https://github.com/apache/iotdb/pull/4079#discussion_r738243744
##########
File path:
cluster/src/test/java/org/apache/iotdb/cluster/client/async/AsyncDataClientTest.java
##########
@@ -4,85 +4,76 @@
package org.apache.iotdb.cluster.client.async;
-import
org.apache.iotdb.cluster.client.async.AsyncDataClient.SingleManagerFactory;
-import org.apache.iotdb.cluster.common.TestUtils;
+import org.apache.iotdb.cluster.client.BaseClientTest;
+import org.apache.iotdb.cluster.client.ClientCategory;
import org.apache.iotdb.cluster.config.ClusterConfig;
+import org.apache.iotdb.cluster.config.ClusterConstant;
import org.apache.iotdb.cluster.config.ClusterDescriptor;
-import org.apache.iotdb.cluster.rpc.thrift.Node;
-import org.apache.iotdb.cluster.server.RaftServer;
-
-import org.apache.thrift.TException;
-import org.apache.thrift.async.AsyncMethodCallback;
-import org.apache.thrift.async.TAsyncClientManager;
-import org.apache.thrift.protocol.TBinaryProtocol.Factory;
-import org.apache.thrift.transport.TNonblockingSocket;
-import org.junit.After;
+
+import org.apache.thrift.protocol.TBinaryProtocol;
+import org.apache.thrift.protocol.TCompactProtocol;
+import org.apache.thrift.protocol.TProtocolFactory;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import java.io.IOException;
-
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-public class AsyncDataClientTest {
+public class AsyncDataClientTest extends BaseClientTest {
private final ClusterConfig config =
ClusterDescriptor.getInstance().getConfig();
- private boolean isAsyncServer;
+ private TProtocolFactory protocolFactory;
@Before
public void setUp() {
- isAsyncServer = config.isUseAsyncServer();
config.setUseAsyncServer(true);
+ protocolFactory =
+ config.isRpcThriftCompressionEnabled()
+ ? new TCompactProtocol.Factory()
+ : new TBinaryProtocol.Factory();
}
- @After
- public void tearDown() {
- config.setUseAsyncServer(isAsyncServer);
+ @Test
+ public void testDataClient() throws Exception {
+
+ AsyncDataClient.AsyncDataClientFactory factory =
+ new AsyncDataClient.AsyncDataClientFactory(protocolFactory,
ClientCategory.DATA);
+
+ AsyncDataClient dataClient = factory.makeObject(defaultNode).getObject();
+
+ assertEquals(
+ "AsyncDataClient{node=Node(internalIp:localhost, metaPort:9003,
nodeIdentifier:0, "
+ + "dataPort:40010, clientPort:0, clientIp:localhost),port=40010}",
+ dataClient.toString());
+ assertCheck(dataClient);
}
@Test
- public void test() throws IOException, TException {
- AsyncClientPool asyncClientPool = new AsyncClientPool(new
SingleManagerFactory(new Factory()));
- AsyncDataClient client;
- Node node = TestUtils.getNode(0);
- client =
- new AsyncDataClient(
- new Factory(),
- new TAsyncClientManager(),
- new TNonblockingSocket(
- node.getInternalIp(), node.getDataPort(),
RaftServer.getConnectionTimeoutInMS()));
- assertTrue(client.isReady());
-
- client = (AsyncDataClient) asyncClientPool.getClient(TestUtils.getNode(0));
-
- assertEquals(TestUtils.getNode(0), client.getNode());
-
- client.matchTerm(
- 0,
- 0,
- TestUtils.getRaftNode(0, 0),
- new AsyncMethodCallback<Boolean>() {
- @Override
- public void onComplete(Boolean aBoolean) {
- // do nothing
- }
-
- @Override
- public void onError(Exception e) {
- // do nothing
- }
- });
- assertFalse(client.isReady());
-
- client.onError(new Exception());
- assertNull(client.getCurrMethod());
- assertFalse(client.isReady());
+ public void testMetaHeartbeatClient() throws Exception {
+
+ AsyncDataClient.AsyncDataClientFactory factory =
+ new AsyncDataClient.AsyncDataClientFactory(protocolFactory,
ClientCategory.DATA_HEARTBEAT);
+
+ AsyncDataClient dataClient = factory.makeObject(defaultNode).getObject();
assertEquals(
- "DataClient{node=ClusterNode{ internalIp='192.168.0.0', metaPort=9003,
nodeIdentifier=0, dataPort=40010, clientPort=6667, clientIp='0.0.0.0'}}",
- client.toString());
+ "AsyncDataHeartbeatClient{node=Node(internalIp:localhost,
metaPort:9003, nodeIdentifier:0, "
+ + "dataPort:40010, clientPort:0, clientIp:localhost),port=40011}",
+ dataClient.toString());
+ assertCheck(dataClient);
+ }
Review comment:
fixed.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]