Search in sources :

Example 81 with TemporaryFolder

use of org.junit.rules.TemporaryFolder in project iaf by ibissource.

the class StatusRecordingTransactionManagerTest method setup.

@Before
public void setup() throws IOException {
    folder = new TemporaryFolder();
    folder.create();
}
Also used : TemporaryFolder(org.junit.rules.TemporaryFolder) Before(org.junit.Before)

Example 82 with TemporaryFolder

use of org.junit.rules.TemporaryFolder in project iaf by ibissource.

the class BtmJtaTransactionManagerTest method setup.

@Before
public void setup() throws IOException {
    folder = new TemporaryFolder();
    folder.create();
}
Also used : TemporaryFolder(org.junit.rules.TemporaryFolder) Before(org.junit.Before)

Example 83 with TemporaryFolder

use of org.junit.rules.TemporaryFolder in project iaf by ibissource.

the class AmazonS3FileSystemTestHelper method _createFile.

@Override
public OutputStream _createFile(final String foldername, final String filename) throws IOException {
    TemporaryFolder folder = new TemporaryFolder();
    folder.create();
    String fileName = folder.getRoot().getAbsolutePath() + "tempFile";
    final File file = new File(fileName);
    final FileOutputStream fos = new FileOutputStream(file);
    final BufferedOutputStream bos = new BufferedOutputStream(fos);
    FilterOutputStream filterOutputStream = new FilterOutputStream(bos) {

        @Override
        public void close() throws IOException {
            super.close();
            bos.close();
            FileInputStream fis = new FileInputStream(file);
            ObjectMetadata metaData = new ObjectMetadata();
            metaData.setContentLength(file.length());
            String filePath = foldername == null ? filename : foldername + "/" + filename;
            s3Client.putObject(bucketName, filePath, fis, metaData);
            fis.close();
            file.delete();
        }
    };
    return filterOutputStream;
}
Also used : FileOutputStream(java.io.FileOutputStream) TemporaryFolder(org.junit.rules.TemporaryFolder) FilterOutputStream(java.io.FilterOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) FileInputStream(java.io.FileInputStream)

Example 84 with TemporaryFolder

use of org.junit.rules.TemporaryFolder in project iaf by ibissource.

the class LocalFileSystemActorTest method setUp.

@Override
public void setUp() throws Exception {
    folder = new TemporaryFolder();
    folder.create();
    super.setUp();
}
Also used : TemporaryFolder(org.junit.rules.TemporaryFolder)

Example 85 with TemporaryFolder

use of org.junit.rules.TemporaryFolder in project flow by vaadin.

the class StaticFileServerTest method concurrentRequestsToJarResources_checksAreCorrect.

