From db9474971a17f7e3bc511b1f1e31121ce63278c7 Mon Sep 17 00:00:00 2001 From: Ivan Bella Date: Wed, 3 May 2023 22:04:58 +0000 Subject: [PATCH 1/7] re #836: VFSClassLoader multi-thread resource loading * Updated the class loader tests to show the errors * Updated ZipFileSystem and TarFileSystem with threadlocal files --- .../vfs2/provider/ftp/FtpClientFactory.java | 2 +- .../vfs2/provider/tar/TarFileSystem.java | 92 ++++++++--- .../vfs2/provider/zip/ZipFileSystem.java | 87 +++++++--- .../vfs2/impl/VfsClassLoaderTests.java | 155 ++++++++++++++++-- .../provider/ftp/FtpProviderTestCase.java | 9 + .../ftps/AbstractFtpsProviderTestCase.java | 15 +- 6 files changed, 287 insertions(+), 73 deletions(-) diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java index c5bf58261c..a19af974ca 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java @@ -120,7 +120,7 @@ private void configureClient(final FileSystemOptions fileSystemOptions, final C * @return A new connection. * @throws FileSystemException if an error occurs while connecting. */ - public C createConnection(final String hostname, final int port, char[] username, char[] password, + public synchronized C createConnection(final String hostname, final int port, char[] username, char[] password, final String workingDirectory, final FileSystemOptions fileSystemOptions) throws FileSystemException { // Determine the username and password to use if (username == null) { diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileSystem.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileSystem.java index df472d49e3..bb47584405 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileSystem.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileSystem.java @@ -16,16 +16,6 @@ */ package org.apache.commons.vfs2.provider.tar; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.zip.GZIPInputStream; - import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; @@ -44,6 +34,16 @@ import org.apache.commons.vfs2.provider.UriParser; import org.apache.commons.vfs2.provider.bzip2.Bzip2FileObject; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.zip.GZIPInputStream; + /** * A read-only file system for Tar files. */ @@ -54,7 +54,53 @@ public class TarFileSystem extends AbstractFileSystem { private final File file; - private TarArchiveInputStream tarFile; + private TarFileThreadLocal tarFile = new TarFileThreadLocal(); + + private class TarFileThreadLocal { + + private ThreadLocal isPresent = new ThreadLocal() { + @Override + protected Boolean initialValue() { + return Boolean.FALSE; + } + }; + private ThreadLocal tarFile = new ThreadLocal() { + @Override + public TarArchiveInputStream initialValue() { + if (isPresent.get()) { + throw new IllegalStateException("Creating an initial value but we already have one"); + } + try { + isPresent.set(Boolean.TRUE); + return createTarFile(TarFileSystem.this.file); + } catch (FileSystemException fse) { + throw new RuntimeException(fse); + } + } + }; + + public TarArchiveInputStream getFile() throws FileSystemException { + try { + return tarFile.get(); + } catch (RuntimeException e) { + if (e.getCause() instanceof FileSystemException) { + throw new FileSystemException(e.getCause()); + } + else { + throw new RuntimeException(e); + } + } + } + + public void closeFile() throws IOException { + if (isPresent.get()) { + TarArchiveInputStream file = tarFile.get(); + file.close(); + tarFile.remove(); + isPresent.set(Boolean.FALSE); + } + } + } /** * Cache doesn't need to be synchronized since it is read-only. @@ -117,10 +163,7 @@ protected TarFileObject createTarFileObject(final AbstractFileName name, final T protected void doCloseCommunicationLink() { // Release the tar file try { - if (tarFile != null) { - tarFile.close(); - tarFile = null; - } + tarFile.closeFile(); } catch (final IOException e) { // getLogger().warn("vfs.provider.tar/close-tar-file.error :" + file, e); VfsLog.warn(getLogger(), LOG, "vfs.provider.tar/close-tar-file.error :" + file, e); @@ -147,6 +190,7 @@ public InputStream getInputStream(final TarArchiveEntry entry) throws FileSystem resetTarFile(); try { ArchiveEntry next; + TarArchiveInputStream tarFile = getTarFile(); while ((next = tarFile.getNextEntry()) != null) { if (next.equals(entry)) { return tarFile; @@ -159,10 +203,7 @@ public InputStream getInputStream(final TarArchiveEntry entry) throws FileSystem } protected TarArchiveInputStream getTarFile() throws FileSystemException { - if (tarFile == null && this.file.exists()) { - recreateTarFile(); - } - return tarFile; + return tarFile.getFile(); } @Override @@ -225,15 +266,12 @@ protected void putFileToCache(final FileObject file) { */ private void recreateTarFile() throws FileSystemException { - if (this.tarFile != null) { - try { - this.tarFile.close(); - } catch (final IOException e) { - throw new FileSystemException("vfs.provider.tar/close-tar-file.error", file, e); - } - tarFile = null; + try { + tarFile.closeFile(); + } catch (final IOException e) { + throw new FileSystemException("vfs.provider.tar/close-tar-file.error", file, e); } - this.tarFile = createTarFile(this.file); + tarFile.getFile(); } /** diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java index 78a57ae373..05b8082b41 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java @@ -16,16 +16,6 @@ */ package org.apache.commons.vfs2.provider.zip; -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.vfs2.Capability; @@ -39,6 +29,16 @@ import org.apache.commons.vfs2.provider.AbstractFileSystem; import org.apache.commons.vfs2.provider.UriParser; +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + /** * A read-only file system for ZIP and JAR files. */ @@ -49,7 +49,53 @@ public class ZipFileSystem extends AbstractFileSystem { private final File file; private final Charset charset; - private ZipFile zipFile; + private ZipFileThreadLocal zipFile = new ZipFileThreadLocal(); + + private class ZipFileThreadLocal { + + private ThreadLocal isPresent = new ThreadLocal() { + @Override + protected Boolean initialValue() { + return Boolean.FALSE; + } + }; + private ThreadLocal zipFile = new ThreadLocal() { + @Override + public ZipFile initialValue() { + if (isPresent.get()) { + throw new IllegalStateException("Creating an initial value but we already have one"); + } + try { + isPresent.set(Boolean.TRUE); + return createZipFile(ZipFileSystem.this.file); + } catch (FileSystemException fse) { + throw new RuntimeException(fse); + } + } + }; + + public ZipFile getFile() throws FileSystemException { + try { + return zipFile.get(); + } catch (RuntimeException e) { + if (e.getCause() instanceof FileSystemException) { + throw new FileSystemException(e.getCause()); + } + else { + throw new RuntimeException(e); + } + } + } + + public void closeFile() throws IOException { + if (isPresent.get()) { + ZipFile file = zipFile.get(); + file.close(); + zipFile.remove(); + isPresent.set(Boolean.FALSE); + } + } + } /** * Cache doesn't need to be synchronized since it is read-only. @@ -71,12 +117,6 @@ public ZipFileSystem(final AbstractFileName rootFileName, final FileObject paren // Make a local copy of the file file = parentLayer.getFileSystem().replicateFile(parentLayer, Selectors.SELECT_SELF); this.charset = ZipFileSystemConfigBuilder.getInstance().getCharset(fileSystemOptions); - - // Open the Zip file - if (!file.exists()) { - // Don't need to do anything - zipFile = null; - } } /** @@ -111,12 +151,9 @@ protected ZipFileObject createZipFileObject(final AbstractFileName name, final Z @Override protected void doCloseCommunicationLink() { - // Release the zip file + // Release the zip files try { - if (zipFile != null) { - zipFile.close(); - zipFile = null; - } + zipFile.closeFile(); } catch (final IOException e) { // getLogger().warn("vfs.provider.zip/close-zip-file.error :" + file, e); VfsLog.warn(getLogger(), LOG, "vfs.provider.zip/close-zip-file.error :" + file, e); @@ -136,11 +173,7 @@ protected FileObject getFileFromCache(final FileName name) { } protected ZipFile getZipFile() throws FileSystemException { - if (zipFile == null && this.file.exists()) { - this.zipFile = createZipFile(this.file); - } - - return zipFile; + return zipFile.getFile(); } @Override diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsClassLoaderTests.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsClassLoaderTests.java index 533ba6763f..cd13f5ebfd 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsClassLoaderTests.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsClassLoaderTests.java @@ -16,39 +16,71 @@ */ package org.apache.commons.vfs2.impl; -import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectoryFile; +import org.apache.commons.io.output.StringBuilderWriter; +import org.apache.commons.vfs2.AbstractProviderTestCase; +import org.apache.commons.vfs2.Capability; +import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSystemException; +import org.apache.commons.vfs2.FileSystemManager; +import org.apache.commons.vfs2.FileType; +import org.apache.commons.vfs2.operations.FileOperationProvider; +import org.junit.Test; import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.io.PrintWriter; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Queue; +import java.util.Set; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.BrokenBarrierException; +import java.util.concurrent.CyclicBarrier; import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; -import org.apache.commons.io.output.StringBuilderWriter; -import org.apache.commons.vfs2.AbstractProviderTestCase; -import org.apache.commons.vfs2.Capability; -import org.apache.commons.vfs2.FileObject; -import org.apache.commons.vfs2.FileSystemException; -import org.apache.commons.vfs2.FileSystemManager; -import org.apache.commons.vfs2.FileType; -import org.junit.Test; +import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectoryFile; /** * VfsClassLoader test cases. */ public class VfsClassLoaderTests extends AbstractProviderTestCase { + final static Map TEST_FILES = Arrays.asList(new Object[][] { + {"read-tests/empty.txt",0L}, + {"read-tests/file1.txt",20L}, + //{"read-tests/file%25.txt",20L}, + {"read-tests/dir1/file1.txt",12L}, + {"read-tests/dir1/file2.txt",12L}, + {"read-tests/dir1/subdir2/file1.txt",12L}, + {"read-tests/dir1/subdir2/file2.txt",12L}, + {"read-tests/dir1/subdir2/file3.txt",12L}, + {"read-tests/dir1/subdir3/file1.txt",12L}, + {"read-tests/dir1/subdir3/file2.txt",12L}, + {"read-tests/dir1/subdir3/file3.txt",12L}, + {"read-tests/dir1/file3.txt",12L}, + {"read-tests/dir1/subdir4.jar/file1.txt",12L}, + {"read-tests/dir1/subdir4.jar/file2.txt",12L}, + {"read-tests/dir1/subdir4.jar/file3.txt",12L}, + {"read-tests/dir1/subdir1/file1.txt",12L}, + {"read-tests/dir1/subdir1/file2.txt",12L}, + {"read-tests/dir1/subdir1/file3.txt",12L}, + //{"read-tests/largefile.txt", 3221225472L}, + {"read-tests/file space.txt",20L} + }).stream().collect(Collectors.toMap(o -> (String)o[0], o -> (Long)o[1])); + /** * Non-Delegating Class Loader. */ @@ -217,7 +249,17 @@ public void testSealing() throws Exception { @Test public void testThreadSafety() throws Exception { - final int THREADS = 40; + final FileSystemManager manager = getManager(); + + // The http4 and sftp mechanisms do not work with this thread safety test + List schemes = Arrays.asList(manager.getSchemes()); + if (schemes.contains("http4") || schemes.contains("sftp")) { + System.out.println("VfsClassLoaderTests skipping thread safety test for schemes :" + schemes); + return; + } + + // note THREADS must be an even number + final int THREADS = 20; final BlockingQueue workQueue = new ArrayBlockingQueue<>(THREADS * 2); final List exceptions = new ArrayList<>(); final Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler() { @@ -229,9 +271,10 @@ public void uncaughtException(Thread t, Throwable e) { } }; final ThreadFactory factory = new ThreadFactory() { + private int count = 0; @Override public Thread newThread(Runnable r) { - Thread thread = new Thread(r, "VfsClassLoaderTests.testThreadSafety"); + Thread thread = new Thread(r, "VfsClassLoaderTests.testThreadSafety #" + count++); thread.setUncaughtExceptionHandler(handler); return thread; } @@ -247,9 +290,12 @@ public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { }; final ThreadPoolExecutor executor = new ThreadPoolExecutor(THREADS, THREADS, 0, TimeUnit.SECONDS, workQueue, factory, rejectionHandler); executor.prestartAllCoreThreads(); - for (int i = 0; i < THREADS; i++) { + VFSClassLoader resourceLoader = createClassLoader(); + final CyclicBarrier barrier = new CyclicBarrier(THREADS); + for (int i = 0; i < THREADS/2; i++) { final VFSClassLoader loader = createClassLoader(); - workQueue.put(new VfsClassLoaderTests.LoadClass(loader)); + workQueue.put(new VfsClassLoaderTests.LoadClass(barrier, loader)); + workQueue.put(new VfsClassLoaderTests.ReadResource(barrier, resourceLoader)); } while (!workQueue.isEmpty()) { Thread.sleep(10); @@ -263,14 +309,14 @@ public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { workQueue.addAll(rejected); } executor.shutdown(); - executor.awaitTermination(30, TimeUnit.SECONDS); + executor.awaitTermination(5, TimeUnit.MINUTES); assertEquals(THREADS, executor.getCompletedTaskCount()); if (!exceptions.isEmpty()) { StringBuilder exceptionMsg = new StringBuilder(); StringBuilderWriter writer = new StringBuilderWriter(exceptionMsg); PrintWriter pWriter = new PrintWriter(writer); for (Throwable t : exceptions) { - pWriter.write(t.getMessage()); + pWriter.write(String.valueOf(t.getMessage())); pWriter.write('\n'); t.printStackTrace(pWriter); pWriter.write('\n'); @@ -282,13 +328,17 @@ public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { private class LoadClass implements Runnable { private final VFSClassLoader loader; - public LoadClass(VFSClassLoader loader) { + private final CyclicBarrier barrier; + + public LoadClass(CyclicBarrier barrier, VFSClassLoader loader) { + this.barrier = barrier; this.loader = loader; } @Override public void run() { try { + barrier.await(); final Class testClass = loader.findClass("code.ClassToLoad"); final Package pack = testClass.getPackage(); assertEquals("code", pack.getName()); @@ -298,7 +348,80 @@ public void run() { assertEquals("**PRIVATE**", testObject.toString()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); + } catch (InterruptedException | BrokenBarrierException e) { + throw new RuntimeException(e); + } + } + } + + private class ReadResource implements Runnable { + private final VFSClassLoader loader; + private final CyclicBarrier barrier; + + public ReadResource(CyclicBarrier barrier, VFSClassLoader loader) { + this.barrier = barrier; + this.loader = loader; + } + + @Override + public void run() { + try { + barrier.await(); + List> files = new ArrayList<>(TEST_FILES.entrySet()); + Collections.shuffle(files); + for (int i = 0; i < 10; i++) { + for (Map.Entry file : files) { + testFindResource(file.getKey(), file.getValue()); + testGetResource(file.getKey(), file.getValue()); + testResourceAsStream(file.getKey(), file.getValue()); + } + } + } catch (InterruptedException | BrokenBarrierException e) { + throw new RuntimeException(e); + } + } + + private void testResourceAsStream(String file, long size) { + try { + try (InputStream stream = loader.getResourceAsStream(file)) { + if (stream == null) { + loader.getResourceAsStream(file); + } + readStream(file, stream, size); + } + } catch (Exception e) { + throw new RuntimeException("Failed to read " + file + " on thread " + Thread.currentThread(), e); + } + } + private void testGetResource(String file, long size) { + try { + URL url = loader.getResource(file); + try (InputStream stream = url.openStream()) { + readStream(file, stream, size); + } + } catch (Exception e) { + throw new RuntimeException("Failed to read " + file + " on thread " + Thread.currentThread(), e); + } + } + private void testFindResource(String file, long size) { + try { + URL url = loader.findResource(file); + try (InputStream stream = url.openStream()) { + readStream(file, stream, size); + } + } catch (Exception e) { + throw new RuntimeException("Failed to read " + file + " on thread " + Thread.currentThread(), e); + } + } + private void readStream(String file, InputStream stream, long size) throws IOException { + long length = 0; + byte[] bytes = new byte[1024]; + int readBytes = stream.read(bytes); + while (readBytes >= 0) { + length += readBytes; + readBytes = stream.read(bytes); } + assertEquals("Incorrect length for " + file + " on thread " + Thread.currentThread(), length, size); } } diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java index c3be9ae5f3..55778b5580 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java @@ -29,6 +29,7 @@ import org.apache.commons.vfs2.FileSystemOptions; import org.apache.commons.vfs2.ProviderTestSuite; import org.apache.commons.vfs2.impl.DefaultFileSystemManager; +import org.apache.ftpserver.ConnectionConfigFactory; import org.apache.ftpserver.FtpServer; import org.apache.ftpserver.FtpServerFactory; import org.apache.ftpserver.command.CommandFactory; @@ -113,6 +114,14 @@ static void setUpClass(final String rootDirectory, final FileSystemFactory fileS if (commandFactory != null) { serverFactory.setCommandFactory(commandFactory); } + ConnectionConfigFactory configFactory = new ConnectionConfigFactory(); + configFactory.setMaxLogins(500); + configFactory.setMaxThreads(500); + configFactory.setMaxAnonymousLogins(500); + configFactory.setMaxLoginFailures(100); + configFactory.setAnonymousLoginEnabled(true); + configFactory.setLoginFailureDelay(1); + serverFactory.setConnectionConfig(configFactory.createConnectionConfig()); final ListenerFactory factory = new ListenerFactory(); // set the port of the listener factory.setPort(0); diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java index ecf768595f..6757e525ad 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java @@ -29,6 +29,7 @@ import org.apache.commons.vfs2.FileSystemOptions; import org.apache.commons.vfs2.ProviderTestSuite; import org.apache.commons.vfs2.impl.DefaultFileSystemManager; +import org.apache.ftpserver.ConnectionConfigFactory; import org.apache.ftpserver.FtpServer; import org.apache.ftpserver.FtpServerFactory; import org.apache.ftpserver.ftplet.FtpException; @@ -152,6 +153,15 @@ synchronized static void setUpClass(final boolean implicit) throws FtpException // replace the default listener serverFactory.addListener(LISTENER_NAME, listenerFactory.createListener()); + ConnectionConfigFactory configFactory = new ConnectionConfigFactory(); + configFactory.setMaxLogins(1000); + configFactory.setMaxThreads(1000); + configFactory.setMaxAnonymousLogins(1000); + configFactory.setMaxLoginFailures(100); + configFactory.setAnonymousLoginEnabled(true); + configFactory.setLoginFailureDelay(1); + serverFactory.setConnectionConfig(configFactory.createConnectionConfig()); + // start the server EmbeddedFtpServer = serverFactory.createServer(); EmbeddedFtpServer.start(); @@ -221,8 +231,9 @@ public void prepare(final DefaultFileSystemManager manager) throws Exception { } protected void setupOptions(final FtpsFileSystemConfigBuilder builder) { - builder.setConnectTimeout(fileSystemOptions, Duration.ofSeconds(10)); - builder.setDataTimeout(fileSystemOptions, Duration.ofSeconds(10)); + builder.setConnectTimeout(fileSystemOptions, Duration.ofSeconds(60)); + builder.setDataTimeout(fileSystemOptions, Duration.ofSeconds(60)); + builder.setSoTimeout(fileSystemOptions, Duration.ofSeconds(60)); } } From ace31a840fca1645b94cc70d71162f44e83946fc Mon Sep 17 00:00:00 2001 From: Ivan Bella Date: Wed, 10 May 2023 14:33:08 +0000 Subject: [PATCH 2/7] re #836: Threaded VFS safety * Updated test suite mechanism to allow exclusing test classes * Skip threaded tests for http4 and ftps mechanisms --- .../webdav/test/WebdavProviderTestSuite.java | 49 +-- .../test/Webdav4ProviderTestSuite.java | 49 +-- .../vfs2/provider/tar/TarFileSystem.java | 37 +-- .../vfs2/provider/zip/ZipFileSystem.java | 37 +-- .../commons/vfs2/AbstractTestSuite.java | 13 +- .../commons/vfs2/ProviderTestSuite.java | 65 ++-- .../vfs2/impl/VfsClassLoaderTests.java | 238 +-------------- .../impl/VfsThreadedClassLoaderTests.java | 280 ++++++++++++++++++ .../provider/ftp/FtpProviderTestCase.java | 12 +- .../ftps/AbstractFtpsProviderTestCase.java | 3 +- .../provider/http/HttpProviderTestCase.java | 9 +- .../provider/http4/Http4ProviderTestCase.java | 15 +- .../provider/http5/Http5ProviderTestCase.java | 10 +- .../sftp/AbstractSftpProviderTestCase.java | 5 +- .../sftp/SftpPermissionExceptionTestCase.java | 9 +- ...SftpProviderClosedExecChannelTestCase.java | 26 +- .../SftpProviderStreamProxyModeTestCase.java | 19 +- .../provider/sftp/SftpPutChannelTestCase.java | 9 +- 18 files changed, 486 insertions(+), 399 deletions(-) create mode 100644 commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsThreadedClassLoaderTests.java diff --git a/commons-vfs2-jackrabbit1/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestSuite.java b/commons-vfs2-jackrabbit1/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestSuite.java index 13ccb7fda9..310f936fc4 100644 --- a/commons-vfs2-jackrabbit1/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestSuite.java +++ b/commons-vfs2-jackrabbit1/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestSuite.java @@ -16,28 +16,24 @@ */ package org.apache.commons.vfs2.provider.webdav.test; -import org.apache.commons.vfs2.ContentTests; -import org.apache.commons.vfs2.LastModifiedTests; -import org.apache.commons.vfs2.NamingTests; -import org.apache.commons.vfs2.ProviderCacheStrategyTests; -import org.apache.commons.vfs2.ProviderDeleteTests; -import org.apache.commons.vfs2.ProviderRandomReadTests; -import org.apache.commons.vfs2.ProviderRandomReadWriteTests; -import org.apache.commons.vfs2.ProviderReadTests; -import org.apache.commons.vfs2.ProviderRenameTests; import org.apache.commons.vfs2.ProviderTestConfig; import org.apache.commons.vfs2.ProviderTestSuite; -import org.apache.commons.vfs2.ProviderWriteAppendTests; -import org.apache.commons.vfs2.ProviderWriteTests; -import org.apache.commons.vfs2.UriTests; -import org.apache.commons.vfs2.UrlStructureTests; -import org.apache.commons.vfs2.UrlTests; +import org.apache.commons.vfs2.impl.VfsClassLoaderTests; +import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; + +import java.util.Arrays; +import java.util.HashSet; /** * The suite of tests for a file system. */ public class WebdavProviderTestSuite extends ProviderTestSuite { + // The class loader test requires the classes be uploaded to the webdav repo. + private static final Class[] EXCLUSIONS = new Class[] { + VfsClassLoaderTests.class, VfsThreadedClassLoaderTests.class + }; + /** * Adds the tests for a file system to this suite. */ @@ -55,30 +51,7 @@ public WebdavProviderTestSuite(final ProviderTestConfig providerConfig, final bo protected WebdavProviderTestSuite(final ProviderTestConfig providerConfig, final String prefix, final boolean nested, final boolean addEmptyDir) throws Exception { - super(providerConfig, prefix, nested, addEmptyDir); - } - - /** - * Adds base tests - excludes the nested test cases. - */ - @Override - protected void addBaseTests() throws Exception { - addTests(ProviderCacheStrategyTests.class); - addTests(UriTests.class); - addTests(NamingTests.class); - addTests(ContentTests.class); - addTests(ProviderReadTests.class); - addTests(ProviderRandomReadTests.class); - addTests(ProviderWriteTests.class); - addTests(ProviderWriteAppendTests.class); - addTests(ProviderRandomReadWriteTests.class); - addTests(ProviderRenameTests.class); - addTests(ProviderDeleteTests.class); - addTests(LastModifiedTests.class); - addTests(UrlTests.class); - addTests(UrlStructureTests.class); - // The class loader test requires the classes be uploaded to the webdav repo. - // addTests(VfsClassLoaderTests.class); + super(providerConfig, prefix, nested, addEmptyDir, new HashSet<>(Arrays.asList(EXCLUSIONS))); } } diff --git a/commons-vfs2-jackrabbit2/src/test/java/org/apache/commons/vfs2/provider/webdav4/test/Webdav4ProviderTestSuite.java b/commons-vfs2-jackrabbit2/src/test/java/org/apache/commons/vfs2/provider/webdav4/test/Webdav4ProviderTestSuite.java index 881642c915..3090392c15 100644 --- a/commons-vfs2-jackrabbit2/src/test/java/org/apache/commons/vfs2/provider/webdav4/test/Webdav4ProviderTestSuite.java +++ b/commons-vfs2-jackrabbit2/src/test/java/org/apache/commons/vfs2/provider/webdav4/test/Webdav4ProviderTestSuite.java @@ -16,22 +16,13 @@ */ package org.apache.commons.vfs2.provider.webdav4.test; -import org.apache.commons.vfs2.ContentTests; -import org.apache.commons.vfs2.LastModifiedTests; -import org.apache.commons.vfs2.NamingTests; -import org.apache.commons.vfs2.ProviderCacheStrategyTests; -import org.apache.commons.vfs2.ProviderDeleteTests; -import org.apache.commons.vfs2.ProviderRandomReadTests; -import org.apache.commons.vfs2.ProviderRandomReadWriteTests; -import org.apache.commons.vfs2.ProviderReadTests; -import org.apache.commons.vfs2.ProviderRenameTests; import org.apache.commons.vfs2.ProviderTestConfig; import org.apache.commons.vfs2.ProviderTestSuite; -import org.apache.commons.vfs2.ProviderWriteAppendTests; -import org.apache.commons.vfs2.ProviderWriteTests; -import org.apache.commons.vfs2.UriTests; -import org.apache.commons.vfs2.UrlStructureTests; -import org.apache.commons.vfs2.UrlTests; +import org.apache.commons.vfs2.impl.VfsClassLoaderTests; +import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; + +import java.util.Arrays; +import java.util.HashSet; /** * The suite of tests for a file system. @@ -39,6 +30,12 @@ * @since 2.5.0 */ public class Webdav4ProviderTestSuite extends ProviderTestSuite { + + // The class loader test requires the classes be uploaded to the webdav repo. + private static final Class[] EXCLUSIONS = new Class[] { + VfsClassLoaderTests.class, VfsThreadedClassLoaderTests.class + }; + /** * Adds the tests for a file system to this suite. */ @@ -56,29 +53,7 @@ public Webdav4ProviderTestSuite(final ProviderTestConfig providerConfig, final b protected Webdav4ProviderTestSuite(final ProviderTestConfig providerConfig, final String prefix, final boolean nested, final boolean addEmptyDir) throws Exception { - super(providerConfig, prefix, nested, addEmptyDir); + super(providerConfig, prefix, nested, addEmptyDir, new HashSet<>(Arrays.asList(EXCLUSIONS))); } - /** - * Adds base tests - excludes the nested test cases. - */ - @Override - protected void addBaseTests() throws Exception { - addTests(ProviderCacheStrategyTests.class); - addTests(UriTests.class); - addTests(NamingTests.class); - addTests(ContentTests.class); - addTests(ProviderReadTests.class); - addTests(ProviderRandomReadTests.class); - addTests(ProviderWriteTests.class); - addTests(ProviderWriteAppendTests.class); - addTests(ProviderRandomReadWriteTests.class); - addTests(ProviderRenameTests.class); - addTests(ProviderDeleteTests.class); - addTests(LastModifiedTests.class); - addTests(UrlTests.class); - addTests(UrlStructureTests.class); - // The class loader test requires the classes be uploaded to the webdav repo. - // addTests(VfsClassLoaderTests.class); - } } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileSystem.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileSystem.java index bb47584405..a20904873d 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileSystem.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileSystem.java @@ -16,6 +16,16 @@ */ package org.apache.commons.vfs2.provider.tar; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.zip.GZIPInputStream; + import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; @@ -34,16 +44,6 @@ import org.apache.commons.vfs2.provider.UriParser; import org.apache.commons.vfs2.provider.bzip2.Bzip2FileObject; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.zip.GZIPInputStream; - /** * A read-only file system for Tar files. */ @@ -56,6 +56,12 @@ public class TarFileSystem extends AbstractFileSystem { private TarFileThreadLocal tarFile = new TarFileThreadLocal(); + private class TarFileCreationException extends RuntimeException { + public TarFileCreationException(Throwable cause) { + super(cause); + } + } + private class TarFileThreadLocal { private ThreadLocal isPresent = new ThreadLocal() { @@ -74,7 +80,7 @@ public TarArchiveInputStream initialValue() { isPresent.set(Boolean.TRUE); return createTarFile(TarFileSystem.this.file); } catch (FileSystemException fse) { - throw new RuntimeException(fse); + throw new TarFileCreationException(fse); } } }; @@ -82,13 +88,8 @@ public TarArchiveInputStream initialValue() { public TarArchiveInputStream getFile() throws FileSystemException { try { return tarFile.get(); - } catch (RuntimeException e) { - if (e.getCause() instanceof FileSystemException) { - throw new FileSystemException(e.getCause()); - } - else { - throw new RuntimeException(e); - } + } catch (TarFileCreationException e) { + throw new FileSystemException(e); } } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java index 05b8082b41..f1338590a4 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java @@ -16,6 +16,16 @@ */ package org.apache.commons.vfs2.provider.zip; +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.Collection; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.vfs2.Capability; @@ -29,16 +39,6 @@ import org.apache.commons.vfs2.provider.AbstractFileSystem; import org.apache.commons.vfs2.provider.UriParser; -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - /** * A read-only file system for ZIP and JAR files. */ @@ -51,6 +51,12 @@ public class ZipFileSystem extends AbstractFileSystem { private final Charset charset; private ZipFileThreadLocal zipFile = new ZipFileThreadLocal(); + private class ZipFileCreationException extends RuntimeException { + public ZipFileCreationException(Throwable cause) { + super(cause); + } + } + private class ZipFileThreadLocal { private ThreadLocal isPresent = new ThreadLocal() { @@ -69,7 +75,7 @@ public ZipFile initialValue() { isPresent.set(Boolean.TRUE); return createZipFile(ZipFileSystem.this.file); } catch (FileSystemException fse) { - throw new RuntimeException(fse); + throw new ZipFileCreationException(fse); } } }; @@ -77,13 +83,8 @@ public ZipFile initialValue() { public ZipFile getFile() throws FileSystemException { try { return zipFile.get(); - } catch (RuntimeException e) { - if (e.getCause() instanceof FileSystemException) { - throw new FileSystemException(e.getCause()); - } - else { - throw new RuntimeException(e); - } + } catch (ZipFileCreationException e) { + throw new FileSystemException(e); } } diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/AbstractTestSuite.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/AbstractTestSuite.java index c068ba77c6..e62b411e67 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/AbstractTestSuite.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/AbstractTestSuite.java @@ -24,8 +24,10 @@ import java.lang.reflect.Modifier; import java.time.Instant; import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.List; +import java.util.Set; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.ArrayUtils; @@ -72,12 +74,17 @@ protected AbstractTestSuite(final ProviderTestConfig providerConfig, final Strin protected AbstractTestSuite(final ProviderTestConfig providerConfig, final String prefix, final boolean nested, final boolean addEmptyDir) throws Exception { + this(providerConfig, prefix, nested, addEmptyDir, Collections.emptySet()); + } + + protected AbstractTestSuite(final ProviderTestConfig providerConfig, final String prefix, final boolean nested, + final boolean addEmptyDir, final Set> exclusions) throws Exception { super(new TestSuite()); testSuite = (TestSuite) fTest; this.providerConfig = providerConfig; this.prefix = prefix; this.addEmptyDir = addEmptyDir; - addBaseTests(); + addBaseTests(exclusions); if (!nested) { // Add nested tests // TODO - move nested jar and zip tests here @@ -88,9 +95,9 @@ protected AbstractTestSuite(final ProviderTestConfig providerConfig, final Strin } /** - * Adds base tests - excludes the nested test cases. + * Adds base tests - excludes the nested test cases and specified exclusions. */ - protected void addBaseTests() throws Exception { + protected void addBaseTests(final Set> exclusions) throws Exception { } /** diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/ProviderTestSuite.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/ProviderTestSuite.java index 92e15f8a68..23b4c2b279 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/ProviderTestSuite.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/ProviderTestSuite.java @@ -17,12 +17,38 @@ package org.apache.commons.vfs2; import org.apache.commons.vfs2.impl.VfsClassLoaderTests; +import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; + +import java.util.Collections; +import java.util.Set; /** * The suite of tests for a file system. */ public class ProviderTestSuite extends AbstractTestSuite { + /** + * The list of base tests to be added to the test suite + */ + private final static Class[] BASE_TESTS = new Class[] { + UrlTests.class, + ProviderCacheStrategyTests.class, + UriTests.class, + NamingTests.class, + ContentTests.class, + ProviderReadTests.class, + ProviderWriteTests.class, + ProviderWriteAppendTests.class, + ProviderRandomReadTests.class, + ProviderRandomReadWriteTests.class, + ProviderRandomSetLengthTests.class, + ProviderRenameTests.class, + ProviderDeleteTests.class, + LastModifiedTests.class, + UrlStructureTests.class, + VfsClassLoaderTests.class, + VfsThreadedClassLoaderTests.class}; + /** * Adds the tests for a file system to this suite. */ @@ -30,6 +56,13 @@ public ProviderTestSuite(final ProviderTestConfig providerConfig) throws Excepti this(providerConfig, "", false, false); } + /** + * Adds the tests for a file system to this suite except for specified exclusions + */ + public ProviderTestSuite(final ProviderTestConfig providerConfig, Set> exclusions) throws Exception { + this(providerConfig, "", false, false, exclusions); + } + /** * Adds the tests for a file system to this suite. Provider has an empty directory. */ @@ -39,30 +72,24 @@ public ProviderTestSuite(final ProviderTestConfig providerConfig, final boolean protected ProviderTestSuite(final ProviderTestConfig providerConfig, final String prefix, final boolean nested, final boolean addEmptyDir) throws Exception { - super(providerConfig, prefix, nested, addEmptyDir); + this(providerConfig, prefix, nested, addEmptyDir, Collections.emptySet()); + } + + protected ProviderTestSuite(final ProviderTestConfig providerConfig, final String prefix, final boolean nested, + final boolean addEmptyDir, final Set> exclusions) throws Exception { + super(providerConfig, prefix, nested, addEmptyDir, exclusions); } /** - * Adds base tests - excludes the nested test cases. + * Adds base tests - excludes the nested test cases and specified exclusions. */ @Override - protected void addBaseTests() throws Exception { - addTests(UrlTests.class); - addTests(ProviderCacheStrategyTests.class); - addTests(UriTests.class); - addTests(NamingTests.class); - addTests(ContentTests.class); - addTests(ProviderReadTests.class); - addTests(ProviderWriteTests.class); - addTests(ProviderWriteAppendTests.class); - addTests(ProviderRandomReadTests.class); - addTests(ProviderRandomReadWriteTests.class); - addTests(ProviderRandomSetLengthTests.class); - addTests(ProviderRenameTests.class); - addTests(ProviderDeleteTests.class); - addTests(LastModifiedTests.class); - addTests(UrlStructureTests.class); - addTests(VfsClassLoaderTests.class); + protected void addBaseTests(Set> exclusions) throws Exception { + for (Class testClass : BASE_TESTS) { + if (!exclusions.contains(testClass)) { + addTests(testClass); + } + } } } diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsClassLoaderTests.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsClassLoaderTests.java index cd13f5ebfd..5f9bc530af 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsClassLoaderTests.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsClassLoaderTests.java @@ -16,71 +16,27 @@ */ package org.apache.commons.vfs2.impl; -import org.apache.commons.io.output.StringBuilderWriter; -import org.apache.commons.vfs2.AbstractProviderTestCase; -import org.apache.commons.vfs2.Capability; -import org.apache.commons.vfs2.FileObject; -import org.apache.commons.vfs2.FileSystemException; -import org.apache.commons.vfs2.FileSystemManager; -import org.apache.commons.vfs2.FileType; -import org.apache.commons.vfs2.operations.FileOperationProvider; -import org.junit.Test; +import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectoryFile; import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintWriter; import java.net.URL; import java.net.URLConnection; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Queue; -import java.util.Set; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.BrokenBarrierException; -import java.util.concurrent.CyclicBarrier; -import java.util.concurrent.RejectedExecutionHandler; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectoryFile; +import org.apache.commons.vfs2.AbstractProviderTestCase; +import org.apache.commons.vfs2.Capability; +import org.apache.commons.vfs2.FileObject; +import org.apache.commons.vfs2.FileSystemException; +import org.apache.commons.vfs2.FileSystemManager; +import org.apache.commons.vfs2.FileType; +import org.junit.Test; /** * VfsClassLoader test cases. */ public class VfsClassLoaderTests extends AbstractProviderTestCase { - final static Map TEST_FILES = Arrays.asList(new Object[][] { - {"read-tests/empty.txt",0L}, - {"read-tests/file1.txt",20L}, - //{"read-tests/file%25.txt",20L}, - {"read-tests/dir1/file1.txt",12L}, - {"read-tests/dir1/file2.txt",12L}, - {"read-tests/dir1/subdir2/file1.txt",12L}, - {"read-tests/dir1/subdir2/file2.txt",12L}, - {"read-tests/dir1/subdir2/file3.txt",12L}, - {"read-tests/dir1/subdir3/file1.txt",12L}, - {"read-tests/dir1/subdir3/file2.txt",12L}, - {"read-tests/dir1/subdir3/file3.txt",12L}, - {"read-tests/dir1/file3.txt",12L}, - {"read-tests/dir1/subdir4.jar/file1.txt",12L}, - {"read-tests/dir1/subdir4.jar/file2.txt",12L}, - {"read-tests/dir1/subdir4.jar/file3.txt",12L}, - {"read-tests/dir1/subdir1/file1.txt",12L}, - {"read-tests/dir1/subdir1/file2.txt",12L}, - {"read-tests/dir1/subdir1/file3.txt",12L}, - //{"read-tests/largefile.txt", 3221225472L}, - {"read-tests/file space.txt",20L} - }).stream().collect(Collectors.toMap(o -> (String)o[0], o -> (Long)o[1])); - /** * Non-Delegating Class Loader. */ @@ -247,184 +203,6 @@ public void testSealing() throws Exception { verifyPackage(pack, true); } - @Test - public void testThreadSafety() throws Exception { - final FileSystemManager manager = getManager(); - - // The http4 and sftp mechanisms do not work with this thread safety test - List schemes = Arrays.asList(manager.getSchemes()); - if (schemes.contains("http4") || schemes.contains("sftp")) { - System.out.println("VfsClassLoaderTests skipping thread safety test for schemes :" + schemes); - return; - } - - // note THREADS must be an even number - final int THREADS = 20; - final BlockingQueue workQueue = new ArrayBlockingQueue<>(THREADS * 2); - final List exceptions = new ArrayList<>(); - final Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler() { - @Override - public void uncaughtException(Thread t, Throwable e) { - synchronized (exceptions) { - exceptions.add(e); - } - } - }; - final ThreadFactory factory = new ThreadFactory() { - private int count = 0; - @Override - public Thread newThread(Runnable r) { - Thread thread = new Thread(r, "VfsClassLoaderTests.testThreadSafety #" + count++); - thread.setUncaughtExceptionHandler(handler); - return thread; - } - }; - final Queue rejections = new LinkedList<>(); - final RejectedExecutionHandler rejectionHandler = new RejectedExecutionHandler() { - @Override - public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { - synchronized (rejections) { - rejections.add(r); - } - } - }; - final ThreadPoolExecutor executor = new ThreadPoolExecutor(THREADS, THREADS, 0, TimeUnit.SECONDS, workQueue, factory, rejectionHandler); - executor.prestartAllCoreThreads(); - VFSClassLoader resourceLoader = createClassLoader(); - final CyclicBarrier barrier = new CyclicBarrier(THREADS); - for (int i = 0; i < THREADS/2; i++) { - final VFSClassLoader loader = createClassLoader(); - workQueue.put(new VfsClassLoaderTests.LoadClass(barrier, loader)); - workQueue.put(new VfsClassLoaderTests.ReadResource(barrier, resourceLoader)); - } - while (!workQueue.isEmpty()) { - Thread.sleep(10); - } - while (!rejections.isEmpty() && executor.getActiveCount() > 0) { - final List rejected = new ArrayList<>(); - synchronized(rejections) { - rejected.addAll(rejections); - rejections.clear(); - } - workQueue.addAll(rejected); - } - executor.shutdown(); - executor.awaitTermination(5, TimeUnit.MINUTES); - assertEquals(THREADS, executor.getCompletedTaskCount()); - if (!exceptions.isEmpty()) { - StringBuilder exceptionMsg = new StringBuilder(); - StringBuilderWriter writer = new StringBuilderWriter(exceptionMsg); - PrintWriter pWriter = new PrintWriter(writer); - for (Throwable t : exceptions) { - pWriter.write(String.valueOf(t.getMessage())); - pWriter.write('\n'); - t.printStackTrace(pWriter); - pWriter.write('\n'); - } - pWriter.flush(); - assertTrue(exceptions.size() + " threads failed: " + exceptionMsg, exceptions.isEmpty()); - } - } - - private class LoadClass implements Runnable { - private final VFSClassLoader loader; - private final CyclicBarrier barrier; - - public LoadClass(CyclicBarrier barrier, VFSClassLoader loader) { - this.barrier = barrier; - this.loader = loader; - } - - @Override - public void run() { - try { - barrier.await(); - final Class testClass = loader.findClass("code.ClassToLoad"); - final Package pack = testClass.getPackage(); - assertEquals("code", pack.getName()); - verifyPackage(pack, false); - - final Object testObject = testClass.newInstance(); - assertEquals("**PRIVATE**", testObject.toString()); - } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InterruptedException | BrokenBarrierException e) { - throw new RuntimeException(e); - } - } - } - - private class ReadResource implements Runnable { - private final VFSClassLoader loader; - private final CyclicBarrier barrier; - - public ReadResource(CyclicBarrier barrier, VFSClassLoader loader) { - this.barrier = barrier; - this.loader = loader; - } - - @Override - public void run() { - try { - barrier.await(); - List> files = new ArrayList<>(TEST_FILES.entrySet()); - Collections.shuffle(files); - for (int i = 0; i < 10; i++) { - for (Map.Entry file : files) { - testFindResource(file.getKey(), file.getValue()); - testGetResource(file.getKey(), file.getValue()); - testResourceAsStream(file.getKey(), file.getValue()); - } - } - } catch (InterruptedException | BrokenBarrierException e) { - throw new RuntimeException(e); - } - } - - private void testResourceAsStream(String file, long size) { - try { - try (InputStream stream = loader.getResourceAsStream(file)) { - if (stream == null) { - loader.getResourceAsStream(file); - } - readStream(file, stream, size); - } - } catch (Exception e) { - throw new RuntimeException("Failed to read " + file + " on thread " + Thread.currentThread(), e); - } - } - private void testGetResource(String file, long size) { - try { - URL url = loader.getResource(file); - try (InputStream stream = url.openStream()) { - readStream(file, stream, size); - } - } catch (Exception e) { - throw new RuntimeException("Failed to read " + file + " on thread " + Thread.currentThread(), e); - } - } - private void testFindResource(String file, long size) { - try { - URL url = loader.findResource(file); - try (InputStream stream = url.openStream()) { - readStream(file, stream, size); - } - } catch (Exception e) { - throw new RuntimeException("Failed to read " + file + " on thread " + Thread.currentThread(), e); - } - } - private void readStream(String file, InputStream stream, long size) throws IOException { - long length = 0; - byte[] bytes = new byte[1024]; - int readBytes = stream.read(bytes); - while (readBytes >= 0) { - length += readBytes; - readBytes = stream.read(bytes); - } - assertEquals("Incorrect length for " + file + " on thread " + Thread.currentThread(), length, size); - } - } - /** * Verify the package loaded with class loader. */ diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsThreadedClassLoaderTests.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsThreadedClassLoaderTests.java new file mode 100644 index 0000000000..c797579035 --- /dev/null +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsThreadedClassLoaderTests.java @@ -0,0 +1,280 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.vfs2.impl; + +import org.apache.commons.io.output.StringBuilderWriter; +import org.apache.commons.vfs2.AbstractProviderTestCase; +import org.apache.commons.vfs2.Capability; +import org.apache.commons.vfs2.FileSystemException; +import org.junit.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.BrokenBarrierException; +import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.RejectedExecutionHandler; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +/** + * VfsClassLoader test cases. + */ +public class VfsThreadedClassLoaderTests extends AbstractProviderTestCase { + + final static Map TEST_FILES = Arrays.asList(new Object[][] { + {"read-tests/empty.txt",0L}, + {"read-tests/file1.txt",20L}, + {"read-tests/dir1/file1.txt",12L}, + {"read-tests/dir1/file2.txt",12L}, + {"read-tests/dir1/subdir2/file1.txt",12L}, + {"read-tests/dir1/subdir2/file2.txt",12L}, + {"read-tests/dir1/subdir2/file3.txt",12L}, + {"read-tests/dir1/subdir3/file1.txt",12L}, + {"read-tests/dir1/subdir3/file2.txt",12L}, + {"read-tests/dir1/subdir3/file3.txt",12L}, + {"read-tests/dir1/file3.txt",12L}, + {"read-tests/dir1/subdir4.jar/file1.txt",12L}, + {"read-tests/dir1/subdir4.jar/file2.txt",12L}, + {"read-tests/dir1/subdir4.jar/file3.txt",12L}, + {"read-tests/dir1/subdir1/file1.txt",12L}, + {"read-tests/dir1/subdir1/file2.txt",12L}, + {"read-tests/dir1/subdir1/file3.txt",12L}, + //{"read-tests/largefile.txt", 3221225472L}, + {"read-tests/file space.txt",20L} + }).stream().collect(Collectors.toMap(o -> (String)o[0], o -> (Long)o[1])); + + /** + * Creates the classloader to use when testing. + */ + private VFSClassLoader createClassLoader() throws FileSystemException { + return new VFSClassLoader(getBaseFolder(), getManager()); + } + + /** + * Returns the capabilities required by the tests of this test case. + */ + @Override + protected Capability[] getRequiredCapabilities() { + return new Capability[] { Capability.READ_CONTENT, Capability.URI }; + } + + @Test + public void testThreadSafety() throws Exception { + // note THREADS must be an even number + final int THREADS = 20; + final BlockingQueue workQueue = new ArrayBlockingQueue<>(THREADS * 2); + final List exceptions = new ArrayList<>(); + final Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + synchronized (exceptions) { + exceptions.add(e); + } + } + }; + final ThreadFactory factory = new ThreadFactory() { + private int count = 0; + @Override + public Thread newThread(Runnable r) { + Thread thread = new Thread(r, "VfsClassLoaderTests.testThreadSafety #" + count++); + thread.setUncaughtExceptionHandler(handler); + return thread; + } + }; + final Queue rejections = new LinkedList<>(); + final RejectedExecutionHandler rejectionHandler = new RejectedExecutionHandler() { + @Override + public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { + synchronized (rejections) { + rejections.add(r); + } + } + }; + final ThreadPoolExecutor executor = new ThreadPoolExecutor(THREADS, THREADS, 0, TimeUnit.SECONDS, workQueue, factory, rejectionHandler); + executor.prestartAllCoreThreads(); + VFSClassLoader resourceLoader = createClassLoader(); + final CyclicBarrier barrier = new CyclicBarrier(THREADS); + for (int i = 0; i < THREADS/2; i++) { + final VFSClassLoader loader = createClassLoader(); + workQueue.put(new VfsThreadedClassLoaderTests.LoadClass(barrier, loader)); + workQueue.put(new VfsThreadedClassLoaderTests.ReadResource(barrier, resourceLoader)); + } + while (!workQueue.isEmpty()) { + Thread.sleep(10); + } + while (!rejections.isEmpty() && executor.getActiveCount() > 0) { + final List rejected = new ArrayList<>(); + synchronized(rejections) { + rejected.addAll(rejections); + rejections.clear(); + } + workQueue.addAll(rejected); + } + executor.shutdown(); + executor.awaitTermination(60, TimeUnit.SECONDS); + assertEquals(THREADS, executor.getCompletedTaskCount()); + if (!exceptions.isEmpty()) { + StringBuilder exceptionMsg = new StringBuilder(); + StringBuilderWriter writer = new StringBuilderWriter(exceptionMsg); + PrintWriter pWriter = new PrintWriter(writer); + for (Throwable t : exceptions) { + pWriter.write(String.valueOf(t.getMessage())); + pWriter.write('\n'); + t.printStackTrace(pWriter); + pWriter.write('\n'); + } + pWriter.flush(); + assertTrue(exceptions.size() + " threads failed: " + exceptionMsg, exceptions.isEmpty()); + } + } + + private class LoadClass implements Runnable { + private final VFSClassLoader loader; + private final CyclicBarrier barrier; + + public LoadClass(CyclicBarrier barrier, VFSClassLoader loader) { + this.barrier = barrier; + this.loader = loader; + } + + @Override + public void run() { + try { + barrier.await(); + final Class testClass = loader.findClass("code.ClassToLoad"); + final Package pack = testClass.getPackage(); + assertEquals("code", pack.getName()); + verifyPackage(pack, false); + + final Object testObject = testClass.newInstance(); + assertEquals("**PRIVATE**", testObject.toString()); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InterruptedException | BrokenBarrierException e) { + throw new RuntimeException(e); + } + } + } + + private class ReadResource implements Runnable { + private final VFSClassLoader loader; + private final CyclicBarrier barrier; + + public ReadResource(CyclicBarrier barrier, VFSClassLoader loader) { + this.barrier = barrier; + this.loader = loader; + } + + @Override + public void run() { + try { + barrier.await(); + List> files = new ArrayList<>(TEST_FILES.entrySet()); + Collections.shuffle(files); + for (int i = 0; i < 10; i++) { + for (Map.Entry file : files) { + testFindResource(file.getKey(), file.getValue()); + testGetResource(file.getKey(), file.getValue()); + testResourceAsStream(file.getKey(), file.getValue()); + } + } + } catch (InterruptedException | BrokenBarrierException e) { + throw new RuntimeException(e); + } + } + + private void testResourceAsStream(String file, long size) { + try { + try (InputStream stream = loader.getResourceAsStream(file)) { + if (stream == null) { + loader.getResourceAsStream(file); + } + readStream(file, stream, size); + } + } catch (Exception e) { + throw new RuntimeException("Failed to read " + file + " on thread " + Thread.currentThread(), e); + } + } + private void testGetResource(String file, long size) { + try { + URL url = loader.getResource(file); + try (InputStream stream = url.openStream()) { + readStream(file, stream, size); + } + } catch (Exception e) { + throw new RuntimeException("Failed to read " + file + " on thread " + Thread.currentThread(), e); + } + } + private void testFindResource(String file, long size) { + try { + URL url = loader.findResource(file); + try (InputStream stream = url.openStream()) { + readStream(file, stream, size); + } + } catch (Exception e) { + throw new RuntimeException("Failed to read " + file + " on thread " + Thread.currentThread(), e); + } + } + private void readStream(String file, InputStream stream, long size) throws IOException { + long length = 0; + byte[] bytes = new byte[1024]; + int readBytes = stream.read(bytes); + while (readBytes >= 0) { + length += readBytes; + readBytes = stream.read(bytes); + } + assertEquals("Incorrect length for " + file + " on thread " + Thread.currentThread(), length, size); + } + } + + /** + * Verify the package loaded with class loader. + */ + private void verifyPackage(final Package pack, final boolean sealed) { + if (getBaseFolder().getFileSystem().hasCapability(Capability.MANIFEST_ATTRIBUTES)) { + assertEquals("ImplTitle", pack.getImplementationTitle()); + assertEquals("ImplVendor", pack.getImplementationVendor()); + assertEquals("1.1", pack.getImplementationVersion()); + assertEquals("SpecTitle", pack.getSpecificationTitle()); + assertEquals("SpecVendor", pack.getSpecificationVendor()); + assertEquals("1.0", pack.getSpecificationVersion()); + assertEquals(sealed, pack.isSealed()); + } else { + assertNull(pack.getImplementationTitle()); + assertNull(pack.getImplementationVendor()); + assertNull(pack.getImplementationVersion()); + assertNull(pack.getSpecificationTitle()); + assertNull(pack.getSpecificationVendor()); + assertNull(pack.getSpecificationVersion()); + assertFalse(pack.isSealed()); + } + } + +} diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java index 55778b5580..97d0fe683e 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.net.URL; import java.time.Duration; +import java.util.Set; import org.apache.commons.vfs2.AbstractProviderTestCase; import org.apache.commons.vfs2.AbstractProviderTestConfig; @@ -114,7 +115,8 @@ static void setUpClass(final String rootDirectory, final FileSystemFactory fileS if (commandFactory != null) { serverFactory.setCommandFactory(commandFactory); } - ConnectionConfigFactory configFactory = new ConnectionConfigFactory(); + // allow more connections + final ConnectionConfigFactory configFactory = new ConnectionConfigFactory(); configFactory.setMaxLogins(500); configFactory.setMaxThreads(500); configFactory.setMaxAnonymousLogins(500); @@ -151,12 +153,14 @@ protected static Test suite(final FtpProviderTestCase testCase, return new ProviderTestSuite(testCase) { @Override - protected void addBaseTests() throws Exception { + protected void addBaseTests(Set> exclusions) throws Exception { if (testClasses.length == 0) { - super.addBaseTests(); + super.addBaseTests(exclusions); } else { for (final Class test : testClasses) { - addTests(test); + if (!exclusions.contains(test)) { + addTests(test); + } } } } diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java index 6757e525ad..a7ecec3e35 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java @@ -153,7 +153,8 @@ synchronized static void setUpClass(final boolean implicit) throws FtpException // replace the default listener serverFactory.addListener(LISTENER_NAME, listenerFactory.createListener()); - ConnectionConfigFactory configFactory = new ConnectionConfigFactory(); + // allow more connections + final ConnectionConfigFactory configFactory = new ConnectionConfigFactory(); configFactory.setMaxLogins(1000); configFactory.setMaxThreads(1000); configFactory.setMaxAnonymousLogins(1000); diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http/HttpProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http/HttpProviderTestCase.java index 4d39fa2d9f..a8e6500a9e 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http/HttpProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http/HttpProviderTestCase.java @@ -20,6 +20,7 @@ import java.io.File; import java.time.Duration; +import java.util.Set; import org.apache.commons.vfs2.AbstractProviderTestConfig; import org.apache.commons.vfs2.FileNotFolderException; @@ -79,9 +80,11 @@ public static junit.framework.Test suite() throws Exception { * Adds base tests - excludes the nested test cases. */ @Override - protected void addBaseTests() throws Exception { - super.addBaseTests(); - addTests(HttpProviderTestCase.class); + protected void addBaseTests(Set> exclusions) throws Exception { + super.addBaseTests(exclusions); + if (!exclusions.contains(HttpProviderTestCase.class)) { + addTests(HttpProviderTestCase.class); + } } @Override diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/Http4ProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/Http4ProviderTestCase.java index de661365ff..bdfaa64d44 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/Http4ProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/Http4ProviderTestCase.java @@ -20,6 +20,8 @@ import java.io.File; import java.time.Duration; +import java.util.Collections; +import java.util.Set; import java.util.concurrent.TimeUnit; import org.apache.commons.vfs2.AbstractProviderTestConfig; @@ -31,6 +33,7 @@ import org.apache.commons.vfs2.ProviderTestSuite; import org.apache.commons.vfs2.VFS; import org.apache.commons.vfs2.impl.DefaultFileSystemManager; +import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; import org.apache.commons.vfs2.util.NHttpFileServer; import org.junit.jupiter.api.Assertions; import org.junit.Test; @@ -73,14 +76,16 @@ private static void setUpClass() throws Exception { * @throws Exception Thrown when the suite cannot be constructed. */ public static junit.framework.Test suite() throws Exception { - return new ProviderTestSuite(new Http4ProviderTestCase()) { + return new ProviderTestSuite(new Http4ProviderTestCase(), Collections.singleton(VfsThreadedClassLoaderTests.class)) { /** - * Adds base tests - excludes the nested test cases. + * Adds base tests - excludes the nested test cases and the threaded class loader tests */ @Override - protected void addBaseTests() throws Exception { - super.addBaseTests(); - addTests(Http4ProviderTestCase.class); + protected void addBaseTests(Set> exclusions) throws Exception { + super.addBaseTests(exclusions); + if (!exclusions.contains(Http4ProviderTestCase.class)) { + addTests(Http4ProviderTestCase.class); + } } @Override diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/Http5ProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/Http5ProviderTestCase.java index 97734a7f36..5919de8430 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/Http5ProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/Http5ProviderTestCase.java @@ -20,6 +20,7 @@ import java.io.File; import java.time.Duration; +import java.util.Set; import java.util.concurrent.TimeUnit; import org.apache.commons.vfs2.AbstractProviderTestConfig; @@ -31,6 +32,7 @@ import org.apache.commons.vfs2.ProviderTestSuite; import org.apache.commons.vfs2.VFS; import org.apache.commons.vfs2.impl.DefaultFileSystemManager; +import org.apache.commons.vfs2.provider.http4.Http4ProviderTestCase; import org.apache.commons.vfs2.util.NHttpFileServer; import org.junit.Test; import org.junit.jupiter.api.Assertions; @@ -78,9 +80,11 @@ public static junit.framework.Test suite() throws Exception { * Adds base tests - excludes the nested test cases. */ @Override - protected void addBaseTests() throws Exception { - super.addBaseTests(); - addTests(Http5ProviderTestCase.class); + protected void addBaseTests(Set> exclusions) throws Exception { + super.addBaseTests(exclusions); + if (!exclusions.contains(Http4ProviderTestCase.class)) { + addTests(Http5ProviderTestCase.class); + } } @Override diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/AbstractSftpProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/AbstractSftpProviderTestCase.java index e549005f61..33690cd72f 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/AbstractSftpProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/AbstractSftpProviderTestCase.java @@ -31,6 +31,7 @@ import java.nio.file.Paths; import java.time.Duration; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.TreeMap; import java.util.regex.Matcher; @@ -43,6 +44,7 @@ import org.apache.commons.vfs2.FileSystemOptions; import org.apache.commons.vfs2.ProviderTestSuite; import org.apache.commons.vfs2.impl.DefaultFileSystemManager; +import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; import org.apache.ftpserver.ftplet.FtpException; import org.apache.sshd.SshServer; import org.apache.sshd.common.NamedFactory; @@ -228,7 +230,8 @@ static class SftpProviderTestSuite extends ProviderTestSuite { private final SessionFactory sessionFactory; public SftpProviderTestSuite(final AbstractSftpProviderTestCase providerConfig) throws Exception { - super(providerConfig); + // exclude the threaded class loader tests + super(providerConfig, Collections.singleton(VfsThreadedClassLoaderTests.class)); this.isExecChannelClosed = providerConfig.isExecChannelClosed(); this.sessionFactory = providerConfig.sessionFactory(); } diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpPermissionExceptionTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpPermissionExceptionTestCase.java index 51a7dc12d3..500b90e019 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpPermissionExceptionTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpPermissionExceptionTestCase.java @@ -20,6 +20,7 @@ import java.io.File; import java.nio.file.Paths; +import java.util.Set; import org.apache.commons.vfs2.Capability; import org.apache.commons.vfs2.FileObject; @@ -40,9 +41,11 @@ public class SftpPermissionExceptionTestCase extends AbstractSftpProviderTestCas public static junit.framework.Test suite() throws Exception { final SftpProviderTestSuite suite = new SftpProviderTestSuite(new SftpPermissionExceptionTestCase()){ @Override - protected void addBaseTests() throws Exception { - // Just tries to read - addTests(SftpPermissionExceptionTestCase.class); + protected void addBaseTests(Set> exclusions) throws Exception { + if (!exclusions.contains(SftpPermissionExceptionTestCase.class)) { + // Just tries to read + addTests(SftpPermissionExceptionTestCase.class); + } } }; return suite; diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpProviderClosedExecChannelTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpProviderClosedExecChannelTestCase.java index 162e520d7b..8bdc761b4c 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpProviderClosedExecChannelTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpProviderClosedExecChannelTestCase.java @@ -25,22 +25,32 @@ import junit.framework.Test; +import java.util.Set; + public class SftpProviderClosedExecChannelTestCase extends AbstractSftpProviderTestCase { + private static final Class[] BASE_TESTS = new Class[] { + ProviderReadTests.class, + ProviderWriteTests.class, + ProviderDeleteTests.class, + ProviderRenameTests.class, + NamingTests.class, + // VFS-405: set/get permissions + PermissionsTests.class + }; + /** * Creates the test suite for the sftp file system. */ public static Test suite() throws Exception { final SftpProviderTestSuite suite = new SftpProviderTestSuite(new SftpProviderClosedExecChannelTestCase()) { @Override - protected void addBaseTests() throws Exception { - addTests(ProviderReadTests.class); - addTests(ProviderWriteTests.class); - addTests(ProviderDeleteTests.class); - addTests(ProviderRenameTests.class); - addTests(NamingTests.class); - // VFS-405: set/get permissions - addTests(PermissionsTests.class); + protected void addBaseTests(Set> exclusions) throws Exception { + for (Class testClass : BASE_TESTS) { + if (!exclusions.contains(testClass)) { + addTests(testClass); + } + } } }; return suite; diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpProviderStreamProxyModeTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpProviderStreamProxyModeTestCase.java index dca2320b5c..4f9deb5c74 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpProviderStreamProxyModeTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpProviderStreamProxyModeTestCase.java @@ -17,6 +17,7 @@ package org.apache.commons.vfs2.provider.sftp; import java.net.URI; +import java.util.Set; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemManager; @@ -30,6 +31,13 @@ public class SftpProviderStreamProxyModeTestCase extends AbstractSftpProviderTestCase { + private static final Class[] BASE_TESTS = new Class[] { + // Just tries to read + ProviderReadTests.class, + // VFS-405: set/get permissions + PermissionsTests.class + }; + // --- VFS-440: stream proxy test suite // We override the addBaseTests method so that only // one test is run (we just test that the input/output are correctly forwarded, and @@ -37,11 +45,12 @@ public class SftpProviderStreamProxyModeTestCase extends AbstractSftpProviderTes public static Test suite() throws Exception { final SftpProviderTestSuite suite = new SftpProviderTestSuite(new SftpProviderStreamProxyModeTestCase()) { @Override - protected void addBaseTests() throws Exception { - // Just tries to read - addTests(ProviderReadTests.class); - // VFS-405: set/get permissions - addTests(PermissionsTests.class); + protected void addBaseTests(Set> exclusions) throws Exception { + for (Class testClass : BASE_TESTS) { + if (!exclusions.contains(testClass)) { + addTests(testClass); + } + } } }; return suite; diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpPutChannelTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpPutChannelTestCase.java index 3873158576..aededc920a 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpPutChannelTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpPutChannelTestCase.java @@ -28,6 +28,7 @@ import org.junit.jupiter.api.Assertions; import java.io.InputStream; +import java.util.Set; /** * Test SftpFileObject.doGetInputStream return the channel to pool when throw an exception. @@ -62,9 +63,11 @@ protected AbstractSession doCreateSession(final IoSession ioSession) throws Exce public static junit.framework.Test suite() throws Exception { final SftpProviderTestSuite suite = new SftpProviderTestSuite(new SftpPutChannelTestCase()) { @Override - protected void addBaseTests() throws Exception { - // Just tries to read - addTests(SftpPutChannelTestCase.class); + protected void addBaseTests(Set> exclusions) throws Exception { + if (!exclusions.contains(SftpPutChannelTestCase.class)) { + // Just tries to read + addTests(SftpPutChannelTestCase.class); + } } }; return suite; From f7899db2e92c60f78605069bfee1e71de47a64ff Mon Sep 17 00:00:00 2001 From: Ivan Bella Date: Wed, 10 May 2023 14:53:09 +0000 Subject: [PATCH 3/7] re #836: Removed redundant modifiers --- .../org/apache/commons/vfs2/provider/tar/TarFileSystem.java | 2 +- .../org/apache/commons/vfs2/provider/zip/ZipFileSystem.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileSystem.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileSystem.java index a20904873d..e2d33a2441 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileSystem.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileSystem.java @@ -57,7 +57,7 @@ public class TarFileSystem extends AbstractFileSystem { private TarFileThreadLocal tarFile = new TarFileThreadLocal(); private class TarFileCreationException extends RuntimeException { - public TarFileCreationException(Throwable cause) { + TarFileCreationException(Throwable cause) { super(cause); } } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java index f1338590a4..549f2d65ae 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java @@ -52,7 +52,7 @@ public class ZipFileSystem extends AbstractFileSystem { private ZipFileThreadLocal zipFile = new ZipFileThreadLocal(); private class ZipFileCreationException extends RuntimeException { - public ZipFileCreationException(Throwable cause) { + ZipFileCreationException(Throwable cause) { super(cause); } } From 8e5be255656100cc24bc2d73c79a4be5231ff791 Mon Sep 17 00:00:00 2001 From: Ivan Bella Date: Wed, 10 May 2023 16:02:04 +0000 Subject: [PATCH 4/7] re #836: Reverted to explicitly include new test cases instead of excluding --- .../webdav/test/WebdavProviderTestSuite.java | 49 ++++++++++---- .../test/Webdav4ProviderTestSuite.java | 49 ++++++++++---- .../vfs2/provider/ftp/FtpClientFactory.java | 2 +- .../commons/vfs2/AbstractTestSuite.java | 13 +--- .../commons/vfs2/ProviderTestSuite.java | 65 ++++++------------- .../provider/ftp/FtpProviderTestCase.java | 19 +----- .../ftps/AbstractFtpsProviderTestCase.java | 16 +---- .../provider/http/HttpProviderTestCase.java | 9 +-- .../provider/http4/Http4ProviderTestCase.java | 15 ++--- .../provider/http5/Http5ProviderTestCase.java | 10 +-- .../provider/jar/JarProviderTestCase.java | 6 +- .../provider/local/LocalProviderTestCase.java | 3 + .../provider/ram/RamProviderTestCase.java | 6 +- .../res/ResourceProviderTestCase.java | 6 +- .../sftp/AbstractSftpProviderTestCase.java | 5 +- .../sftp/SftpPermissionExceptionTestCase.java | 9 +-- ...SftpProviderClosedExecChannelTestCase.java | 26 +++----- .../SftpProviderStreamProxyModeTestCase.java | 19 ++---- .../provider/sftp/SftpPutChannelTestCase.java | 9 +-- .../provider/tar/TarProviderTestCase.java | 6 +- .../provider/zip/ZipProviderTestCase.java | 6 +- .../zip/ZipProviderWithCharsetTestCase.java | 6 +- 22 files changed, 167 insertions(+), 187 deletions(-) diff --git a/commons-vfs2-jackrabbit1/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestSuite.java b/commons-vfs2-jackrabbit1/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestSuite.java index 310f936fc4..13ccb7fda9 100644 --- a/commons-vfs2-jackrabbit1/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestSuite.java +++ b/commons-vfs2-jackrabbit1/src/test/java/org/apache/commons/vfs2/provider/webdav/test/WebdavProviderTestSuite.java @@ -16,24 +16,28 @@ */ package org.apache.commons.vfs2.provider.webdav.test; +import org.apache.commons.vfs2.ContentTests; +import org.apache.commons.vfs2.LastModifiedTests; +import org.apache.commons.vfs2.NamingTests; +import org.apache.commons.vfs2.ProviderCacheStrategyTests; +import org.apache.commons.vfs2.ProviderDeleteTests; +import org.apache.commons.vfs2.ProviderRandomReadTests; +import org.apache.commons.vfs2.ProviderRandomReadWriteTests; +import org.apache.commons.vfs2.ProviderReadTests; +import org.apache.commons.vfs2.ProviderRenameTests; import org.apache.commons.vfs2.ProviderTestConfig; import org.apache.commons.vfs2.ProviderTestSuite; -import org.apache.commons.vfs2.impl.VfsClassLoaderTests; -import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; - -import java.util.Arrays; -import java.util.HashSet; +import org.apache.commons.vfs2.ProviderWriteAppendTests; +import org.apache.commons.vfs2.ProviderWriteTests; +import org.apache.commons.vfs2.UriTests; +import org.apache.commons.vfs2.UrlStructureTests; +import org.apache.commons.vfs2.UrlTests; /** * The suite of tests for a file system. */ public class WebdavProviderTestSuite extends ProviderTestSuite { - // The class loader test requires the classes be uploaded to the webdav repo. - private static final Class[] EXCLUSIONS = new Class[] { - VfsClassLoaderTests.class, VfsThreadedClassLoaderTests.class - }; - /** * Adds the tests for a file system to this suite. */ @@ -51,7 +55,30 @@ public WebdavProviderTestSuite(final ProviderTestConfig providerConfig, final bo protected WebdavProviderTestSuite(final ProviderTestConfig providerConfig, final String prefix, final boolean nested, final boolean addEmptyDir) throws Exception { - super(providerConfig, prefix, nested, addEmptyDir, new HashSet<>(Arrays.asList(EXCLUSIONS))); + super(providerConfig, prefix, nested, addEmptyDir); + } + + /** + * Adds base tests - excludes the nested test cases. + */ + @Override + protected void addBaseTests() throws Exception { + addTests(ProviderCacheStrategyTests.class); + addTests(UriTests.class); + addTests(NamingTests.class); + addTests(ContentTests.class); + addTests(ProviderReadTests.class); + addTests(ProviderRandomReadTests.class); + addTests(ProviderWriteTests.class); + addTests(ProviderWriteAppendTests.class); + addTests(ProviderRandomReadWriteTests.class); + addTests(ProviderRenameTests.class); + addTests(ProviderDeleteTests.class); + addTests(LastModifiedTests.class); + addTests(UrlTests.class); + addTests(UrlStructureTests.class); + // The class loader test requires the classes be uploaded to the webdav repo. + // addTests(VfsClassLoaderTests.class); } } diff --git a/commons-vfs2-jackrabbit2/src/test/java/org/apache/commons/vfs2/provider/webdav4/test/Webdav4ProviderTestSuite.java b/commons-vfs2-jackrabbit2/src/test/java/org/apache/commons/vfs2/provider/webdav4/test/Webdav4ProviderTestSuite.java index 3090392c15..881642c915 100644 --- a/commons-vfs2-jackrabbit2/src/test/java/org/apache/commons/vfs2/provider/webdav4/test/Webdav4ProviderTestSuite.java +++ b/commons-vfs2-jackrabbit2/src/test/java/org/apache/commons/vfs2/provider/webdav4/test/Webdav4ProviderTestSuite.java @@ -16,13 +16,22 @@ */ package org.apache.commons.vfs2.provider.webdav4.test; +import org.apache.commons.vfs2.ContentTests; +import org.apache.commons.vfs2.LastModifiedTests; +import org.apache.commons.vfs2.NamingTests; +import org.apache.commons.vfs2.ProviderCacheStrategyTests; +import org.apache.commons.vfs2.ProviderDeleteTests; +import org.apache.commons.vfs2.ProviderRandomReadTests; +import org.apache.commons.vfs2.ProviderRandomReadWriteTests; +import org.apache.commons.vfs2.ProviderReadTests; +import org.apache.commons.vfs2.ProviderRenameTests; import org.apache.commons.vfs2.ProviderTestConfig; import org.apache.commons.vfs2.ProviderTestSuite; -import org.apache.commons.vfs2.impl.VfsClassLoaderTests; -import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; - -import java.util.Arrays; -import java.util.HashSet; +import org.apache.commons.vfs2.ProviderWriteAppendTests; +import org.apache.commons.vfs2.ProviderWriteTests; +import org.apache.commons.vfs2.UriTests; +import org.apache.commons.vfs2.UrlStructureTests; +import org.apache.commons.vfs2.UrlTests; /** * The suite of tests for a file system. @@ -30,12 +39,6 @@ * @since 2.5.0 */ public class Webdav4ProviderTestSuite extends ProviderTestSuite { - - // The class loader test requires the classes be uploaded to the webdav repo. - private static final Class[] EXCLUSIONS = new Class[] { - VfsClassLoaderTests.class, VfsThreadedClassLoaderTests.class - }; - /** * Adds the tests for a file system to this suite. */ @@ -53,7 +56,29 @@ public Webdav4ProviderTestSuite(final ProviderTestConfig providerConfig, final b protected Webdav4ProviderTestSuite(final ProviderTestConfig providerConfig, final String prefix, final boolean nested, final boolean addEmptyDir) throws Exception { - super(providerConfig, prefix, nested, addEmptyDir, new HashSet<>(Arrays.asList(EXCLUSIONS))); + super(providerConfig, prefix, nested, addEmptyDir); } + /** + * Adds base tests - excludes the nested test cases. + */ + @Override + protected void addBaseTests() throws Exception { + addTests(ProviderCacheStrategyTests.class); + addTests(UriTests.class); + addTests(NamingTests.class); + addTests(ContentTests.class); + addTests(ProviderReadTests.class); + addTests(ProviderRandomReadTests.class); + addTests(ProviderWriteTests.class); + addTests(ProviderWriteAppendTests.class); + addTests(ProviderRandomReadWriteTests.class); + addTests(ProviderRenameTests.class); + addTests(ProviderDeleteTests.class); + addTests(LastModifiedTests.class); + addTests(UrlTests.class); + addTests(UrlStructureTests.class); + // The class loader test requires the classes be uploaded to the webdav repo. + // addTests(VfsClassLoaderTests.class); + } } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java index a19af974ca..c5bf58261c 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java @@ -120,7 +120,7 @@ private void configureClient(final FileSystemOptions fileSystemOptions, final C * @return A new connection. * @throws FileSystemException if an error occurs while connecting. */ - public synchronized C createConnection(final String hostname, final int port, char[] username, char[] password, + public C createConnection(final String hostname, final int port, char[] username, char[] password, final String workingDirectory, final FileSystemOptions fileSystemOptions) throws FileSystemException { // Determine the username and password to use if (username == null) { diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/AbstractTestSuite.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/AbstractTestSuite.java index e62b411e67..c068ba77c6 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/AbstractTestSuite.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/AbstractTestSuite.java @@ -24,10 +24,8 @@ import java.lang.reflect.Modifier; import java.time.Instant; import java.util.ArrayList; -import java.util.Collections; import java.util.Enumeration; import java.util.List; -import java.util.Set; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.ArrayUtils; @@ -74,17 +72,12 @@ protected AbstractTestSuite(final ProviderTestConfig providerConfig, final Strin protected AbstractTestSuite(final ProviderTestConfig providerConfig, final String prefix, final boolean nested, final boolean addEmptyDir) throws Exception { - this(providerConfig, prefix, nested, addEmptyDir, Collections.emptySet()); - } - - protected AbstractTestSuite(final ProviderTestConfig providerConfig, final String prefix, final boolean nested, - final boolean addEmptyDir, final Set> exclusions) throws Exception { super(new TestSuite()); testSuite = (TestSuite) fTest; this.providerConfig = providerConfig; this.prefix = prefix; this.addEmptyDir = addEmptyDir; - addBaseTests(exclusions); + addBaseTests(); if (!nested) { // Add nested tests // TODO - move nested jar and zip tests here @@ -95,9 +88,9 @@ protected AbstractTestSuite(final ProviderTestConfig providerConfig, final Strin } /** - * Adds base tests - excludes the nested test cases and specified exclusions. + * Adds base tests - excludes the nested test cases. */ - protected void addBaseTests(final Set> exclusions) throws Exception { + protected void addBaseTests() throws Exception { } /** diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/ProviderTestSuite.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/ProviderTestSuite.java index 23b4c2b279..92e15f8a68 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/ProviderTestSuite.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/ProviderTestSuite.java @@ -17,38 +17,12 @@ package org.apache.commons.vfs2; import org.apache.commons.vfs2.impl.VfsClassLoaderTests; -import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; - -import java.util.Collections; -import java.util.Set; /** * The suite of tests for a file system. */ public class ProviderTestSuite extends AbstractTestSuite { - /** - * The list of base tests to be added to the test suite - */ - private final static Class[] BASE_TESTS = new Class[] { - UrlTests.class, - ProviderCacheStrategyTests.class, - UriTests.class, - NamingTests.class, - ContentTests.class, - ProviderReadTests.class, - ProviderWriteTests.class, - ProviderWriteAppendTests.class, - ProviderRandomReadTests.class, - ProviderRandomReadWriteTests.class, - ProviderRandomSetLengthTests.class, - ProviderRenameTests.class, - ProviderDeleteTests.class, - LastModifiedTests.class, - UrlStructureTests.class, - VfsClassLoaderTests.class, - VfsThreadedClassLoaderTests.class}; - /** * Adds the tests for a file system to this suite. */ @@ -56,13 +30,6 @@ public ProviderTestSuite(final ProviderTestConfig providerConfig) throws Excepti this(providerConfig, "", false, false); } - /** - * Adds the tests for a file system to this suite except for specified exclusions - */ - public ProviderTestSuite(final ProviderTestConfig providerConfig, Set> exclusions) throws Exception { - this(providerConfig, "", false, false, exclusions); - } - /** * Adds the tests for a file system to this suite. Provider has an empty directory. */ @@ -72,24 +39,30 @@ public ProviderTestSuite(final ProviderTestConfig providerConfig, final boolean protected ProviderTestSuite(final ProviderTestConfig providerConfig, final String prefix, final boolean nested, final boolean addEmptyDir) throws Exception { - this(providerConfig, prefix, nested, addEmptyDir, Collections.emptySet()); - } - - protected ProviderTestSuite(final ProviderTestConfig providerConfig, final String prefix, final boolean nested, - final boolean addEmptyDir, final Set> exclusions) throws Exception { - super(providerConfig, prefix, nested, addEmptyDir, exclusions); + super(providerConfig, prefix, nested, addEmptyDir); } /** - * Adds base tests - excludes the nested test cases and specified exclusions. + * Adds base tests - excludes the nested test cases. */ @Override - protected void addBaseTests(Set> exclusions) throws Exception { - for (Class testClass : BASE_TESTS) { - if (!exclusions.contains(testClass)) { - addTests(testClass); - } - } + protected void addBaseTests() throws Exception { + addTests(UrlTests.class); + addTests(ProviderCacheStrategyTests.class); + addTests(UriTests.class); + addTests(NamingTests.class); + addTests(ContentTests.class); + addTests(ProviderReadTests.class); + addTests(ProviderWriteTests.class); + addTests(ProviderWriteAppendTests.class); + addTests(ProviderRandomReadTests.class); + addTests(ProviderRandomReadWriteTests.class); + addTests(ProviderRandomSetLengthTests.class); + addTests(ProviderRenameTests.class); + addTests(ProviderDeleteTests.class); + addTests(LastModifiedTests.class); + addTests(UrlStructureTests.class); + addTests(VfsClassLoaderTests.class); } } diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java index 97d0fe683e..c3be9ae5f3 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.net.URL; import java.time.Duration; -import java.util.Set; import org.apache.commons.vfs2.AbstractProviderTestCase; import org.apache.commons.vfs2.AbstractProviderTestConfig; @@ -30,7 +29,6 @@ import org.apache.commons.vfs2.FileSystemOptions; import org.apache.commons.vfs2.ProviderTestSuite; import org.apache.commons.vfs2.impl.DefaultFileSystemManager; -import org.apache.ftpserver.ConnectionConfigFactory; import org.apache.ftpserver.FtpServer; import org.apache.ftpserver.FtpServerFactory; import org.apache.ftpserver.command.CommandFactory; @@ -115,15 +113,6 @@ static void setUpClass(final String rootDirectory, final FileSystemFactory fileS if (commandFactory != null) { serverFactory.setCommandFactory(commandFactory); } - // allow more connections - final ConnectionConfigFactory configFactory = new ConnectionConfigFactory(); - configFactory.setMaxLogins(500); - configFactory.setMaxThreads(500); - configFactory.setMaxAnonymousLogins(500); - configFactory.setMaxLoginFailures(100); - configFactory.setAnonymousLoginEnabled(true); - configFactory.setLoginFailureDelay(1); - serverFactory.setConnectionConfig(configFactory.createConnectionConfig()); final ListenerFactory factory = new ListenerFactory(); // set the port of the listener factory.setPort(0); @@ -153,14 +142,12 @@ protected static Test suite(final FtpProviderTestCase testCase, return new ProviderTestSuite(testCase) { @Override - protected void addBaseTests(Set> exclusions) throws Exception { + protected void addBaseTests() throws Exception { if (testClasses.length == 0) { - super.addBaseTests(exclusions); + super.addBaseTests(); } else { for (final Class test : testClasses) { - if (!exclusions.contains(test)) { - addTests(test); - } + addTests(test); } } } diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java index a7ecec3e35..ecf768595f 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java @@ -29,7 +29,6 @@ import org.apache.commons.vfs2.FileSystemOptions; import org.apache.commons.vfs2.ProviderTestSuite; import org.apache.commons.vfs2.impl.DefaultFileSystemManager; -import org.apache.ftpserver.ConnectionConfigFactory; import org.apache.ftpserver.FtpServer; import org.apache.ftpserver.FtpServerFactory; import org.apache.ftpserver.ftplet.FtpException; @@ -153,16 +152,6 @@ synchronized static void setUpClass(final boolean implicit) throws FtpException // replace the default listener serverFactory.addListener(LISTENER_NAME, listenerFactory.createListener()); - // allow more connections - final ConnectionConfigFactory configFactory = new ConnectionConfigFactory(); - configFactory.setMaxLogins(1000); - configFactory.setMaxThreads(1000); - configFactory.setMaxAnonymousLogins(1000); - configFactory.setMaxLoginFailures(100); - configFactory.setAnonymousLoginEnabled(true); - configFactory.setLoginFailureDelay(1); - serverFactory.setConnectionConfig(configFactory.createConnectionConfig()); - // start the server EmbeddedFtpServer = serverFactory.createServer(); EmbeddedFtpServer.start(); @@ -232,9 +221,8 @@ public void prepare(final DefaultFileSystemManager manager) throws Exception { } protected void setupOptions(final FtpsFileSystemConfigBuilder builder) { - builder.setConnectTimeout(fileSystemOptions, Duration.ofSeconds(60)); - builder.setDataTimeout(fileSystemOptions, Duration.ofSeconds(60)); - builder.setSoTimeout(fileSystemOptions, Duration.ofSeconds(60)); + builder.setConnectTimeout(fileSystemOptions, Duration.ofSeconds(10)); + builder.setDataTimeout(fileSystemOptions, Duration.ofSeconds(10)); } } diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http/HttpProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http/HttpProviderTestCase.java index a8e6500a9e..4d39fa2d9f 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http/HttpProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http/HttpProviderTestCase.java @@ -20,7 +20,6 @@ import java.io.File; import java.time.Duration; -import java.util.Set; import org.apache.commons.vfs2.AbstractProviderTestConfig; import org.apache.commons.vfs2.FileNotFolderException; @@ -80,11 +79,9 @@ public static junit.framework.Test suite() throws Exception { * Adds base tests - excludes the nested test cases. */ @Override - protected void addBaseTests(Set> exclusions) throws Exception { - super.addBaseTests(exclusions); - if (!exclusions.contains(HttpProviderTestCase.class)) { - addTests(HttpProviderTestCase.class); - } + protected void addBaseTests() throws Exception { + super.addBaseTests(); + addTests(HttpProviderTestCase.class); } @Override diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/Http4ProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/Http4ProviderTestCase.java index bdfaa64d44..de661365ff 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/Http4ProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http4/Http4ProviderTestCase.java @@ -20,8 +20,6 @@ import java.io.File; import java.time.Duration; -import java.util.Collections; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.apache.commons.vfs2.AbstractProviderTestConfig; @@ -33,7 +31,6 @@ import org.apache.commons.vfs2.ProviderTestSuite; import org.apache.commons.vfs2.VFS; import org.apache.commons.vfs2.impl.DefaultFileSystemManager; -import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; import org.apache.commons.vfs2.util.NHttpFileServer; import org.junit.jupiter.api.Assertions; import org.junit.Test; @@ -76,16 +73,14 @@ private static void setUpClass() throws Exception { * @throws Exception Thrown when the suite cannot be constructed. */ public static junit.framework.Test suite() throws Exception { - return new ProviderTestSuite(new Http4ProviderTestCase(), Collections.singleton(VfsThreadedClassLoaderTests.class)) { + return new ProviderTestSuite(new Http4ProviderTestCase()) { /** - * Adds base tests - excludes the nested test cases and the threaded class loader tests + * Adds base tests - excludes the nested test cases. */ @Override - protected void addBaseTests(Set> exclusions) throws Exception { - super.addBaseTests(exclusions); - if (!exclusions.contains(Http4ProviderTestCase.class)) { - addTests(Http4ProviderTestCase.class); - } + protected void addBaseTests() throws Exception { + super.addBaseTests(); + addTests(Http4ProviderTestCase.class); } @Override diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/Http5ProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/Http5ProviderTestCase.java index 5919de8430..97734a7f36 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/Http5ProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/http5/Http5ProviderTestCase.java @@ -20,7 +20,6 @@ import java.io.File; import java.time.Duration; -import java.util.Set; import java.util.concurrent.TimeUnit; import org.apache.commons.vfs2.AbstractProviderTestConfig; @@ -32,7 +31,6 @@ import org.apache.commons.vfs2.ProviderTestSuite; import org.apache.commons.vfs2.VFS; import org.apache.commons.vfs2.impl.DefaultFileSystemManager; -import org.apache.commons.vfs2.provider.http4.Http4ProviderTestCase; import org.apache.commons.vfs2.util.NHttpFileServer; import org.junit.Test; import org.junit.jupiter.api.Assertions; @@ -80,11 +78,9 @@ public static junit.framework.Test suite() throws Exception { * Adds base tests - excludes the nested test cases. */ @Override - protected void addBaseTests(Set> exclusions) throws Exception { - super.addBaseTests(exclusions); - if (!exclusions.contains(Http4ProviderTestCase.class)) { - addTests(Http5ProviderTestCase.class); - } + protected void addBaseTests() throws Exception { + super.addBaseTests(); + addTests(Http5ProviderTestCase.class); } @Override diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/jar/JarProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/jar/JarProviderTestCase.java index 64defb9213..60c353ded6 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/jar/JarProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/jar/JarProviderTestCase.java @@ -27,6 +27,8 @@ import org.apache.commons.vfs2.impl.DefaultFileSystemManager; import junit.framework.Test; +import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; +import org.apache.commons.vfs2.provider.tar.TarProviderTestCase; /** * Tests for the Jar file system. @@ -43,7 +45,9 @@ static FileObject getTestJar(final FileSystemManager manager, final String name) * Creates the test suite for the jar file system. */ public static Test suite() throws Exception { - return new ProviderTestSuite(new JarProviderTestCase(), true); + final ProviderTestSuite testSuite = new ProviderTestSuite(new JarProviderTestCase(), true); + testSuite.addTests(VfsThreadedClassLoaderTests.class); + return testSuite; } /** diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/local/LocalProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/local/LocalProviderTestCase.java index 538a16ea3e..732dcbfae8 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/local/LocalProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/local/LocalProviderTestCase.java @@ -26,6 +26,7 @@ import org.apache.commons.vfs2.ProviderTestSuite; import junit.framework.Test; +import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; /** * Tests for the local file system. @@ -48,6 +49,8 @@ public static Test suite() throws Exception { testSuite.addTests(WindowsFileNameTests.class); } + testSuite.addTests(VfsThreadedClassLoaderTests.class); + return testSuite; } diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ram/RamProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ram/RamProviderTestCase.java index e19b2b9ef9..f077c5a67d 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ram/RamProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ram/RamProviderTestCase.java @@ -25,9 +25,11 @@ import org.apache.commons.vfs2.FileSystemManager; import org.apache.commons.vfs2.ProviderTestSuite; import org.apache.commons.vfs2.impl.DefaultFileSystemManager; +import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; import org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider; import junit.framework.Test; +import org.apache.commons.vfs2.provider.tar.TarProviderTestCase; /** * Tests for the RAM file system. @@ -43,7 +45,9 @@ public class RamProviderTestCase extends AbstractProviderTestConfig { * Creates the test suite for the ram file system. */ public static Test suite() throws Exception { - return new ProviderTestSuite(new RamProviderTestCase()); + final ProviderTestSuite testSuite = new ProviderTestSuite(new RamProviderTestCase()); + testSuite.addTests(VfsThreadedClassLoaderTests.class); + return testSuite; } /** diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/res/ResourceProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/res/ResourceProviderTestCase.java index 8e5a6fbdbd..8dd8b23903 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/res/ResourceProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/res/ResourceProviderTestCase.java @@ -23,7 +23,9 @@ import org.apache.commons.vfs2.FileSystemManager; import org.apache.commons.vfs2.ProviderTestSuite; import org.apache.commons.vfs2.impl.DefaultFileSystemManager; +import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; import org.apache.commons.vfs2.provider.jar.JarFileProvider; +import org.apache.commons.vfs2.provider.tar.TarProviderTestCase; import org.apache.commons.vfs2.provider.url.UrlFileProvider; import junit.framework.Test; @@ -34,7 +36,9 @@ public class ResourceProviderTestCase extends AbstractProviderTestConfig { public static Test suite() throws Exception { - return new ProviderTestSuite(new ResourceProviderTestCase()); + final ProviderTestSuite testSuite = new ProviderTestSuite(new ResourceProviderTestCase(), true); + testSuite.addTests(VfsThreadedClassLoaderTests.class); + return testSuite; } /** diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/AbstractSftpProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/AbstractSftpProviderTestCase.java index 33690cd72f..e549005f61 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/AbstractSftpProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/AbstractSftpProviderTestCase.java @@ -31,7 +31,6 @@ import java.nio.file.Paths; import java.time.Duration; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.TreeMap; import java.util.regex.Matcher; @@ -44,7 +43,6 @@ import org.apache.commons.vfs2.FileSystemOptions; import org.apache.commons.vfs2.ProviderTestSuite; import org.apache.commons.vfs2.impl.DefaultFileSystemManager; -import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; import org.apache.ftpserver.ftplet.FtpException; import org.apache.sshd.SshServer; import org.apache.sshd.common.NamedFactory; @@ -230,8 +228,7 @@ static class SftpProviderTestSuite extends ProviderTestSuite { private final SessionFactory sessionFactory; public SftpProviderTestSuite(final AbstractSftpProviderTestCase providerConfig) throws Exception { - // exclude the threaded class loader tests - super(providerConfig, Collections.singleton(VfsThreadedClassLoaderTests.class)); + super(providerConfig); this.isExecChannelClosed = providerConfig.isExecChannelClosed(); this.sessionFactory = providerConfig.sessionFactory(); } diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpPermissionExceptionTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpPermissionExceptionTestCase.java index 500b90e019..51a7dc12d3 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpPermissionExceptionTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpPermissionExceptionTestCase.java @@ -20,7 +20,6 @@ import java.io.File; import java.nio.file.Paths; -import java.util.Set; import org.apache.commons.vfs2.Capability; import org.apache.commons.vfs2.FileObject; @@ -41,11 +40,9 @@ public class SftpPermissionExceptionTestCase extends AbstractSftpProviderTestCas public static junit.framework.Test suite() throws Exception { final SftpProviderTestSuite suite = new SftpProviderTestSuite(new SftpPermissionExceptionTestCase()){ @Override - protected void addBaseTests(Set> exclusions) throws Exception { - if (!exclusions.contains(SftpPermissionExceptionTestCase.class)) { - // Just tries to read - addTests(SftpPermissionExceptionTestCase.class); - } + protected void addBaseTests() throws Exception { + // Just tries to read + addTests(SftpPermissionExceptionTestCase.class); } }; return suite; diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpProviderClosedExecChannelTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpProviderClosedExecChannelTestCase.java index 8bdc761b4c..162e520d7b 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpProviderClosedExecChannelTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpProviderClosedExecChannelTestCase.java @@ -25,32 +25,22 @@ import junit.framework.Test; -import java.util.Set; - public class SftpProviderClosedExecChannelTestCase extends AbstractSftpProviderTestCase { - private static final Class[] BASE_TESTS = new Class[] { - ProviderReadTests.class, - ProviderWriteTests.class, - ProviderDeleteTests.class, - ProviderRenameTests.class, - NamingTests.class, - // VFS-405: set/get permissions - PermissionsTests.class - }; - /** * Creates the test suite for the sftp file system. */ public static Test suite() throws Exception { final SftpProviderTestSuite suite = new SftpProviderTestSuite(new SftpProviderClosedExecChannelTestCase()) { @Override - protected void addBaseTests(Set> exclusions) throws Exception { - for (Class testClass : BASE_TESTS) { - if (!exclusions.contains(testClass)) { - addTests(testClass); - } - } + protected void addBaseTests() throws Exception { + addTests(ProviderReadTests.class); + addTests(ProviderWriteTests.class); + addTests(ProviderDeleteTests.class); + addTests(ProviderRenameTests.class); + addTests(NamingTests.class); + // VFS-405: set/get permissions + addTests(PermissionsTests.class); } }; return suite; diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpProviderStreamProxyModeTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpProviderStreamProxyModeTestCase.java index 4f9deb5c74..dca2320b5c 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpProviderStreamProxyModeTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpProviderStreamProxyModeTestCase.java @@ -17,7 +17,6 @@ package org.apache.commons.vfs2.provider.sftp; import java.net.URI; -import java.util.Set; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemManager; @@ -31,13 +30,6 @@ public class SftpProviderStreamProxyModeTestCase extends AbstractSftpProviderTestCase { - private static final Class[] BASE_TESTS = new Class[] { - // Just tries to read - ProviderReadTests.class, - // VFS-405: set/get permissions - PermissionsTests.class - }; - // --- VFS-440: stream proxy test suite // We override the addBaseTests method so that only // one test is run (we just test that the input/output are correctly forwarded, and @@ -45,12 +37,11 @@ public class SftpProviderStreamProxyModeTestCase extends AbstractSftpProviderTes public static Test suite() throws Exception { final SftpProviderTestSuite suite = new SftpProviderTestSuite(new SftpProviderStreamProxyModeTestCase()) { @Override - protected void addBaseTests(Set> exclusions) throws Exception { - for (Class testClass : BASE_TESTS) { - if (!exclusions.contains(testClass)) { - addTests(testClass); - } - } + protected void addBaseTests() throws Exception { + // Just tries to read + addTests(ProviderReadTests.class); + // VFS-405: set/get permissions + addTests(PermissionsTests.class); } }; return suite; diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpPutChannelTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpPutChannelTestCase.java index aededc920a..3873158576 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpPutChannelTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/sftp/SftpPutChannelTestCase.java @@ -28,7 +28,6 @@ import org.junit.jupiter.api.Assertions; import java.io.InputStream; -import java.util.Set; /** * Test SftpFileObject.doGetInputStream return the channel to pool when throw an exception. @@ -63,11 +62,9 @@ protected AbstractSession doCreateSession(final IoSession ioSession) throws Exce public static junit.framework.Test suite() throws Exception { final SftpProviderTestSuite suite = new SftpProviderTestSuite(new SftpPutChannelTestCase()) { @Override - protected void addBaseTests(Set> exclusions) throws Exception { - if (!exclusions.contains(SftpPutChannelTestCase.class)) { - // Just tries to read - addTests(SftpPutChannelTestCase.class); - } + protected void addBaseTests() throws Exception { + // Just tries to read + addTests(SftpPutChannelTestCase.class); } }; return suite; diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/TarProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/TarProviderTestCase.java index de229430fc..a4578dc60a 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/TarProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/TarProviderTestCase.java @@ -27,6 +27,8 @@ import org.apache.commons.vfs2.impl.DefaultFileSystemManager; import junit.framework.Test; +import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; +import org.apache.commons.vfs2.provider.local.LocalProviderTestCase; /** * Tests for the Tar file system. @@ -37,7 +39,9 @@ public class TarProviderTestCase extends AbstractProviderTestConfig { * Creates the test suite for the tar file system. */ public static Test suite() throws Exception { - return new ProviderTestSuite(new TarProviderTestCase(), true); + final ProviderTestSuite testSuite = new ProviderTestSuite(new TarProviderTestCase(), true); + testSuite.addTests(VfsThreadedClassLoaderTests.class); + return testSuite; } /** diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderTestCase.java index 45d7fb0497..c40b3ff875 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderTestCase.java @@ -27,6 +27,8 @@ import org.apache.commons.vfs2.impl.DefaultFileSystemManager; import junit.framework.Test; +import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; +import org.apache.commons.vfs2.provider.tar.TarProviderTestCase; /** * Tests for the Zip file system. @@ -37,7 +39,9 @@ public class ZipProviderTestCase extends AbstractProviderTestConfig { * Creates the test suite for the ZIP file system. */ public static Test suite() throws Exception { - return new ProviderTestSuite(new ZipProviderTestCase(), true); + final ProviderTestSuite testSuite = new ProviderTestSuite(new ZipProviderTestCase(), true); + testSuite.addTests(VfsThreadedClassLoaderTests.class); + return testSuite; } /** diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetTestCase.java index bc5714a2ff..9ff7573234 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetTestCase.java @@ -28,6 +28,8 @@ import org.apache.commons.vfs2.FileSystemOptions; import org.apache.commons.vfs2.ProviderTestSuite; import org.apache.commons.vfs2.impl.DefaultFileSystemManager; +import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; +import org.apache.commons.vfs2.provider.tar.TarProviderTestCase; import org.junit.jupiter.api.Assertions; import junit.framework.Test; @@ -41,7 +43,9 @@ public class ZipProviderWithCharsetTestCase extends AbstractProviderTestConfig { * Creates the test suite for the ZIP file system. */ public static Test suite() throws Exception { - return new ProviderTestSuite(new ZipProviderWithCharsetTestCase(), true); + final ProviderTestSuite testSuite = new ProviderTestSuite(new ZipProviderWithCharsetTestCase(), true); + testSuite.addTests(VfsThreadedClassLoaderTests.class); + return testSuite; } /** From bb4f8afc1596e04391408a5408b9001d68cd6cf7 Mon Sep 17 00:00:00 2001 From: Ivan Bella Date: Wed, 10 May 2023 16:05:40 +0000 Subject: [PATCH 5/7] re #836: removed unused imports --- .../apache/commons/vfs2/provider/ram/RamProviderTestCase.java | 1 - .../commons/vfs2/provider/res/ResourceProviderTestCase.java | 1 - .../apache/commons/vfs2/provider/tar/TarProviderTestCase.java | 1 - .../apache/commons/vfs2/provider/zip/ZipProviderTestCase.java | 1 - .../vfs2/provider/zip/ZipProviderWithCharsetTestCase.java | 1 - 5 files changed, 5 deletions(-) diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ram/RamProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ram/RamProviderTestCase.java index f077c5a67d..c9f24b5254 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ram/RamProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ram/RamProviderTestCase.java @@ -29,7 +29,6 @@ import org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider; import junit.framework.Test; -import org.apache.commons.vfs2.provider.tar.TarProviderTestCase; /** * Tests for the RAM file system. diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/res/ResourceProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/res/ResourceProviderTestCase.java index 8dd8b23903..1db9453f5b 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/res/ResourceProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/res/ResourceProviderTestCase.java @@ -25,7 +25,6 @@ import org.apache.commons.vfs2.impl.DefaultFileSystemManager; import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; import org.apache.commons.vfs2.provider.jar.JarFileProvider; -import org.apache.commons.vfs2.provider.tar.TarProviderTestCase; import org.apache.commons.vfs2.provider.url.UrlFileProvider; import junit.framework.Test; diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/TarProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/TarProviderTestCase.java index a4578dc60a..74671d38dc 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/TarProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/tar/TarProviderTestCase.java @@ -28,7 +28,6 @@ import junit.framework.Test; import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; -import org.apache.commons.vfs2.provider.local.LocalProviderTestCase; /** * Tests for the Tar file system. diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderTestCase.java index c40b3ff875..b1589b2ff5 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderTestCase.java @@ -28,7 +28,6 @@ import junit.framework.Test; import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; -import org.apache.commons.vfs2.provider.tar.TarProviderTestCase; /** * Tests for the Zip file system. diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetTestCase.java index 9ff7573234..f3711b5bc8 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/ZipProviderWithCharsetTestCase.java @@ -29,7 +29,6 @@ import org.apache.commons.vfs2.ProviderTestSuite; import org.apache.commons.vfs2.impl.DefaultFileSystemManager; import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; -import org.apache.commons.vfs2.provider.tar.TarProviderTestCase; import org.junit.jupiter.api.Assertions; import junit.framework.Test; From e152b17460c2964b4f212ba9f9e024c4521cf9c1 Mon Sep 17 00:00:00 2001 From: Ivan Bella Date: Wed, 10 May 2023 18:37:36 +0000 Subject: [PATCH 6/7] re #836: removed thread safety test for resource provider --- .../commons/vfs2/provider/res/ResourceProviderTestCase.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/res/ResourceProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/res/ResourceProviderTestCase.java index 1db9453f5b..030dd72165 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/res/ResourceProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/res/ResourceProviderTestCase.java @@ -23,7 +23,6 @@ import org.apache.commons.vfs2.FileSystemManager; import org.apache.commons.vfs2.ProviderTestSuite; import org.apache.commons.vfs2.impl.DefaultFileSystemManager; -import org.apache.commons.vfs2.impl.VfsThreadedClassLoaderTests; import org.apache.commons.vfs2.provider.jar.JarFileProvider; import org.apache.commons.vfs2.provider.url.UrlFileProvider; @@ -35,9 +34,7 @@ public class ResourceProviderTestCase extends AbstractProviderTestConfig { public static Test suite() throws Exception { - final ProviderTestSuite testSuite = new ProviderTestSuite(new ResourceProviderTestCase(), true); - testSuite.addTests(VfsThreadedClassLoaderTests.class); - return testSuite; + return new ProviderTestSuite(new ResourceProviderTestCase(), true); } /** From a12580047944ea6fa15b69a6c0c280ddc05edde6 Mon Sep 17 00:00:00 2001 From: Ivan Bella Date: Thu, 11 May 2023 15:36:35 +0000 Subject: [PATCH 7/7] re #836: inadvertant change reverted --- .../commons/vfs2/provider/res/ResourceProviderTestCase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/res/ResourceProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/res/ResourceProviderTestCase.java index 030dd72165..8e5a6fbdbd 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/res/ResourceProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/res/ResourceProviderTestCase.java @@ -34,7 +34,7 @@ public class ResourceProviderTestCase extends AbstractProviderTestConfig { public static Test suite() throws Exception { - return new ProviderTestSuite(new ResourceProviderTestCase(), true); + return new ProviderTestSuite(new ResourceProviderTestCase()); } /**