Search in sources :

Example 66 with ScheduledFuture

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();
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) DelegatingScheduledFutureStripper(com.hazelcast.scheduledexecutor.impl.DelegatingScheduledFutureStripper) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 67 with ScheduledFuture

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();
}
Also used : ExecutionException(java.util.concurrent.ExecutionException) ScheduledFuture(java.util.concurrent.ScheduledFuture) DelegatingScheduledFutureStripper(com.hazelcast.scheduledexecutor.impl.DelegatingScheduledFutureStripper) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 68 with ScheduledFuture

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();
    }
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ScheduledFuture(java.util.concurrent.ScheduledFuture) IdleReaderException(com.twitter.distributedlog.exceptions.IdleReaderException) Test(org.junit.Test)

Example 69 with ScheduledFuture

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();
    }
}
Also used : IdleReaderException(com.twitter.distributedlog.exceptions.IdleReaderException) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ScheduledFuture(java.util.concurrent.ScheduledFuture) IdleReaderException(com.twitter.distributedlog.exceptions.IdleReaderException) Test(org.junit.Test)

Example 70 with ScheduledFuture

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();
    }
}
Also used : IdleReaderException(com.twitter.distributedlog.exceptions.IdleReaderException) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ScheduledFuture(java.util.concurrent.ScheduledFuture) IdleReaderException(com.twitter.distributedlog.exceptions.IdleReaderException) Test(org.junit.Test)

Aggregations

ScheduledFuture (java.util.concurrent.ScheduledFuture)85 Test (org.junit.Test)27 Date (java.util.Date)10 DelegatingScheduledFutureStripper (com.hazelcast.scheduledexecutor.impl.DelegatingScheduledFutureStripper)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 IOException (java.io.IOException)8 Map (java.util.Map)7 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)7 TimeValue (org.elasticsearch.common.unit.TimeValue)6 None (com.linkedin.common.util.None)5 D2Client (com.linkedin.d2.balancer.D2Client)5 D2ClientBuilder (com.linkedin.d2.balancer.D2ClientBuilder)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 JSONObject (org.json.simple.JSONObject)5 IdleReaderException (com.twitter.distributedlog.exceptions.IdleReaderException)4 Future (java.util.concurrent.Future)4 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)4