提交 4c4bf104 编写于 作者: Q qqeasonchen

add unittest of request/response pattern

上级 5e1732a9
...@@ -50,7 +50,7 @@ public class ProducerManagerTest { ...@@ -50,7 +50,7 @@ public class ProducerManagerTest {
public void scanNotActiveChannel() throws Exception { public void scanNotActiveChannel() throws Exception {
producerManager.registerProducer(group, clientInfo); producerManager.registerProducer(group, clientInfo);
assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNotNull(); assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNotNull();
assertThat(producerManager.findChannel("clientId")).isNotNull();
Field field = ProducerManager.class.getDeclaredField("CHANNEL_EXPIRED_TIMEOUT"); Field field = ProducerManager.class.getDeclaredField("CHANNEL_EXPIRED_TIMEOUT");
field.setAccessible(true); field.setAccessible(true);
long CHANNEL_EXPIRED_TIMEOUT = field.getLong(producerManager); long CHANNEL_EXPIRED_TIMEOUT = field.getLong(producerManager);
...@@ -58,22 +58,28 @@ public class ProducerManagerTest { ...@@ -58,22 +58,28 @@ public class ProducerManagerTest {
when(channel.close()).thenReturn(mock(ChannelFuture.class)); when(channel.close()).thenReturn(mock(ChannelFuture.class));
producerManager.scanNotActiveChannel(); producerManager.scanNotActiveChannel();
assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNull(); assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNull();
assertThat(producerManager.findChannel("clientId")).isNull();
} }
@Test @Test
public void doChannelCloseEvent() throws Exception { public void doChannelCloseEvent() throws Exception {
producerManager.registerProducer(group, clientInfo); producerManager.registerProducer(group, clientInfo);
assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNotNull(); assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNotNull();
assertThat(producerManager.findChannel("clientId")).isNotNull();
producerManager.doChannelCloseEvent("127.0.0.1", channel); producerManager.doChannelCloseEvent("127.0.0.1", channel);
assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNull(); assertThat(producerManager.getGroupChannelTable().get(group).get(channel)).isNull();
assertThat(producerManager.findChannel("clientId")).isNull();
} }
@Test @Test
public void testRegisterProducer() throws Exception { public void testRegisterProducer() throws Exception {
producerManager.registerProducer(group, clientInfo); producerManager.registerProducer(group, clientInfo);
HashMap<Channel, ClientChannelInfo> channelMap = producerManager.getGroupChannelTable().get(group); HashMap<Channel, ClientChannelInfo> channelMap = producerManager.getGroupChannelTable().get(group);
Channel channel1 = producerManager.findChannel("clientId");
assertThat(channelMap).isNotNull(); assertThat(channelMap).isNotNull();
assertThat(channel1).isNotNull();
assertThat(channelMap.get(channel)).isEqualTo(clientInfo); assertThat(channelMap.get(channel)).isEqualTo(clientInfo);
assertThat(channel1).isEqualTo(channel);
} }
@Test @Test
...@@ -82,10 +88,15 @@ public class ProducerManagerTest { ...@@ -82,10 +88,15 @@ public class ProducerManagerTest {
HashMap<Channel, ClientChannelInfo> channelMap = producerManager.getGroupChannelTable().get(group); HashMap<Channel, ClientChannelInfo> channelMap = producerManager.getGroupChannelTable().get(group);
assertThat(channelMap).isNotNull(); assertThat(channelMap).isNotNull();
assertThat(channelMap.get(channel)).isEqualTo(clientInfo); assertThat(channelMap.get(channel)).isEqualTo(clientInfo);
Channel channel1 = producerManager.findChannel("clientId");
assertThat(channel1).isNotNull();
assertThat(channel1).isEqualTo(channel);
producerManager.unregisterProducer(group, clientInfo); producerManager.unregisterProducer(group, clientInfo);
channelMap = producerManager.getGroupChannelTable().get(group); channelMap = producerManager.getGroupChannelTable().get(group);
channel1 = producerManager.findChannel("clientId");
assertThat(channelMap).isNull(); assertThat(channelMap).isNull();
assertThat(channel1).isNull();
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册