ExtensionLoader { protected void readLine(URL url, String line) { String[] aliasAndClassName = parseAliasAndClassName(line); if (aliasAndClassName == null || aliasAndClassName.length != 2) { return; } String alias = aliasAndClassName[0]; String className = aliasAndClassName[1]; Class tmp; try { tmp = ClassUtils.forName(className, false); } catch (Throwable e) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Extension {} of extensible {} is disabled, cause by: {}", className, interfaceName, ExceptionUtils.toShortString(e, 2)); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Extension " + className + " of extensible " + interfaceName + " is disabled.", e); } return; } loadExtension(alias, tmp, StringUtils.toString(url), className); } ExtensionLoader(Class<T> interfaceClass, ExtensionLoaderListener<T> listener); protected  ExtensionLoader(Class<T> interfaceClass); protected  ExtensionLoader(Class<T> interfaceClass, boolean autoLoad, ExtensionLoaderListener<T> listener); ConcurrentMap<String, ExtensionClass<T>> getAllExtensions(); ExtensionClass<T> getExtensionClass(String alias); T getExtension(String alias); T getExtension(String alias, Class[] argTypes, Object[] args); void loadExtension(Class loadedClass); void addListener(ExtensionLoaderListener<T> listener);  }
@Test public void testReadLine() throws Exception { ExtensionLoader loader = new ExtensionLoader<Filter>(Filter.class, false, null); URL url = Filter.class.getResource("/META-INF/sofa-rpc/" + Filter.class.getName()); try { loader.readLine(url, "com.alipay.sofa.rpc.ext.NotFilter"); } catch (Throwable t) { LOGGER.error(t.getMessage()); } Assert.assertTrue(loader.all.isEmpty()); try { loader.readLine(url, null); } catch (Throwable t) { LOGGER.error(t.getMessage()); } Assert.assertTrue(loader.all.isEmpty()); try { loader.readLine(url, " "); } catch (Throwable t) { LOGGER.error(t.getMessage()); } Assert.assertTrue(loader.all.isEmpty()); loader.all.clear(); try { loader.readLine(url, "com.alipay.sofa.rpc.ext.WrongFilter0"); } catch (Throwable t) { LOGGER.error(t.getMessage()); } try { loader.readLine(url, "com.alipay.sofa.rpc.ext.WrongFilter1"); } catch (Throwable t) { LOGGER.error(t.getMessage()); } try { loader.readLine(url, "com.alipay.sofa.rpc.ext.WrongFilter2"); } catch (Throwable t) { LOGGER.error(t.getMessage()); } try { loader.readLine(url, "com.alipay.sofa.rpc.ext.WrongFilter3"); } catch (Throwable t) { LOGGER.error(t.getMessage()); } try { loader.readLine(url, "w3=com.alipay.sofa.rpc.ext.WrongFilter4"); } catch (Throwable t) { LOGGER.error(t.getMessage()); } try { loader.readLine(url, "echo1=com.alipay.sofa.rpc.ext.ExtensionFilter"); } catch (Throwable t) { LOGGER.error(t.getMessage()); } Assert.assertTrue(loader.all.isEmpty()); try { loader.readLine(url, "com.alipay.sofa.rpc.ext.RightFilter0"); } catch (Throwable t) { LOGGER.error(t.getMessage()); } Assert.assertFalse(loader.all.isEmpty()); loader.all.clear(); try { loader.readLine(url, "rightxx0=com.alipay.sofa.rpc.ext.RightFilter0"); } catch (Throwable t) { LOGGER.error(t.getMessage()); } Assert.assertFalse(loader.all.isEmpty()); boolean isOk = true; try { loader.readLine(url, "com.alipay.sofa.rpc.ext.RightFilter0"); } catch (Throwable t) { LOGGER.error(t.getMessage()); isOk = false; } Assert.assertFalse(isOk); Assert.assertFalse(loader.all.isEmpty()); Assert.assertTrue(loader.all.size() == 1); ExtensionLoader loader2 = new ExtensionLoader<Protocol>(Protocol.class, false, null); URL url2 = Filter.class.getResource("/META-INF/sofa-rpc/" + Protocol.class.getName()); try { loader2.readLine(url2, "com.alipay.sofa.rpc.ext.WrongProtocol"); } catch (Throwable t) { LOGGER.error(t.getMessage()); } Assert.assertTrue(loader2.all.isEmpty()); }