Bootstraps { public static <T> ProviderBootstrap<T> from(ProviderConfig<T> providerConfig) { String bootstrap = providerConfig.getBootstrap(); if (StringUtils.isEmpty(bootstrap)) { bootstrap = RpcConfigs.getStringValue(RpcOptions.DEFAULT_PROVIDER_BOOTSTRAP); providerConfig.setBootstrap(bootstrap); } ProviderBootstrap providerBootstrap = ExtensionLoaderFactory.getExtensionLoader(ProviderBootstrap.class) .getExtension(bootstrap, new Class[] { ProviderConfig.class }, new Object[] { providerConfig }); return (ProviderBootstrap<T>) providerBootstrap; }  static ProviderBootstrap<T> from(ProviderConfig<T> providerConfig); static ConsumerBootstrap<T> from(ConsumerConfig<T> consumerConfig);  }
@Test public void from() throws Exception { ProviderConfig providerConfig = new ProviderConfig().setBootstrap("test"); ProviderBootstrap bootstrap = Bootstraps.from(providerConfig); Assert.assertEquals(TestProviderBootstrap.class, bootstrap.getClass()); Assert.assertEquals(providerConfig, bootstrap.getProviderConfig()); providerConfig = new ProviderConfig(); bootstrap = Bootstraps.from(providerConfig); Assert.assertEquals(TestProviderBootstrap.class, bootstrap.getClass()); Assert.assertEquals(providerConfig, bootstrap.getProviderConfig()); }
@Test public void from1() throws Exception { ConsumerConfig consumerConfig = new ConsumerConfig().setProtocol("test") .setBootstrap("test"); ConsumerBootstrap bootstrap = Bootstraps.from(consumerConfig); Assert.assertEquals(TestConsumerBootstrap.class, bootstrap.getClass()); Assert.assertEquals(consumerConfig, bootstrap.getConsumerConfig()); consumerConfig = new ConsumerConfig().setProtocol("test"); bootstrap = Bootstraps.from(consumerConfig); Assert.assertEquals(TestConsumerBootstrap.class, bootstrap.getClass()); Assert.assertEquals(consumerConfig, bootstrap.getConsumerConfig()); consumerConfig = new ConsumerConfig().setProtocol("xx"); bootstrap = Bootstraps.from(consumerConfig); Assert.assertEquals(TestConsumerBootstrap.class, bootstrap.getClass()); Assert.assertEquals(consumerConfig, bootstrap.getConsumerConfig()); }