Example usage for java.util.concurrent Executors newSingleThreadExecutor

List of usage examples for java.util.concurrent Executors newSingleThreadExecutor

Introduction

In this page you can find the example usage for java.util.concurrent Executors newSingleThreadExecutor.

Prototype

public static ExecutorService newSingleThreadExecutor() 

Source Link

Document

Creates an Executor that uses a single worker thread operating off an unbounded queue.

Usage

From source file:com.yahoo.omid.OmidTestBase.java

@BeforeClass
public static void setupOmid() throws Exception {
    LOG.info("Setting up OmidTestBase...");

    // Bookkeeper setup
    bkExecutor = Executors.newSingleThreadExecutor();
    Runnable bkTask = new Runnable() {
        public void run() {
            try {
                String[] args = new String[1];
                args[0] = "5";
                LOG.info("Starting bk");
                LocalBookKeeper.main(args);
            } catch (InterruptedException e) {
                // go away quietly
            } catch (Exception e) {
                LOG.error("Error starting local bk", e);
            }//from  w w  w  .j a  va2  s . co  m
        }
    };

    bkExecutor.execute(bkTask);
    if (!LocalBookKeeper.waitForServerUp("localhost:2181", 10000)) {
        throw new Exception("Error starting zookeeper/bookkeeper");
    }

    Thread.sleep(1000);

    // TSO Setup
    tsoExecutor = Executors.newSingleThreadExecutor();
    Runnable tsoTask = new Runnable() {
        public void run() {
            try {
                String[] args = new String[] { "-port", "1234", "-batch", "100", "-ensemble", "4", "-quorum",
                        "2", "-zk", "localhost:2181" };
                TSOServer.main(args);
            } catch (InterruptedException e) {
                // go away quietly
            } catch (Exception e) {
                LOG.error("Error starting TSO", e);
            }
        }
    };

    tsoExecutor.execute(tsoTask);
    TestUtils.waitForSocketListening("localhost", 1234, 1000);

    // HBase setup
    hbaseConf = HBaseConfiguration.create();
    hbaseConf.set("hbase.coprocessor.region.classes", "com.yahoo.omid.regionserver.Compacter");
    hbaseConf.setInt("hbase.hregion.memstore.flush.size", 100 * 1024);
    hbaseConf.setInt("hbase.regionserver.nbreservationblocks", 1);
    hbaseConf.set("tso.host", "localhost");
    hbaseConf.setInt("tso.port", 1234);
    final String rootdir = "/tmp/hbase.test.dir/";
    File rootdirFile = new File(rootdir);
    if (rootdirFile.exists()) {
        delete(rootdirFile);
    }
    hbaseConf.set("hbase.rootdir", rootdir);

    hbasecluster = new LocalHBaseCluster(hbaseConf, 1, 1);
    hbasecluster.startup();

    while (hbasecluster.getActiveMaster() == null || !hbasecluster.getActiveMaster().isInitialized()) {
        Thread.sleep(500);
    }
}

From source file:demo.utils.MiniClusterUtils.java

public static void startMiniCluster() {
    if (clusterLauncher != null) {
        throw new IllegalStateException("MiniClustrer is currently running");
    }/* www  .  j  a  v  a  2 s  . com*/
    File file = new File(System.getProperty("user.dir"));
    Path path = Paths.get(file.getAbsolutePath());
    Path parentPath = path.getParent();
    String[] resources = file.list();
    for (String resource : resources) {
        if (resource.equals("yaya-demo")) {
            parentPath = path;
            break;
        }
    }
    File miniClusterExe = new File(
            parentPath.toString() + "/yarn-test-cluster/build/install/yarn-test-cluster/bin/yarn-test-cluster");
    System.out.println(miniClusterExe.getAbsolutePath());
    if (!miniClusterExe.exists()) {
        logger.info("BUILDING MINI_CLUSTER");
        CommandProcessLauncher buildLauncher = new CommandProcessLauncher(
                path.toString() + "/build-mini-cluster");
        buildLauncher.launch();
    }
    Assert.isTrue(miniClusterExe.exists(), "Failed to find mini-cluster executable");
    clusterLauncher = new CommandProcessLauncher(miniClusterExe.getAbsolutePath());
    executor = Executors.newSingleThreadExecutor();
    executor.execute(new Runnable() {
        @Override
        public void run() {
            logger.info("STARTING MINI_CLUSTER");
            clusterLauncher.launch();
        }
    });
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}

From source file:com.consol.citrus.samples.docker.AbstractDockerIT.java

@BeforeSuite(alwaysRun = true)
public void checkDockerEnvironment() {
    try {//w w  w  .  java  2s.  co  m
        Future<Boolean> future = Executors.newSingleThreadExecutor().submit(() -> {
            dockerClient.getEndpointConfiguration().getDockerClient().pingCmd().exec();
            return true;
        });

        future.get(5000, TimeUnit.MILLISECONDS);
        connected = true;
    } catch (Exception e) {
        log.warn("Skipping Docker test execution as no proper Docker environment is available on host system!",
                e);
    }
}

From source file:com.codefollower.lealone.omid.OmidTestBase.java

