use of java.util.concurrent.Executor in project druid by druid-io.
the class TaskLifecycleTest method testRealtimeIndexTask.
@Test(timeout = 60_000L)
public void testRealtimeIndexTask() throws Exception {
publishCountDown = new CountDownLatch(1);
monitorScheduler.addMonitor(EasyMock.anyObject(Monitor.class));
EasyMock.expectLastCall().atLeastOnce();
monitorScheduler.removeMonitor(EasyMock.anyObject(Monitor.class));
EasyMock.expectLastCall().anyTimes();
EasyMock.replay(monitorScheduler, queryRunnerFactoryConglomerate);
RealtimeIndexTask realtimeIndexTask = newRealtimeIndexTask();
final String taskId = realtimeIndexTask.getId();
taskQueue.start();
taskQueue.add(realtimeIndexTask);
//wait for task to process events and publish segment
publishCountDown.await();
// Realtime Task has published the segment, simulate loading of segment to a historical node so that task finishes with SUCCESS status
Assert.assertEquals(1, handOffCallbacks.size());
Pair<Executor, Runnable> executorRunnablePair = Iterables.getOnlyElement(handOffCallbacks.values());
executorRunnablePair.lhs.execute(executorRunnablePair.rhs);
handOffCallbacks.clear();
// Wait for realtime index task to handle callback in plumber and succeed
while (tsqa.getStatus(taskId).get().isRunnable()) {
Thread.sleep(10);
}
Assert.assertTrue("Task should be in Success state", tsqa.getStatus(taskId).get().isSuccess());
Assert.assertEquals(1, announcedSinks);
Assert.assertEquals(1, pushedSegments);
Assert.assertEquals(1, mdc.getPublished().size());
DataSegment segment = mdc.getPublished().iterator().next();
Assert.assertEquals("test_ds", segment.getDataSource());
Assert.assertEquals(ImmutableList.of("dim1", "dim2"), segment.getDimensions());
Assert.assertEquals(new Interval(now.toString("YYYY-MM-dd") + "/" + now.plusDays(1).toString("YYYY-MM-dd")), segment.getInterval());
Assert.assertEquals(ImmutableList.of("count"), segment.getMetrics());
EasyMock.verify(monitorScheduler, queryRunnerFactoryConglomerate);
}
use of java.util.concurrent.Executor in project jetty.project by eclipse.
the class Server method doStart.
/* ------------------------------------------------------------ */
@Override
protected void doStart() throws Exception {
// Create an error handler if there is none
if (_errorHandler == null)
_errorHandler = getBean(ErrorHandler.class);
if (_errorHandler == null)
setErrorHandler(new ErrorHandler());
if (_errorHandler instanceof ErrorHandler.ErrorPageMapper)
LOG.warn("ErrorPageMapper not supported for Server level Error Handling");
//with the shutdown handler thread.
if (getStopAtShutdown())
ShutdownThread.register(this);
//Register the Server with the handler thread for receiving
//remote stop commands
ShutdownMonitor.register(this);
//Start a thread waiting to receive "stop" commands.
// initialize
ShutdownMonitor.getInstance().start();
LOG.info("jetty-" + getVersion());
if (!Jetty.STABLE) {
LOG.warn("THIS IS NOT A STABLE RELEASE! DO NOT USE IN PRODUCTION!");
LOG.warn("Download a stable release from http://download.eclipse.org/jetty/");
}
HttpGenerator.setJettyVersion(HttpConfiguration.SERVER_VERSION);
// Check that the thread pool size is enough.
SizedThreadPool pool = getBean(SizedThreadPool.class);
int max = pool == null ? -1 : pool.getMaxThreads();
int selectors = 0;
int acceptors = 0;
for (Connector connector : _connectors) {
if (connector instanceof AbstractConnector) {
AbstractConnector abstractConnector = (AbstractConnector) connector;
Executor connectorExecutor = connector.getExecutor();
if (connectorExecutor != pool) {
// the server level, because the connector uses a dedicated executor.
continue;
}
acceptors += abstractConnector.getAcceptors();
if (connector instanceof ServerConnector) {
// The SelectorManager uses 2 threads for each selector,
// one for the normal and one for the low priority strategies.
selectors += 2 * ((ServerConnector) connector).getSelectorManager().getSelectorCount();
}
}
}
int needed = 1 + selectors + acceptors;
if (max > 0 && needed > max)
throw new IllegalStateException(String.format("Insufficient threads: max=%d < needed(acceptors=%d + selectors=%d + request=1)", max, acceptors, selectors));
MultiException mex = new MultiException();
try {
super.doStart();
} catch (Throwable e) {
mex.add(e);
}
// start connectors last
for (Connector connector : _connectors) {
try {
connector.start();
} catch (Throwable e) {
mex.add(e);
}
}
if (isDumpAfterStart())
dumpStdErr();
mex.ifExceptionThrow();
LOG.info(String.format("Started @%dms", Uptime.getUptime()));
}
use of java.util.concurrent.Executor in project jetty.project by eclipse.
the class HttpInput method wake.
protected void wake() {
HttpChannel channel = _channelState.getHttpChannel();
Executor executor = channel.getConnector().getServer().getThreadPool();
executor.execute(channel);
}
use of java.util.concurrent.Executor in project jetty.project by eclipse.
the class HTTP2ClientConnectionFactory method newConnection.
@Override
public Connection newConnection(EndPoint endPoint, Map<String, Object> context) throws IOException {
HTTP2Client client = (HTTP2Client) context.get(CLIENT_CONTEXT_KEY);
ByteBufferPool byteBufferPool = (ByteBufferPool) context.get(BYTE_BUFFER_POOL_CONTEXT_KEY);
Executor executor = (Executor) context.get(EXECUTOR_CONTEXT_KEY);
Scheduler scheduler = (Scheduler) context.get(SCHEDULER_CONTEXT_KEY);
Session.Listener listener = (Session.Listener) context.get(SESSION_LISTENER_CONTEXT_KEY);
@SuppressWarnings("unchecked") Promise<Session> promise = (Promise<Session>) context.get(SESSION_PROMISE_CONTEXT_KEY);
Generator generator = new Generator(byteBufferPool);
FlowControlStrategy flowControl = client.getFlowControlStrategyFactory().newFlowControlStrategy();
HTTP2ClientSession session = new HTTP2ClientSession(scheduler, endPoint, generator, listener, flowControl);
Parser parser = new Parser(byteBufferPool, session, 4096, 8192);
HTTP2ClientConnection connection = new HTTP2ClientConnection(client, byteBufferPool, executor, endPoint, parser, session, client.getInputBufferSize(), promise, listener);
connection.addListener(connectionListener);
return customize(connection, context);
}
use of java.util.concurrent.Executor in project jetty.project by eclipse.
the class HttpClientTimeoutTest method testIdleTimeout.
@Test
public void testIdleTimeout() throws Throwable {
long timeout = 1000;
start(new TimeoutHandler(2 * timeout));
client.stop();
final AtomicBoolean sslIdle = new AtomicBoolean();
client = new HttpClient(new HttpClientTransportOverHTTP() {
@Override
public HttpDestination newHttpDestination(Origin origin) {
return new HttpDestinationOverHTTP(getHttpClient(), origin) {
@Override
protected ClientConnectionFactory newSslClientConnectionFactory(ClientConnectionFactory connectionFactory) {
HttpClient client = getHttpClient();
return new SslClientConnectionFactory(client.getSslContextFactory(), client.getByteBufferPool(), client.getExecutor(), connectionFactory) {
@Override
protected SslConnection newSslConnection(ByteBufferPool byteBufferPool, Executor executor, EndPoint endPoint, SSLEngine engine) {
return new SslConnection(byteBufferPool, executor, endPoint, engine) {
@Override
protected boolean onReadTimeout() {
sslIdle.set(true);
return super.onReadTimeout();
}
};
}
};
}
};
}
}, sslContextFactory);
client.setIdleTimeout(timeout);
client.start();
try {
client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).send();
Assert.fail();
} catch (Exception x) {
Assert.assertFalse(sslIdle.get());
Assert.assertThat(x.getCause(), Matchers.instanceOf(TimeoutException.class));
}
}
Aggregations