1 package org.apache.commons.jcs3.auxiliary.remote.server;
2
3 import java.rmi.server.RMISocketFactory;
4 import java.util.Properties;
5
6 import org.apache.commons.jcs3.auxiliary.remote.behavior.ICommonRemoteCacheAttributes;
7 import org.apache.commons.jcs3.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 final String eventQueuePoolName = "specialName";
39 final Properties props = new Properties();
40 props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".EventQueuePoolName", eventQueuePoolName );
41
42
43 final RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props );
44
45
46 assertEquals( "Wrong eventQueuePoolName", eventQueuePoolName, result.getEventQueuePoolName() );
47 }
48
49
50 public void testConfigureRemoteCacheServerAttributes_timeoutNotPresent()
51 {
52
53 final Properties props = new Properties();
54
55
56 final RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props );
57
58
59 assertEquals( "Wrong timeout", ICommonRemoteCacheAttributes.DEFAULT_RMI_SOCKET_FACTORY_TIMEOUT_MILLIS, result.getRmiSocketFactoryTimeoutMillis() );
60 }
61
62
63 public void testConfigureRemoteCacheServerAttributes_registryKeepAliveDelayMillisPresent()
64 {
65
66 final int registryKeepAliveDelayMillis = 123245;
67 final Properties props = new Properties();
68 props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".registryKeepAliveDelayMillis", String.valueOf( registryKeepAliveDelayMillis ) );
69
70
71 final RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props );
72
73
74 assertEquals( "Wrong registryKeepAliveDelayMillis", registryKeepAliveDelayMillis, result.getRegistryKeepAliveDelayMillis() );
75 }
76
77
78 public void testConfigureRemoteCacheServerAttributes_useRegistryKeepAlivePresent()
79 {
80
81 final boolean useRegistryKeepAlive = false;
82 final Properties props = new Properties();
83 props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".useRegistryKeepAlive", String.valueOf( useRegistryKeepAlive ) );
84
85
86 final RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props );
87
88
89 assertEquals( "Wrong useRegistryKeepAlive", useRegistryKeepAlive, result.isUseRegistryKeepAlive() );
90 }
91
92
93 public void testConfigureRemoteCacheServerAttributes_startRegistryPresent()
94 {
95
96 final boolean startRegistry = false;
97 final Properties props = new Properties();
98 props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".startRegistry", String.valueOf( startRegistry ) );
99
100
101 final RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props );
102
103
104 assertEquals( "Wrong startRegistry", startRegistry, result.isStartRegistry() );
105 }
106
107
108 public void testConfigureRemoteCacheServerAttributes_rmiSocketFactoryTimeoutMillisPresent()
109 {
110
111 final int rmiSocketFactoryTimeoutMillis = 123245;
112 final Properties props = new Properties();
113 props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".rmiSocketFactoryTimeoutMillis", String.valueOf( rmiSocketFactoryTimeoutMillis ) );
114
115
116 final 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 final boolean allowClusterGet = false;
127 final Properties props = new Properties();
128 props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".allowClusterGet", String.valueOf( allowClusterGet ) );
129
130
131 final 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 final boolean localClusterConsistency = false;
142 final Properties props = new Properties();
143 props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".localClusterConsistency", String.valueOf( localClusterConsistency ) );
144
145
146 final 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 final String testValue = "123245";
157 final 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 final 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 final int readTimeout = 1234;
174 final int openTimeout = 1234;
175 final 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 final 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 }