1 package org.apache.commons.jcs.auxiliary.remote.server;
2
3 import java.rmi.server.RMISocketFactory;
4 import java.util.Properties;
5
6 import org.apache.commons.jcs.auxiliary.remote.behavior.ICommonRemoteCacheAttributes;
7 import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheConstants;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 import junit.framework.TestCase;
29
30
31 public class RemoteCacheServerFactoryUnitTest
32 extends TestCase
33 {
34
35 public void testConfigureRemoteCacheServerAttributes_eventQueuePoolName()
36 {
37
38 String eventQueuePoolName = "specialName";
39 Properties props = new Properties();
40 props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".EventQueuePoolName", eventQueuePoolName );
41
42
43 RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props );
44
45
46 assertEquals( "Wrong eventQueuePoolName", eventQueuePoolName, result.getEventQueuePoolName() );
47 }
48
49
50 public void testConfigureRemoteCacheServerAttributes_timeoutPresent()
51 {
52
53 int timeout = 123245;
54 Properties props = new Properties();
55 props.put( IRemoteCacheConstants.SOCKET_TIMEOUT_MILLIS, String.valueOf( timeout ) );
56
57
58 RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props );
59
60
61 assertEquals( "Wrong timeout", timeout, result.getRmiSocketFactoryTimeoutMillis() );
62 }
63
64
65 public void testConfigureRemoteCacheServerAttributes_timeoutNotPresent()
66 {
67
68 Properties props = new Properties();
69
70
71 RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props );
72
73
74 assertEquals( "Wrong timeout", ICommonRemoteCacheAttributes.DEFAULT_RMI_SOCKET_FACTORY_TIMEOUT_MILLIS, result.getRmiSocketFactoryTimeoutMillis() );
75 }
76
77
78 public void testConfigureRemoteCacheServerAttributes_registryKeepAliveDelayMillisPresent()
79 {
80
81 int registryKeepAliveDelayMillis = 123245;
82 Properties props = new Properties();
83 props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".registryKeepAliveDelayMillis", String.valueOf( registryKeepAliveDelayMillis ) );
84
85
86 RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props );
87
88
89 assertEquals( "Wrong registryKeepAliveDelayMillis", registryKeepAliveDelayMillis, result.getRegistryKeepAliveDelayMillis() );
90 }
91
92
93 public void testConfigureRemoteCacheServerAttributes_useRegistryKeepAlivePresent()
94 {
95
96 boolean useRegistryKeepAlive = false;
97 Properties props = new Properties();
98 props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".useRegistryKeepAlive", String.valueOf( useRegistryKeepAlive ) );
99
100
101 RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props );
102
103
104 assertEquals( "Wrong useRegistryKeepAlive", useRegistryKeepAlive, result.isUseRegistryKeepAlive() );
105 }
106
107
108 public void testConfigureRemoteCacheServerAttributes_rmiSocketFactoryTimeoutMillisPresent()
109 {
110
111 int rmiSocketFactoryTimeoutMillis = 123245;
112 Properties props = new Properties();
113 props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".rmiSocketFactoryTimeoutMillis", String.valueOf( rmiSocketFactoryTimeoutMillis ) );
114
115
116 RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props );
117
118
119 assertEquals( "Wrong rmiSocketFactoryTimeoutMillis", rmiSocketFactoryTimeoutMillis, result.getRmiSocketFactoryTimeoutMillis() );
120 }
121
122
123 public void testConfigureRemoteCacheServerAttributes_allowClusterGetPresent()
124 {
125
126 boolean allowClusterGet = false;
127 Properties props = new Properties();
128 props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".allowClusterGet", String.valueOf( allowClusterGet ) );
129
130
131 RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props );
132
133
134 assertEquals( "Wrong allowClusterGet", allowClusterGet, result.isAllowClusterGet() );
135 }
136
137
138 public void testConfigureRemoteCacheServerAttributes_localClusterConsistencyPresent()
139 {
140
141 boolean localClusterConsistency = false;
142 Properties props = new Properties();
143 props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".localClusterConsistency", String.valueOf( localClusterConsistency ) );
144
145
146 RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props );
147
148
149 assertEquals( "Wrong localClusterConsistency", localClusterConsistency, result.isLocalClusterConsistency() );
150 }
151
152
153 public void testConfigureObjectSpecificCustomFactory_withProperty()
154 {
155
156 String testValue = "123245";
157 Properties props = new Properties();
158 props.put( IRemoteCacheConstants.CUSTOM_RMI_SOCKET_FACTORY_PROPERTY_PREFIX, MockRMISocketFactory.class.getName() );
159 props.put( IRemoteCacheConstants.CUSTOM_RMI_SOCKET_FACTORY_PROPERTY_PREFIX + ".testStringProperty", testValue );
160
161
162 RMISocketFactory result = RemoteCacheServerFactory.configureObjectSpecificCustomFactory( props );
163
164
165 assertNotNull( "Should have a custom socket factory.", result );
166 assertEquals( "Wrong testValue", testValue, ((MockRMISocketFactory)result).getTestStringProperty() );
167 }
168
169
170 public void testConfigureObjectSpecificCustomFactory_withProperty_TimeoutConfigurableRMIScoketFactory()
171 {
172
173 int readTimeout = 1234;
174 int openTimeout = 1234;
175 Properties props = new Properties();
176 props.put( IRemoteCacheConstants.CUSTOM_RMI_SOCKET_FACTORY_PROPERTY_PREFIX, TimeoutConfigurableRMISocketFactory.class.getName() );
177 props.put( IRemoteCacheConstants.CUSTOM_RMI_SOCKET_FACTORY_PROPERTY_PREFIX + ".readTimeout", String.valueOf( readTimeout ) );
178 props.put( IRemoteCacheConstants.CUSTOM_RMI_SOCKET_FACTORY_PROPERTY_PREFIX + ".openTimeout", String.valueOf( openTimeout ) );
179
180
181 RMISocketFactory result = RemoteCacheServerFactory.configureObjectSpecificCustomFactory( props );
182
183
184 assertNotNull( "Should have a custom socket factory.", result );
185 assertEquals( "Wrong readTimeout", readTimeout, ((TimeoutConfigurableRMISocketFactory)result).getReadTimeout() );
186 assertEquals( "Wrong readTimeout", openTimeout, ((TimeoutConfigurableRMISocketFactory)result).getOpenTimeout() );
187 }
188 }