Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Close device when R plot has error

AuthorDaveJarvis <email>
Date2022-06-28 12:52:23 GMT-0700
Commit4971256a456ce3a1f2a033600b5ccdd01edc1fd9
Parent4045cfe
Delta47 lines added, 0 lines removed, 47-line increase
src/test/java/com/keenwrite/io/FileObjectTest.java
+package com.keenwrite.io;
+
+import org.apache.commons.vfs2.FileSystemException;
+import org.junit.jupiter.api.Disabled;
+import org.renjin.eval.SessionBuilder;
+
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+
+import static java.io.File.separator;
+import static java.lang.String.format;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+/**
+ * Tests file resource allocation.
+ */
+public class FileObjectTest {
+ private final static String TEMP_DIR = System.getProperty( "java.io.tmpdir" );
+
+ /**
+ * Test that resources are not exhausted.
+ *
+ * Disabled because no issue was found and this test thrashes the I/O.
+ */
+ @Disabled
+ void test_Open_MultipleFiles_NoResourcesExpire() throws FileSystemException {
+ final var builder = new SessionBuilder();
+ final var session = builder.build();
+
+ for( int i = 0; i < 10000; i++ ) {
+ final var filename = format( "%s%s%d.txt", TEMP_DIR, separator, i );
+ final var fileObject = session
+ .getFileSystemManager()
+ .resolveFile( filename );
+
+ try(
+ final var stream = fileObject.getContent().getOutputStream();
+ final var writer = new OutputStreamWriter( stream, UTF_8 ) ) {
+ writer.write( "contents" );
+ } catch( final IOException e ) {
+ throw new FileSystemException( e );
+ }
+
+ fileObject.delete();
+ }
+ }
+}