use of jp.ossc.nimbus.service.aop.DefaultInterceptorChain in project nimbus by nimbus-org.
the class MethodMappingInterceptorServiceTest method test4.
public void test4() throws Throwable {
ServiceManagerFactory.registerManager("Test");
ServiceMetaData serviceData = new ServiceMetaData();
serviceData.setCode(MethodMappingInterceptorService.class.getName());
serviceData.setName("MethodMappingInterceptor");
AttributeMetaData attr = new AttributeMetaData(serviceData);
attr.setName("TargetMethodReturnMapping");
attr.setValue("java.util.HashMap#get(java.lang.Object)=A\n" + "java.util.HashMap#put(java.lang.Object, java.lang.Object)=B");
serviceData.addAttribute(attr);
attr = new AttributeMetaData(serviceData);
attr.setName("ContextServiceName");
attr.setValue("#Context");
serviceData.addAttribute(attr);
ServiceManagerFactory.registerService("Test", serviceData);
Interceptor interceptor1 = (Interceptor) ServiceManagerFactory.getServiceObject("Test", "MethodMappingInterceptor");
Context context = new DefaultContextService();
ServiceManagerFactory.registerService("Test", "Context", context);
try {
ServiceManagerFactory.findManager("Test").createAllService();
ServiceManagerFactory.findManager("Test").startAllService();
context.put("A", new Integer(100));
context.put("B", new Integer(200));
assertEquals(new Integer(100), new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("get", new Class[] { Object.class }), null)));
assertEquals(new Integer(200), new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("put", new Class[] { Object.class, Object.class }), null)));
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.DefaultInterceptorChain in project nimbus by nimbus-org.
the class MethodMappingInterceptorServiceTest method test1.
public void test1() throws Throwable {
ServiceManagerFactory.registerManager("Test");
ServiceMetaData serviceData = new ServiceMetaData();
serviceData.setCode(MethodMappingInterceptorService.class.getName());
serviceData.setName("MethodMappingInterceptor");
AttributeMetaData attr = new AttributeMetaData(serviceData);
attr.setName("TargetMethodMapping");
attr.setValue("java.util.HashMap#get(java.lang.Object)=#Interceptor2\n" + "java.util.HashMap#put(java.lang.Object, java.lang.Object)=#Interceptor3");
serviceData.addAttribute(attr);
ServiceManagerFactory.registerService("Test", serviceData);
Interceptor interceptor1 = (Interceptor) ServiceManagerFactory.getServiceObject("Test", "MethodMappingInterceptor");
Interceptor interceptor2 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
return this;
}
};
ServiceManagerFactory.registerService("Test", "Interceptor2", interceptor2);
Interceptor interceptor3 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
return this;
}
};
ServiceManagerFactory.registerService("Test", "Interceptor3", interceptor3);
try {
ServiceManagerFactory.findManager("Test").createAllService();
ServiceManagerFactory.findManager("Test").startAllService();
assertEquals(interceptor2, new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("get", new Class[] { Object.class }), null)));
assertEquals(interceptor3, new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1 }), null).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("put", new Class[] { Object.class, Object.class }), null)));
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.DefaultInterceptorChain in project nimbus by nimbus-org.
the class MethodMetricsInterceptorServiceTest method test2.
public void test2() throws Throwable {
ServiceManagerFactory.registerManager("Test");
MethodMetricsInterceptorService interceptor = new MethodMetricsInterceptorService();
ServiceManagerFactory.registerService("Test", "MethodMetricsInterceptor", interceptor);
try {
ServiceManagerFactory.findManager("Test").createAllService();
ServiceManagerFactory.findManager("Test").startAllService();
try {
new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {
public Object invoke(InvocationContext context) throws Throwable {
Thread.sleep(new Random().nextInt(400) + 100);
throw new IllegalArgumentException();
}
}).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("get", new Class[] { Object.class }), null));
fail();
} catch (IllegalArgumentException e) {
}
MetricsInfo info = interceptor.getMetricsInfo(HashMap.class.getMethod("get", new Class[] { Object.class }));
assertNotNull(info);
assertEquals("java.util.HashMap#get(java.lang.Object)", info.getKey());
assertEquals(1L, info.getTotalCount());
assertEquals(0L, info.getCount());
assertTrue(info.getLastTime() > 0);
assertEquals(1L, info.getExceptionCount());
assertTrue(info.getLastExceptionTime() > 0);
assertEquals(0L, info.getErrorCount());
assertEquals(0L, info.getLastErrorTime());
assertTrue(info.getBestPerformance() > 0);
assertTrue(info.getBestPerformanceTime() > 0);
assertTrue(info.getWorstPerformance() > 0);
assertTrue(info.getWorstPerformanceTime() > 0);
assertTrue(info.getAveragePerformance() > 0);
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.DefaultInterceptorChain in project nimbus by nimbus-org.
the class MethodMetricsInterceptorServiceTest method test1.
public void test1() throws Throwable {
ServiceManagerFactory.registerManager("Test");
MethodMetricsInterceptorService interceptor = new MethodMetricsInterceptorService();
ServiceManagerFactory.registerService("Test", "MethodMetricsInterceptor", interceptor);
try {
ServiceManagerFactory.findManager("Test").createAllService();
ServiceManagerFactory.findManager("Test").startAllService();
assertEquals("test", new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {
public Object invoke(InvocationContext context) throws Throwable {
Thread.sleep(new Random().nextInt(400) + 100);
return "test";
}
}).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("get", new Class[] { Object.class }), null)));
MetricsInfo info = interceptor.getMetricsInfo(HashMap.class.getMethod("get", new Class[] { Object.class }));
assertNotNull(info);
assertEquals("java.util.HashMap#get(java.lang.Object)", info.getKey());
assertEquals(1L, info.getTotalCount());
assertEquals(1L, info.getCount());
assertTrue(info.getLastTime() > 0);
assertEquals(0L, info.getExceptionCount());
assertEquals(0L, info.getLastExceptionTime());
assertEquals(0L, info.getErrorCount());
assertEquals(0L, info.getLastErrorTime());
assertTrue(info.getBestPerformance() > 0);
assertTrue(info.getBestPerformanceTime() > 0);
assertTrue(info.getWorstPerformance() > 0);
assertTrue(info.getWorstPerformanceTime() > 0);
assertTrue(info.getAveragePerformance() > 0);
interceptor.reset();
info = interceptor.getMetricsInfo(HashMap.class.getMethod("get", new Class[] { Object.class }));
assertNull(info);
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.DefaultInterceptorChain in project nimbus by nimbus-org.
the class MethodMetricsInterceptorServiceTest method test4.
public void test4() throws Throwable {
ServiceManagerFactory.registerManager("Test");
MethodMetricsInterceptorService interceptor = new MethodMetricsInterceptorService();
ServiceManagerFactory.registerService("Test", "MethodMetricsInterceptor", interceptor);
try {
ServiceManagerFactory.findManager("Test").createAllService();
interceptor.setCalculateOnlyNormal(true);
ServiceManagerFactory.findManager("Test").startAllService();
try {
new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor }), new Invoker() {
public Object invoke(InvocationContext context) throws Throwable {
Thread.sleep(new Random().nextInt(400) + 100);
throw new IllegalArgumentException();
}
}).invokeNext(new DefaultMethodInvocationContext(null, HashMap.class.getMethod("get", new Class[] { Object.class }), null));
fail();
} catch (IllegalArgumentException e) {
}
MetricsInfo info = interceptor.getMetricsInfo(HashMap.class.getMethod("get", new Class[] { Object.class }));
assertNotNull(info);
assertEquals("java.util.HashMap#get(java.lang.Object)", info.getKey());
assertEquals(1L, info.getTotalCount());
assertEquals(0L, info.getCount());
assertTrue(info.getLastTime() > 0);
assertEquals(1L, info.getExceptionCount());
assertTrue(info.getLastExceptionTime() > 0);
assertEquals(0L, info.getErrorCount());
assertEquals(0L, info.getLastErrorTime());
assertEquals(Long.MAX_VALUE, info.getBestPerformance());
assertEquals(0L, info.getBestPerformanceTime());
assertEquals(Long.MIN_VALUE, info.getWorstPerformance());
assertEquals(0L, info.getWorstPerformanceTime());
assertEquals(0L, info.getAveragePerformance());
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
Aggregations