use of java.util.concurrent.ExecutorService in project elasticsearch by elastic.
the class IndexAliasesIT method testWaitForAliasSimultaneousUpdate.
public void testWaitForAliasSimultaneousUpdate() throws Exception {
final int aliasCount = 10;
logger.info("--> creating index [test]");
createIndex("test");
ensureGreen();
ExecutorService executor = Executors.newFixedThreadPool(aliasCount);
for (int i = 0; i < aliasCount; i++) {
final String aliasName = "alias" + i;
executor.submit(new Runnable() {
@Override
public void run() {
assertAcked(admin().indices().prepareAliases().addAlias("test", aliasName));
client().index(indexRequest(aliasName).type("type1").id("1").source(source("1", "test"), XContentType.JSON)).actionGet();
}
});
}
executor.shutdown();
boolean done = executor.awaitTermination(20, TimeUnit.SECONDS);
assertThat(done, equalTo(true));
if (!done) {
executor.shutdownNow();
}
}
use of java.util.concurrent.ExecutorService in project jetty.project by eclipse.
the class QoSFilterTest method testQosFilter.
@Test
public void testQosFilter() throws Exception {
FilterHolder holder = new FilterHolder(QoSFilter2.class);
holder.setAsyncSupported(true);
holder.setInitParameter(QoSFilter.MAX_REQUESTS_INIT_PARAM, String.valueOf(MAX_QOS));
_tester.getContext().getServletHandler().addFilterWithMapping(holder, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
List<Worker2> workers = new ArrayList<>();
for (int i = 0; i < NUM_CONNECTIONS; ++i) {
workers.add(new Worker2(i));
}
ExecutorService executor = Executors.newFixedThreadPool(NUM_CONNECTIONS);
List<Future<Void>> futures = executor.invokeAll(workers, 20, TimeUnit.SECONDS);
rethrowExceptions(futures);
if (TestServlet.__maxSleepers < MAX_QOS)
LOG.warn("TEST WAS NOT PARALLEL ENOUGH!");
else
Assert.assertEquals(TestServlet.__maxSleepers, MAX_QOS);
}
use of java.util.concurrent.ExecutorService in project che by eclipse.
the class WorkspaceRuntimes method shutdown.
/**
* Terminates workspace runtimes service, so no more workspaces are allowed to start
* or to be stopped directly, all the running workspaces are going to be stopped,
* all the starting tasks will be eventually interrupted.
*
* @throws IllegalStateException
* if component shutdown is already called
*/
public void shutdown() throws InterruptedException {
if (!isShutdown.compareAndSet(false, true)) {
throw new IllegalStateException("Workspace runtimes service shutdown has been already called");
}
List<String> idsToStop;
try (@SuppressWarnings("unused") Unlocker u = locks.writeAllLock()) {
idsToStop = states.entrySet().stream().filter(e -> e.getValue().status != WorkspaceStatus.STOPPING).map(Map.Entry::getKey).collect(Collectors.toList());
states.clear();
}
if (!idsToStop.isEmpty()) {
LOG.info("Shutdown running environments, environments to stop: '{}'", idsToStop.size());
ExecutorService executor = Executors.newFixedThreadPool(2 * Runtime.getRuntime().availableProcessors(), new ThreadFactoryBuilder().setNameFormat("StopEnvironmentsPool-%d").setDaemon(false).build());
for (String id : idsToStop) {
executor.execute(() -> {
try {
envEngine.stop(id);
} catch (EnvironmentNotRunningException ignored) {
// might be already stopped
} catch (Exception x) {
LOG.error(x.getMessage(), x);
}
});
}
executor.shutdown();
try {
if (!executor.awaitTermination(30, TimeUnit.SECONDS)) {
executor.shutdownNow();
if (!executor.awaitTermination(60, TimeUnit.SECONDS)) {
LOG.error("Unable to stop runtimes termination pool");
}
}
} catch (InterruptedException e) {
executor.shutdownNow();
Thread.currentThread().interrupt();
}
}
}
use of java.util.concurrent.ExecutorService in project jetty.project by eclipse.
the class SameNodeLoadTest method testLoad.
@Test
@Slow
public void testLoad() throws Exception {
DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory();
cacheFactory.setEvictionPolicy(SessionCache.NEVER_EVICT);
SessionDataStoreFactory storeFactory = new TestSessionDataStoreFactory();
String contextPath = "";
String servletMapping = "/server";
TestServer server1 = new TestServer(0, -1, 4, cacheFactory, storeFactory);
server1.addContext(contextPath).addServlet(TestServlet.class, servletMapping);
try {
server1.start();
int port1 = server1.getPort();
HttpClient client = new HttpClient();
client.start();
try {
String url = "http://localhost:" + port1 + contextPath + servletMapping;
//create session via first server
ContentResponse response1 = client.GET(url + "?action=init");
assertEquals(HttpServletResponse.SC_OK, response1.getStatus());
String sessionCookie = response1.getHeaders().get("Set-Cookie");
assertTrue(sessionCookie != null);
// Mangle the cookie, replacing Path with $Path, etc.
sessionCookie = sessionCookie.replaceFirst("(\\W)(P|p)ath=", "$1\\$Path=");
//simulate 10 clients making 100 requests each
ExecutorService executor = Executors.newCachedThreadPool();
int clientsCount = 10;
CyclicBarrier barrier = new CyclicBarrier(clientsCount + 1);
int requestsCount = 100;
Worker[] workers = new Worker[clientsCount];
for (int i = 0; i < clientsCount; ++i) {
workers[i] = new Worker(barrier, client, requestsCount, sessionCookie, url);
executor.execute(workers[i]);
}
// Wait for all workers to be ready
barrier.await();
long start = System.nanoTime();
// Wait for all workers to be done
barrier.await();
long end = System.nanoTime();
long elapsed = TimeUnit.NANOSECONDS.toMillis(end - start);
System.err.println("Elapsed ms:" + elapsed);
executor.shutdownNow();
// Perform one request to get the result
Request request = client.newRequest(url + "?action=result");
request.header("Cookie", sessionCookie);
ContentResponse response2 = request.send();
assertEquals(HttpServletResponse.SC_OK, response2.getStatus());
String response = response2.getContentAsString();
assertEquals(response.trim(), String.valueOf(clientsCount * requestsCount));
} finally {
client.stop();
}
} finally {
server1.stop();
}
}
use of java.util.concurrent.ExecutorService in project che by eclipse.
the class SystemManager method stopServices.
/**
* Stops some of the system services preparing system to lighter shutdown.
* System status is changed from {@link SystemStatus#RUNNING} to
* {@link SystemStatus#PREPARING_TO_SHUTDOWN}.
*
* @throws ConflictException
* when system status is different from running
*/
public void stopServices() throws ConflictException {
if (!statusRef.compareAndSet(RUNNING, PREPARING_TO_SHUTDOWN)) {
throw new ConflictException("System shutdown has been already called, system status: " + statusRef.get());
}
ExecutorService exec = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setDaemon(false).setNameFormat("ShutdownSystemServicesPool").setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()).build());
exec.execute(ThreadLocalPropagateContext.wrap(this::doStopServices));
exec.shutdown();
}
Aggregations