@BeforeClass
public static void setupOmid() throws Exception {
    LOG.info("Setting up OmidTestBase...");

    // Bookkeeper setup
    bkExecutor = Executors.newSingleThreadExecutor();
    Runnable bkTask = new Runnable() {
        public void run() {
            try {
                String[] args = new String[1];
                args[0] = "5";
                LOG.info("Starting bk");
                LocalBookKeeper.main(args);
            } catch (InterruptedException e) {
                // go away quietly
            } catch (Exception e) {
                LOG.error("Error starting local bk", e);
            }/*from ww  w.  j a  v a 2  s.  c o  m*/
        }
    };

    bkExecutor.execute(bkTask);
    if (!LocalBookKeeper.waitForServerUp("localhost:2181", 10000)) {
        throw new Exception("Error starting zookeeper/bookkeeper");
    }

    Thread.sleep(1000);

    // TSO Setup
    tsoExecutor = Executors.newSingleThreadExecutor();
    Runnable tsoTask = new Runnable() {
        public void run() {
            try {
                String[] args = new String[] { "-port", "1234", "-batch", "100", "-ensemble", "4", "-quorum",
                        "2", "-zk", "localhost:2181" };
                TSOServer.main(args);
            } catch (InterruptedException e) {
                // go away quietly
            } catch (Exception e) {
                LOG.error("Error starting TSO", e);
            }
        }
    };

    tsoExecutor.execute(tsoTask);
    TestUtils.waitForSocketListening("localhost", 1234, 1000);

    // HBase setup
    hbaseConf = HBaseConfiguration.create();
    hbaseConf.set("hbase.coprocessor.region.classes", "com.codefollower.lealone.omid.regionserver.Compacter");
    hbaseConf.setInt("hbase.hregion.memstore.flush.size", 100 * 1024);
    hbaseConf.setInt("hbase.regionserver.nbreservationblocks", 1);
    hbaseConf.set("tso.host", "localhost");
    hbaseConf.setInt("tso.port", 1234);
    final String rootdir = "/tmp/hbase.test.dir/";
    File rootdirFile = new File(rootdir);
    if (rootdirFile.exists()) {
        delete(rootdirFile);
    }
    hbaseConf.set("hbase.rootdir", rootdir);

    hbasecluster = new LocalHBaseCluster(hbaseConf, 1, 1);
    hbasecluster.startup();

    while (hbasecluster.getActiveMaster() == null || !hbasecluster.getActiveMaster().isInitialized()) {
        Thread.sleep(500);
    }
}

From source file:io.pravega.segmentstore.server.host.stat.AutoScaleProcessorTest.java

@Before
public void setup() {
    executor = Executors.newSingleThreadExecutor();
    maintenanceExecutor = Executors.newSingleThreadScheduledExecutor();
}

From source file:com.github.jrialland.ajpclient.servlet.TestWrongHost.java

/**
 * tries to make a request to an unknown host, verifies that the request
 * fails (the library does not hangs) and that we have a 502 error
 * //from www  .j  a  va 2s  .co m
 * @throws Exception
 */
@Test
public void testWrongTargetHost() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/dizzy.mp4");
    final MockHttpServletResponse response = new MockHttpServletResponse();

    final Future<Integer> statusFuture = Executors.newSingleThreadExecutor().submit(new Callable<Integer>() {
        @Override
        public Integer call() throws Exception {
            AjpServletProxy.forHost("unknownhost.inexistentdomain.com", 8415).forward(request, response);
            return response.getStatus();
        }
    });

    final long start = System.currentTimeMillis();

    // should finish in less that seconds
    final int status = statusFuture.get(10, TimeUnit.SECONDS);

    Assert.assertTrue(System.currentTimeMillis() - start < 8000);

    Assert.assertEquals(HttpServletResponse.SC_BAD_GATEWAY, status);
}

From source file:org.jasig.cas.monitor.DataSourceMonitorTests.java

@Test
public void testObserve() throws Exception {
    final DataSourceMonitor monitor = new DataSourceMonitor(this.dataSource);
    monitor.setExecutor(Executors.newSingleThreadExecutor());
    monitor.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS");
    final PoolStatus status = monitor.observe();
    assertEquals(StatusCode.OK, status.getCode());
}

From source file:com.skcraft.launcher.selfupdate.SelfUpdater.java

@Override
public File call() throws Exception {
    ExecutorService executor = Executors.newSingleThreadExecutor();

    try {//  www. j  av a2  s  .  c  om
        File dir = launcher.getLauncherBinariesDir();
        File file = new File(dir, String.valueOf(System.currentTimeMillis()) + ".jar.pack");
        File tempFile = installer.getDownloader().download(url, "", 10000, "launcher.jar.pack");

        progress = installer.getDownloader();
        installer.download();

        installer.queue(new FileMover(tempFile, file));

        progress = installer;
        installer.execute();

        updatedAlready = true;

        return file;
    } finally {
        executor.shutdownNow();
    }
}

From source file:be.solidx.hot.test.data.jdbc.TestPyAsyncCollectionApi.java

@PostConstruct
public void init() {
    asyncDB = new PyAsyncDB(db, Executors.newCachedThreadPool(), Executors.newSingleThreadExecutor());
}

From source file:thingynet.event.EventTestConfig.java

@Bean
ExecutorService eventExecutorService() {
    return Executors.newSingleThreadExecutor();
}