2121import org .apache .activemq .artemis .api .core .QueueConfiguration ;
2222import org .apache .activemq .artemis .api .core .RoutingType ;
2323import org .apache .activemq .artemis .api .core .SimpleString ;
24- import org .apache .activemq .artemis .api .core .client .ClientConsumer ;
25- import org .apache .activemq .artemis .api .core .client .ClientMessage ;
2624import org .apache .activemq .artemis .api .core .client .ClientProducer ;
2725import org .apache .activemq .artemis .api .core .client .ClientSession ;
2826import org .apache .activemq .artemis .api .core .client .ClientSessionFactory ;
3331import org .apache .activemq .artemis .utils .Base64 ;
3432import org .apache .activemq .artemis .utils .RandomUtil ;
3533import org .apache .activemq .artemis .utils .Wait ;
34+ import org .apache .qpid .jms .JmsConnectionFactory ;
3635import org .junit .Assert ;
3736import org .junit .Before ;
3837import org .junit .Test ;
3938
39+ import javax .jms .Connection ;
40+ import javax .jms .ConnectionFactory ;
41+ import javax .jms .MessageConsumer ;
42+ import javax .jms .MessageProducer ;
43+ import javax .jms .Session ;
44+ import javax .jms .TextMessage ;
4045import javax .management .MBeanServerConnection ;
4146import javax .management .MBeanServerInvocationHandler ;
4247import javax .management .remote .JMXConnector ;
@@ -131,7 +136,7 @@ public void testAuditLog() throws Exception {
131136
132137 checkAuditLogRecord (true , "gets security check failure:" , "guest does not have permission='DELETE_NON_DURABLE_QUEUE'" );
133138 //hot patch not in log
134- checkAuditLogRecord (true , "is sending a core message" );
139+ checkAuditLogRecord (true , "is sending a message" );
135140 }
136141
137142 protected JMXConnector getJmxConnector () throws MalformedURLException {
@@ -159,7 +164,16 @@ protected JMXConnector getJmxConnector() throws MalformedURLException {
159164 }
160165
161166 @ Test
162- public void testAuditHotLog () throws Exception {
167+ public void testAuditHotLogCore () throws Exception {
168+ internalSend ("CORE" );
169+ }
170+
171+ @ Test
172+ public void testAuditHotLogAMQP () throws Exception {
173+ internalSend ("AMQP" );
174+ }
175+
176+ public void internalSend (String protocol ) throws Exception {
163177 JMXConnector jmxConnector = getJmxConnector ();
164178 MBeanServerConnection mBeanServerConnection = jmxConnector .getMBeanServerConnection ();
165179 String brokerName = "0.0.0.0" ; // configured e.g. in broker.xml <broker-name> element
@@ -172,25 +186,41 @@ public void testAuditHotLog() throws Exception {
172186 Assert .assertEquals (0 , addressControl .getQueueNames ().length );
173187 session .createQueue (new QueueConfiguration (address ).setRoutingType (RoutingType .ANYCAST ));
174188 Assert .assertEquals (1 , addressControl .getQueueNames ().length );
175- String uniqueStr = Base64 .encodeBytes (UUID .randomUUID ().toString ().getBytes ());
176-
177- ClientProducer producer = session .createProducer (address );
178- producer .send (session .createMessage (true ));
179- producer .send (session .createMessage (true ));
180- // addressControl.sendMessage(null, Message.BYTES_TYPE, uniqueStr, false, null, null);
189+ String uniqueStr = RandomUtil .randomString ();
181190
182- Wait .waitFor (() -> addressControl .getMessageCount () == 2 );
183- Assert .assertEquals (2 , addressControl .getMessageCount ());
191+ session .close ();
184192
185- checkAuditLogRecord (true , "sending a core message" );
186-
187- ClientConsumer consumer = session .createConsumer (address );
188- session .start ();
189- ClientMessage clientMessage = consumer .receiveImmediate ();
190- Assert .assertNotNull (clientMessage );
191- clientMessage = consumer .receiveImmediate ();
192- Assert .assertNotNull (clientMessage );
193- checkAuditLogRecord (true , "is consuming a message from" );
193+ ConnectionFactory factory = createConnectionFactory (protocol , "tcp://localhost:61616" );
194+ Connection connection = factory .createConnection ();
195+ try {
196+ Session session = connection .createSession ();
197+ MessageProducer producer = session .createProducer (session .createQueue (address .toString ()));
198+ TextMessage message = session .createTextMessage ("msg1" );
199+ message .setStringProperty ("str" , uniqueStr );
200+ producer .send (message );
201+
202+ message = session .createTextMessage ("msg2" );
203+ message .setStringProperty ("str" , "Hello2" );
204+ producer .send (message );
205+ // addressControl.sendMessage(null, Message.BYTES_TYPE, uniqueStr, false, null, null);
206+
207+ Wait .waitFor (() -> addressControl .getMessageCount () == 2 );
208+ Assert .assertEquals (2 , addressControl .getMessageCount ());
209+
210+ checkAuditLogRecord (true , "sending a message" );
211+ checkAuditLogRecord (true , uniqueStr );
212+ checkAuditLogRecord (true , "Hello2" );
213+
214+ connection .start ();
215+ MessageConsumer consumer = session .createConsumer (session .createQueue (address .toString ()));
216+ javax .jms .Message clientMessage = consumer .receive (5000 );
217+ Assert .assertNotNull (clientMessage );
218+ clientMessage = consumer .receive (5000 );
219+ Assert .assertNotNull (clientMessage );
220+ checkAuditLogRecord (true , "is consuming a message from" );
221+ } finally {
222+ connection .close ();
223+ }
194224 }
195225
196226 //check the audit log has a line that contains all the values
@@ -223,4 +253,21 @@ private void checkAuditLogRecord(boolean exist, String... values) throws Excepti
223253 }
224254 }
225255 }
256+
257+ public static ConnectionFactory createConnectionFactory (String protocol , String uri ) {
258+ if (protocol .toUpperCase ().equals ("OPENWIRE" )) {
259+ return new org .apache .activemq .ActiveMQConnectionFactory (uri );
260+ } else if (protocol .toUpperCase ().equals ("AMQP" )) {
261+
262+ if (uri .startsWith ("tcp://" )) {
263+ // replacing tcp:// by amqp://
264+ uri = "amqp" + uri .substring (3 );
265+ }
266+ return new JmsConnectionFactory (uri );
267+ } else if (protocol .toUpperCase ().equals ("CORE" ) || protocol .toUpperCase ().equals ("ARTEMIS" )) {
268+ return new org .apache .activemq .artemis .jms .client .ActiveMQConnectionFactory (uri );
269+ } else {
270+ throw new IllegalStateException ("Unkown:" + protocol );
271+ }
272+ }
226273}
0 commit comments