use of com.alipay.sofa.runtime.spi.component.SofaRuntimeManager in project sofa-boot by alipay.
the class HealthCheckerProcessorTest method testComponentHealthCheckerFailedFirst.
@Test
public void testComponentHealthCheckerFailedFirst() {
SofaRuntimeManager manager = new StandardSofaRuntimeManager("testComponentHealthCheckerFailedFirst", Thread.currentThread().getContextClassLoader(), null);
manager.getComponentManager().register(new TestComponent("component1", true));
manager.getComponentManager().register(new TestComponent("component2", true));
manager.getComponentManager().register(new TestComponent("component3", false));
manager.getComponentManager().register(new TestComponent("component4", true));
manager.getComponentManager().register(new TestComponent("component5", false));
ComponentHealthChecker componentHealthChecker = new ComponentHealthChecker(new SofaRuntimeContext(manager, manager.getComponentManager(), null));
int i = 0;
for (Map.Entry<String, Object> entry : componentHealthChecker.isHealthy().getDetails().entrySet()) {
if (i < 2) {
Assert.assertEquals(entry.getValue().toString(), "failed");
} else {
Assert.assertEquals(entry.getValue().toString(), "passed");
}
++i;
}
}
use of com.alipay.sofa.runtime.spi.component.SofaRuntimeManager in project sofa-boot by alipay.
the class SofaRuntimeAutoConfiguration method sofaRuntimeManager.
@Bean
@ConditionalOnMissingBean
public static SofaRuntimeManager sofaRuntimeManager(Environment environment, BindingConverterFactory bindingConverterFactory, BindingAdapterFactory bindingAdapterFactory) {
ClientFactoryInternal clientFactoryInternal = new ClientFactoryImpl();
SofaRuntimeManager sofaRuntimeManager = new StandardSofaRuntimeManager(environment.getProperty("spring.application.name"), Thread.currentThread().getContextClassLoader(), clientFactoryInternal);
sofaRuntimeManager.getComponentManager().registerComponentClient(ReferenceClient.class, new ReferenceClientImpl(sofaRuntimeManager.getSofaRuntimeContext(), bindingConverterFactory, bindingAdapterFactory));
sofaRuntimeManager.getComponentManager().registerComponentClient(ServiceClient.class, new ServiceClientImpl(sofaRuntimeManager.getSofaRuntimeContext(), bindingConverterFactory, bindingAdapterFactory));
SofaFramework.registerSofaRuntimeManager(sofaRuntimeManager);
return sofaRuntimeManager;
}
use of com.alipay.sofa.runtime.spi.component.SofaRuntimeManager in project sofa-boot by alipay.
the class BeanPostProcessorOrderTest method getApplicationShutdownAwares.
@SuppressWarnings("unchecked")
private List<RuntimeShutdownAware> getApplicationShutdownAwares() throws Exception {
SofaRuntimeManager sofaRuntimeManager = sofaRuntimeContext.getSofaRuntimeManager();
Field applicationShutdownAwaresField = sofaRuntimeManager.getClass().getDeclaredField("runtimeShutdownAwares");
applicationShutdownAwaresField.setAccessible(true);
return (List<RuntimeShutdownAware>) applicationShutdownAwaresField.get(sofaRuntimeManager);
}
use of com.alipay.sofa.runtime.spi.component.SofaRuntimeManager in project sofa-boot by alipay.
the class SofaFrameworkInitializer method addSofaRuntimeManager.
private static void addSofaRuntimeManager(String appName, ConfigurableApplicationContext applicationContext) {
if (!SofaFrameworkHolder.containsSofaFramework()) {
SofaFrameworkHolder.setSofaFramework(new SofaFrameworkImpl());
}
SofaFrameworkImpl sofaFramework = (SofaFrameworkImpl) SofaFrameworkHolder.getSofaFramework();
AppConfiguration applicationConfiguration = createAppConfigurationImpl(applicationContext);
ClientFactoryInternal clientFactoryInternal = new ClientFactoryImpl();
SofaRuntimeManager sofaRuntimeManager = new StandardSofaRuntimeManager(appName, SofaFrameworkInitializer.class.getClassLoader(), applicationConfiguration, clientFactoryInternal);
ComponentManager componentManager = sofaRuntimeManager.getComponentManager();
// register service client & reference client
componentManager.registerComponentClient(ServiceClient.class, new ServiceClientImpl(sofaRuntimeManager.getSofaRuntimeContext()));
componentManager.registerComponentClient(ReferenceClient.class, new ReferenceClientImpl(sofaRuntimeManager.getSofaRuntimeContext()));
sofaFramework.registerSofaRuntimeManager(sofaRuntimeManager);
}
use of com.alipay.sofa.runtime.spi.component.SofaRuntimeManager in project sofa-boot by alipay.
the class SofaEventHandlerTest method testDynamicProxyFinder.
@Test
public void testDynamicProxyFinder() throws Exception {
SofaFramework.registerSofaRuntimeManager(sofaRuntimeManager);
new MockUp<DynamicJvmServiceProxyFinder>() {
@Mock
public Biz getBiz(SofaRuntimeManager sofaRuntimeManager) {
return biz;
}
};
new Expectations() {
{
biz.getIdentity();
result = "MockName:MockVersion";
biz.getBizState();
result = BizState.ACTIVATED;
sofaRuntimeManager.getAppClassLoader();
result = ctx.getClassLoader().getParent();
}
};
new Expectations() {
{
sofaRuntimeManager.getComponentManager();
result = ((SofaRuntimeContext) ctx.getBean("sofaRuntimeContext")).getComponentManager();
contract.getInterfaceType();
result = SampleService.class;
contract.getUniqueId();
result = "";
contract.getBinding(JvmBinding.JVM_BINDING_TYPE);
result = new JvmBinding();
invocation.getArguments();
result = new Object[] {};
invocation.getMethod();
result = SampleService.class.getMethod("service");
}
};
DynamicJvmServiceProxyFinder.getDynamicJvmServiceProxyFinder().setHasFinishStartup(true);
ServiceProxy serviceProxy = DynamicJvmServiceProxyFinder.getDynamicJvmServiceProxyFinder().findServiceProxy(ctx.getClassLoader(), contract);
try {
Assert.assertTrue(SofaEventHandlerTest.class.getName().equals(serviceProxy.invoke(invocation)));
} catch (Throwable throwable) {
throw new RuntimeException("testDynamicProxyFinder case failed.", throwable);
}
}
Aggregations