1 /* 2 * Copyright (c) 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 26 /* 27 * @test 28 * @bug 8245302 29 * @summary test the relationship between 30 * thread id long and int methods 31 * @build LogRecordThreadIdTest 32 * @run testng/othervm LogRecordThreadIdTest 33 */ 34 35 import java.util.logging.Level; 36 import java.util.logging.LogRecord; 37 import org.testng.annotations.BeforeTest; 38 import org.testng.annotations.Test; 39 import static org.testng.Assert.assertEquals; 40 import static org.testng.Assert.assertNotEquals; 41 42 43 44 public class LogRecordThreadIdTest { 45 46 LogRecord record, record1, record2; 47 48 @BeforeTest setUp()49 public void setUp() throws Exception { 50 record = new LogRecord(Level.INFO, "record"); 51 record1 = new LogRecord(Level.INFO, "record1"); 52 record2 = new LogRecord(Level.INFO, "record2"); 53 } 54 55 /** 56 * Tests threadID setter methods for consistency 57 * with longThreadID 58 */ 59 @Test testSetThreadId()60 public void testSetThreadId() { 61 record.setThreadID(Integer.MAX_VALUE - 20); 62 record1.setThreadID(Integer.MAX_VALUE - 1); 63 assertEquals(record.getLongThreadID(), Integer.MAX_VALUE - 20L); 64 assertEquals(record.getThreadID(), Integer.MAX_VALUE - 20); 65 assertEquals(record1.getThreadID(), Integer.MAX_VALUE - 1); 66 assertEquals(record1.getLongThreadID(), Integer.MAX_VALUE - 1); 67 } 68 69 /** 70 * Tests longThreadID methods for consistency 71 * with threadID 72 */ 73 @Test testSetLongThreadId()74 public void testSetLongThreadId() { 75 record.setLongThreadID(Integer.MAX_VALUE - 20L); 76 record1.setLongThreadID(Integer.MAX_VALUE + 10L); 77 record2.setLongThreadID(Integer.MAX_VALUE); 78 assertEquals(record.getThreadID(), Integer.MAX_VALUE - 20); 79 assertEquals(record.getLongThreadID(), Integer.MAX_VALUE - 20L); 80 assertNotEquals(record1.getThreadID(), Integer.MAX_VALUE + 10L); 81 assertEquals(record1.getLongThreadID(), Integer.MAX_VALUE + 10L); 82 assertEquals(record2.getThreadID(), Integer.MAX_VALUE); 83 assertEquals(record2.getLongThreadID(), Integer.MAX_VALUE); 84 85 } 86 } 87