Search in sources :

Example 61 with TimeoutException

use of java.util.concurrent.TimeoutException in project pulsar by yahoo.

the class PersistentTopicTest method testCreateTopicMLFailure.

@Test
public void testCreateTopicMLFailure() throws Exception {
    final String jinxedTopicName = "persistent://prop/use/ns-abc/topic3";
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            new Thread(() -> {
                ((OpenLedgerCallback) invocationOnMock.getArguments()[2]).openLedgerFailed(new ManagedLedgerException("Managed ledger failure"), null);
            }).start();
            return null;
        }
    }).when(mlFactoryMock).asyncOpen(anyString(), any(ManagedLedgerConfig.class), any(OpenLedgerCallback.class), anyObject());
    CompletableFuture<Topic> future = brokerService.getTopic(jinxedTopicName);
    // wait for completion
    try {
        future.get(1, TimeUnit.SECONDS);
        fail("should have failed");
    } catch (TimeoutException e) {
        fail("Should not time out");
    } catch (Exception e) {
    // OK
    }
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) TimeoutException(java.util.concurrent.TimeoutException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ExecutionException(java.util.concurrent.ExecutionException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyObject(org.mockito.Matchers.anyObject) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) PersistentTopic(com.yahoo.pulsar.broker.service.persistent.PersistentTopic) OpenLedgerCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OpenLedgerCallback) TimeoutException(java.util.concurrent.TimeoutException) Test(org.testng.annotations.Test)

Example 62 with TimeoutException

use of java.util.concurrent.TimeoutException in project pulsar by yahoo.

the class MessagingServiceShutdownHook method run.

@Override
public void run() {
    if (service.getConfiguration() != null) {
        LOG.info("messaging service shutdown hook started, lookup port=" + service.getConfiguration().getWebServicePort() + ", broker url=" + service.getBrokerServiceUrl());
    }
    ExecutorService executor = Executors.newSingleThreadExecutor(new DefaultThreadFactory("shutdown-thread"));
    try {
        CompletableFuture<Void> future = new CompletableFuture<>();
        executor.execute(() -> {
            try {
                service.close();
                future.complete(null);
            } catch (PulsarServerException e) {
                future.completeExceptionally(e);
            }
        });
        future.get(service.getConfiguration().getBrokerShutdownTimeoutMs(), TimeUnit.MILLISECONDS);
        LOG.info("Completed graceful shutdown. Exiting");
    } catch (TimeoutException e) {
        LOG.warn("Graceful shutdown timeout expired. Closing now");
    } catch (Exception e) {
        LOG.error("Failed to perform graceful shutdown, Exiting anyway", e);
    } finally {
        immediateFlushBufferedLogs();
        // always put system to halt immediately
        Runtime.getRuntime().halt(0);
    }
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutorService(java.util.concurrent.ExecutorService) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 63 with TimeoutException

use of java.util.concurrent.TimeoutException in project hazelcast by hazelcast.

the class AsyncTest method testRemoveAsyncWithImmediateTimeout.

@Test
public void testRemoveAsyncWithImmediateTimeout() throws Exception {
    final IMap<String, String> map = instance.getMap(randomString());
    // populate map
    map.put(key, value1);
    final CountDownLatch latch = new CountDownLatch(1);
    new Thread(new Runnable() {

        public void run() {
            map.lock(key);
            latch.countDown();
        }
    }).start();
    assertTrue(latch.await(20, TimeUnit.SECONDS));
    Future<String> f1 = map.removeAsync(key);
    try {
        assertEquals(value1, f1.get(0L, TimeUnit.SECONDS));
    } catch (TimeoutException e) {
        // expected
        return;
    }
    fail("Failed to throw TimeoutException with zero timeout");
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) TimeoutException(java.util.concurrent.TimeoutException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 64 with TimeoutException

use of java.util.concurrent.TimeoutException in project hazelcast by hazelcast.

the class CallIdSequenceWithBackpressureTest method next_whenNoCapacity_thenBlockTillTimeout.

@Test
public void next_whenNoCapacity_thenBlockTillTimeout() {
    sequence = new CallIdSequenceWithBackpressure(1, 2000);
    // first invocation consumes the available call ID
    nextCallId(sequence, false);
    long oldLastCallId = sequence.getLastCallId();
    try {
        sequence.next(false);
        fail();
    } catch (TimeoutException e) {
    // expected
    }
    assertEquals(oldLastCallId, sequence.getLastCallId());
}
Also used : CallIdSequenceWithBackpressure(com.hazelcast.spi.impl.operationservice.impl.CallIdSequence.CallIdSequenceWithBackpressure) TimeoutException(java.util.concurrent.TimeoutException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 65 with TimeoutException

use of java.util.concurrent.TimeoutException in project hazelcast by hazelcast.

the class FutureUtilTest method testTransactionTimedOutExceptionHandler.

@Test(expected = TransactionTimedOutException.class)
public void testTransactionTimedOutExceptionHandler() throws Exception {
    final ExceptionHandler exceptionHandler = FutureUtil.RETHROW_TRANSACTION_EXCEPTION;
    final Throwable throwable = new TimeoutException();
    exceptionHandler.handleException(throwable);
}
Also used : ExceptionHandler(com.hazelcast.util.FutureUtil.ExceptionHandler) TimeoutException(java.util.concurrent.TimeoutException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

TimeoutException (java.util.concurrent.TimeoutException)788 ExecutionException (java.util.concurrent.ExecutionException)249 IOException (java.io.IOException)184 Test (org.junit.Test)149 ArrayList (java.util.ArrayList)75 CountDownLatch (java.util.concurrent.CountDownLatch)73 ExecutorService (java.util.concurrent.ExecutorService)71 Future (java.util.concurrent.Future)54 CancellationException (java.util.concurrent.CancellationException)44 Test (org.testng.annotations.Test)44 List (java.util.List)39 HashMap (java.util.HashMap)38 Map (java.util.Map)38 File (java.io.File)36 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)36 TimeUnit (java.util.concurrent.TimeUnit)34 AtomicReference (java.util.concurrent.atomic.AtomicReference)26 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 URI (java.net.URI)21 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)21