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
}
}
}
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
}
}
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
}
}
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);
}
}
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);
}
}
Aggregations