summaryrefslogtreecommitdiff
path: root/qpid/java/systests/src/main/java/org/apache/qpid/management/jmx/ManagementActorLoggingTest.java
blob: 19657ef39617e0023a9da3febb9111b547f076bc (plain)
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
/*
 *
 * 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.qpid.management.jmx;

import org.apache.qpid.management.common.mbeans.ManagedBroker;
import org.apache.qpid.management.common.mbeans.ManagedConnection;
import org.apache.qpid.management.common.mbeans.ManagedExchange;
import org.apache.qpid.server.logging.AbstractTestLogging;
import org.apache.qpid.server.logging.subjects.AbstractTestLogSubject;
import org.apache.qpid.test.utils.JMXTestUtils;

import javax.jms.Connection;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
import javax.management.JMException;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * Test class to test if any change in the broker JMX code is affesting the management console
 * There are some hardcoding of management feature names and parameter names to create a customized
 * look in the console.
 */
public class ManagementActorLoggingTest extends AbstractTestLogging
{
    private JMXTestUtils _jmxUtils;
    private boolean _closed = false;
    private static final String USER = "admin";

    @Override
    public void setUp() throws Exception
    {
        _jmxUtils = new JMXTestUtils(this, USER, USER);
        _jmxUtils.setUp();
        super.setUp();
        _jmxUtils.open();
    }

    @Override
    public void tearDown() throws Exception
    {
        if(!_closed)
        {
            _jmxUtils.close();
        }
        super.tearDown();
    }

    /**
     * Description:
     * When a JMX Management connection is made then this will be logged out.
     *
     * Input:
     *
     * 1. Running Broker
     * 2. Connect Management client via JMX
     * Output:
     *
     * <date> MNG-1007 : Open <user>
     *
     * Validation Steps:
     * 1. The MNG ID is correct
     * 2. The user is correct
     *
     * On connection close a MNG-1008 is expected
     *
     * * <date> MNG-1008 : Close
     *
     * Validation Steps:
     * 1. The MNG ID is correct
     *
     * @throws java.io.IOException - if there is a problem reseting the log monitor
     */
    public void testJMXManagementConsoleConnection() throws IOException
    {
        List<String> results = waitAndFindMatches("MNG-1007");

        assertEquals("Unexpected Management Connection count", 1, results.size());

        String log = getLogMessage(results, 0);

        validateMessageID("MNG-1007", log);

        assertTrue("User not in log message:" + log, log.endsWith(USER));
        // Extract the id from the log string
        //  MESSAGE [mng:1(rmi://169.24.29.116)] MNG-1007 : Open : User admin
        int connectionID = Integer.parseInt(fromActor(getLog(results.get(0))).charAt(4) + "");

        results = findMatches("MNG-1008");

        assertEquals("Unexpected Management Connection close count", 0, results.size());

        _jmxUtils.close();
        _closed  = true;
        
        results = waitAndFindMatches("MNG-1008");

        assertEquals("Unexpected Management Connection count", 1, results.size());

        assertEquals("Close does not have same id as open,", connectionID,
                     Integer.parseInt(fromActor(getLog(results.get(0))).charAt(4) + ""));
    }

    /**
     * Description:
     * When a connected client has its connection closed via the Management Console this will be logged as a CON-1002 message.
     * Input:
     *
     * 1. Running Broker
     * 2. Connected Client
     * 3. Connection is closed via Management Console
     * Output:
     *
     * <date> CON-1002 : Close
     *
     * Validation Steps:
     * 4. The CON ID is correct
     * 5. This must be the last CON message for the Connection
     * 6. It must be preceded by a CON-1001 for this Connection
     *
     * @throws Exception           - {@see ManagedConnection.closeConnection and #getConnection}
     * @throws java.io.IOException - if there is a problem reseting the log monitor
     */
    public void testConnectionCloseViaManagement() throws IOException, Exception
    {
        //Create a connection to the broker
        Connection connection = getConnection();

        // Monitor the connection for an exception being thrown
        // this should be a DisconnectionException but it is not this tests
        // job to valiate that. Only use the exception as a synchronisation
        // to check the log file for the Close message
        final CountDownLatch exceptionReceived = new CountDownLatch(1);
        connection.setExceptionListener(new ExceptionListener()
        {
            public void onException(JMSException e)
            {
                //Failover being attempted.
                exceptionReceived.countDown();
            }
        });

        //Remove the connection close from any 0-10 connections
        _monitor.reset();

        // Get a managedConnection
        ManagedConnection mangedConnection = _jmxUtils.getManagedObject(ManagedConnection.class, "org.apache.qpid:type=VirtualHost.Connection,*");

        //Close the connection
        mangedConnection.closeConnection();

        //Wait for the connection to close
        assertTrue("Timed out waiting for conneciton to report close",
                   exceptionReceived.await(2, TimeUnit.SECONDS));

        //Validate results
        List<String> results = waitAndFindMatches("CON-1002");

        assertEquals("Unexpected Connection Close count", 1, results.size());
    }

