Search in sources :

Example 76 with EOFException

use of java.io.EOFException in project lucene-solr by apache.

the class TestSwappedIndexFiles method swapOneFile.

private void swapOneFile(Directory dir1, Directory dir2, String victim) throws IOException {
    if (VERBOSE) {
        System.out.println("TEST: swap file " + victim);
    }
    try (BaseDirectoryWrapper dirCopy = newDirectory()) {
        dirCopy.setCheckIndexOnClose(false);
        // Copy all files from dir1 to dirCopy, except victim which we copy from dir2:
        for (String name : dir1.listAll()) {
            if (name.equals(victim) == false) {
                dirCopy.copyFrom(dir1, name, name, IOContext.DEFAULT);
            } else {
                dirCopy.copyFrom(dir2, name, name, IOContext.DEFAULT);
            }
            dirCopy.sync(Collections.singleton(name));
        }
        try {
            // NOTE: we .close so that if the test fails (truncation not detected) we don't also get all these confusing errors about open files:
            DirectoryReader.open(dirCopy).close();
            fail("wrong file " + victim + " not detected");
        } catch (CorruptIndexException | EOFException | IndexFormatTooOldException e) {
        // expected
        }
        // CheckIndex should also fail:
        try {
            TestUtil.checkIndex(dirCopy, true, true, null);
            fail("wrong file " + victim + " not detected");
        } catch (CorruptIndexException | EOFException | IndexFormatTooOldException e) {
        // expected
        }
    }
}
Also used : EOFException(java.io.EOFException) BaseDirectoryWrapper(org.apache.lucene.store.BaseDirectoryWrapper)

Example 77 with EOFException

use of java.io.EOFException in project jackrabbit-oak by apache.

the class IOUtilsTest method testVarEOF.

