< prev index next >

jdk/test/java/util/zip/ZipFile/MultiThreadedReadTest.java

Print this page
rev 17249 : 8180887: move FileUtils to top level testlibrary
Reviewed-by: duke
   1 /*
   2  * Copyright (c) 2014, 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 /* @test
  25  * @bug 8038491
  26  * @summary Crash in ZipFile.read() when ZipFileInputStream is shared between threads
  27  * @library /lib/testlibrary
  28  * @build jdk.testlibrary.FileUtils
  29  * @run main MultiThreadedReadTest
  30  * @key randomness
  31  */
  32 
  33 import java.io.File;
  34 import java.io.FileOutputStream;
  35 import java.io.InputStream;
  36 import java.nio.file.Paths;
  37 import java.util.Random;
  38 import java.util.zip.ZipEntry;
  39 import java.util.zip.ZipFile;
  40 import java.util.zip.ZipOutputStream;
  41 import jdk.testlibrary.FileUtils;
  42 
  43 public class MultiThreadedReadTest extends Thread {
  44 
  45     private static final int NUM_THREADS = 10;
  46     private static final String ZIPFILE_NAME = "large.zip";
  47     private static final String ZIPENTRY_NAME = "random.txt";
  48     private static InputStream is = null;
  49 
  50     public static void main(String args[]) throws Exception {
  51         createZipFile();
  52         try (ZipFile zf = new ZipFile(new File(ZIPFILE_NAME))) {
  53             is = zf.getInputStream(zf.getEntry(ZIPENTRY_NAME));
  54             Thread[] threadArray = new Thread[NUM_THREADS];
  55             for (int i = 0; i < threadArray.length; i++) {
  56                 threadArray[i] = new MultiThreadedReadTest();
  57             }
  58             for (int i = 0; i < threadArray.length; i++) {
  59                 threadArray[i].start();
  60             }
  61             for (int i = 0; i < threadArray.length; i++) {


   1 /*
   2  * Copyright (c) 2014, 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 /* @test
  25  * @bug 8038491
  26  * @summary Crash in ZipFile.read() when ZipFileInputStream is shared between threads
  27  * @library /test/lib

  28  * @run main MultiThreadedReadTest
  29  * @key randomness
  30  */
  31 
  32 import java.io.File;
  33 import java.io.FileOutputStream;
  34 import java.io.InputStream;
  35 import java.nio.file.Paths;
  36 import java.util.Random;
  37 import java.util.zip.ZipEntry;
  38 import java.util.zip.ZipFile;
  39 import java.util.zip.ZipOutputStream;
  40 import jdk.test.lib.util.FileUtils;
  41 
  42 public class MultiThreadedReadTest extends Thread {
  43 
  44     private static final int NUM_THREADS = 10;
  45     private static final String ZIPFILE_NAME = "large.zip";
  46     private static final String ZIPENTRY_NAME = "random.txt";
  47     private static InputStream is = null;
  48 
  49     public static void main(String args[]) throws Exception {
  50         createZipFile();
  51         try (ZipFile zf = new ZipFile(new File(ZIPFILE_NAME))) {
  52             is = zf.getInputStream(zf.getEntry(ZIPENTRY_NAME));
  53             Thread[] threadArray = new Thread[NUM_THREADS];
  54             for (int i = 0; i < threadArray.length; i++) {
  55                 threadArray[i] = new MultiThreadedReadTest();
  56             }
  57             for (int i = 0; i < threadArray.length; i++) {
  58                 threadArray[i].start();
  59             }
  60             for (int i = 0; i < threadArray.length; i++) {


< prev index next >