    /**
     * Description:
     * Exchange creation is possible from the Management Console.
     * When an exchanged is created in this way then a EXH-1001 create message
     * is expected to be logged.
     * Input:
     *
     * 1. Running broker
     * 2. Connected Management Console
     * 3. Exchange Created via Management Console
     * Output:
     *
     * EXH-1001 : Create : [Durable] Type:<value> Name:<value>
     *
     * Validation Steps:
     * 4. The EXH ID is correct
     * 5. The correct tags are present in the message based on the create options
     *
     * @throws java.io.IOException          - if there is a problem reseting the log monitor
     * @throws javax.management.JMException - {@see #createQueue and ManagedExchange.deleteQueue}
     */
    public void testCreateExchangeDirectTransientViaManagementConsole() throws IOException, JMException
    {
        _monitor.reset();

        _jmxUtils.createExchange("test", getName(), "direct", false);

        // Validate

        //1 - ID is correct
        List<String> results = waitAndFindMatches("EXH-1001");

        assertEquals("More than one exchange creation found", 1, results.size());

        String log = getLogMessage(results, 0);

        // Validate correct exchange name
        assertTrue("Incorrect exchange name created:" + log, log.endsWith(getName()));

        // Validate it was a management actor.
        String actor = fromActor(log);
        assertTrue("Actor is not a manangement actor:" + actor, actor.startsWith("mng"));
    }

    public void testCreateExchangeTopicTransientViaManagementConsole() throws IOException, JMException
    {
        //Remove any previous exchange declares
        _monitor.reset();

        _jmxUtils.createExchange("test", getName(), "topic", false);

        // Validate

        //1 - ID is correct
        List<String> results = waitAndFindMatches("EXH-1001");

        assertEquals("More than one exchange creation found", 1, results.size());

        String log = getLogMessage(results, 0);

        // Validate correct exchange name
        assertTrue("Incorrect exchange name created:" + log, log.endsWith(getName()));

        // Validate it was a management actor.
        String actor = fromActor(log);
        assertTrue("Actor is not a manangement actor:" + actor, actor.startsWith("mng"));

    }

    public void testCreateExchangeFanoutTransientViaManagementConsole() throws IOException, JMException
    {
        //Remove any previous exchange declares
        _monitor.reset();

        _jmxUtils.createExchange("test", getName(), "fanout", false);

        // Validate

        //1 - ID is correct
        List<String> results = waitAndFindMatches("EXH-1001");

        assertEquals("More than one exchange creation found", 1, results.size());

        String log = getLogMessage(results, 0);

        // Validate correct exchange name
        assertTrue("Incorrect exchange name created:" + log, log.endsWith(getName()));

        // Validate it was a management actor.
        String actor = fromActor(log);
        assertTrue("Actor is not a manangement actor:" + actor, actor.startsWith("mng"));

    }

    public void testCreateExchangeHeadersTransientViaManagementConsole() throws IOException, JMException
    {
        //Remove any previous exchange declares
        _monitor.reset();

        _jmxUtils.createExchange("test", getName(), "headers", false);

        // Validate

        //1 - ID is correct
        List<String> results = waitAndFindMatches("EXH-1001");

        assertEquals("More than one exchange creation found", 1, results.size());

        String log = getLogMessage(results, 0);

        // Validate correct exchange name
        assertTrue("Incorrect exchange name created:" + log, log.endsWith(getName()));

        // Validate it was a management actor.
        String actor = fromActor(log);
        assertTrue("Actor is not a manangement actor:" + actor, actor.startsWith("mng"));

    }

