ServerFactory { public synchronized static Server getServer(ServerConfig serverConfig) { try { Server server = SERVER_MAP.get(Integer.toString(serverConfig.getPort())); if (server == null) { resolveServerConfig(serverConfig); ExtensionClass<Server> ext = ExtensionLoaderFactory.getExtensionLoader(Server.class) .getExtensionClass(serverConfig.getProtocol()); if (ext == null) { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_UNSUPPORTED_PROTOCOL, serverConfig.getProtocol())); } server = ext.getExtInstance(); server.init(serverConfig); SERVER_MAP.put(serverConfig.getPort() + "", server); } return server; } catch (SofaRpcRuntimeException e) { throw e; } catch (Throwable e) { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_GET_SERVER), e); } }  synchronized static Server getServer(ServerConfig serverConfig); static List<Server> getServers(); static void destroyAll(); static void destroyServer(ServerConfig serverConfig);  }
@Test public void getServer() { ServerConfig serverConfig = new ServerConfig().setProtocol("test").setPort(1234); Server server = ServerFactory.getServer(serverConfig); Assert.assertNotNull(server); boolean error = false; try { serverConfig = new ServerConfig().setProtocol("test1").setPort(2345); ServerFactory.getServer(serverConfig); } catch (Exception e) { error = true; } Assert.assertTrue(error); Assert.assertTrue(ServerFactory.getServers().size() > 0); ServerFactory.destroyAll(); }