a

package com.paic.hm.user.front.web.controller.message;




import java.util.Map;


import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;


import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistry;
import com.alibaba.dubbo.remoting.zookeeper.zkclient.ZkclientZookeeperTransporter;


public class ZookeeperRegistryTest {





    String            service     = "aaaaaaaaaaaaabbbbbbbbbbbbbbcccccccccccccc";
    URL               registryUrl = URL.valueOf("zookeeper://127.0.0.1:2181/");
    URL               serviceUrl  = URL.valueOf("zookeeper://127.0.0.1:2181/" + service + "?notify=false&methods=test1,test2");
    URL               consumerUrl = URL.valueOf("zookeeper://consumer/" + service + "?notify=false&methods=test1,test2");
    ZookeeperRegistry registry    = new ZookeeperRegistry(registryUrl,new ZkclientZookeeperTransporter());


    /**
     * @throws java.lang.Exception
     */
    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
    }


    /**
     * @throws java.lang.Exception
     */
//    @Before
//    public void setUp() throws Exception {
       registry.register(service, serviceUrl);
//     System.out.println(serviceUrl.getAddress());
//     System.out.println(serviceUrl.getPort());
//     Map<String,String> map = serviceUrl.getParameters();
//     for (Map.Entry<String, String> entry: map.entrySet()) {
// System.out.println(entry.getKey()+":"+entry.getValue());
// }
//     registry.register(serviceUrl);
//    }


    @Test(expected = IllegalStateException.class)
    public void testUrlerror() {
        URL errorUrl = URL.valueOf("zookeeper://zookeeper/");
        registry.register(errorUrl);
    }
    
    @Test
    public void testDefaultPort() {
//        Assert.assertEquals("10.20.153.10:2181", ZookeeperRegistry.appendDefaultPort("10.20.153.10:0"));
//        Assert.assertEquals("10.20.153.10:2181", ZookeeperRegistry.appendDefaultPort("10.20.153.10"));
    }


    /**
     * Test method for {@link com.alibaba.dubbo.registry.support.injvm.InjvmRegistry#register(java.util.Map)}.
     */
//    @Test
//    public void testRegister() {
//        List<URL> registered = null;
//        // clear first
//        registered = registry.getRegistered(service);
//
//        for (int i = 0; i < 2; i++) {
//            registry.register(service, serviceUrl);
//            registered = registry.getRegistered(service);
//            assertTrue(registered.contains(serviceUrl));
//        }
//        // confirm only 1 regist success;
//        registered = registry.getRegistered(service);
//        assertEquals(1, registered.size());
//    }


    /**
     * Test method for
     * {@link com.alibaba.dubbo.registry.support.injvm.InjvmRegistry#subscribe(java.util.Map, com.alibaba.dubbo.registry.support.NotifyListener)}
     * .
     */
    @Test
    public void testSubscribe() {
        /*final String subscribearg = "arg1=1&arg2=2";
        // verify lisener.
        final AtomicReference<Map<String, String>> args = new AtomicReference<Map<String, String>>();
        registry.subscribe(service, new URL("dubbo", NetUtils.getLocalHost(), 0, StringUtils.parseQueryString(subscribearg)), new NotifyListener() {


            public void notify(List<URL> urls) {
                // FIXME assertEquals(ZookeeperRegistry.this.service, service);
                args.set(urls.get(0).getParameters());
            }
        });
        assertEquals(serviceUrl.toParameterString(), StringUtils.toQueryString(args.get()));
        Map<String, String> arg = registry.getSubscribed(service);
        assertEquals(subscribearg, StringUtils.toQueryString(arg));*/


    }





}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值