< prev index next >

jdk/test/java/util/logging/FileHandlerMaxLocksTest.java

Print this page
rev 17249 : 8180887: move FileUtils to top level testlibrary
Reviewed-by: duke
   1 /*
   2  * Copyright (c) 2016, 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  * @bug 8153955
  27  * @summary test the FileHandler's new property
  28  *  "java.util.logging.FileHandler.maxLocks" which will be present in
  29  *  "logging.properties" file with default value of 100. This property can be
  30  *  overriden by specifying this property in the custom config file.
  31  * @library /lib/testlibrary
  32  * @build jdk.testlibrary.FileUtils
  33  * @author rpatil
  34  * @run main/othervm FileHandlerMaxLocksTest
  35  */
  36 import java.io.File;
  37 import java.io.FileWriter;
  38 import java.io.IOException;
  39 import java.nio.file.Paths;
  40 import java.util.ArrayList;
  41 import java.util.List;
  42 import java.util.logging.FileHandler;
  43 import jdk.testlibrary.FileUtils;
  44 
  45 public class FileHandlerMaxLocksTest {
  46 
  47     private static final String LOGGER_DIR = "logger-dir";
  48     private static final String MAX_LOCK_PROPERTY = "java.util.logging.FileHandler.maxLocks = 200";
  49     private static final String CONFIG_FILE_NAME = "logging.properties";
  50 
  51     public static void main(String[] args) throws Exception {
  52         File loggerDir = createLoggerDir();
  53         String configFilePath = loggerDir.getPath() + File.separator + CONFIG_FILE_NAME;
  54         File configFile = new File(configFilePath);
  55         createFile(configFile, false);
  56         System.setProperty("java.util.logging.config.file", configFilePath);
  57         List<FileHandler> fileHandlers = new ArrayList<>();
  58         try (FileWriter writer = new FileWriter(configFile)) {
  59             writer.write(MAX_LOCK_PROPERTY);
  60             writer.flush();
  61             // 200 raises the default limit of 100, we try 102 times
  62             for (int i = 0; i < 102; i++) {
  63                 fileHandlers.add(new FileHandler(loggerDir.getPath() + File.separator + "test_%u.log"));


   1 /*
   2  * Copyright (c) 2016, 2017, 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  * @bug 8153955
  27  * @summary test the FileHandler's new property
  28  *  "java.util.logging.FileHandler.maxLocks" which will be present in
  29  *  "logging.properties" file with default value of 100. This property can be
  30  *  overriden by specifying this property in the custom config file.
  31  * @library /test/lib

  32  * @author rpatil
  33  * @run main/othervm FileHandlerMaxLocksTest
  34  */
  35 import java.io.File;
  36 import java.io.FileWriter;
  37 import java.io.IOException;
  38 import java.nio.file.Paths;
  39 import java.util.ArrayList;
  40 import java.util.List;
  41 import java.util.logging.FileHandler;
  42 import jdk.test.lib.util.FileUtils;
  43 
  44 public class FileHandlerMaxLocksTest {
  45 
  46     private static final String LOGGER_DIR = "logger-dir";
  47     private static final String MAX_LOCK_PROPERTY = "java.util.logging.FileHandler.maxLocks = 200";
  48     private static final String CONFIG_FILE_NAME = "logging.properties";
  49 
  50     public static void main(String[] args) throws Exception {
  51         File loggerDir = createLoggerDir();
  52         String configFilePath = loggerDir.getPath() + File.separator + CONFIG_FILE_NAME;
  53         File configFile = new File(configFilePath);
  54         createFile(configFile, false);
  55         System.setProperty("java.util.logging.config.file", configFilePath);
  56         List<FileHandler> fileHandlers = new ArrayList<>();
  57         try (FileWriter writer = new FileWriter(configFile)) {
  58             writer.write(MAX_LOCK_PROPERTY);
  59             writer.flush();
  60             // 200 raises the default limit of 100, we try 102 times
  61             for (int i = 0; i < 102; i++) {
  62                 fileHandlers.add(new FileHandler(loggerDir.getPath() + File.separator + "test_%u.log"));


< prev index next >