Skip to content

Commit 3207e73

Browse files
committed
8279536: jdk/nio/zipfs/ZipFSOutputStreamTest.java timed out
Backport-of: ff0cb98965a0b6be2f6c399e4645630c10b3466e
1 parent 81bb36e commit 3207e73

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

test/jdk/jdk/nio/zipfs/ZipFSOutputStreamTest.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -37,15 +37,15 @@
3737
import java.nio.file.FileSystems;
3838
import java.nio.file.Files;
3939
import java.nio.file.Path;
40+
import java.util.Arrays;
4041
import java.util.Map;
41-
import java.util.Random;
4242

4343

4444
/**
4545
* @test
4646
* @summary Verify that the outputstream created for zip file entries, through the ZipFileSystem
4747
* works fine for varying sizes of the zip file entries
48-
* @bug 8190753 8011146
48+
* @bug 8190753 8011146 8279536
4949
* @run testng/timeout=300 ZipFSOutputStreamTest
5050
*/
5151
public class ZipFSOutputStreamTest {
@@ -90,17 +90,22 @@ private Object[][] zipFSCreationEnv() {
9090
public void testOutputStream(final Map<String, ?> env) throws Exception {
9191
final URI uri = URI.create("jar:" + ZIP_FILE.toUri() );
9292
final byte[] chunk = new byte[1024];
93-
new Random().nextBytes(chunk);
93+
// fill it with some fixed content (the fixed content will later on help ease
94+
// the verification of the content written out)
95+
Arrays.fill(chunk, (byte) 42);
9496
try (final FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {
9597
// create the zip with varying sized entries
9698
for (final Map.Entry<String, Long> entry : ZIP_ENTRIES.entrySet()) {
9799
final Path entryPath = zipfs.getPath(entry.getKey());
98100
if (entryPath.getParent() != null) {
99101
Files.createDirectories(entryPath.getParent());
100102
}
103+
long start = System.currentTimeMillis();
101104
try (final OutputStream os = Files.newOutputStream(entryPath)) {
102105
writeAsChunks(os, chunk, entry.getValue());
103106
}
107+
System.out.println("Wrote entry " + entryPath + " of bytes " + entry.getValue()
108+
+ " in " + (System.currentTimeMillis() - start) + " milli seconds");
104109
}
105110
}
106111
// now verify the written content
@@ -111,15 +116,15 @@ public void testOutputStream(final Map<String, ?> env) throws Exception {
111116
final byte[] buf = new byte[chunk.length];
112117
int numRead;
113118
long totalRead = 0;
119+
long start = System.currentTimeMillis();
114120
while ((numRead = is.read(buf)) != -1) {
115121
totalRead += numRead;
116122
// verify the content
117-
for (int i = 0, chunkoffset = (int) ((totalRead - numRead) % chunk.length);
118-
i < numRead; i++, chunkoffset++) {
119-
Assert.assertEquals(buf[i], chunk[chunkoffset % chunk.length],
120-
"Unexpected content in " + entryPath);
121-
}
123+
Assert.assertEquals(Arrays.mismatch(buf, chunk), -1,
124+
"Unexpected content in " + entryPath);
122125
}
126+
System.out.println("Read entry " + entryPath + " of bytes " + totalRead
127+
+ " in " + (System.currentTimeMillis() - start) + " milli seconds");
123128
Assert.assertEquals(totalRead, (long) entry.getValue(),
124129
"Unexpected number of bytes read from zip entry " + entryPath);
125130
}

0 commit comments

Comments
 (0)