test/hotspot/jtreg/vmTestbase/nsk/monitoring/MemoryNotificationInfo/from/from001.java
author iignatyev
Wed, 02 May 2018 16:43:56 -0700
changeset 49958 cc29d7717e3a
permissions -rw-r--r--
8199375: [TESTBUG] Open source vm testbase monitoring tests Reviewed-by: kvn, ihse, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49958
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     1
/*
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     4
 *
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     8
 *
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    14
 *
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    18
 *
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    21
 * questions.
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    22
 */
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    23
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    24
package nsk.monitoring.MemoryNotificationInfo.from;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    25
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    26
import java.lang.management.*;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    27
import javax.management.*;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    28
import javax.management.openmbean.*;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    29
import java.util.List;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    30
import java.util.concurrent.atomic.AtomicReference;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    31
import java.util.concurrent.SynchronousQueue;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    32
import nsk.share.*;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    33
import nsk.share.gc.Algorithms;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    34
import nsk.share.gc.Memory;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    35
import nsk.share.gc.gp.GarbageUtils;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    36
import nsk.monitoring.share.*;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    37
import nsk.share.test.Stresser;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    38
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    39
public class from001 {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    40
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    41
    private static boolean testFailed = false;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    42
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    43
    public static void main(String[] args) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    44
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    45
        ArgumentHandler argHandler = new ArgumentHandler(args);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    46
        Log log = new Log(System.out, argHandler);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    47
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    48
        log.display("MemoryNotificationInfo/from/from001/from001.java test started.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    49
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    50
        MemoryMonitor monitor = Monitor.getMemoryMonitor(log, argHandler);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    51
        MBeanServer mbs = Monitor.getMBeanServer();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    52
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    53
        // 1. Check null CompositeData - null must be returned
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    54
        MemoryNotificationInfo result = MemoryNotificationInfo.from(null);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    55
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    56
        if (result != null) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    57
            log.complain("FAILURE 1.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    58
            log.complain("MemoryNotificationInfo.from(null) returned " + result
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    59
                      + ", expected: null.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    60
            testFailed = true;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    61
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    62
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    63
        log.display("null CompositeData check passed.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    64
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    65
        // 2. Check CompositeData that doest not represnt
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    66
        // MemoryNotificationInfo - IllegalArgumentException must be thrown
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    67
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    68
        ObjectName mbeanObjectName = null;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    69
        CompositeData cdata = null;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    70
        try {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    71
            mbeanObjectName = new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    72
            cdata = (CompositeData )mbs.getAttribute(mbeanObjectName,
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    73
                                                                "HeapMemoryUsage");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    74
        } catch (Exception e) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    75
            log.complain("Unexpected exception " + e);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    76
            e.printStackTrace(log.getOutStream());
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    77
            testFailed = true;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    78
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    79
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    80
        try {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    81
            result = MemoryNotificationInfo.from(cdata);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    82
            log.complain("FAILURE 2.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    83
            log.complain("MemoryNotificationInfo.from(CompositeData) returned "
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    84
                      + result + ", expected: IllegalArgumentException.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    85
            testFailed = true;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    86
        } catch (IllegalArgumentException e) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    87
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    88
            // Expected: CompositeData doest not represnt MemoryNotificationInfo
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    89
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    90
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    91
        log.display("check for CompositeData doest not represnt MemoryNotificationInfo passed.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    92
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    93
        // 3. Check correct CompositeData
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    94
        Object poolObject = null;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    95
        try {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    96
            mbeanObjectName = new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    97
            mbs.addNotificationListener(mbeanObjectName, new from001Listener(),
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    98
                                                              null, null);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
    99
            List<?> pools = monitor.getMemoryPoolMBeans();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   100
            if (pools.isEmpty()) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   101
               log.complain("No Memory Pool Beans found. Test case will hang/fail.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   102
               testFailed = true;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   103
            }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   104
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   105
            for (int i = 0; i < pools.size(); i++) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   106
                Object pool = pools.get(i);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   107
                if (monitor.isUsageThresholdSupported(pool)) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   108
                    if (monitor.getType(pool).equals(MemoryType.HEAP)) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   109
                        poolObject = pool;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   110
                        monitor.setUsageThreshold(pool, 1);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   111
                        log.display("Usage threshold set for pool :" + poolObject);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   112
                        break;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   113
                    }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   114
                }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   115
            }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   116
        } catch (Exception e) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   117
            log.complain("Unexpected exception " + e);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   118
            e.printStackTrace(log.getOutStream());
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   119
            testFailed = true;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   120
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   121
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   122
        if (testFailed) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   123
            throw new TestFailure("TEST FAILED. See log.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   124
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   125
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   126
        // eat memory just to emmit notification
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   127
        Stresser stresser = new Stresser(args) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   128
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   129
            @Override
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   130
            public boolean continueExecution() {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   131
                return from001Listener.data.get() == null
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   132
                        && super.continueExecution();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   133
            }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   134
        };
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   135
        stresser.start(0);// we use timeout, not iterations
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   136
        GarbageUtils.eatMemory(stresser);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   137
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   138
        boolean messageNotRecieved = true;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   139
        while(messageNotRecieved) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   140
            try {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   141
                from001Listener.queue.take();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   142
                messageNotRecieved = false;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   143
            } catch (InterruptedException e) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   144
                messageNotRecieved = true;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   145
            }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   146
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   147
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   148
        result = MemoryNotificationInfo.from(from001Listener.data.get());
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   149
        try {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   150
           ObjectName poolObjectName = new ObjectName(monitor.getName(poolObject));
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   151
           ObjectName resultObjectName = new ObjectName(
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   152
                     ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE +
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   153
                     ",name=" + result.getPoolName());
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   154
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   155
           log.display("poolObjectName : " + poolObjectName +
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   156
                              " resultObjectName : " + resultObjectName);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   157
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   158
           if (!poolObjectName.equals(resultObjectName)) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   159
              log.complain("FAILURE 3.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   160
              log.complain("Wrong pool name : " + resultObjectName +
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   161
                           ", expected : " + poolObjectName);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   162
              testFailed = true;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   163
           }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   164
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   165
        } catch (Exception e) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   166
            log.complain("Unexpected exception " + e);
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   167
            e.printStackTrace(log.getOutStream());
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   168
            testFailed = true;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   169
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   170
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   171
        if (testFailed) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   172
            throw new TestFailure("TEST FAILED. See log.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   173
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   174
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   175
        log.display("Test passed.");
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   176
    }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   177
}
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   178
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   179
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   180
class from001Listener implements NotificationListener {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   181
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   182
    static AtomicReference<CompositeData> data = new AtomicReference<CompositeData>();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   183
    static SynchronousQueue<Object> queue = new SynchronousQueue<Object>();
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   184
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   185
    public void handleNotification(Notification notification, Object handback) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   186
        if (data.get() != null)
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   187
            return;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   188
        data.set((CompositeData) notification.getUserData());
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   189
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   190
        boolean messageNotSent = true;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   191
        while(messageNotSent){
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   192
            try {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   193
                queue.put(new Object());
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   194
                messageNotSent = false;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   195
            } catch(InterruptedException e) {
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   196
                messageNotSent = true;
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   197
            }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   198
        }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   199
    }
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   200
cc29d7717e3a 8199375: [TESTBUG] Open source vm testbase monitoring tests
iignatyev
parents:
diff changeset
   201
}