1/*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/**
25 * A JVM with JDP off should not send multicast JDP packets at all.
26 * com.sun.management.jmxremote.autodiscovery=false should be respected.
27 */
28
29import java.net.SocketTimeoutException;
30import java.util.Map;
31
32public class JdpOffTestCase extends JdpTestCase {
33
34    private boolean testPassed = false;
35
36    public JdpOffTestCase(ClientConnection connection) {
37        super(connection);
38    }
39
40    /**
41     * Subclasses: JdpOnTestCase and JdpOffTestCase have different messages.
42     */
43    @Override
44    protected String initialLogMessage() {
45        return "Expecting NOT to receive any packets with jdp.name=" + connection.instanceName;
46    }
47
48    /**
49     * The socket has not received anything, and this is the expected behavior.
50     */
51    @Override
52    protected void onSocketTimeOut(SocketTimeoutException e) throws Exception {
53        log.fine("No packages received. Test passed!");
54        testPassed = true;
55    }
56
57
58    /**
59     * This method is executed after a correct Jdp packet, coming from this VM has been received.
60     *
61     * @param payload A dictionary containing the data if the received Jdp packet.
62     */
63    @Override
64    protected void packetFromThisVMReceived(Map<String, String> payload) throws Exception {
65        String message = "Jdp packet from this VM received. This should not happen!";
66        log.severe(message);
67        throw new Exception(message);
68    }
69
70
71    /**
72     * The test should stop after the socket has timed out. See onSocketTimeOut {@link}.
73     */
74    @Override
75    protected boolean shouldContinue() {
76        return !testPassed;
77    }
78
79    public static void main(String[] args) throws Exception {
80        JdpTestCase client = new JdpOffTestCase(new ClientConnection());
81        client.run();
82    }
83
84}
85