-
Notifications
You must be signed in to change notification settings - Fork 912
/
SessionFactoryTest.java
390 lines (356 loc) · 20.7 KB
/
SessionFactoryTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.tests.integration.client;
import java.util.Arrays;
import org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration;
import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration;
import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory;
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
import org.apache.activemq.artemis.api.core.client.ClientSession;
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.core.config.Configuration;
import org.apache.activemq.artemis.core.config.ha.SharedStorePrimaryPolicyConfiguration;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.utils.RandomUtil;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class SessionFactoryTest extends ActiveMQTestBase {
private final DiscoveryGroupConfiguration groupConfiguration = new DiscoveryGroupConfiguration().setBroadcastEndpointFactory(new UDPBroadcastEndpointFactory().setGroupAddress(getUDPDiscoveryAddress()).setGroupPort(getUDPDiscoveryPort()));
private ActiveMQServer liveService;
private TransportConfiguration liveTC;
@Override
@Before
public void setUp() throws Exception {
super.setUp();
startServer();
}
@Test
public void testCloseUnusedClientSessionFactoryWithoutGlobalPools() throws Exception {
ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(liveTC);
ClientSessionFactory csf = createSessionFactory(locator);
csf.close();
}
@Test
public void testDiscoveryConstructor() throws Exception {
ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(groupConfiguration);
assertFactoryParams(locator, null, groupConfiguration, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS);
ClientSessionFactory cf = createSessionFactory(locator);
ClientSession session = cf.createSession(false, true, true);
Assert.assertNotNull(session);
session.close();
testSettersThrowException(cf);
cf.close();
locator.close();
}
@Test
public void testStaticConnectorListConstructor() throws Exception {
TransportConfiguration[] tc = new TransportConfiguration[]{liveTC};
ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(tc);
assertFactoryParams(locator, tc, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS);
ClientSessionFactory cf = createSessionFactory(locator);
ClientSession session = cf.createSession(false, true, true);
Assert.assertNotNull(session);
session.close();
testSettersThrowException(cf);
cf.close();
}
@Test
public void testGettersAndSetters() throws Exception {
long clientFailureCheckPeriod = RandomUtil.randomPositiveLong();
long connectionTTL = RandomUtil.randomPositiveLong();
long callTimeout = RandomUtil.randomPositiveLong();
int minLargeMessageSize = RandomUtil.randomPositiveInt();
int consumerWindowSize = RandomUtil.randomPositiveInt();
int consumerMaxRate = RandomUtil.randomPositiveInt();
int confirmationWindowSize = RandomUtil.randomPositiveInt();
int producerMaxRate = RandomUtil.randomPositiveInt();
boolean blockOnAcknowledge = RandomUtil.randomBoolean();
boolean blockOnDurableSend = RandomUtil.randomBoolean();
boolean blockOnNonDurableSend = RandomUtil.randomBoolean();
boolean autoGroup = RandomUtil.randomBoolean();
boolean preAcknowledge = RandomUtil.randomBoolean();
String loadBalancingPolicyClassName = RandomUtil.randomString();
int ackBatchSize = RandomUtil.randomPositiveInt();
boolean useGlobalPools = RandomUtil.randomBoolean();
int scheduledThreadPoolMaxSize = RandomUtil.randomPositiveInt();
int threadPoolMaxSize = RandomUtil.randomPositiveInt();
long retryInterval = RandomUtil.randomPositiveLong();
double retryIntervalMultiplier = RandomUtil.randomDouble();
int reconnectAttempts = RandomUtil.randomPositiveInt();
TransportConfiguration[] tc = new TransportConfiguration[]{liveTC};
ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(tc).setClientFailureCheckPeriod(clientFailureCheckPeriod).setConnectionTTL(connectionTTL).setCallTimeout(callTimeout).setMinLargeMessageSize(minLargeMessageSize).setConsumerWindowSize(consumerWindowSize).setConsumerMaxRate(consumerMaxRate).setConfirmationWindowSize(confirmationWindowSize).setProducerMaxRate(producerMaxRate).setBlockOnAcknowledge(blockOnAcknowledge).setBlockOnDurableSend(blockOnDurableSend).setBlockOnNonDurableSend(blockOnNonDurableSend).setAutoGroup(autoGroup).setPreAcknowledge(preAcknowledge).setConnectionLoadBalancingPolicyClassName(loadBalancingPolicyClassName).setAckBatchSize(ackBatchSize).setUseGlobalPools(useGlobalPools).setScheduledThreadPoolMaxSize(scheduledThreadPoolMaxSize).setThreadPoolMaxSize(threadPoolMaxSize).setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryIntervalMultiplier).setReconnectAttempts(reconnectAttempts);
assertEqualsTransportConfigurations(tc, locator.getStaticTransportConfigurations());
Assert.assertEquals(clientFailureCheckPeriod, locator.getClientFailureCheckPeriod());
Assert.assertEquals(connectionTTL, locator.getConnectionTTL());
Assert.assertEquals(callTimeout, locator.getCallTimeout());
Assert.assertEquals(minLargeMessageSize, locator.getMinLargeMessageSize());
Assert.assertEquals(consumerWindowSize, locator.getConsumerWindowSize());
Assert.assertEquals(consumerMaxRate, locator.getConsumerMaxRate());
Assert.assertEquals(confirmationWindowSize, locator.getConfirmationWindowSize());
Assert.assertEquals(producerMaxRate, locator.getProducerMaxRate());
Assert.assertEquals(blockOnAcknowledge, locator.isBlockOnAcknowledge());
Assert.assertEquals(blockOnDurableSend, locator.isBlockOnDurableSend());
Assert.assertEquals(blockOnNonDurableSend, locator.isBlockOnNonDurableSend());
Assert.assertEquals(autoGroup, locator.isAutoGroup());
Assert.assertEquals(preAcknowledge, locator.isPreAcknowledge());
Assert.assertEquals(loadBalancingPolicyClassName, locator.getConnectionLoadBalancingPolicyClassName());
Assert.assertEquals(ackBatchSize, locator.getAckBatchSize());
Assert.assertEquals(useGlobalPools, locator.isUseGlobalPools());
Assert.assertEquals(scheduledThreadPoolMaxSize, locator.getScheduledThreadPoolMaxSize());
Assert.assertEquals(threadPoolMaxSize, locator.getThreadPoolMaxSize());
Assert.assertEquals(retryInterval, locator.getRetryInterval());
Assert.assertEquals(retryIntervalMultiplier, locator.getRetryIntervalMultiplier(), 0.000001);
Assert.assertEquals(reconnectAttempts, locator.getReconnectAttempts());
}
private void testSettersThrowException(final ClientSessionFactory cf) {
long clientFailureCheckPeriod = RandomUtil.randomPositiveLong();
long connectionTTL = RandomUtil.randomPositiveLong();
long callTimeout = RandomUtil.randomPositiveLong();
int minLargeMessageSize = RandomUtil.randomPositiveInt();
int consumerWindowSize = RandomUtil.randomPositiveInt();
int consumerMaxRate = RandomUtil.randomPositiveInt();
int confirmationWindowSize = RandomUtil.randomPositiveInt();
int producerMaxRate = RandomUtil.randomPositiveInt();
boolean blockOnAcknowledge = RandomUtil.randomBoolean();
boolean blockOnDurableSend = RandomUtil.randomBoolean();
boolean blockOnNonDurableSend = RandomUtil.randomBoolean();
boolean autoGroup = RandomUtil.randomBoolean();
boolean preAcknowledge = RandomUtil.randomBoolean();
String loadBalancingPolicyClassName = RandomUtil.randomString();
int ackBatchSize = RandomUtil.randomPositiveInt();
boolean useGlobalPools = RandomUtil.randomBoolean();
int scheduledThreadPoolMaxSize = RandomUtil.randomPositiveInt();
int threadPoolMaxSize = RandomUtil.randomPositiveInt();
long retryInterval = RandomUtil.randomPositiveLong();
double retryIntervalMultiplier = RandomUtil.randomDouble();
int reconnectAttempts = RandomUtil.randomPositiveInt();
try {
cf.getServerLocator().setClientFailureCheckPeriod(clientFailureCheckPeriod);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setConnectionTTL(connectionTTL);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setCallTimeout(callTimeout);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setMinLargeMessageSize(minLargeMessageSize);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setConsumerWindowSize(consumerWindowSize);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setConsumerMaxRate(consumerMaxRate);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setConfirmationWindowSize(confirmationWindowSize);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setProducerMaxRate(producerMaxRate);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setBlockOnAcknowledge(blockOnAcknowledge);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setBlockOnDurableSend(blockOnDurableSend);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setBlockOnNonDurableSend(blockOnNonDurableSend);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setAutoGroup(autoGroup);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setPreAcknowledge(preAcknowledge);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setConnectionLoadBalancingPolicyClassName(loadBalancingPolicyClassName);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setAckBatchSize(ackBatchSize);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setUseGlobalPools(useGlobalPools);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setScheduledThreadPoolMaxSize(scheduledThreadPoolMaxSize);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setThreadPoolMaxSize(threadPoolMaxSize);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setRetryInterval(retryInterval);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setRetryIntervalMultiplier(retryIntervalMultiplier);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
try {
cf.getServerLocator().setReconnectAttempts(reconnectAttempts);
Assert.fail("Should throw exception");
} catch (IllegalStateException e) {
// OK
}
cf.getServerLocator().getStaticTransportConfigurations();
cf.getServerLocator().getClientFailureCheckPeriod();
cf.getServerLocator().getConnectionTTL();
cf.getServerLocator().getCallTimeout();
cf.getServerLocator().getMinLargeMessageSize();
cf.getServerLocator().getConsumerWindowSize();
cf.getServerLocator().getConsumerMaxRate();
cf.getServerLocator().getConfirmationWindowSize();
cf.getServerLocator().getProducerMaxRate();
cf.getServerLocator().isBlockOnAcknowledge();
cf.getServerLocator().isBlockOnDurableSend();
cf.getServerLocator().isBlockOnNonDurableSend();
cf.getServerLocator().isAutoGroup();
cf.getServerLocator().isPreAcknowledge();
cf.getServerLocator().getConnectionLoadBalancingPolicyClassName();
cf.getServerLocator().getAckBatchSize();
cf.getServerLocator().isUseGlobalPools();
cf.getServerLocator().getScheduledThreadPoolMaxSize();
cf.getServerLocator().getThreadPoolMaxSize();
cf.getServerLocator().getRetryInterval();
cf.getServerLocator().getRetryIntervalMultiplier();
cf.getServerLocator().getReconnectAttempts();
}
private void assertFactoryParams(final ServerLocator locator,
final TransportConfiguration[] staticConnectors,
final DiscoveryGroupConfiguration discoveryGroupConfiguration,
final long clientFailureCheckPeriod,
final long connectionTTL,
final long callTimeout,
final int minLargeMessageSize,
final int consumerWindowSize,
final int consumerMaxRate,
final int confirmationWindowSize,
final int producerMaxRate,
final boolean blockOnAcknowledge,
final boolean blockOnDurableSend,
final boolean blockOnNonDurableSend,
final boolean autoGroup,
final boolean preAcknowledge,
final String loadBalancingPolicyClassName,
final int ackBatchSize,
final boolean useGlobalPools,
final int scheduledThreadPoolMaxSize,
final int threadPoolMaxSize,
final long retryInterval,
final double retryIntervalMultiplier,
final int reconnectAttempts) {
if (staticConnectors == null) {
Assert.assertTrue("no static connectors", Arrays.equals(new String[]{}, locator.getStaticTransportConfigurations()));
} else {
assertEqualsTransportConfigurations(staticConnectors, locator.getStaticTransportConfigurations());
}
Assert.assertEquals(locator.getDiscoveryGroupConfiguration(), discoveryGroupConfiguration);
Assert.assertEquals(locator.getClientFailureCheckPeriod(), clientFailureCheckPeriod);
Assert.assertEquals(locator.getConnectionTTL(), connectionTTL);
Assert.assertEquals(locator.getCallTimeout(), callTimeout);
Assert.assertEquals(locator.getMinLargeMessageSize(), minLargeMessageSize);
Assert.assertEquals(locator.getConsumerWindowSize(), consumerWindowSize);
Assert.assertEquals(locator.getConsumerMaxRate(), consumerMaxRate);
Assert.assertEquals(locator.getConfirmationWindowSize(), confirmationWindowSize);
Assert.assertEquals(locator.getProducerMaxRate(), producerMaxRate);
Assert.assertEquals(locator.isBlockOnAcknowledge(), blockOnAcknowledge);
Assert.assertEquals(locator.isBlockOnDurableSend(), blockOnDurableSend);
Assert.assertEquals(locator.isBlockOnNonDurableSend(), blockOnNonDurableSend);
Assert.assertEquals(locator.isAutoGroup(), autoGroup);
Assert.assertEquals(locator.isPreAcknowledge(), preAcknowledge);
Assert.assertEquals(locator.getConnectionLoadBalancingPolicyClassName(), loadBalancingPolicyClassName);
Assert.assertEquals(locator.getAckBatchSize(), ackBatchSize);
Assert.assertEquals(locator.isUseGlobalPools(), useGlobalPools);
Assert.assertEquals(locator.getScheduledThreadPoolMaxSize(), scheduledThreadPoolMaxSize);
Assert.assertEquals(locator.getThreadPoolMaxSize(), threadPoolMaxSize);
Assert.assertEquals(locator.getRetryInterval(), retryInterval);
Assert.assertEquals(locator.getRetryIntervalMultiplier(), retryIntervalMultiplier, 0.000001);
Assert.assertEquals(locator.getReconnectAttempts(), reconnectAttempts);
}
private void startServer() throws Exception {
liveTC = new TransportConfiguration(INVM_CONNECTOR_FACTORY);
final long broadcastPeriod = 250;
final String bcGroupName = "bc1";
final int localBindPort = 5432;
BroadcastGroupConfiguration broadcastGroupConfiguration = new BroadcastGroupConfiguration().setName(bcGroupName).setBroadcastPeriod(broadcastPeriod).setConnectorInfos(Arrays.asList(liveTC.getName())).setEndpointFactory(new UDPBroadcastEndpointFactory().setGroupAddress(getUDPDiscoveryAddress()).setGroupPort(getUDPDiscoveryPort()).setLocalBindPort(localBindPort));
Configuration primaryConf = createDefaultInVMConfig().addConnectorConfiguration(liveTC.getName(), liveTC).setHAPolicyConfiguration(new SharedStorePrimaryPolicyConfiguration()).addBroadcastGroupConfiguration(broadcastGroupConfiguration);
liveService = createServer(false, primaryConf);
liveService.start();
}
}