jdk/test/com/sun/jmx/snmp/TimeTicksWrapping.java
author sherman
Tue, 22 Jun 2010 14:04:36 -0400
changeset 5962 0913689fd3a0
parent 5506 202f599c92aa
permissions -rw-r--r--
6963156: TEST_BUG: Several tests under sun/nio/cs failed Summary: Updated the test cases and removed them from ProblemList.txt Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2285
diff changeset
     2
 * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2285
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2285
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2285
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary Test that SnmpTimeTicks wraps around when it is passed a long
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *          value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @bug     4955105
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @build   TimeTicksWrapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run     main TimeTicksWrapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    32
import java.lang.reflect.Constructor;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    33
import java.lang.reflect.InvocationTargetException;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    34
import java.lang.reflect.Method;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public class TimeTicksWrapping {
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    37
    // We use an SnmpTimeticksBuilder in order to adapt this test case to a
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    38
    // configuration where the SNMP packages are not present in rt.jar.
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    39
    //
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    40
    public static final class SnmpTimeticksBuilder {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    41
        public static final long   MAX_VALUE = 0x0ffffffffL;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    42
        public static final String SNMP_TIME_TICKS_CLASS_NAME =
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    43
            "com.sun.jmx.snmp.SnmpTimeticks";
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    44
        private static final Class<?> SNMP_TIME_TICKS_CLASS;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    45
        private static final Constructor<?> SNMP_long_CTOR;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    46
        private static final Constructor<?> SNMP_LONG_CTOR;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    47
        private static final Method SNMP_LONG_VALUE;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    48
        static {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    49
            Class<?> snmpTimeTicksClass;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    50
            try {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    51
                snmpTimeTicksClass =
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    52
                    Class.forName(SNMP_TIME_TICKS_CLASS_NAME, true, null);
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    53
            } catch (ClassNotFoundException x) {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    54
                snmpTimeTicksClass = null;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    55
                System.err.println("WARNING: can't load "+
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    56
                        SNMP_TIME_TICKS_CLASS_NAME);
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    57
            } catch (NoClassDefFoundError x) {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    58
                snmpTimeTicksClass = null;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    59
                System.err.println("WARNING: can't load "+
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    60
                        SNMP_TIME_TICKS_CLASS_NAME);
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    61
            }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    62
            SNMP_TIME_TICKS_CLASS = snmpTimeTicksClass;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    63
            if (SNMP_TIME_TICKS_CLASS != null) {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    64
                try {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    65
                  SNMP_long_CTOR =
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    66
                          SNMP_TIME_TICKS_CLASS.getConstructor(long.class);
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    67
                } catch (Exception x) {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    68
                    throw new ExceptionInInitializerError(x);
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    69
                }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    70
            } else {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    71
                SNMP_long_CTOR = null;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    72
            }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    73
            if (SNMP_TIME_TICKS_CLASS != null) {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    74
                try {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    75
                  SNMP_LONG_CTOR =
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    76
                          SNMP_TIME_TICKS_CLASS.getConstructor(Long.class);
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    77
                } catch (Exception x) {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    78
                    throw new ExceptionInInitializerError(x);
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    79
                }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    80
            } else {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    81
                SNMP_LONG_CTOR = null;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    82
            }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    83
            if (SNMP_TIME_TICKS_CLASS != null) {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    84
                try {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    85
                  SNMP_LONG_VALUE =
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    86
                          SNMP_TIME_TICKS_CLASS.getMethod("longValue");
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    87
                } catch (Exception x) {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    88
                    throw new ExceptionInInitializerError(x);
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    89
                }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    90
            } else {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    91
                SNMP_LONG_VALUE = null;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    92
            }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    93
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    94
        }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    95
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    96
        private final Object timeticks;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    97
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    98
        public SnmpTimeticksBuilder(long ticks) throws Exception {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
    99
            timeticks = newSnmpTimeticks(ticks);
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   100
        }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   101
        public SnmpTimeticksBuilder(Long ticks) throws Exception {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   102
            timeticks = newSnmpTimeticks(ticks);
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   103
        }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   104
        public long longValue() throws Exception {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   105
            return longValue(timeticks);
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   106
        }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   107
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   108
        public static boolean isSnmpPresent() {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   109
            System.out.println(TimeTicksWrapping.class.getName()+
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   110
                    ": Testing for SNMP Packages...");
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   111
            return SNMP_TIME_TICKS_CLASS != null;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   112
        }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   113
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   114
        private static Object newSnmpTimeticks(long time)
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   115
                throws Exception {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   116
            try {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   117
                return SNMP_long_CTOR.newInstance(time);
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   118
            } catch (InvocationTargetException x) {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   119
                final Throwable cause = x.getCause();
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   120
                if (cause instanceof Exception) throw (Exception) cause;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   121
                if (cause instanceof Error) throw (Error) cause;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   122
                throw x;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   123
            }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   124
        }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   125
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   126
        private static Object newSnmpTimeticks(Long time)
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   127
            throws Exception {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   128
            try {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   129
                return SNMP_LONG_CTOR.newInstance(time);
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   130
            } catch (InvocationTargetException x) {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   131
                final Throwable cause = x.getCause();
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   132
                if (cause instanceof Exception) throw (Exception) cause;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   133
                if (cause instanceof Error) throw (Error) cause;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   134
                throw x;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   135
            }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   136
        }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   137
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   138
        private static long longValue(Object o)
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   139
                throws Exception {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   140
            try {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   141
                return ((Long)SNMP_LONG_VALUE.invoke(o)).longValue();
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   142
            } catch (InvocationTargetException x) {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   143
                final Throwable cause = x.getCause();
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   144
                if (cause instanceof Exception) throw (Exception) cause;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   145
                if (cause instanceof Error) throw (Error) cause;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   146
                throw x;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   147
            }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   148
        }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   149
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   150
    }
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   151
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public static final long[] oks = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        0L, 1L, (long)Integer.MAX_VALUE, (long)Integer.MAX_VALUE*2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        (long)Integer.MAX_VALUE*2+1L, (long)Integer.MAX_VALUE*2+2L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        (long)Integer.MAX_VALUE*3,
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   156
        SnmpTimeticksBuilder.MAX_VALUE, SnmpTimeticksBuilder.MAX_VALUE+1L,
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   157
        SnmpTimeticksBuilder.MAX_VALUE*3-1L, Long.MAX_VALUE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public static final long[] kos = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        -1L, (long)Integer.MIN_VALUE, (long)Integer.MIN_VALUE*2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        (long)Integer.MIN_VALUE*2-1L, (long)Integer.MIN_VALUE*3,
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   163
        -SnmpTimeticksBuilder.MAX_VALUE, -(SnmpTimeticksBuilder.MAX_VALUE+1L),
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   164
        -(SnmpTimeticksBuilder.MAX_VALUE*3-1L), Long.MIN_VALUE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   167
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public static void main(String args[]) {
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   169
        if (!SnmpTimeticksBuilder.isSnmpPresent()) {
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   170
            System.err.println("WARNING: "+
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   171
                    SnmpTimeticksBuilder.SNMP_TIME_TICKS_CLASS_NAME+
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   172
                    " not present.");
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   173
            System.err.println(TimeTicksWrapping.class.getName()+
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   174
                    ": test skipped.");
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   175
            return;
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   176
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        try {
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   178
            SnmpTimeticksBuilder t = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            for (int i=0;i<oks.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                final long t1,t2,t3;
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   182
                t1 = (new SnmpTimeticksBuilder(oks[i])).longValue();
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   183
                t2 = (new SnmpTimeticksBuilder(new Long(oks[i]))).longValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                t3 = oks[i]%0x0100000000L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                if (t1 != t3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                    throw new Exception("Value should have wrapped: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                                        oks[i] + " expected: " + t3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                if (t2 != t3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    throw new Exception("Value should have wrapped: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                                        "Long("+oks[i]+") expected: " + t3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   192
                if (t1 > SnmpTimeticksBuilder.MAX_VALUE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    throw new Exception("Value should have wrapped " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                                        "for " + oks[i] + ": " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                                        t1 + " exceeds max: " +
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   196
                                        SnmpTimeticksBuilder.MAX_VALUE);
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   197
                if (t2 > SnmpTimeticksBuilder.MAX_VALUE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    throw new Exception("Value should have wrapped " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                                        "for " + oks[i] + ": " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                                        t2 + " exceeds max: " +
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   201
                                        SnmpTimeticksBuilder.MAX_VALUE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                if (t1 < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    throw new Exception("Value should have wrapped: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                                        "for " + oks[i] + ": " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                                        t1 + " is negative");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                if (t2 < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    throw new Exception("Value should have wrapped: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                        "for " + oks[i] + ": " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                                        t2 + " is negative");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                System.out.println("TimeTicks[" + oks[i] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                                   "] rightfully accepted: " + t3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            for (int i=0;i<kos.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                try {
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   218
                    t = new SnmpTimeticksBuilder(kos[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    throw new Exception("Value should have been rejected: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                        kos[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                } catch (IllegalArgumentException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    // OK!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                try {
2285
37fdbed8178f 6661448: Make the SNMP agent optional when OPENJDK=true and IMPORT_BINARY_PLUGS=false
dfuchs
parents: 2
diff changeset
   225
                    t = new SnmpTimeticksBuilder(new Long(kos[i]));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                    throw new Exception("Value should have been rejected: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                                        "Long("+kos[i]+")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                } catch (IllegalArgumentException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    // OK!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                System.out.println("TimeTicks[" + kos[i] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                                   "] rightfully rejected.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        } catch(Exception x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            x.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
}