@Test
public void concurrentRequestsToJarResources_checksAreCorrect() throws IOException, InterruptedException, ExecutionException, URISyntaxException {
    fileServer.writeResponse = false;
    Assert.assertTrue("Can not run concurrently with other test", StaticFileServer.openFileSystems.isEmpty());
    final TemporaryFolder folder = TemporaryFolder.builder().build();
    folder.create();
    Path tempArchive = generateZipArchive(folder);
    setupRequestURI("", "", "/frontend/.");
    final URL folderResourceURL = new URL("jar:file:///" + tempArchive.toString().replaceAll("\\\\", "/") + "!/frontend");
    Mockito.when(servletService.getStaticResource("/frontend/.")).thenReturn(folderResourceURL);
    int THREADS = 5;
    List<Callable<Result>> folderNotResource = IntStream.range(0, THREADS).mapToObj(i -> {
        Callable<Result> callable = () -> {
            try {
                if (fileServer.serveStaticResource(request, response)) {
                    throw new IllegalArgumentException("Folder 'frontend' in jar should not be a static resource.");
                }
            } catch (Exception e) {
                return new Result(e);
            }
            return new Result(null);
        };
        return callable;
    }).collect(Collectors.toList());
    ExecutorService executor = Executors.newFixedThreadPool(THREADS);
    List<Future<Result>> futures = executor.invokeAll(folderNotResource);
    List<String> exceptions = new ArrayList<>();
    executor.shutdown();
    for (Future<Result> resultFuture : futures) {
        Result result = resultFuture.get();
        if (result.exception != null) {
            exceptions.add(result.exception.getMessage());
        }
    }
    Assert.assertTrue("There were exceptions in concurrent requests {" + exceptions + "}", exceptions.isEmpty());
    Assert.assertFalse("Folder URI should have been cleared", StaticFileServer.openFileSystems.containsKey(folderResourceURL.toURI()));
    try {
        FileSystems.getFileSystem(folderResourceURL.toURI());
        Assert.fail("FileSystem for folder resource should be closed");
    } catch (FileSystemNotFoundException fsnfe) {
    // This should happen as we should not have an open FileSystem here.
    }
    setupRequestURI("", "", "/file.txt");
    final URL fileResourceURL = new URL("jar:file:///" + tempArchive.toString().replaceAll("\\\\", "/") + "!/file.txt");
    Mockito.when(servletService.getStaticResource("/file.txt")).thenReturn(fileResourceURL);
    List<Callable<Result>> fileIsResource = IntStream.range(0, THREADS).mapToObj(i -> {
        Callable<Result> callable = () -> {
            try {
                if (!fileServer.serveStaticResource(request, response)) {
                    throw new IllegalArgumentException("File 'file.txt' inside jar should be a static resource.");
                }
            } catch (Exception e) {
                return new Result(e);
            }
            return new Result(null);
        };
        return callable;
    }).collect(Collectors.toList());
    executor = Executors.newFixedThreadPool(THREADS);
    futures = executor.invokeAll(fileIsResource);
    exceptions = new ArrayList<>();
    executor.shutdown();
    for (Future<Result> resultFuture : futures) {
        Result result = resultFuture.get();
        if (result.exception != null) {
            exceptions.add(result.exception.getMessage());
        }
    }
    Assert.assertTrue("There were exceptions in concurrent requests {" + exceptions + "}", exceptions.isEmpty());
    Assert.assertFalse("URI should have been cleared", fileServer.openFileSystems.containsKey(fileResourceURL.toURI()));
    try {
        FileSystems.getFileSystem(fileResourceURL.toURI());
        Assert.fail("FileSystem for file resource should be closed");
    } catch (FileSystemNotFoundException fsnfe) {
    // This should happen as we should not have an open FileSystem here.
    }
    folder.delete();
}
Also used : Path(java.nio.file.Path) STATISTICS_JSON_DEFAULT(com.vaadin.flow.server.Constants.STATISTICS_JSON_DEFAULT) Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) URL(java.net.URL) CurrentInstance(com.vaadin.flow.internal.CurrentInstance) URISyntaxException(java.net.URISyntaxException) POLYFILLS_DEFAULT_VALUE(com.vaadin.flow.server.Constants.POLYFILLS_DEFAULT_VALUE) Future(java.util.concurrent.Future) WarURLStreamHandlerFactory(com.vaadin.flow.WarURLStreamHandlerFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) VAADIN_SERVLET_RESOURCES(com.vaadin.flow.server.Constants.VAADIN_SERVLET_RESOURCES) ZoneOffset(java.time.ZoneOffset) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) FileSystem(java.nio.file.FileSystem) ResponseWriter(com.vaadin.flow.internal.ResponseWriter) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) Serializable(java.io.Serializable) NotThreadSafe(net.jcip.annotations.NotThreadSafe) URLStreamHandler(java.net.URLStreamHandler) List(java.util.List) IntStream(java.util.stream.IntStream) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BeforeClass(org.junit.BeforeClass) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletOutputStream(javax.servlet.ServletOutputStream) WriteListener(javax.servlet.WriteListener) URLConnection(java.net.URLConnection) SERVLET_PARAMETER_STATISTICS_JSON(com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_STATISTICS_JSON) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) MalformedURLException(java.net.MalformedURLException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) Files(java.nio.file.Files) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Test(org.junit.Test) Field(java.lang.reflect.Field) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Mockito(org.mockito.Mockito) ServletContext(javax.servlet.ServletContext) Assert(org.junit.Assert) Collections(java.util.Collections) FileSystems(java.nio.file.FileSystems) TemporaryFolder(org.junit.rules.TemporaryFolder) ArrayList(java.util.ArrayList) URL(java.net.URL) Callable(java.util.concurrent.Callable) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) TemporaryFolder(org.junit.rules.TemporaryFolder) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Test(org.junit.Test)

Aggregations

TemporaryFolder (org.junit.rules.TemporaryFolder)106 File (java.io.File)40 Before (org.junit.Before)28 Test (org.junit.Test)28 BeforeClass (org.junit.BeforeClass)13 URL (java.net.URL)7 Path (java.nio.file.Path)7 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)3 UserState (alluxio.security.user.UserState)2 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2 RocksDBPersistenceProvider (com.iota.iri.storage.rocksDB.RocksDBPersistenceProvider)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URISyntaxException (java.net.URISyntaxException)2 BdpDataPlanePlugin (org.batfish.bdp.BdpDataPlanePlugin)2 Batfish (org.batfish.main.Batfish)2 NotNull (org.jetbrains.annotations.NotNull)2 DefaultSafeModeManager (alluxio.master.DefaultSafeModeManager)1 InMemoryReferenceSequenceFile (au.edu.wehi.idsv.picard.InMemoryReferenceSequenceFile)1 SynchronousReferenceLookupAdapter (au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter)1