⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 channelimpltest.java

📁 是离开的肌肤了卡机是离开的就富利卡及是了的开发及拉考试及的福利科技阿斯利康的肌肤莱卡及时的离开福建阿斯顿发
💻 JAVA
字号:
/** *  */package org.mortbay.cometd;import java.security.SecureRandom;import java.util.Arrays;import java.util.Random;import java.util.concurrent.ConcurrentHashMap;import junit.framework.TestCase;import org.cometd.Channel;import org.cometd.ChannelBayeuxListener;import org.cometd.Client;/** * @author athena * */public class ChannelImplTest extends TestCase{    private Channel _channel;    private AbstractBayeux _bayeux;    public void setUp() throws Exception     {        _bayeux = new BayeuxStub();    }    public void testRemoves() throws Exception    {        String[][] tests = new String[][] {           // added,  expected   , remove , removed, expected           {"/test", "[/, /test]", "/test", "/test", "[/]"},           {"/test/123", "[/, /test, /test/123]", "/test/123", "/test/123", "[/, /test]"},           {"/test/123", "[/, /test, /test/123]", "/test/abc", null, "[/, /test, /test/123]"},           {"/test/123", "[/, /test, /test/123]", "/123", null, "[/, /test, /test/123]"},           {"/test/123", "[/, /test, /test/123]", "/test", null, "[/, /test, /test/123]"}        };                for ( String[] test : tests )        {            _bayeux.getChannel(test[0], true);            assertEquals(test[1], _bayeux.getChannels().toString());                        Channel removed = _bayeux.removeChannel(test[2]);            assertEquals(test[3], removed == null? null : removed.toString());            assertEquals(test[4], _bayeux.getChannels().toString());        }    }        public void testChannelSubscriptions () throws Exception    {         String[] chans = {"/service", "/service/foo", "/service/foo/bar", "/service/foo/bob"};      final String[] results = new String[chans.length];                  class MyChannelBayeuxListener implements ChannelBayeuxListener      {          int r = 0;          String[] res;          public MyChannelBayeuxListener (String[] res)          {              this.res=res;          }          public void channelAdded(Channel channel)          {              this.res[r++] = channel.getId();          }          public void channelRemoved(Channel channel)          {                        }      }            _bayeux.addListener (new MyChannelBayeuxListener(results));      _bayeux.getChannel("/service/foo/bar", true);      _bayeux.getChannel("/service/foo/bob", true);      assertTrue(Arrays.equals(chans,results));    }        static class BayeuxStub extends AbstractBayeux    {        public BayeuxStub()        {            try            {                _random=SecureRandom.getInstance("SHA1PRNG");            }            catch (Exception e)            {                _random=new Random();            }            _random.setSeed(_random.nextLong()^hashCode()^Runtime.getRuntime().freeMemory());            _channelIdCache=new ConcurrentHashMap<String, ChannelId>();        }                 public ClientImpl newRemoteClient()        {            return null;        }            }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -