use of org.apache.dubbo.common.URLBuilder in project dubbo by alibaba.
the class DubboMonitorTest method testSum.
@Test
public void testSum() {
URL statistics = new URLBuilder(DUBBO_PROTOCOL, "10.20.153.11", 0).addParameter(MonitorService.APPLICATION, "morgan").addParameter(MonitorService.INTERFACE, "MemberService").addParameter(MonitorService.METHOD, "findPerson").addParameter(MonitorService.CONSUMER, "10.20.153.11").addParameter(MonitorService.SUCCESS, 1).addParameter(MonitorService.FAILURE, 0).addParameter(MonitorService.ELAPSED, 3).addParameter(MonitorService.MAX_ELAPSED, 3).addParameter(MonitorService.CONCURRENT, 1).addParameter(MonitorService.MAX_CONCURRENT, 1).build();
Invoker invoker = mock(Invoker.class);
MonitorService monitorService = mock(MonitorService.class);
given(invoker.getUrl()).willReturn(URL.valueOf("dubbo://127.0.0.1:7070?interval=20"));
DubboMonitor dubboMonitor = new DubboMonitor(invoker, monitorService);
dubboMonitor.collect(statistics);
dubboMonitor.collect(statistics.addParameter(MonitorService.SUCCESS, 3).addParameter(MonitorService.CONCURRENT, 2).addParameter(MonitorService.INPUT, 1).addParameter(MonitorService.OUTPUT, 2));
dubboMonitor.collect(statistics.addParameter(MonitorService.SUCCESS, 6).addParameter(MonitorService.ELAPSED, 2));
dubboMonitor.send();
ArgumentCaptor<URL> summaryCaptor = ArgumentCaptor.forClass(URL.class);
verify(monitorService, atLeastOnce()).collect(summaryCaptor.capture());
List<URL> allValues = summaryCaptor.getAllValues();
assertThat(allValues, not(nullValue()));
assertThat(allValues, hasItem(new CustomMatcher<URL>("Monitor count should greater than 1") {
@Override
public boolean matches(Object item) {
URL url = (URL) item;
return Integer.valueOf(url.getParameter(MonitorService.SUCCESS)) > 1;
}
}));
}
use of org.apache.dubbo.common.URLBuilder in project dubbo by alibaba.
the class StatisticsTest method testEquals.
@Test
public void testEquals() {
URL statistics = new URLBuilder(DUBBO_PROTOCOL, "10.20.153.10", 0).addParameter(MonitorService.APPLICATION, "morgan").addParameter(MonitorService.INTERFACE, "MemberService").addParameter(MonitorService.METHOD, "findPerson").addParameter(MonitorService.CONSUMER, "10.20.153.11").addParameter(MonitorService.SUCCESS, 1).addParameter(MonitorService.FAILURE, 0).addParameter(MonitorService.ELAPSED, 3).addParameter(MonitorService.MAX_ELAPSED, 3).addParameter(MonitorService.CONCURRENT, 1).addParameter(MonitorService.MAX_CONCURRENT, 1).build();
Statistics statistics1 = new Statistics(statistics);
Statistics statistics2 = new Statistics(statistics);
MatcherAssert.assertThat(statistics1, equalTo(statistics1));
MatcherAssert.assertThat(statistics1, equalTo(statistics2));
statistics1.setVersion("2");
MatcherAssert.assertThat(statistics1, not(equalTo(statistics2)));
MatcherAssert.assertThat(statistics1.hashCode(), not(equalTo(statistics2.hashCode())));
statistics1.setMethod("anotherMethod");
MatcherAssert.assertThat(statistics1, not(equalTo(statistics2)));
MatcherAssert.assertThat(statistics1.hashCode(), not(equalTo(statistics2.hashCode())));
statistics1.setClient("anotherClient");
MatcherAssert.assertThat(statistics1, not(equalTo(statistics2)));
MatcherAssert.assertThat(statistics1.hashCode(), not(equalTo(statistics2.hashCode())));
}
use of org.apache.dubbo.common.URLBuilder in project dubbo by alibaba.
the class StandardMetadataServiceURLBuilder method build.
/**
* Build the {@link URL urls} from {@link ServiceInstance#getMetadata() the metadata} of {@link ServiceInstance}
*
* @param serviceInstance {@link ServiceInstance}
* @return the not-null {@link List}
*/
@Override
public List<URL> build(ServiceInstance serviceInstance) {
Map<String, Map<String, String>> paramsMap = getMetadataServiceURLsParams(serviceInstance);
List<URL> urls = new ArrayList<>(paramsMap.size());
String serviceName = serviceInstance.getServiceName();
String host = serviceInstance.getHost();
for (Map.Entry<String, Map<String, String>> entry : paramsMap.entrySet()) {
String protocol = entry.getKey();
Map<String, String> params = entry.getValue();
int port = Integer.parseInt(params.get(PORT_KEY));
URLBuilder urlBuilder = new URLBuilder().setHost(host).setPort(port).setProtocol(protocol).setPath(MetadataService.class.getName()).addParameter(TIMEOUT_KEY, ConfigurationUtils.get(METADATA_PROXY_TIMEOUT_KEY, DEFAULT_METADATA_TIMEOUT_VALUE)).addParameter(SIDE_KEY, CONSUMER);
// add parameters
params.forEach((name, value) -> urlBuilder.addParameter(name, valueOf(value)));
// add the default parameters
urlBuilder.addParameter(GROUP_KEY, serviceName);
urls.add(urlBuilder.build());
}
return urls;
}
use of org.apache.dubbo.common.URLBuilder in project dubbo by alibaba.
the class ClusterUtilsTest method testMergeUrl.
@Test
public void testMergeUrl() throws Exception {
URL providerURL = URL.valueOf("dubbo://localhost:55555");
providerURL = providerURL.setPath("path").setUsername("username").setPassword("password");
providerURL = URLBuilder.from(providerURL).addParameter(GROUP_KEY, "dubbo").addParameter(VERSION_KEY, "1.2.3").addParameter(DUBBO_VERSION_KEY, "2.3.7").addParameter(THREADPOOL_KEY, "fixed").addParameter(THREADS_KEY, Integer.MAX_VALUE).addParameter(THREAD_NAME_KEY, "test").addParameter(CORE_THREADS_KEY, Integer.MAX_VALUE).addParameter(QUEUES_KEY, Integer.MAX_VALUE).addParameter(ALIVE_KEY, Integer.MAX_VALUE).addParameter(DEFAULT_KEY_PREFIX + THREADS_KEY, Integer.MAX_VALUE).addParameter(DEFAULT_KEY_PREFIX + THREADPOOL_KEY, "fixed").addParameter(DEFAULT_KEY_PREFIX + CORE_THREADS_KEY, Integer.MAX_VALUE).addParameter(DEFAULT_KEY_PREFIX + QUEUES_KEY, Integer.MAX_VALUE).addParameter(DEFAULT_KEY_PREFIX + ALIVE_KEY, Integer.MAX_VALUE).addParameter(DEFAULT_KEY_PREFIX + THREAD_NAME_KEY, "test").addParameter(APPLICATION_KEY, "provider").addParameter(REFERENCE_FILTER_KEY, "filter1,filter2").addParameter(TAG_KEY, "TTT").build();
URL consumerURL = new URLBuilder(DUBBO_PROTOCOL, "localhost", 55555).addParameter(PID_KEY, "1234").addParameter(THREADPOOL_KEY, "foo").addParameter(APPLICATION_KEY, "consumer").addParameter(REFERENCE_FILTER_KEY, "filter3").addParameter(TAG_KEY, "UUU").build();
URL url = ClusterUtils.mergeUrl(providerURL, consumerURL.getParameters());
Assertions.assertFalse(url.hasParameter(THREADS_KEY));
Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + THREADS_KEY));
Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + THREADPOOL_KEY));
Assertions.assertFalse(url.hasParameter(CORE_THREADS_KEY));
Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + CORE_THREADS_KEY));
Assertions.assertFalse(url.hasParameter(QUEUES_KEY));
Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + QUEUES_KEY));
Assertions.assertFalse(url.hasParameter(ALIVE_KEY));
Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + ALIVE_KEY));
Assertions.assertFalse(url.hasParameter(THREAD_NAME_KEY));
Assertions.assertFalse(url.hasParameter(DEFAULT_KEY_PREFIX + THREAD_NAME_KEY));
Assertions.assertEquals(url.getPath(), "path");
Assertions.assertEquals(url.getUsername(), "username");
Assertions.assertEquals(url.getPassword(), "password");
Assertions.assertEquals(url.getParameter(PID_KEY), "1234");
Assertions.assertEquals(url.getParameter(THREADPOOL_KEY), "foo");
Assertions.assertEquals(url.getParameter(APPLICATION_KEY), "consumer");
Assertions.assertEquals(url.getParameter(REMOTE_APPLICATION_KEY), "provider");
Assertions.assertEquals(url.getParameter(REFERENCE_FILTER_KEY), "filter1,filter2,filter3");
Assertions.assertEquals(url.getParameter(TAG_KEY), "TTT");
}
use of org.apache.dubbo.common.URLBuilder in project dubbo by alibaba.
the class WebserviceProtocolTest method testWebserviceJetty.
@Test
public void testWebserviceJetty() throws LifecycleException {
Tomcat tomcat = buildTomcat("/dubbo-webservice", "/services/*", 55065);
DemoService service = new DemoServiceImpl();
int port = NetUtils.getAvailablePort();
URLBuilder builder = new URLBuilder().setProtocol("webservice").setHost("127.0.0.1").setPort(port).setPath("dubbo-webservice3/" + DemoService.class.getName()).addParameter("server", "jetty").addParameter("bind.port", port).addParameter("contextpath", "dubbo-webservice2").addParameter("codec", "exchange").addParameter("timeout", 3000);
URL url = builder.build();
tomcat.start();
Exporter<DemoService> exporter = protocol.export(proxy.getInvoker(service, DemoService.class, url));
service = proxy.getProxy(protocol.refer(DemoService.class, url));
assertEquals(service.getSize(new String[] { "", "", "" }), 3);
exporter.unexport();
tomcat.stop();
tomcat.destroy();
}
Aggregations