    /**
     * Description:
     * Queue creation is possible from the Management Console. When a queue is created in this way then a QUE-1001 create message is expected to be logged.
     * Input:
     *
     * 1. Running broker
     * 2. Connected Management Console
     * 3. Queue Created via Management Console
     * Output:
     *
     * <date> QUE-1001 : Create : Transient Owner:<name>
     *
     * Validation Steps:
     * 4. The QUE ID is correct
     * 5. The correct tags are present in the message based on the create options
     *
     * @throws java.io.IOException          - if there is a problem reseting the log monitor
     * @throws javax.management.JMException - {@see #createQueue and ManagedExchange.deleteQueue}
     */
    public void testCreateQueueTransientViaManagementConsole() throws IOException, JMException
    {
        //Remove any previous queue declares
        _monitor.reset();

        _jmxUtils.createQueue("test", getName(), null, false);

        // Validate

        List<String> results = waitAndFindMatches("QUE-1001");

        assertEquals("More than one queue creation found", 1, results.size());

        String log = getLogMessage(results, 0);

        // Validate correct queue name
        String subject = fromSubject(log);
        assertEquals("Incorrect queue name created", getName(), AbstractTestLogSubject.getSlice("qu", subject));

        // Validate it was a management actor.
        String actor = fromActor(log);
        assertTrue("Actor is not a manangement actor:" + actor, actor.startsWith("mng"));
    }

    /**
     * Description:
     * The ManagementConsole can be used to delete a queue. When this is done a QUE-1002 Deleted message must be logged.
     * Input:
     *
     * 1. Running Broker
     * 2. Queue created on the broker with no subscribers
     * 3. Management Console connected
     * 4. Queue is deleted via Management Console
     * Output:
     *
     * <date> QUE-1002 : Deleted
     *
     * Validation Steps:
     * 5. The QUE ID is correct
     *
     * @throws java.io.IOException          - if there is a problem reseting the log monitor
     * @throws javax.management.JMException - {@see #createQueue and ManagedExchange.deleteQueue}
     */
    public void testQueueDeleteViaManagementConsole() throws IOException, JMException
    {
        //Remove any previous queue declares
        _monitor.reset();

        _jmxUtils.createQueue("test", getName(), null, false);

        ManagedBroker managedBroker = _jmxUtils.getManagedBroker("test");

        managedBroker.deleteQueue(getName());

        List<String> results = waitAndFindMatches("QUE-1002");

        assertEquals("More than one queue deletion found", 1, results.size());

        String log = getLog(results.get(0));

        // Validate correct binding
        String subject = fromSubject(log);
        assertEquals("Incorrect queue named in delete", getName(), AbstractTestLogSubject.getSlice("qu", subject));

        // Validate it was a management actor.
        String actor = fromActor(log);
        assertTrue("Actor is not a manangement actor:" + actor, actor.startsWith("mng"));

    }

    /**
     * Description:
     * The binding of a Queue and an Exchange is done via a Binding. When this Binding is created via the Management Console a BND-1001 Create message will be logged.
     * Input:
     *
     * 1. Running Broker
     * 2. Connected Management Console
     * 3. Use Management Console to perform binding
     * Output:
     *
     * <date> BND-1001 : Create
     *
     * Validation Steps:
     * 4. The BND ID is correct
     * 5. This will be the first message for the given binding
     *
     * @throws java.io.IOException          - if there is a problem reseting the log monitor
     * @throws javax.management.JMException - {@see #createQueue and ManagedExchange.createNewBinding}
     */
    public void testBindingCreateOnDirectViaManagementConsole() throws IOException, JMException
    {
        //Remove any previous queue declares
        _monitor.reset();

        _jmxUtils.createQueue("test", getName(), null, false);

        ManagedExchange managedExchange = _jmxUtils.getManagedExchange("amq.direct");

        managedExchange.createNewBinding(getName(), getName());

        List<String> results = waitAndFindMatches("BND-1001");

        assertEquals("More than one bind creation found", 1, results.size());

        String log = getLogMessage(results, 0);

        // Validate correct binding
        String subject = fromSubject(log);
        assertEquals("Incorrect queue named in create", getName(), AbstractTestLogSubject.getSlice("qu", subject));
        assertEquals("Incorrect routing key in create", getName(), AbstractTestLogSubject.getSlice("rk", subject));

        // Validate it was a management actor.
        String actor = fromActor(log);
        assertTrue("Actor is not a manangement actor:" + actor, actor.startsWith("mng"));
    }

