43 44 public static void main(String[] args) throws Exception { 45 testFlag(); 46 testFlagPlus(); 47 testFlagMinus(); 48 testFlagEqual(); 49 50 testInvalidFlag(); 51 52 testSolarisSpecificFlag(); 53 } 54 55 private static void testFlag() throws Exception { 56 OutputAnalyzer output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError"); 57 output.shouldHaveExitValue(0); 58 assertTrue(output.getStderr().isEmpty(), "'jinfo -flag HeapDumpOnOutOfMemoryError' stderr should be empty"); 59 output.shouldContain("+HeapDumpOnOutOfMemoryError"); 60 } 61 62 private static void testFlagPlus() throws Exception { 63 OutputAnalyzer output = JInfoHelper.jinfo("-flag", "+PrintGC"); 64 output.shouldHaveExitValue(0); 65 output = JInfoHelper.jinfo("-flag", "PrintGC"); 66 output.shouldHaveExitValue(0); 67 output.shouldContain("+PrintGC"); 68 verifyIsEnabled("PrintGC"); 69 } 70 71 private static void testFlagMinus() throws Exception { 72 OutputAnalyzer output = JInfoHelper.jinfo("-flag", "-PrintGC"); 73 output.shouldHaveExitValue(0); 74 output = JInfoHelper.jinfo("-flag", "PrintGC"); 75 output.shouldHaveExitValue(0); 76 output.shouldContain("-PrintGC"); 77 verifyIsDisabled("PrintGC"); 78 } 79 80 private static void testFlagEqual() throws Exception { 81 OutputAnalyzer output = JInfoHelper.jinfo("-flag", "PrintGC=1"); 82 output.shouldHaveExitValue(0); 83 output = JInfoHelper.jinfo("-flag", "PrintGC"); 84 output.shouldHaveExitValue(0); 85 output.shouldContain("+PrintGC"); 86 verifyIsEnabled("PrintGC"); 87 } 88 89 private static void testInvalidFlag() throws Exception { 90 OutputAnalyzer output = JInfoHelper.jinfo("-flag", "monkey"); 91 assertNotEquals(output.getExitValue(), 0, "A non-zero exit code should be returned for invalid flag"); 92 } 93 94 private static void testSolarisSpecificFlag() throws Exception { 95 if (!isSolaris()) 96 return; 97 98 OutputAnalyzer output = JInfoHelper.jinfo("-flag", "+ExtendedDTraceProbes"); 99 output.shouldHaveExitValue(0); 100 output = JInfoHelper.jinfo(); 101 output.shouldContain("+ExtendedDTraceProbes"); 102 verifyIsEnabled("ExtendedDTraceProbes"); 103 104 output = JInfoHelper.jinfo("-flag", "-ExtendedDTraceProbes"); 105 output.shouldHaveExitValue(0); 106 output = JInfoHelper.jinfo(); | 43 44 public static void main(String[] args) throws Exception { 45 testFlag(); 46 testFlagPlus(); 47 testFlagMinus(); 48 testFlagEqual(); 49 50 testInvalidFlag(); 51 52 testSolarisSpecificFlag(); 53 } 54 55 private static void testFlag() throws Exception { 56 OutputAnalyzer output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError"); 57 output.shouldHaveExitValue(0); 58 assertTrue(output.getStderr().isEmpty(), "'jinfo -flag HeapDumpOnOutOfMemoryError' stderr should be empty"); 59 output.shouldContain("+HeapDumpOnOutOfMemoryError"); 60 } 61 62 private static void testFlagPlus() throws Exception { 63 OutputAnalyzer output = JInfoHelper.jinfo("-flag", "+HeapDumpOnOutOfMemoryError"); 64 output.shouldHaveExitValue(0); 65 output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError"); 66 output.shouldHaveExitValue(0); 67 output.shouldContain("+HeapDumpOnOutOfMemoryError"); 68 verifyIsEnabled("HeapDumpOnOutOfMemoryError"); 69 } 70 71 private static void testFlagMinus() throws Exception { 72 OutputAnalyzer output = JInfoHelper.jinfo("-flag", "-HeapDumpOnOutOfMemoryError"); 73 output.shouldHaveExitValue(0); 74 output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError"); 75 output.shouldHaveExitValue(0); 76 output.shouldContain("-HeapDumpOnOutOfMemoryError"); 77 verifyIsDisabled("HeapDumpOnOutOfMemoryError"); 78 } 79 80 private static void testFlagEqual() throws Exception { 81 OutputAnalyzer output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError=1"); 82 output.shouldHaveExitValue(0); 83 output = JInfoHelper.jinfo("-flag", "HeapDumpOnOutOfMemoryError"); 84 output.shouldHaveExitValue(0); 85 output.shouldContain("+HeapDumpOnOutOfMemoryError"); 86 verifyIsEnabled("HeapDumpOnOutOfMemoryError"); 87 } 88 89 private static void testInvalidFlag() throws Exception { 90 OutputAnalyzer output = JInfoHelper.jinfo("-flag", "monkey"); 91 assertNotEquals(output.getExitValue(), 0, "A non-zero exit code should be returned for invalid flag"); 92 } 93 94 private static void testSolarisSpecificFlag() throws Exception { 95 if (!isSolaris()) 96 return; 97 98 OutputAnalyzer output = JInfoHelper.jinfo("-flag", "+ExtendedDTraceProbes"); 99 output.shouldHaveExitValue(0); 100 output = JInfoHelper.jinfo(); 101 output.shouldContain("+ExtendedDTraceProbes"); 102 verifyIsEnabled("ExtendedDTraceProbes"); 103 104 output = JInfoHelper.jinfo("-flag", "-ExtendedDTraceProbes"); 105 output.shouldHaveExitValue(0); 106 output = JInfoHelper.jinfo(); |