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  * @key stress randomness
27  *
28  * @summary converted from VM Testbase nsk/monitoring/ThreadMXBean/ThreadInfo/Multi/Multi001.
29  * VM Testbase keywords: [monitoring, stress, stressopt, feature_136, nonconcurrent, vm6, quarantine]
30  * VM Testbase comments: 7187073
31  *
32  * @library /vmTestbase
33  *          /test/lib
34  * @run main/othervm nsk.monitoring.ThreadMXBean.ThreadInfo.Multi.Multi001.Multi001
35  */
36 
37 package nsk.monitoring.ThreadMXBean.ThreadInfo.Multi.Multi001;
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 import nsk.share.test.Stresser;
45 
46 /**
47  * This test starts huge number of scenarios of different types. Each
48  * thread is then brought into pre-defined state and ThreadInfo
49  * information obtained from ThreadMXBean is verified. This is repeated
50  * several times.
51  */
52 public class Multi001 extends MonitoringTestBase implements RunParamsAware {
53         private RunParams runParams;
54         private ThreadMXBean thread;
55         private int scenarioCount;
56         private ThreadMonitoringScenarioFactory scenarioFactory;
57         private int iterations = 3;
58         private int maxDepth = 200;
59 
runOne()60         private void runOne() {
61                 ThreadMonitoringScenario scenario = new MultiScenario(scenarioFactory, scenarioCount);
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 
run()78         public void run() {
79                 scenarioFactory = new StandardThreadMonitoringScenarioFactory(log, maxDepth, runParams.getMediumLoadThreadsCount());
80                 thread = monitoringFactory.getThreadMXBean();
81                 //scenarioCount = runParams.getHighLoadThreadsCount();
82                 scenarioCount = scenarioFactory.getScenarioCount(runParams.getBasicLoadThreadsCount());
83                 log.info("Scenario count: " + scenarioCount);
84                 Stresser stresser = new Stresser(runParams.getStressOptions());
85                 try {
86                         stresser.start(iterations);
87                         while (stresser.iteration());
88                                 runOne();
89                 } finally {
90                         stresser.finish();
91                 }
92                 log.info("TEST PASSED");
93         }
94 
setRunParams(RunParams runParams)95         public void setRunParams(RunParams runParams) {
96                 this.runParams = runParams;
97         }
98 
main(String[] args)99         public static void main(String[] args) {
100                 Monitoring.runTest(new Multi001(), args);
101         }
102 }
103