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