summaryrefslogtreecommitdiff
path: root/java/systests/src/main/java/org/apache/qpid/server/logging/ManagementLoggingTest.java
blob: 8b7c881a3245feb58c1a785e41ac119e4e8d77ec (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
/*
 *
 * 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.server.logging;

import junit.framework.AssertionFailedError;
import org.apache.qpid.util.LogMonitor;

import java.util.List;
import java.io.File;

/**
 * Management Console Test Suite
 *
 * The Management Console test suite validates that the follow log messages as specified in the Functional Specification.
 *
 * This suite of tests validate that the management console messages occur correctly and according to the following format:
 *
 * MNG-1001 : Startup
 * MNG-1002 : Starting : <service> : Listening on port <Port>
 * MNG-1003 : Shutting down : <service> : port <Port>
 * MNG-1004 : Ready
 * MNG-1005 : Stopped
 * MNG-1006 : Using SSL Keystore : <path>
 */
public class ManagementLoggingTest extends AbstractTestLogging
{
    private static final String MNG_PREFIX = "MNG-";

    public void setUp() throws Exception
    {
        // We either do this here or have a null check in tearDown.
        // As when this test is run against profiles other than java it will NPE
        _monitor = new LogMonitor(_outputFile);
        //We explicitly do not call super.setUp as starting up the broker is
        //part of the test case.

    }

    /**
     * Description:
     * Using the startup configuration validate that the management startup
     * message is logged correctly.
     * Input:
     * Standard configuration with management enabled
     * Output:
     *
     * <date> MNG-1001 : Startup
     *
     * Constraints:
     * This is the FIRST message logged by MNG
     * Validation Steps:
     *
     * 1. The BRK ID is correct
     * 2. This is the FIRST message logged by MNG
     */
    public void testManagementStartupEnabled() throws Exception
    {
        // This test only works on external java brokers due to the fact that
        // Management is disabled on InVM brokers.
        if (isJavaBroker() && isExternalBroker())
        {
            //Ensure management is on
            setConfigurationProperty("management.enabled", "true");

            startBroker();

            // Now we can create the monitor as _outputFile will now be defined
            _monitor = new LogMonitor(_outputFile);

            List<String> results = _monitor.findMatches(MNG_PREFIX);
            try
            {
                // Validation

                assertTrue("MNGer message not logged", results.size() > 0);

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

                //1
                validateMessageID("MNG-1001", log);

                //2
                results = _monitor.findMatches("MNG-1001");
                assertEquals("More than one startup message found.",
                             1, results.size());

                //3
                assertEquals("Startup log message is not 'Startup'.", "Startup",
                             getMessageString(log));
            }
            catch (AssertionFailedError afe)
            {
                System.err.println("Log Dump:");
                for (String log : results)
                {
                    System.err.println(log);
                }
                throw afe;
            }
        }
    }

    /**
     * Description:
     * Verify that when management is disabled in the configuration file the
     * startup message is not logged.
     * Input:
     * Standard configuration with management disabled
     * Output:
     * NO MNG messages
     * Validation Steps:
     *
     * 1. Validate that no MNG messages are produced.
     */
    public void testManagementStartupDisabled() throws Exception
    {
        // This test only works on external java brokers due to the fact that
        // Management is disabled on InVM brokers.
        if (isJavaBroker() && isExternalBroker())
        {
            //Ensure management is off
            setConfigurationProperty("management.enabled", "false");

            startBroker();

            // Now we can create the monitor as _outputFile will now be defined
            _monitor = new LogMonitor(_outputFile);

            List<String> results = _monitor.findMatches(MNG_PREFIX);
            try
            {
                // Validation

                assertEquals("MNGer messages logged", 0, results.size());
            }
            catch (AssertionFailedError afe)
            {
                System.err.println("Log Dump:");
                for (String log : results)
                {
                    System.err.println(log);
                }
                throw afe;
            }
        }
    }

    /**
     * The two MNG-1002 messages are logged at the same time so lets test them
     * at the same time.
     *
     * Description:
     * Using the default configuration validate that the RMI Registry socket is
     * correctly reported as being opened
     *
     * Input:
     * The default configuration file
     * Output:
     *
     * <date> MESSAGE MNG-1002 : Starting : RMI Registry : Listening on port 8999
     *
     * Constraints:
     * The RMI ConnectorServer and Registry log messages do not have a prescribed order
     * Validation Steps:
     *
     * 1. The MNG ID is correct
     * 2. The specified port is the correct '8999'
     *
     * Description:
     * Using the default configuration validate that the RMI ConnectorServer
     * socket is correctly reported as being opened
     *
     * Input:
     * The default configuration file
     * Output:
     *
     * <date> MESSAGE MNG-1002 : Starting : RMI ConnectorServer : Listening on port 9099
     *
     * Constraints:
     * The RMI ConnectorServer and Registry log messages do not have a prescribed order
     * Validation Steps:
     *
     * 1. The MNG ID is correct
     * 2. The specified port is the correct '9099'
     */
    public void testManagementStartupRMIEntries() throws Exception
    {
        // This test only works on external java brokers due to the fact that
        // Management is disabled on InVM brokers.
        if (isJavaBroker() && isExternalBroker())
        {
            //Ensure management is on
            setConfigurationProperty("management.enabled", "true");

            startBroker();

            // Now we can create the monitor as _outputFile will now be defined
            _monitor = new LogMonitor(_outputFile);

            List<String> results = _monitor.findMatches("MNG-1002");
            try
            {
                // Validation

                assertEquals("MNGer message not logged expected message", 2, results.size());

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

                //1
                validateMessageID("MNG-1002", log);

                // Validate we only have one MNG-1002
                results = _monitor.findMatches("MNG-1002");
                assertEquals("More than two RMI entries found.",
                             2, results.size());

                // We expect the RMI Server port to be 100 higher than
                // the RMIConnector Server Port                
                int mPort = getPort() + (DEFAULT_MANAGEMENT_PORT - DEFAULT_PORT);
                assertTrue("RMI Registry port not as expected(" + mPort + ").:" + getMessageString(log),
                           getMessageString(log).endsWith(String.valueOf(mPort)));

                log = getLog(results.get(1));

                //1
                validateMessageID("MNG-1002", log);

                // We expect the RMIConnector Server port to be 100 higher than
                // the RMI Server Port
                mPort = getPort() + (DEFAULT_MANAGEMENT_PORT - DEFAULT_PORT) + 100;
                assertTrue("RMI ConnectorServer port not as expected(" + mPort + ").:" + getMessageString(log),
                           getMessageString(log).endsWith(String.valueOf(mPort)));
            }
            catch (AssertionFailedError afe)
            {
                System.err.println("Log Dump:");
                for (String log : results)
                {
                    System.err.println(log);
                }
                throw afe;
            }
        }
    }
    /**
     * Description:
     * Using the default configuration with SSL enabled for the management port the SSL Keystore path should be reported via MNG-1006
     * Input:
     * Management SSL enabled default configuration.
     * Output:
     *
     * <date> MESSAGE MNG-1006 : Using SSL Keystore : test_resources/ssl/keystore.jks
     *
     * Validation Steps:
     *
     * 1. The MNG ID is correct
     * 2. The keystore path is as specified in the configuration
     */
    public void testManagementStartupSSLKeystore() throws Exception
    {
        // This test only works on external java brokers due to the fact that
        // Management is disabled on InVM brokers.
        if (isJavaBroker() && isExternalBroker())
        {
            //Ensure management is on
            setConfigurationProperty("management.enabled", "true");
            // This test requires we have an ssl connection
            setConfigurationProperty("management.ssl.enabled", "true");

            startBroker();

            // Now we can create the monitor as _outputFile will now be defined
            _monitor = new LogMonitor(_outputFile);

            List<String> results = _monitor.findMatches("MNG-1006");
            try
            {
                // Validation

                assertTrue("MNGer message not logged", results.size() > 0);

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

                //1
                validateMessageID("MNG-1006", log);

                // Validate we only have one MNG-1002
                results = _monitor.findMatches("MNG-1006");
                assertEquals("More than one SSL Keystore entry found.",
                             1, results.size());

                // We expect the RMIConnector Server port to be 100 higher than
                // the RMI Server Port
                assertTrue("SSL Keystore entry expected.:" + getMessageString(log),
                           getMessageString(log).endsWith(new File(getConfigurationStringProperty("management.ssl.keyStorePath")).getName()));
            }
            catch (AssertionFailedError afe)
            {
                System.err.println("Log Dump:");
                for (String log : results)
                {
                    System.err.println(log);
                }
                throw afe;
            }
        }

    }
}