    public void testBindingCreateOnTopicViaManagementConsole() throws IOException, JMException
    {
        //Remove any previous queue declares
        _monitor.reset();

        _jmxUtils.createQueue("test", getName(), null, false);

        ManagedExchange managedExchange = _jmxUtils.getManagedExchange("amq.topic");

        managedExchange.createNewBinding(getName(), getName());

        List<String> results = waitAndFindMatches("BND-1001");

        assertEquals("More than one bind creation found", 1, results.size());

        String log = getLogMessage(results, 0);

        // Validate correct binding
        String subject = fromSubject(log);
        assertEquals("Incorrect queue named in create", getName(), AbstractTestLogSubject.getSlice("qu", subject));
        assertEquals("Incorrect routing key in create", getName(), AbstractTestLogSubject.getSlice("rk", subject));

        // Validate it was a management actor.
        String actor = fromActor(log);
        assertTrue("Actor is not a manangement actor:" + actor, actor.startsWith("mng"));
    }

    public void testBindingCreateOnFanoutViaManagementConsole() throws IOException, JMException
    {
        //Remove any previous queue declares
        _monitor.reset();

        _jmxUtils.createQueue("test", getName(), null, false);

        ManagedExchange managedExchange = _jmxUtils.getManagedExchange("amq.fanout");

        managedExchange.createNewBinding(getName(), getName());

        List<String> results = waitAndFindMatches("BND-1001");

        assertEquals("More than one bind creation found", 1, results.size());

        String log = getLogMessage(results, 0);

        // Validate correct binding
        String subject = fromSubject(log);
        assertEquals("Incorrect queue named in create", getName(), AbstractTestLogSubject.getSlice("qu", subject));
        assertEquals("Incorrect routing key in create", getName(), AbstractTestLogSubject.getSlice("rk", subject));

        // Validate it was a management actor.
        String actor = fromActor(log);
        assertTrue("Actor is not a manangement actor:" + actor, actor.startsWith("mng"));
    }

    /**
     * Description:
     * Bindings can be deleted so that a queue can be rebound with a different set of values. This can be performed via the Management Console
     * Input:
     *
     * 1. Running Broker
     * 2. Management Console connected
     * 3. Management Console is used to perform unbind.
     * Output:
     *
     * <date> BND-1002 : Deleted
     *
     * Validation Steps:
     * 4. The BND ID is correct
     * 5. There must have been a BND-1001 Create message first.
     * 6. This will be the last message for the given binding
     *
     * @throws java.io.IOException          - if there is a problem reseting the log monitor or an issue with the JMX Connection
     * @throws javax.management.JMException - {@see #createExchange and ManagedBroker.unregisterExchange}
     */
    public void testUnRegisterExchangeViaManagementConsole() throws IOException, JMException
    {
        //Remove any previous queue declares
        _monitor.reset();

        _jmxUtils.createExchange("test", getName(), "direct", false);

        ManagedBroker managedBroker = _jmxUtils.getManagedBroker("test");

        managedBroker.unregisterExchange(getName());

        List<String> results = waitAndFindMatches("EXH-1002");

        assertEquals("More than one exchange deletion found", 1, results.size());

        String log = getLog(results.get(0));

        // Validate correct binding
        String subject = fromSubject(log);
        assertEquals("Incorrect exchange named in delete", "direct/" + getName(), AbstractTestLogSubject.getSlice("ex", subject));

        // Validate it was a management actor.
        String actor = fromActor(log);
        assertTrue("Actor is not a manangement actor:" + actor, actor.startsWith("mng"));
    }

}