Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/fileTest/fileTest.java
41155 views
/*1* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @key stress26*27* @summary converted from VM Testbase gc/gctests/fileTest.28* VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]29*30* @library /vmTestbase31* /test/lib32* @run main/othervm gc.gctests.fileTest.fileTest -Filename fileTest.java -iterations 50033*/3435package gc.gctests.fileTest;3637import java.io.*;38import java.util.*;39import jdk.test.lib.Utils;40import nsk.share.test.*;41import nsk.share.gc.*;42import nsk.share.TestBug;43import nsk.share.TestFailure;4445public class fileTest extends GCTestBase {46private File [] fileArray;47private FileInputStream [] fileInputArray;48private final static int fileNumber = 10000;49// The number of open file descriptors per process varies from one50// system to another. lets expermiment with just 20 open fd's.51private final static int inputStreamNumber = 20;52private String fileName;5354public fileTest(String fileName) {55this.fileName = fileName;56fileArray = new File[fileNumber];57fileInputArray = new FileInputStream[inputStreamNumber];58}5960public void runIteration() throws IOException {61for (int i = 0; i < fileNumber; ++i)62fileArray[i] = new File(Utils.TEST_SRC, fileName);63for (int i = 0; i < inputStreamNumber; ++i)64fileInputArray[i] = new FileInputStream(Utils.TEST_SRC + File.separator + fileName);65for (int i = 0; i < inputStreamNumber; ++i)66fileInputArray[i].close();67}6869public void run() {70try {71Stresser stresser = new Stresser(runParams.getStressOptions());72stresser.start(runParams.getIterations());73try {74while (stresser.iteration())75runIteration();76} finally {77stresser.finish();78}79} catch (IOException e) {80throw new TestFailure(e);81}82}8384public static void main(String args[]) {85String fileName = null;86for (int i = 0 ; i < args.length ; i++) {87if( args[i].equals("-Filename"))88fileName = args[++i];89}90if (fileName == null)91throw new TestBug("No -Filename option is specified");92GC.runTest(new fileTest(fileName), args);93}94}959697