]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - cddl/contrib/opensolaris/cmd/dtrace/test/tst/common/java_api/src/TestMaxConsumers.java
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / cddl / contrib / opensolaris / cmd / dtrace / test / tst / common / java_api / src / TestMaxConsumers.java
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  * ident        "%Z%%M% %I%     %E% SMI"
27  */
28
29 import org.opensolaris.os.dtrace.*;
30
31 /**
32  * Regression for 6506495 -DJAVA_DTRACE_MAX_CONSUMERS=N for any N < 8
33  * is treated as if it were 8.
34  */
35 public class TestMaxConsumers {
36     static final String MAX_CONSUMERS_PROPERTY_NAME =
37             "JAVA_DTRACE_MAX_CONSUMERS";
38
39     static Integer
40     getIntegerProperty(String name)
41     {
42         Integer value = null;
43         String property = System.getProperty(name);
44         if (property != null && property.length() != 0) {
45             try {
46                 value = Integer.parseInt(property);
47             } catch (NumberFormatException e) {
48                 e.printStackTrace();
49             }
50         }
51         return value;
52     }
53
54     public static void
55     main(String[] args)
56     {
57         Integer property = getIntegerProperty(MAX_CONSUMERS_PROPERTY_NAME);
58         int max = (property == null ? 0 : property);
59         int n = (property == null ? 11 : (max < 1 ? 1 : max));
60
61         Consumer[] consumers = new Consumer[n];
62         try {
63             for (int i = 0; i < n; ++i) {
64                 consumers[i] = new LocalConsumer();
65                 consumers[i].open();
66             }
67             for (int i = 0; i < n; ++i) {
68                 consumers[i].close();
69             }
70             for (int i = 0; i < n; ++i) {
71                 consumers[i] = new LocalConsumer();
72                 consumers[i].open();
73             }
74         } catch (Exception e) {
75             e.printStackTrace();
76             System.exit(1);
77         }
78
79         try {
80             Consumer consumer = new LocalConsumer();
81             consumer.open();
82             if (max > 0) {
83                 System.out.println("Error: " + (max + 1) + " > " +
84                         MAX_CONSUMERS_PROPERTY_NAME);
85             } else {
86                 System.out.println("Success");
87             }
88             consumer.close();
89         } catch (Exception e) {
90             System.out.println("Success");
91         } finally {
92             for (int i = 0; i < n; ++i) {
93                 consumers[i].close();
94             }
95         }
96     }
97 }