Java Code Examples for net.jodah.concurrentunit.Waiter#resume()

The following examples show how to use net.jodah.concurrentunit.Waiter#resume() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IPythonInterpreterTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Test
public void testIPythonProcessKilled() throws InterruptedException, TimeoutException {
  final Waiter waiter = new Waiter();
  Thread thread = new Thread() {
    @Override
    public void run() {
      try {
        InterpreterResult result = interpreter.interpret("import time\ntime.sleep(1000)",
                getInterpreterContext());
        waiter.assertEquals(InterpreterResult.Code.ERROR, result.code());
        waiter.assertEquals(
                "IPython kernel is abnormally exited, please check your code and log.",
                result.message().get(0).getData());
      } catch (InterpreterException e) {
        waiter.fail("Should not throw exception\n" + ExceptionUtils.getStackTrace(e));
      }
      waiter.resume();
    }
  };
  thread.start();
  Thread.sleep(3000);
  IPythonInterpreter iPythonInterpreter = (IPythonInterpreter)
          ((LazyOpenInterpreter) interpreter).getInnerInterpreter();
  iPythonInterpreter.getKernelProcessLauncher().stop();
  waiter.await(3000);
}
 
Example 2
Source File: PythonInterpreterTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Test
public void testPythonProcessKilled() throws InterruptedException, TimeoutException {
  final Waiter waiter = new Waiter();
  Thread thread = new Thread() {
    @Override
    public void run() {
      try {
        InterpreterResult result = interpreter.interpret("import time\ntime.sleep(1000)",
                getInterpreterContext());
        waiter.assertEquals(InterpreterResult.Code.ERROR, result.code());
        waiter.assertEquals(
                "Python process is abnormally exited, please check your code and log.",
                result.message().get(0).getData());
      } catch (InterpreterException e) {
        waiter.fail("Should not throw exception\n" + ExceptionUtils.getStackTrace(e));
      }
      waiter.resume();
    }
  };
  thread.start();
  Thread.sleep(3000);
  PythonInterpreter pythonInterpreter = (PythonInterpreter)
          ((LazyOpenInterpreter) interpreter).getInnerInterpreter();
  pythonInterpreter.getPythonProcessLauncher().stop();
  waiter.await(3000);
}
 
Example 3
Source File: JDBCInterpreterTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Test
public void testSelectWithRefresh() throws IOException, InterruptedException, TimeoutException {
  Properties properties = new Properties();
  properties.setProperty("common.max_count", "1000");
  properties.setProperty("common.max_retry", "3");
  properties.setProperty("default.driver", "org.h2.Driver");
  properties.setProperty("default.url", getJdbcConnection());
  properties.setProperty("default.user", "");
  properties.setProperty("default.password", "");
  JDBCInterpreter t = new JDBCInterpreter(properties);
  t.open();

  final Waiter waiter = new Waiter();
  context.getLocalProperties().put("refreshInterval", "1000");
  Thread thread = new Thread(() -> {
    String sqlQuery = "select * from test_table WHERE ID in ('a', 'b');";
    try {
      InterpreterResult interpreterResult = t.interpret(sqlQuery, context);
      assertEquals(InterpreterResult.Code.ERROR, interpreterResult.code());
    } catch (InterpreterException e) {
      fail("Should not be here");
    }
    waiter.resume();
  });

  thread.start();

  Thread.sleep(5000);
  t.cancel(context);
  waiter.await(5000);
}