use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class ExtensionLoader_Adaptive_Test method test_urlHolder_getAdaptiveExtension_noExtension.
@Test
public void test_urlHolder_getAdaptiveExtension_noExtension() throws Exception {
Ext2 ext = ExtensionLoader.getExtensionLoader(Ext2.class).getAdaptiveExtension();
URL url = new URL("p1", "1.2.3.4", 1010, "path1");
UrlHolder holder = new UrlHolder();
holder.setUrl(url);
try {
ext.echo(holder, "haha");
fail();
} catch (IllegalStateException expected) {
assertThat(expected.getMessage(), containsString("Fail to get extension("));
}
url = url.addParameter("ext2", "XXX");
holder.setUrl(url);
try {
ext.echo(holder, "haha");
fail();
} catch (IllegalStateException expected) {
assertThat(expected.getMessage(), containsString("No such extension"));
}
}
use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class ExtensionLoader_Adaptive_Test method test_urlHolder_getAdaptiveExtension_ExceptionWhenNameNotProvided.
@Test
public void test_urlHolder_getAdaptiveExtension_ExceptionWhenNameNotProvided() throws Exception {
Ext2 ext = ExtensionLoader.getExtensionLoader(Ext2.class).getAdaptiveExtension();
URL url = new URL("p1", "1.2.3.4", 1010, "path1");
UrlHolder holder = new UrlHolder();
holder.setUrl(url);
try {
ext.echo(holder, "impl1");
fail();
} catch (IllegalStateException expected) {
assertThat(expected.getMessage(), containsString("Fail to get extension("));
}
url = url.addParameter("key1", "impl1");
holder.setUrl(url);
try {
ext.echo(holder, "haha");
fail();
} catch (IllegalStateException expected) {
assertThat(expected.getMessage(), containsString("Fail to get extension(com.alibaba.dubbo.common.extensionloader.ext2.Ext2) name from url"));
}
}
use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class ExtensionLoader_Adaptive_Test method test_getAdaptiveExtension_inject.
@Test
public void test_getAdaptiveExtension_inject() throws Exception {
LogUtil.start();
Ext6 ext = ExtensionLoader.getExtensionLoader(Ext6.class).getAdaptiveExtension();
URL url = new URL("p1", "1.2.3.4", 1010, "path1");
url = url.addParameters("ext6", "impl1");
assertEquals("Ext6Impl1-echo-Ext1Impl1-echo", ext.echo(url, "ha"));
Assert.assertTrue("can not find error.", LogUtil.checkNoError());
LogUtil.stop();
url = url.addParameters("simple.ext", "impl2");
assertEquals("Ext6Impl1-echo-Ext1Impl2-echo", ext.echo(url, "ha"));
}
use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class ExtensionLoader_Adaptive_Test method test_getAdaptiveExtension_ExceptionWhenNotAdaptiveMethod.
@Test
public void test_getAdaptiveExtension_ExceptionWhenNotAdaptiveMethod() throws Exception {
SimpleExt ext = ExtensionLoader.getExtensionLoader(SimpleExt.class).getAdaptiveExtension();
Map<String, String> map = new HashMap<String, String>();
URL url = new URL("p1", "1.2.3.4", 1010, "path1", map);
try {
ext.bang(url, 33);
fail();
} catch (UnsupportedOperationException expected) {
assertThat(expected.getMessage(), containsString("method "));
assertThat(expected.getMessage(), containsString("of interface com.alibaba.dubbo.common.extensionloader.ext1.SimpleExt is not adaptive method!"));
}
}
use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.
the class AbstractSerializationTest method test_URL_mutable_withType.
// ================ final field test ================
@Test
public void test_URL_mutable_withType() throws Exception {
URL data = URL.valueOf("dubbo://admin:hello1234@10.20.130.230:20880/context/path?version=1.0.0&application=morgan&noValue");
ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
objectOutput.writeObject(data);
objectOutput.flushBuffer();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
URL actual = (URL) deserialize.readObject(URL.class);
assertEquals(data, actual);
assertEquals(data.getParameters(), actual.getParameters());
try {
deserialize.readObject();
fail();
} catch (IOException expected) {
}
}
Aggregations