01: package junit;
02:
03: import java.rmi.registry.LocateRegistry;
04: import java.util.*;
05: import javax.cache.Cache;
06: import javax.cache.CacheException;
07:
08: import ri.cache.BasicCache;
09: import ri.cache.transport.*;
10: import org.junit.Before;
11: import org.junit.After;
12: import org.junit.Test;
13:
14: /**
15: * RmiPullTestCase -- test case for a parent-child cache, where one cache pulls from another, over the
16: * RMI transport
17: *
18: * @author Brian Goetz
19: */
20: public class RmiPullTestCase extends ParentChildCacheTestCase {
21:
22: protected TransportListenerAdapter parentTransportListener;
23:
24: protected TransportEndpointFactory getTransportFactory() {
25: return RmiTransportFactory.getFactory();
26: }
27:
28: protected Map getNameMap() {
29: Map nameMap = new HashMap();
30: nameMap.put(RmiTransportFactory.ENTITY_NAME, "a");
31: return nameMap;
32: }
33:
34: @Before
35: public void setUp() throws Exception {
36: LocateRegistry.createRegistry(1099);
37: super .setUp();
38: }
39:
40: @After
41: public void tearDown() throws Exception {
42: getTransportFactory().unregisterListener(getNameMap(),
43: parentTransportListener);
44: super .tearDown();
45: }
46:
47: protected Cache createParentCache() throws TransportException {
48: Cache c = new BasicCache("TestCache", new IdentityLoader());
49: parentTransportListener = new ReadOnlyTransportListenerAdapter(
50: c);
51: getTransportFactory().registerListener(getNameMap(),
52: parentTransportListener);
53: return c;
54: }
55:
56: protected Cache createChildCache() throws TransportException {
57: return new BasicCache("TestCache", new RemoteCacheLoader(
58: getTransportFactory().getEndpoint(getNameMap())));
59: }
60:
61: @Test
62: public void rmiPullTest() throws CacheException {
63: doTest1();
64: }
65: }
|