use of java.util.concurrent.ScheduledFuture in project hazelcast by hazelcast.
the class DelegatingScheduledFutureStripperTest method get_interrupted.
@Test(expected = InterruptedException.class)
public void get_interrupted() throws ExecutionException, InterruptedException {
ScheduledFuture outter = mock(ScheduledFuture.class);
ScheduledFuture inner = mock(ScheduledFuture.class);
when(outter.get()).thenThrow(new InterruptedException());
when(inner.get()).thenReturn(2);
new DelegatingScheduledFutureStripper(outter).get();
}
use of java.util.concurrent.ScheduledFuture in project hazelcast by hazelcast.
the class DelegatingScheduledFutureStripperTest method get_executionExc.
@Test(expected = ExecutionException.class)
public void get_executionExc() throws ExecutionException, InterruptedException {
ScheduledFuture outter = mock(ScheduledFuture.class);
ScheduledFuture inner = mock(ScheduledFuture.class);
when(outter.get()).thenThrow(new ExecutionException(new NullPointerException()));
when(inner.get()).thenReturn(2);
new DelegatingScheduledFutureStripper(outter).get();
}
use of java.util.concurrent.ScheduledFuture in project distributedlog by twitter.
the class TestNonBlockingReads method testNonBlockingRead.
@Test(timeout = 100000)
public void testNonBlockingRead() throws Exception {
String name = "distrlog-non-blocking-reader";
final DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.loadConf(conf);
confLocal.setReadAheadBatchSize(1);
confLocal.setReadAheadMaxRecords(1);
confLocal.setReaderIdleWarnThresholdMillis(100);
final DistributedLogManager dlm = createNewDLM(confLocal, name);
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
ScheduledFuture writerClosedFuture = null;
try {
final Thread currentThread = Thread.currentThread();
writerClosedFuture = executor.schedule(new Runnable() {
@Override
public void run() {
try {
writeRecordsForNonBlockingReads(confLocal, dlm, false);
} catch (Exception exc) {
currentThread.interrupt();
}
}
}, 100, TimeUnit.MILLISECONDS);
readNonBlocking(dlm, false);
assertFalse(currentThread.isInterrupted());
} finally {
if (writerClosedFuture != null) {
// ensure writer.closeAndComplete is done before we close dlm
writerClosedFuture.get();
}
executor.shutdown();
dlm.close();
}
}
use of java.util.concurrent.ScheduledFuture in project distributedlog by twitter.
the class TestNonBlockingReads method testNonBlockingReadAheadStall.
@Test(timeout = 60000)
public void testNonBlockingReadAheadStall() throws Exception {
String name = "distrlog-non-blocking-reader-stall";
final DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.loadConf(conf);
confLocal.setReadAheadBatchSize(1);
confLocal.setReadAheadMaxRecords(3);
confLocal.setReaderIdleWarnThresholdMillis(500);
confLocal.setReaderIdleErrorThresholdMillis(30000);
final DistributedLogManager dlm = createNewDLM(confLocal, name);
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
ScheduledFuture writerClosedFuture = null;
try {
final Thread currentThread = Thread.currentThread();
writerClosedFuture = executor.schedule(new Runnable() {
@Override
public void run() {
try {
writeRecordsForNonBlockingReads(confLocal, dlm, false, 3);
} catch (Exception exc) {
currentThread.interrupt();
}
}
}, 10, TimeUnit.MILLISECONDS);
boolean exceptionEncountered = false;
try {
readNonBlocking(dlm, false, 3, false);
} catch (IdleReaderException exc) {
LOG.info("Exception encountered", exc);
exceptionEncountered = true;
}
assertFalse(exceptionEncountered);
assertFalse(currentThread.isInterrupted());
} finally {
if (writerClosedFuture != null) {
// ensure writer.closeAndComplete is done before we close dlm
writerClosedFuture.get();
}
executor.shutdown();
dlm.close();
}
}
use of java.util.concurrent.ScheduledFuture in project distributedlog by twitter.
the class TestNonBlockingReads method testNonBlockingReadIdleError.
@Test(timeout = 100000)
public void testNonBlockingReadIdleError() throws Exception {
String name = "distrlog-non-blocking-reader-error";
final DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
confLocal.loadConf(conf);
confLocal.setReadAheadBatchSize(1);
confLocal.setReadAheadMaxRecords(1);
confLocal.setReaderIdleWarnThresholdMillis(50);
confLocal.setReaderIdleErrorThresholdMillis(100);
final DistributedLogManager dlm = createNewDLM(confLocal, name);
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
ScheduledFuture writerClosedFuture = null;
try {
final Thread currentThread = Thread.currentThread();
writerClosedFuture = executor.schedule(new Runnable() {
@Override
public void run() {
try {
writeRecordsForNonBlockingReads(confLocal, dlm, false);
} catch (Exception exc) {
currentThread.interrupt();
}
}
}, 100, TimeUnit.MILLISECONDS);
boolean exceptionEncountered = false;
try {
readNonBlocking(dlm, false, DEFAULT_SEGMENT_SIZE, true);
} catch (IdleReaderException exc) {
exceptionEncountered = true;
}
assertTrue(exceptionEncountered);
assertFalse(currentThread.isInterrupted());
} finally {
if (writerClosedFuture != null) {
// ensure writer.closeAndComplete is done before we close dlm
writerClosedFuture.get();
}
executor.shutdown();
dlm.close();
}
}
Aggregations