Search in sources :

Example 46 with URL

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"));
    }
}
Also used : Ext2(com.alibaba.dubbo.common.extensionloader.ext2.Ext2) UrlHolder(com.alibaba.dubbo.common.extensionloader.ext2.UrlHolder) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 47 with URL

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"));
    }
}
Also used : Ext2(com.alibaba.dubbo.common.extensionloader.ext2.Ext2) UrlHolder(com.alibaba.dubbo.common.extensionloader.ext2.UrlHolder) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 48 with 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"));
}
Also used : Ext6(com.alibaba.dubbo.common.extensionloader.ext6_inject.Ext6) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 49 with URL

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!"));
    }
}
Also used : JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) SimpleExt(com.alibaba.dubbo.common.extensionloader.ext1.SimpleExt) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 50 with URL

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) {
    }
}
Also used : ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(com.alibaba.dubbo.common.serialize.ObjectInput) IOException(java.io.IOException) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Aggregations

URL (com.alibaba.dubbo.common.URL)283 Test (org.junit.Test)157 ArrayList (java.util.ArrayList)73 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)62 HashMap (java.util.HashMap)39 Result (com.alibaba.dubbo.rpc.Result)37 Map (java.util.Map)36 Invoker (com.alibaba.dubbo.rpc.Invoker)34 List (java.util.List)30 ConcurrentMap (java.util.concurrent.ConcurrentMap)29 RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)28 Invocation (com.alibaba.dubbo.rpc.Invocation)28 RpcException (com.alibaba.dubbo.rpc.RpcException)22 NotifyListener (com.alibaba.dubbo.registry.NotifyListener)20 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)17 RpcResult (com.alibaba.dubbo.rpc.RpcResult)16 DemoService (com.alibaba.dubbo.rpc.support.DemoService)12 Set (java.util.Set)12 ConcurrentHashSet (com.alibaba.dubbo.common.utils.ConcurrentHashSet)11 Protocol (com.alibaba.dubbo.rpc.Protocol)10