Search in sources :

Example 1 with IOError

use of java.io.IOError in project elasticsearch by elastic.

the class ElasticsearchUncaughtExceptionHandlerTests method testUncaughtError.

public void testUncaughtError() throws InterruptedException {
    final Error error = randomFrom(new InternalError(), new OutOfMemoryError(), new StackOverflowError(), new UnknownError(), new IOError(new IOException("fatal")), new Error() {
    });
    final Thread thread = new Thread(() -> {
        throw error;
    });
    final String name = randomAsciiOfLength(10);
    thread.setName(name);
    final AtomicBoolean halt = new AtomicBoolean();
    final AtomicInteger observedStatus = new AtomicInteger();
    final AtomicReference<String> threadNameReference = new AtomicReference<>();
    final AtomicReference<Throwable> throwableReference = new AtomicReference<>();
    thread.setUncaughtExceptionHandler(new ElasticsearchUncaughtExceptionHandler(() -> "testUncaughtError") {

        @Override
        void halt(int status) {
            halt.set(true);
            observedStatus.set(status);
        }

        @Override
        void onFatalUncaught(String threadName, Throwable t) {
            threadNameReference.set(threadName);
            throwableReference.set(t);
        }

        @Override
        void onNonFatalUncaught(String threadName, Throwable t) {
            fail();
        }
    });
    thread.start();
    thread.join();
    assertTrue(halt.get());
    final int status;
    if (expectedStatus.containsKey(error.getClass())) {
        status = expectedStatus.get(error.getClass());
    } else {
        status = 1;
    }
    assertThat(observedStatus.get(), equalTo(status));
    assertThat(threadNameReference.get(), equalTo(name));
    assertThat(throwableReference.get(), equalTo(error));
}
Also used : IOError(java.io.IOError) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOError(java.io.IOError) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 2 with IOError

use of java.io.IOError in project bazel by bazelbuild.

the class BlazeJavacMain method setLocations.

private static void setLocations(JavacFileManager fileManager, BlazeJavacArguments arguments) {
    try {
        fileManager.setLocationFromPaths(StandardLocation.CLASS_PATH, arguments.classPath());
        fileManager.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, ImmutableList.of(arguments.classOutput()));
        fileManager.setLocationFromPaths(StandardLocation.SOURCE_PATH, arguments.sourcePath());
        // TODO(cushon): require an explicit bootclasspath
        Iterable<Path> bootClassPath = arguments.bootClassPath();
        if (!Iterables.isEmpty(bootClassPath)) {
            fileManager.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, bootClassPath);
        }
        fileManager.setLocationFromPaths(StandardLocation.ANNOTATION_PROCESSOR_PATH, arguments.processorPath());
        if (arguments.sourceOutput() != null) {
            fileManager.setLocationFromPaths(StandardLocation.SOURCE_OUTPUT, ImmutableList.of(arguments.sourceOutput()));
        }
    } catch (IOException e) {
        throw new IOError(e);
    }
}
Also used : Path(java.nio.file.Path) IOError(java.io.IOError) IOException(java.io.IOException)

Example 3 with IOError

use of java.io.IOError in project error-prone by google.

the class ErrorProneJavaCompilerTest method doCompile.

private CompilationResult doCompile(List<String> fileNames, List<String> extraArgs, List<Class<? extends BugChecker>> customCheckers) {
    DiagnosticTestHelper diagnosticHelper = new DiagnosticTestHelper();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(outputStream, UTF_8), true);
    ErrorProneInMemoryFileManager fileManager = new ErrorProneInMemoryFileManager();
    List<String> args = Lists.newArrayList("-d", tempDir.getRoot().getAbsolutePath(), "-proc:none");
    args.addAll(extraArgs);
    JavaCompiler errorProneJavaCompiler = (customCheckers.isEmpty()) ? new ErrorProneJavaCompiler() : new ErrorProneJavaCompiler(ScannerSupplier.fromBugCheckerClasses(customCheckers));
    JavaCompiler.CompilationTask task = errorProneJavaCompiler.getTask(printWriter, fileManager, diagnosticHelper.collector, args, null, fileManager.forResources(getClass(), fileNames.toArray(new String[0])));
    try {
        fileManager.close();
    } catch (IOException e) {
        throw new IOError(e);
    }
    return new CompilationResult(task.call(), diagnosticHelper);
}
Also used : JavaCompiler(javax.tools.JavaCompiler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) IOError(java.io.IOError) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter)

Example 4 with IOError

use of java.io.IOError in project qpid-broker-j by apache.

the class BrokerFileLoggerStatusListenerTest method testAddStatusEventForIOError.

public void testAddStatusEventForIOError() throws Exception {
    Status event = createEvent(new IOError(new IOException("Mocked: No disk space left")), Status.ERROR);
    _statusListener.addStatusEvent(event);
    verify(_systemConfig).closeAsync();
}
Also used : Status(ch.qos.logback.core.status.Status) IOError(java.io.IOError) IOException(java.io.IOException)

Example 5 with IOError

use of java.io.IOError in project qpid-broker-j by apache.

the class BrokerFileLoggerStatusListenerTest method testAddStatusEventForIOErrorWithFailOnLoggerIOErrorDisabled.

public void testAddStatusEventForIOErrorWithFailOnLoggerIOErrorDisabled() throws Exception {
    Status event = createEvent(new IOError(new IOException("Mocked: No disk space left")), Status.ERROR);
    when(_fileLogger.getContextValue(Boolean.class, BrokerFileLogger.BROKER_FAIL_ON_LOGGER_IO_ERROR)).thenReturn(false);
    _statusListener.addStatusEvent(event);
    verify(_systemConfig, never()).closeAsync();
}
Also used : Status(ch.qos.logback.core.status.Status) IOError(java.io.IOError) IOException(java.io.IOException)

Aggregations

IOError (java.io.IOError)78 IOException (java.io.IOException)58 File (java.io.File)11 ArrayList (java.util.ArrayList)8 Path (java.nio.file.Path)5 Status (ch.qos.logback.core.status.Status)4 BufferedReader (java.io.BufferedReader)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Console (java.io.Console)4 DataInputStream (java.io.DataInputStream)4 IPartitioner (org.apache.cassandra.dht.IPartitioner)4 FastByteArrayInputStream (org.apache.cassandra.io.util.FastByteArrayInputStream)4 Test (org.junit.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 ByteBuffer (java.nio.ByteBuffer)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 QueryPath (org.apache.cassandra.db.filter.QueryPath)3 CorruptSSTableException (org.apache.cassandra.io.sstable.CorruptSSTableException)3 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)3