01: // Copyright 2004, 2005 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package hivemind.test.services;
16:
17: import hivemind.test.FrameworkTestCase;
18:
19: import org.apache.hivemind.HiveMind;
20: import org.apache.hivemind.Registry;
21: import org.apache.hivemind.service.ThreadEventNotifier;
22:
23: /**
24: * Tests {@link org.apache.hivemind.impl.PooledServiceModel}.
25: *
26: * @author Howard Lewis Ship
27: */
28: public class TestPooledServiceModel extends FrameworkTestCase {
29:
30: /**
31: * Tests basic interaction of pooling with thread cleanup.
32: */
33: public void testManaged() throws Exception {
34: Registry r = buildFrameworkRegistry("Pooled.xml");
35:
36: StringHolder s = (StringHolder) r.getService(
37: "hivemind.test.services.Managed", StringHolder.class);
38:
39: interceptLogging("hivemind.test.services.Managed");
40:
41: assertNull(s.getValue());
42:
43: assertLoggedMessage("activateService()");
44:
45: s.setValue("funky monkey");
46: assertEquals("funky monkey", s.getValue());
47:
48: ThreadEventNotifier n = (ThreadEventNotifier) r.getService(
49: HiveMind.THREAD_EVENT_NOTIFIER_SERVICE,
50: ThreadEventNotifier.class);
51:
52: n.fireThreadCleanup();
53:
54: assertLoggedMessage("passivateService()");
55:
56: assertNull(s.getValue());
57: }
58:
59: public void testUnmanaged() throws Exception {
60: Registry r = buildFrameworkRegistry("Pooled.xml");
61:
62: StringHolder s = (StringHolder) r.getService(
63: "hivemind.test.services.Unmanaged", StringHolder.class);
64:
65: assertNull(s.getValue());
66:
67: s.setValue("funky monkey");
68: assertEquals("funky monkey", s.getValue());
69:
70: ThreadEventNotifier n = (ThreadEventNotifier) r.getService(
71: HiveMind.THREAD_EVENT_NOTIFIER_SERVICE,
72: ThreadEventNotifier.class);
73:
74: n.fireThreadCleanup();
75:
76: assertEquals("funky monkey", s.getValue());
77: }
78: }
|