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));*/
}
}
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));*/
}
}