public void testVarEOF() throws IOException {
    try {
        IOUtils.readVarInt(new ByteArrayInputStream(new byte[0]));
        fail();
    } catch (EOFException e) {
    // expected
    }
    try {
        IOUtils.readVarLong(new ByteArrayInputStream(new byte[0]));
        fail();
    } catch (EOFException e) {
    // expected
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) EOFException(java.io.EOFException)

Example 78 with EOFException

use of java.io.EOFException in project jackrabbit-oak by apache.

the class IOUtilsTest method testSkipFully.

public void testSkipFully() throws IOException {
    final Random r = new Random(1);
    byte[] data = new byte[1000];
    r.nextBytes(data);
    FilterInputStream in = new FilterInputStream(new ByteArrayInputStream(data)) {

        @Override
        public int read(byte[] buffer, int off, int max) throws IOException {
            return in.read(buffer, off, Math.min(10, max));
        }
    };
    in.mark(10000);
    IOUtils.skipFully(in, 1000);
    assertEquals(-1, in.read());
    in.reset();
    try {
        IOUtils.skipFully(in, 1001);
        fail();
    } catch (EOFException e) {
    // expected
    }
}
Also used : FilterInputStream(java.io.FilterInputStream) Random(java.util.Random) ByteArrayInputStream(java.io.ByteArrayInputStream) EOFException(java.io.EOFException)

Example 79 with EOFException

use of java.io.EOFException in project geode by apache.

the class PRClientServerRegionFunctionExecutionSingleHopDUnitTest method executeFunction.

public static void executeFunction() throws ServerException, InterruptedException {
    Region region = cache.getRegion(PartitionedRegionName);
    assertNotNull(region);
    final HashSet testKeysSet = new HashSet();
    for (int i = (totalNumBuckets.intValue() * 10); i > 0; i--) {
        testKeysSet.add("execKey-" + i);
    }
    DistributedSystem.setThreadsSocketPolicy(false);
    Function function = new TestFunction(true, TEST_FUNCTION2);
    FunctionService.registerFunction(function);
    Execution dataSet = FunctionService.onRegion(region);
    try {
        ResultCollector rc1 = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(function.getId());
        HashMap resultMap = ((HashMap) rc1.getResult());
        assertEquals(3, resultMap.size());
        Iterator mapIterator = resultMap.entrySet().iterator();
        Map.Entry entry = null;
        ArrayList resultListForMember = null;
        while (mapIterator.hasNext()) {
            entry = (Map.Entry) mapIterator.next();
            resultListForMember = (ArrayList) entry.getValue();
            for (Object result : resultListForMember) {
                assertEquals(Boolean.TRUE, result);
            }
        }
    } catch (Exception e) {
        LogWriterUtils.getLogWriter().info("Got an exception : " + e.getMessage());
        assertTrue(e instanceof EOFException || e instanceof SocketException || e instanceof SocketTimeoutException || e instanceof ServerException || e instanceof IOException || e instanceof CacheClosedException);
    }
}
Also used : SocketException(java.net.SocketException) ServerException(java.rmi.ServerException) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CacheClosedException(org.apache.geode.cache.CacheClosedException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ServerException(java.rmi.ServerException) FunctionException(org.apache.geode.cache.execute.FunctionException) SocketException(java.net.SocketException) CacheClosedException(org.apache.geode.cache.CacheClosedException) SocketTimeoutException(java.net.SocketTimeoutException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) IOException(java.io.IOException) EOFException(java.io.EOFException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) Execution(org.apache.geode.cache.execute.Execution) SocketTimeoutException(java.net.SocketTimeoutException) Iterator(java.util.Iterator) EOFException(java.io.EOFException) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 80 with EOFException

use of java.io.EOFException in project geode by apache.

the class PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest method executeFunction.

public static void executeFunction() throws ServerException, InterruptedException {
    Region region = cache.getRegion(PartitionedRegionName);
    assertNotNull(region);
    final HashSet testKeysSet = new HashSet();
    for (int i = (totalNumBuckets.intValue() * 10); i > 0; i--) {
        testKeysSet.add("execKey-" + i);
    }
    DistributedSystem.setThreadsSocketPolicy(false);
    Function function = new TestFunction(true, TEST_FUNCTION2);
    FunctionService.registerFunction(function);
    Execution dataSet = FunctionService.onRegion(region);
    try {
        ResultCollector rc1 = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(function.getId());
        HashMap resultMap = ((HashMap) rc1.getResult());
        assertEquals(3, resultMap.size());
        Iterator mapIterator = resultMap.entrySet().iterator();
        Map.Entry entry = null;
        DistributedMember key = null;
        ArrayList resultListForMember = null;
        while (mapIterator.hasNext()) {
            entry = (Map.Entry) mapIterator.next();
            key = (DistributedMember) entry.getKey();
            resultListForMember = (ArrayList) entry.getValue();
            for (Object result : resultListForMember) {
                assertEquals(Boolean.TRUE, result);
            }
        }
    } catch (Exception e) {
        LogWriterUtils.getLogWriter().info("Got an exception : " + e.getMessage());
        assertTrue(e instanceof EOFException || e instanceof SocketException || e instanceof SocketTimeoutException || e instanceof ServerException || e instanceof IOException || e instanceof CacheClosedException);
    }
}
Also used : SocketException(java.net.SocketException) ServerException(java.rmi.ServerException) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CacheClosedException(org.apache.geode.cache.CacheClosedException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ServerException(java.rmi.ServerException) FunctionException(org.apache.geode.cache.execute.FunctionException) SocketException(java.net.SocketException) CacheClosedException(org.apache.geode.cache.CacheClosedException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) EOFException(java.io.EOFException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) Execution(org.apache.geode.cache.execute.Execution) SocketTimeoutException(java.net.SocketTimeoutException) Iterator(java.util.Iterator) DistributedMember(org.apache.geode.distributed.DistributedMember) EOFException(java.io.EOFException) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

EOFException (java.io.EOFException)1149 IOException (java.io.IOException)508 DataInputStream (java.io.DataInputStream)139 FileInputStream (java.io.FileInputStream)124 InputStream (java.io.InputStream)100 ByteArrayInputStream (java.io.ByteArrayInputStream)95 ArrayList (java.util.ArrayList)84 Test (org.junit.Test)84 ByteBuffer (java.nio.ByteBuffer)75 File (java.io.File)74 FileNotFoundException (java.io.FileNotFoundException)61 BufferedInputStream (java.io.BufferedInputStream)56 RandomAccessFile (java.io.RandomAccessFile)46 SocketTimeoutException (java.net.SocketTimeoutException)43 HashMap (java.util.HashMap)38 ByteArrayOutputStream (java.io.ByteArrayOutputStream)32 SocketException (java.net.SocketException)31 Map (java.util.Map)30 InterruptedIOException (java.io.InterruptedIOException)29 Path (org.apache.hadoop.fs.Path)29