-
Notifications
You must be signed in to change notification settings - Fork 912
/
SimpleJNDIClientTest.java
834 lines (698 loc) · 44.6 KB
/
SimpleJNDIClientTest.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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
/*
* 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.jms;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.JMSSecurityException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.Topic;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.LinkedList;
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
import org.apache.activemq.artemis.api.core.BroadcastEndpoint;
import org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration;
import org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration;
import org.apache.activemq.artemis.api.core.JGroupsFileBroadcastEndpoint;
import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.api.core.UDPBroadcastEndpointFactory;
import org.apache.activemq.artemis.api.jms.JMSFactoryType;
import org.apache.activemq.artemis.core.config.Configuration;
import org.apache.activemq.artemis.core.config.ha.SharedStorePrimaryPolicyConfiguration;
import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl;
import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
import org.apache.activemq.artemis.core.security.Role;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.ActiveMQServers;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
import org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory;
import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.utils.Wait;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
/**
* ActiveMQConnectionFactoryTest
*/
public class SimpleJNDIClientTest extends ActiveMQTestBase {
private final String groupAddress = getUDPDiscoveryAddress();
private final int groupPort = getUDPDiscoveryPort();
private ActiveMQServer liveService;
private TransportConfiguration liveTC;
private List<ActiveMQConnectionFactory> factories = new LinkedList<>();
// adding connection factories that need to be closed
// this is because UDP connection factories could hold a UDP thread running if they are not closed
private void addCF(ConnectionFactory factory) {
if (factory instanceof ActiveMQConnectionFactory) {
factories.add((ActiveMQConnectionFactory)factory);
}
}
@After
public void closeCFs() {
factories.forEach(cf -> {
cf.close();
});
}
@Test
public void testMultipleConnectionFactories() throws NamingException, JMSException {
Hashtable<String, Object> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.VmConnectionFactory", "vm://0");
props.put("connectionFactory.TCPConnectionFactory", "tcp://localhost:61616");
props.put("connectionFactory.UDPConnectionFactory", "udp://" + getUDPDiscoveryAddress() + ":" + getUDPDiscoveryPort());
props.put("connectionFactory.JGroupsConnectionFactory", "jgroups://mychannelid?file=test-jgroups-file_ping.xml");
Context ctx = new InitialContext(props);
ctx.lookup("VmConnectionFactory");
ctx.lookup("TCPConnectionFactory");
ctx.lookup("UDPConnectionFactory");
ctx.lookup("JGroupsConnectionFactory");
ctx.close();
}
@Test
public void testVMCF0() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.ConnectionFactory", "vm://0");
Context ctx = new InitialContext(props);
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("ConnectionFactory");
connectionFactory.createConnection().close();
ctx.close();
}
@Test
public void testEmptyConnectionFactoryString() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.ConnectionFactory", "vm://0");
//IIB v10 assumes this property is mandatory and sets it to an empty string when not specified
props.put("java.naming.provider.url", "");
Context ctx = new InitialContext(props);//Must not throw an exception
ctx.close();
}
@Test
public void testVMCF1() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.ConnectionFactory", "vm://1");
Context ctx = new InitialContext(props);
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("ConnectionFactory");
connectionFactory.createConnection().close();
}
@Test
public void testXACF() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.myConnectionFactory", "vm://0?type=XA_CF");
Context ctx = new InitialContext(props);
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
Assert.assertEquals(JMSFactoryType.XA_CF.intValue(), connectionFactory.getFactoryType());
}
@Test
public void testQueueCF() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.myConnectionFactory", "vm://0?type=QUEUE_CF");
Context ctx = new InitialContext(props);
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
Assert.assertEquals(JMSFactoryType.QUEUE_CF.intValue(), connectionFactory.getFactoryType());
}
@Test
public void testQueueXACF() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.myConnectionFactory", "vm://0?type=QUEUE_XA_CF");
Context ctx = new InitialContext(props);
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
Assert.assertEquals(JMSFactoryType.QUEUE_XA_CF.intValue(), connectionFactory.getFactoryType());
}
@Test
public void testTopicCF() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.myConnectionFactory", "vm://0?type=TOPIC_CF");
Context ctx = new InitialContext(props);
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
Assert.assertEquals(JMSFactoryType.TOPIC_CF.intValue(), connectionFactory.getFactoryType());
}
@Test
public void testTopicXACF() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.myConnectionFactory", "vm://0?type=TOPIC_XA_CF");
Context ctx = new InitialContext(props);
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
Assert.assertEquals(JMSFactoryType.TOPIC_XA_CF.intValue(), connectionFactory.getFactoryType());
}
@Test
public void testRemoteCFWithTCP() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.myConnectionFactory", "tcp://127.0.0.1:61616");
Context ctx = new InitialContext(props);
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("myConnectionFactory");
connectionFactory.createConnection().close();
}
@Test
public void testRemoteCFWithTCPandHA() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.myConnectionFactory", "tcp://127.0.0.1:61616?ha=true");
Context ctx = new InitialContext(props);
ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
Assert.assertEquals(true, cf.isHA());
}
@Test
public void testRemoteCFWithJGroups() throws Exception {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.myConnectionFactory", "jgroups://mychannelid?file=test-jgroups-file_ping.xml");
Context ctx = new InitialContext(props);
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
connectionFactory.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory().createBroadcastEndpoint().close(false);
}
@Test
public void testRemoteCFWithJgroupsWithTransportConfigFile() throws Exception {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory.class.getCanonicalName());
props.put("connectionFactory.myConnectionFactory", "jgroups://testChannelName?file=test-jgroups-file_ping.xml&" +
ActiveMQInitialContextFactory.REFRESH_TIMEOUT + "=5000&" +
ActiveMQInitialContextFactory.DISCOVERY_INITIAL_WAIT_TIMEOUT + "=6000");
Context ctx = new InitialContext(props);
ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
DiscoveryGroupConfiguration discoveryGroupConfiguration = cf.getDiscoveryGroupConfiguration();
Assert.assertEquals(5000, discoveryGroupConfiguration.getRefreshTimeout());
Assert.assertEquals(6000, discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout());
BroadcastEndpoint broadcastEndpoint = cf.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory().createBroadcastEndpoint();
Assert.assertTrue(broadcastEndpoint instanceof JGroupsFileBroadcastEndpoint);
broadcastEndpoint.close(false);
}
@Test
public void testRemoteCFWithUDP() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.myConnectionFactory", "udp://" + getUDPDiscoveryAddress() + ":" + getUDPDiscoveryPort());
Context ctx = new InitialContext(props);
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("myConnectionFactory");
addCF(connectionFactory);
connectionFactory.createConnection().close();
ctx.close();
}
@Test
public void testRemoteCFWithUDPWithTransportConfig() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getCanonicalName());
props.put("connectionFactory.myConnectionFactory", "udp://" + getUDPDiscoveryAddress() + ":" + getUDPDiscoveryPort() + "?" +
TransportConstants.LOCAL_ADDRESS_PROP_NAME + "=Server1&" +
TransportConstants.LOCAL_PORT_PROP_NAME + "=1198&" +
ActiveMQInitialContextFactory.REFRESH_TIMEOUT + "=5000&" +
ActiveMQInitialContextFactory.DISCOVERY_INITIAL_WAIT_TIMEOUT + "=6000");
Context ctx = new InitialContext(props);
ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
addCF(cf);
DiscoveryGroupConfiguration discoveryGroupConfiguration = cf.getDiscoveryGroupConfiguration();
Assert.assertEquals(5000, discoveryGroupConfiguration.getRefreshTimeout());
Assert.assertEquals(6000, discoveryGroupConfiguration.getDiscoveryInitialWaitTimeout());
UDPBroadcastEndpointFactory udpBroadcastEndpointFactory = (UDPBroadcastEndpointFactory) discoveryGroupConfiguration.getBroadcastEndpointFactory();
//these 2 are transient so are ignored
Assert.assertNotEquals("Server1", udpBroadcastEndpointFactory.getLocalBindAddress());
Assert.assertNotEquals(1198, udpBroadcastEndpointFactory.getLocalBindPort());
Assert.assertEquals(getUDPDiscoveryAddress(), udpBroadcastEndpointFactory.getGroupAddress());
Assert.assertEquals(getUDPDiscoveryPort(), udpBroadcastEndpointFactory.getGroupPort());
ctx.close();
}
@Test
public void testRemoteCFWithMultipleHosts() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.myConnectionFactory", "tcp://127.0.0.1:61616/httpEnabled=true&foo=bar,tcp://127.0.0.2:61617?httpEnabled=false?clientID=myClientID");
Context ctx = new InitialContext(props);
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("myConnectionFactory");
connectionFactory.createConnection().close();
ctx.close();
}
@Test
public void testRemoteCFWithTransportConfig() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.myConnectionFactory", "tcp://127.0.0.1:61616?" +
TransportConstants.SSL_ENABLED_PROP_NAME + "=mySSLEnabledPropValue&" +
TransportConstants.HTTP_ENABLED_PROP_NAME + "=myHTTPEnabledPropValue&" +
TransportConstants.HTTP_CLIENT_IDLE_PROP_NAME + "=myHTTPClientIdlePropValue&" +
TransportConstants.HTTP_CLIENT_IDLE_SCAN_PERIOD + "=myHTTPClientIdleScanPeriodValue&" +
TransportConstants.HTTP_REQUIRES_SESSION_ID + "=myHTTPRequiresSessionIDValue&" +
TransportConstants.HTTP_UPGRADE_ENABLED_PROP_NAME + "=myHTTPUpgradeEnabledPropValue&" +
TransportConstants.HTTP_UPGRADE_ENDPOINT_PROP_NAME + "=myHTTPUpgradeEndpointPropValue&" +
TransportConstants.USE_SERVLET_PROP_NAME + "=myUseServletPropValue&" +
TransportConstants.SERVLET_PATH + "=myServletPathValue&" +
TransportConstants.USE_NIO_PROP_NAME + "=myUseNIOPropValue&" +
TransportConstants.USE_NIO_GLOBAL_WORKER_POOL_PROP_NAME + "=myUseNIOGlobalWorkerPoolPropValue&" +
TransportConstants.LOCAL_ADDRESS_PROP_NAME + "=myLocalAddressPropValue&" +
TransportConstants.LOCAL_PORT_PROP_NAME + "=myLocalPortPropValue&" +
TransportConstants.KEYSTORE_PROVIDER_PROP_NAME + "=myKeystoreProviderPropValue&" +
TransportConstants.KEYSTORE_TYPE_PROP_NAME + "=myKeystoreTypePropValue&" +
TransportConstants.KEYSTORE_PATH_PROP_NAME + "=myKeystorePathPropValue&" +
TransportConstants.KEYSTORE_PASSWORD_PROP_NAME + "=myKeystorePasswordPropValue&" +
TransportConstants.TRUSTSTORE_PROVIDER_PROP_NAME + "=myTruststoreProviderPropValue&" +
TransportConstants.TRUSTSTORE_TYPE_PROP_NAME + "=myTruststoreTypePropValue&" +
TransportConstants.TRUSTSTORE_PATH_PROP_NAME + "=myTruststorePathPropValue&" +
TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME + "=myTruststorePasswordPropValue&" +
TransportConstants.ENABLED_CIPHER_SUITES_PROP_NAME + "=myEnabledCipherSuitesPropValue&" +
TransportConstants.ENABLED_PROTOCOLS_PROP_NAME + "=myEnabledProtocolsPropValue&" +
TransportConstants.TCP_NODELAY_PROPNAME + "=myTCPNoDelayPropValue&" +
TransportConstants.TCP_SENDBUFFER_SIZE_PROPNAME + "=myTCPSendbufferSizePropValue&" +
TransportConstants.TCP_RECEIVEBUFFER_SIZE_PROPNAME + "=myTCPReceivebufferSizePropValue&" +
TransportConstants.NIO_REMOTING_THREADS_PROPNAME + "=myNIORemotingThreadsPropValue&" +
TransportConstants.BATCH_DELAY + "=myBatchDelay&" +
ActiveMQDefaultConfiguration.getPropMaskPassword() + "=myPropMaskPassword&" +
ActiveMQDefaultConfiguration.getPropPasswordCodec() + "=myPropPasswordCodec&" +
TransportConstants.NETTY_CONNECT_TIMEOUT + "=myNettyConnectTimeout&");
Context ctx = new InitialContext(props);
ActiveMQConnectionFactory cf = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
Map<String, Object> parametersFromJNDI = cf.getServerLocator().getStaticTransportConfigurations()[0].getParams();
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.SSL_ENABLED_PROP_NAME), "mySSLEnabledPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.HTTP_ENABLED_PROP_NAME), "myHTTPEnabledPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.HTTP_CLIENT_IDLE_PROP_NAME), "myHTTPClientIdlePropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.HTTP_CLIENT_IDLE_SCAN_PERIOD), "myHTTPClientIdleScanPeriodValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.HTTP_REQUIRES_SESSION_ID), "myHTTPRequiresSessionIDValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.HTTP_UPGRADE_ENABLED_PROP_NAME), "myHTTPUpgradeEnabledPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.HTTP_UPGRADE_ENDPOINT_PROP_NAME), "myHTTPUpgradeEndpointPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.USE_SERVLET_PROP_NAME), "myUseServletPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.SERVLET_PATH), "myServletPathValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.USE_NIO_PROP_NAME), "myUseNIOPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.USE_NIO_GLOBAL_WORKER_POOL_PROP_NAME), "myUseNIOGlobalWorkerPoolPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.LOCAL_ADDRESS_PROP_NAME), "myLocalAddressPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.LOCAL_PORT_PROP_NAME), "myLocalPortPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.KEYSTORE_PROVIDER_PROP_NAME), "myKeystoreProviderPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.KEYSTORE_TYPE_PROP_NAME), "myKeystoreTypePropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.KEYSTORE_PATH_PROP_NAME), "myKeystorePathPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME), "myKeystorePasswordPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.TRUSTSTORE_PROVIDER_PROP_NAME), "myTruststoreProviderPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.TRUSTSTORE_TYPE_PROP_NAME), "myTruststoreTypePropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.TRUSTSTORE_PATH_PROP_NAME), "myTruststorePathPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME), "myTruststorePasswordPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.ENABLED_CIPHER_SUITES_PROP_NAME), "myEnabledCipherSuitesPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.ENABLED_PROTOCOLS_PROP_NAME), "myEnabledProtocolsPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.TCP_NODELAY_PROPNAME), "myTCPNoDelayPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.TCP_SENDBUFFER_SIZE_PROPNAME), "myTCPSendbufferSizePropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.TCP_RECEIVEBUFFER_SIZE_PROPNAME), "myTCPReceivebufferSizePropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.NIO_REMOTING_THREADS_PROPNAME), "myNIORemotingThreadsPropValue");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.BATCH_DELAY), "myBatchDelay");
Assert.assertEquals(parametersFromJNDI.get(ActiveMQDefaultConfiguration.getPropMaskPassword()), "myPropMaskPassword");
Assert.assertEquals(parametersFromJNDI.get(ActiveMQDefaultConfiguration.getPropPasswordCodec()), "myPropPasswordCodec");
Assert.assertEquals(parametersFromJNDI.get(TransportConstants.NETTY_CONNECT_TIMEOUT), "myNettyConnectTimeout");
ctx.close();
}
@Override
@Before
public void setUp() throws Exception {
super.setUp();
startServer();
}
private void startServer() throws Exception {
liveTC = new TransportConfiguration(INVM_CONNECTOR_FACTORY);
Map<String, TransportConfiguration> connectors = new HashMap<>();
connectors.put(liveTC.getName(), liveTC);
List<String> connectorNames = new ArrayList<>();
connectorNames.add(liveTC.getName());
Map<String, Object> params = new HashMap<>();
params.put(org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, 1);
Configuration primaryConf = createBasicConfig().addAcceptorConfiguration(new TransportConfiguration(INVM_ACCEPTOR_FACTORY)).addAcceptorConfiguration(new TransportConfiguration(INVM_ACCEPTOR_FACTORY, params)).addAcceptorConfiguration(new TransportConfiguration(NETTY_ACCEPTOR_FACTORY)).setConnectorConfigurations(connectors).setHAPolicyConfiguration(new SharedStorePrimaryPolicyConfiguration()).setSecurityEnabled(true);
final long broadcastPeriod = 250;
final String bcGroupName = "bc1";
final int localBindPort = 5432;
BroadcastGroupConfiguration bcConfig1 = new BroadcastGroupConfiguration().setName(bcGroupName).setBroadcastPeriod(broadcastPeriod).setConnectorInfos(connectorNames).setEndpointFactory(new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress).setGroupPort(groupPort).setLocalBindPort(localBindPort));
List<BroadcastGroupConfiguration> bcConfigs1 = new ArrayList<>();
bcConfigs1.add(bcConfig1);
primaryConf.setBroadcastGroupConfigurations(bcConfigs1);
liveService = addServer(ActiveMQServers.newActiveMQServer(primaryConf, false));
((ActiveMQJAASSecurityManager) liveService.getSecurityManager()).getConfiguration().addUser("guest", "guest");
((ActiveMQJAASSecurityManager) liveService.getSecurityManager()).getConfiguration().setDefaultUser("guest");
liveService.start();
}
@Test
public void testQueue() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("queue.myQueue", "myQueue");
props.put("queue.queues/myQueue", "myQueue");
Context ctx = new InitialContext(props);
Destination destination = (Destination) ctx.lookup("myQueue");
Assert.assertTrue(destination instanceof Queue);
destination = (Destination) ctx.lookup("queues/myQueue");
Assert.assertTrue(destination instanceof Queue);
}
@Test
public void testQueueFQQN() throws Exception {
final String QUEUE = "myQueue";
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("queue.myQueue", "myAddress::" + QUEUE);
Context ctx = new InitialContext(props);
liveService.getSecurityStore().setSecurityEnabled(false);
Destination destination = (Destination) ctx.lookup(QUEUE);
Assert.assertTrue(destination instanceof Queue);
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
try (Connection connection = connectionFactory.createConnection()) {
Session session = connection.createSession();
MessageProducer producer = session.createProducer(destination);
producer.send(session.createMessage());
Wait.assertTrue(() -> liveService.locateQueue(QUEUE).getMessageCount() == 1, 2000, 100);
MessageConsumer consumer = session.createConsumer(destination);
connection.start();
assertNotNull(consumer.receiveNoWait());
}
}
@Test
public void testDynamicQueue() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
Context ctx = new InitialContext(props);
Destination destination = (Destination) ctx.lookup("dynamicQueues/myQueue");
Assert.assertTrue(destination instanceof Queue);
}
@Test
public void testDynamicQueueFQQN() throws Exception {
final String QUEUE = "myQueue";
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
Context ctx = new InitialContext(props);
liveService.getSecurityStore().setSecurityEnabled(false);
Destination destination = (Destination) ctx.lookup("dynamicQueues/myAddress::" + QUEUE);
Assert.assertTrue(destination instanceof Queue);
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
try (Connection connection = connectionFactory.createConnection()) {
Session session = connection.createSession();
MessageProducer producer = session.createProducer(destination);
producer.send(session.createMessage());
Wait.assertTrue(() -> liveService.locateQueue(QUEUE).getMessageCount() == 1, 2000, 100);
MessageConsumer consumer = session.createConsumer(destination);
connection.start();
assertNotNull(consumer.receiveNoWait());
}
}
@Test
public void testTopic() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("topic.myTopic", "myTopic");
props.put("topic.topics/myTopic", "myTopic");
Context ctx = new InitialContext(props);
Destination destination = (Destination) ctx.lookup("myTopic");
Assert.assertTrue(destination instanceof Topic);
destination = (Destination) ctx.lookup("topics/myTopic");
Assert.assertTrue(destination instanceof Topic);
}
@Test
public void testTopicFQQN() throws Exception {
final String SUBSCRIPTION = "mySubsription";
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("topic.myTopic", "myTopic::" + SUBSCRIPTION);
Context ctx = new InitialContext(props);
liveService.getSecurityStore().setSecurityEnabled(false);
Destination destination = (Destination) ctx.lookup("myTopic");
Assert.assertTrue(destination instanceof Topic);
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession();
MessageProducer producer = session.createProducer(destination);
producer.send(session.createMessage());
Wait.assertTrue(() -> liveService.locateQueue(SUBSCRIPTION).getMessageCount() == 1, 2000, 100);
MessageConsumer consumer = session.createConsumer(destination);
connection.start();
assertNotNull(consumer.receiveNoWait());
}
@Test
public void testDynamicTopic() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
Context ctx = new InitialContext(props);
Destination destination = (Destination) ctx.lookup("dynamicTopics/myTopic");
Assert.assertTrue(destination instanceof Topic);
}
@Test
public void testDynamicTopicFQQN() throws Exception {
final String SUBSCRIPTION = "mySubsription";
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("topic.myTopic", "myTopic::" + SUBSCRIPTION);
Context ctx = new InitialContext(props);
liveService.getSecurityStore().setSecurityEnabled(false);
Destination destination = (Destination) ctx.lookup("dynamicTopics/myTopic::" + SUBSCRIPTION);
Assert.assertTrue(destination instanceof Topic);
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession();
MessageProducer producer = session.createProducer(destination);
producer.send(session.createMessage());
Wait.assertTrue(() -> liveService.locateQueue(SUBSCRIPTION).getMessageCount() == 1, 2000, 100);
MessageConsumer consumer = session.createConsumer(destination);
connection.start();
assertNotNull(consumer.receiveNoWait());
}
@Test
public void testRemoteCFWithTCPUserPassword() throws Exception {
//setup user and role on broker
((ActiveMQJAASSecurityManager) liveService.getSecurityManager()).getConfiguration().addUser("myUser", "myPassword");
((ActiveMQJAASSecurityManager) liveService.getSecurityManager()).getConfiguration().addRole("myUser", "consumeCreateRole");
Role consumeCreateRole = new Role("consumeCreateRole", false, true, true, true, true, true, true, true, true, true);
Set<Role> consumerCreateRoles = new HashSet<>();
consumerCreateRoles.add(consumeCreateRole);
liveService.getSecurityRepository().addMatch("test.queue", consumerCreateRoles);
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
//user and password set on URL
props.put("connectionFactory.myConnectionFactory", "tcp://127.0.0.1:61616?user=myUser&password=myPassword");
Context ctx = new InitialContext(props);
//create a connection factory
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup("myConnectionFactory");
Assert.assertEquals("ensure user is set", "myUser", connectionFactory.getUser());
Assert.assertEquals("ensure password is set", "myPassword", connectionFactory.getPassword());
//Connect to broker to verify credentials are used with connection
Connection connection = connectionFactory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue("test.queue");
try {
try {
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage("test Msg"));
Assert.fail("Sending message should throw a JMSSecurityException");
} catch (JMSSecurityException e) {
//expected
}
MessageConsumer consumer = session.createConsumer(queue);
} finally {
connection.close();
}
}
public void testContext(Context ctx, String jndiName, JMSFactoryType expectedFactoryType) {
try {
ActiveMQConnectionFactory connectionFactory = (ActiveMQConnectionFactory) ctx.lookup(jndiName);
if (expectedFactoryType == null) {
Assert.fail("expected no factory, should have thrown NamingException");
} else {
Assert.assertEquals(expectedFactoryType.intValue(), connectionFactory.getFactoryType());
}
} catch (NamingException namingException) {
Assert.assertNull("NamingException should only occur when no ExpectedFactoryType, but one existed", expectedFactoryType);
}
}
@Test
public void testProviderUrlDefault() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put(Context.PROVIDER_URL, "vm://0");
Context ctx = new InitialContext(props);
testContext(ctx, "ConnectionFactory", JMSFactoryType.CF);
testContext(ctx, "QueueConnectionFactory", JMSFactoryType.QUEUE_CF);
testContext(ctx, "TopicConnectionFactory", JMSFactoryType.TOPIC_CF);
testContext(ctx, "XAConnectionFactory", JMSFactoryType.XA_CF);
testContext(ctx, "XAQueueConnectionFactory", JMSFactoryType.QUEUE_XA_CF);
testContext(ctx, "XATopicConnectionFactory", JMSFactoryType.TOPIC_XA_CF);
}
@Test
public void testProviderUrlCF() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put(Context.PROVIDER_URL, "vm://0?type=CF");
Context ctx = new InitialContext(props);
testContext(ctx, "ConnectionFactory", JMSFactoryType.CF);
testContext(ctx, "QueueConnectionFactory", null);
testContext(ctx, "TopicConnectionFactory", null);
testContext(ctx, "XAConnectionFactory", null);
testContext(ctx, "XAQueueConnectionFactory", null);
testContext(ctx, "XATopicConnectionFactory", null);
}
@Test
public void testProviderUrlXACF() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put(Context.PROVIDER_URL, "vm://0?type=XA_CF");
Context ctx = new InitialContext(props);
testContext(ctx, "ConnectionFactory", null);
testContext(ctx, "QueueConnectionFactory", null);
testContext(ctx, "TopicConnectionFactory", null);
testContext(ctx, "XAConnectionFactory", JMSFactoryType.XA_CF);
testContext(ctx, "XAQueueConnectionFactory", null);
testContext(ctx, "XATopicConnectionFactory", null);
}
@Test
public void testProviderUrlQueueCF() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put(Context.PROVIDER_URL, "vm://0?type=QUEUE_CF");
Context ctx = new InitialContext(props);
testContext(ctx, "ConnectionFactory", null);
testContext(ctx, "QueueConnectionFactory", JMSFactoryType.QUEUE_CF);
testContext(ctx, "TopicConnectionFactory", null);
testContext(ctx, "XAConnectionFactory", null);
testContext(ctx, "XAQueueConnectionFactory", null);
testContext(ctx, "XATopicConnectionFactory", null);
}
@Test
public void testProviderUrlQueueXACF() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put(Context.PROVIDER_URL, "vm://0?type=QUEUE_XA_CF");
Context ctx = new InitialContext(props);
testContext(ctx, "ConnectionFactory", null);
testContext(ctx, "QueueConnectionFactory", null);
testContext(ctx, "TopicConnectionFactory", null);
testContext(ctx, "XAConnectionFactory", null);
testContext(ctx, "XAQueueConnectionFactory", JMSFactoryType.QUEUE_XA_CF);
testContext(ctx, "XATopicConnectionFactory", null);
}
@Test
public void testProviderUrlTopicCF() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put(Context.PROVIDER_URL, "vm://0?type=TOPIC_CF");
Context ctx = new InitialContext(props);
testContext(ctx, "ConnectionFactory", null);
testContext(ctx, "QueueConnectionFactory", null);
testContext(ctx, "TopicConnectionFactory", JMSFactoryType.TOPIC_CF);
testContext(ctx, "XAConnectionFactory", null);
testContext(ctx, "XAQueueConnectionFactory", null);
testContext(ctx, "XATopicConnectionFactory", null);
}
@Test
public void testProviderUrlTopicXACF() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put(Context.PROVIDER_URL, "vm://0?type=TOPIC_XA_CF");
Context ctx = new InitialContext(props);
testContext(ctx, "ConnectionFactory", null);
testContext(ctx, "QueueConnectionFactory", null);
testContext(ctx, "TopicConnectionFactory", null);
testContext(ctx, "XAConnectionFactory", null);
testContext(ctx, "XAQueueConnectionFactory", null);
testContext(ctx, "XATopicConnectionFactory", JMSFactoryType.TOPIC_XA_CF);
}
@Test
public void testProviderUrlDefaultAndCustom() throws NamingException, JMSException {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put(Context.PROVIDER_URL, "vm://0");
props.put("connectionFactory.myConnectionFactory", "vm://0");
Context ctx = new InitialContext(props);
testContext(ctx, "ConnectionFactory", JMSFactoryType.CF);
testContext(ctx, "QueueConnectionFactory", JMSFactoryType.QUEUE_CF);
testContext(ctx, "TopicConnectionFactory", JMSFactoryType.TOPIC_CF);
testContext(ctx, "XAConnectionFactory", JMSFactoryType.XA_CF);
testContext(ctx, "XAQueueConnectionFactory", JMSFactoryType.QUEUE_XA_CF);
testContext(ctx, "XATopicConnectionFactory", JMSFactoryType.TOPIC_XA_CF);
testContext(ctx, "myConnectionFactory", JMSFactoryType.CF);
}
@Test
public void test1xNaming() throws NamingException, JMSException {
liveService.getSecurityStore().setSecurityEnabled(false);
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.ConnectionFactory", "vm://0?enable1xPrefixes=true");
props.put("connectionFactory.ConnectionFactory2", "vm://0");
Context ctx = new InitialContext(props);
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("ConnectionFactory");
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession();
assertTrue(((ActiveMQDestination)session.createQueue("testQueue")).getSimpleAddress().startsWith(PacketImpl.OLD_QUEUE_PREFIX));
assertTrue(((ActiveMQDestination)session.createTemporaryQueue()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX));
assertTrue(((ActiveMQDestination)session.createTopic("testTopic")).getSimpleAddress().startsWith(PacketImpl.OLD_TOPIC_PREFIX));
assertTrue(((ActiveMQDestination)session.createTemporaryTopic()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX));
// The name should not include the prefix
assertFalse(session.createQueue("testQueue").getQueueName().startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString()));
assertFalse(session.createTemporaryQueue().getQueueName().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString()));
assertFalse(session.createTopic("testTopic").getTopicName().startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString()));
assertFalse(session.createTemporaryTopic().getTopicName().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString()));
connection.close();
// test setting programmatically
connectionFactory = (ConnectionFactory) ctx.lookup("ConnectionFactory2");
((ActiveMQConnectionFactory)connectionFactory).setEnable1xPrefixes(true);
connection = connectionFactory.createConnection();
session = connection.createSession();
assertTrue(((ActiveMQDestination)session.createQueue("testQueue")).getSimpleAddress().startsWith(PacketImpl.OLD_QUEUE_PREFIX));
assertTrue(((ActiveMQDestination)session.createTemporaryQueue()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX));
assertTrue(((ActiveMQDestination)session.createTopic("testTopic")).getSimpleAddress().startsWith(PacketImpl.OLD_TOPIC_PREFIX));
assertTrue(((ActiveMQDestination)session.createTemporaryTopic()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX));
// The name should not include the prefix
assertFalse(session.createQueue("testQueue").getQueueName().startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString()));
assertFalse(session.createTemporaryQueue().getQueueName().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString()));
assertFalse(session.createTopic("testTopic").getTopicName().startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString()));
assertFalse(session.createTemporaryTopic().getTopicName().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString()));
connection.close();
}
@Test
public void test1xNamingNegative() throws NamingException, JMSException {
liveService.getSecurityStore().setSecurityEnabled(false);
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.ConnectionFactory", "vm://0");
Context ctx = new InitialContext(props);
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("ConnectionFactory");
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession();
assertFalse(((ActiveMQDestination)session.createQueue("testQueue")).getSimpleAddress().startsWith(PacketImpl.OLD_QUEUE_PREFIX));
assertFalse(((ActiveMQDestination)session.createTemporaryQueue()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX));
assertFalse(((ActiveMQDestination)session.createTopic("testTopic")).getSimpleAddress().startsWith(PacketImpl.OLD_TOPIC_PREFIX));
assertFalse(((ActiveMQDestination)session.createTemporaryTopic()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX));
connection.close();
}
@Test
public void testUseTopologyForLoadBalancing() throws Exception {
Hashtable<String, String> props = new Hashtable<>();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
props.put("connectionFactory.ConnectionFactory", "vm://0?useTopologyForLoadBalancing=false");
Context ctx = new InitialContext(props);
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("ConnectionFactory");
assertFalse(((ActiveMQConnectionFactory)connectionFactory).getServerLocator().getUseTopologyForLoadBalancing());
}
}