Skip to content

Commit

Permalink
添加TopicConfigSerializeWrapper单测
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangbiao committed Feb 26, 2019
1 parent c24ab03 commit af89a3e
Showing 1 changed file with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
package org.apache.rocketmq.common.protocol.body;

import org.apache.rocketmq.common.DataVersion;
import org.apache.rocketmq.common.TopicConfig;
import org.apache.rocketmq.remoting.protocol.RemotingSerializable;
import org.junit.Assert;
import org.junit.Test;

public class TopicConfigSerializeWrapperTest {
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

String topicName = "xxxx";
public class TopicConfigSerializeWrapperTest {

@Test
public void testEncode(){
TopicConfig config = new TopicConfig(topicName);
Assert.assertNotNull(TopicConfigSerializeWrapper.encode(config));
}
public void testFromJson(){
TopicConfigSerializeWrapper wrapper = new TopicConfigSerializeWrapper();

@Test
public void testDecode(){
String json = "{\"order\":false,\"perm\":6,\"readQueueNums\":16,\"topicFilterType\":\"SINGLE_TAG\",\"topicName\":\"xxxx\",\"topicSysFlag\":0,\"writeQueueNums\":16}";
TopicConfig config = TopicConfigSerializeWrapper.decode(json.getBytes(), TopicConfig.class);
Assert.assertNotNull(config);
Assert.assertEquals(topicName, config.getTopicName());
}
ConcurrentMap<String, TopicConfig> topicConfigs = new ConcurrentHashMap<String, TopicConfig>();
TopicConfig topicConfig = new TopicConfig("topic-xxx");
topicConfigs.put("config", topicConfig);
wrapper.setTopicConfigTable(topicConfigs);

DataVersion dataVersion = new DataVersion();
dataVersion.nextVersion();
wrapper.setDataVersion(dataVersion);

String json = RemotingSerializable.toJson(wrapper, false);

TopicConfigSerializeWrapper fromJsonWrapper =
RemotingSerializable.fromJson(json, TopicConfigSerializeWrapper.class);

Assert.assertEquals("topic-xxx", fromJsonWrapper.getTopicConfigTable().get("config").getTopicName());
}

}

0 comments on commit af89a3e

Please sign in to comment.