01: package com.xoetrope.service.test;
02:
03: import net.xoetrope.optional.service.XRouteManager;
04: import net.xoetrope.optional.service.XServiceModelNode;
05: import com.xoetrope.service.XCachingService;
06: import com.xoetrope.service.servlet.XUnreliableServiceServlet;
07: import net.xoetrope.xui.data.XModel;
08: import net.xoetrope.xui.XProjectManager;
09:
10: /**
11: * Test the unreliable service servelt to see that it returns the expected errors
12: * <p>Copyright (c) Xoetrope Ltd. 2001-2004</p>
13: * $Revision: 1.2 $
14: */
15: public class XCachingProxyTest extends XServiceTest {
16: public static final long TTL = 1000;
17: int callbackToken = -1;
18:
19: public XCachingProxyTest() {
20: super ();
21: defaultURLStr = "http://localhost:8080/xunreliableservlet";
22: }
23:
24: public void testServer() {
25: String[] argNames = { "reliability" };
26:
27: XServiceModelNode node = new XServiceModelNode();
28: XModel.getInstance().set("TestPersistenProxyService", node);
29: try {
30: XRouteManager routeMgr = (XRouteManager) XProjectManager
31: .getCurrentProject().getObject("Routes");
32: node.setupService("getName64", routeMgr.getRoute(
33: "cachingRoute",
34: "com.xoetrope.service.test.CalcTestService"),
35: argNames);
36: XCachingService sp = (XCachingService) node
37: .getServiceProxy();
38: sp.setServiceName("TestCachingService");
39: sp.setTTL(-1); // Live forever
40: node.setNumAttributes(1);
41: node.setAttribValue(0, Integer.toString(
42: XUnreliableServiceServlet.RELIABLE).toString());
43: Object result = node.get();
44: assertTrue(result != null);
45:
46: // A second request should get an identical result object instance
47: Object result2 = node.get();
48: assertTrue(result == result2);
49:
50: // A request following a sleep longer than the TTL should fail
51: sp.setTTL(TTL);
52: Thread.currentThread().sleep(TTL);
53: result2 = node.get();
54: assertFalse(result == result2);
55:
56: // Now programatically stop the caching for this method.
57: node.setupService("getNameNoCache", routeMgr.getRoute(
58: "cachingRoute",
59: "com.xoetrope.service.test.CalcTestService"),
60: argNames);
61: sp = (XCachingService) node.getServiceProxy();
62: sp.setServiceName("TestCachingService");
63: sp.setTTL(-1); // Live forever
64: sp.setCachable(false);
65: node.setNumAttributes(1);
66: node.setAttribValue(0, Integer.toString(
67: XUnreliableServiceServlet.RELIABLE).toString());
68: result = node.get();
69: assertTrue(result != null);
70:
71: // A second request should not get an identical result object instance as
72: // the object should NOT be cached
73: result2 = node.get();
74: assertFalse(result == result2);
75: } catch (Exception e) {
76: e.printStackTrace();
77: assertTrue(false);
78: }
79: }
80: }
|