1 /* 2 * Copyright (c) 2007, 2020, 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 * @test 26 * 27 * @summary converted from VM Testbase nsk/monitoring/ThreadMXBean/ThreadInfo/RunningThread/RunningThread001. 28 * VM Testbase keywords: [quick, monitoring, feature_136, vm6] 29 * 30 * @library /vmTestbase 31 * /test/lib 32 * @run main/othervm 33 * nsk.monitoring.ThreadMXBean.ThreadInfo.RunningThread.RunningThread001.RunningThread001 34 * -scenarioType=running 35 */ 36 37 package nsk.monitoring.ThreadMXBean.ThreadInfo.RunningThread.RunningThread001; 38 39 import java.lang.management.*; 40 import nsk.share.runner.*; 41 import nsk.monitoring.share.*; 42 import nsk.monitoring.share.thread.*; 43 import nsk.share.TestFailure; 44 45 /** 46 * This test starts huge number of threads of different types. Each 47 * thread is then brought into pre-defined state and ThreadInfo 48 * information obtained from ThreadMXBean is verified. This is repeated 49 * several times. 50 */ 51 public class RunningThread001 extends MonitoringTestBase implements RunParamsAware, ScenarioTypeAware { 52 private RunParams runParams; 53 private ThreadMXBean thread; 54 private int threadCount; 55 private ThreadMonitoringScenarioFactory scenarioFactory; 56 private String scenarioType; 57 private int iterations; 58 private int maxDepth = 200; 59 runOne()60 private void runOne() { 61 ThreadMonitoringScenario scenario = scenarioFactory.createScenario(scenarioType); 62 try { 63 log.info("Starting: " + scenario); 64 scenario.begin(); 65 scenario.waitState(); 66 log.info("State reached"); 67 log.info("Checking: " + scenario); 68 scenario.check(thread); 69 } finally { 70 log.info("Finishing: " + scenario); 71 scenarioFactory.finish(); 72 scenario.finish(); 73 log.info("Ending: " + scenario); 74 scenario.end(); 75 } 76 77 } 78 run()79 public void run() { 80 thread = monitoringFactory.getThreadMXBean(); 81 scenarioFactory = new StandardThreadMonitoringScenarioFactory(log, maxDepth, runParams.getMediumLoadThreadsCount()); 82 iterations = argHandler.getIterations(); 83 for (int i = 0; i < iterations; ++i) 84 runOne(); 85 log.info("TEST PASSED"); 86 } 87 setRunParams(RunParams runParams)88 public void setRunParams(RunParams runParams) { 89 this.runParams = runParams; 90 } 91 setScenarioType(String scenarioType)92 public void setScenarioType(String scenarioType) { 93 this.scenarioType = scenarioType; 94 } 95 main(String[] args)96 public static void main(String[] args) { 97 Monitoring.runTest(new RunningThread001(), args); 98 } 99 } 100