Search in sources :

Example 1 with LogEvent

use of org.wso2.carbon.logging.view.stub.types.carbon.LogEvent in project product-iots by wso2.

the class SampleInstallationTest method waitForRestart.

/**
 * Wait until the server restarts.
 * This method looks for "Mgt console URL:" to be appeared in the terminal.
 * If it does not appear within the given timeout an Exception will be thrown.
 */
private void waitForRestart() {
    ExecutorService service = Executors.newSingleThreadExecutor();
    try {
        Runnable r = new Runnable() {

            @Override
            public void run() {
                try {
                    LogEvent[] logEvents = logViewerClient.getAllRemoteSystemLogs();
                    for (LogEvent event : logEvents) {
                        log.info(event.getMessage() + " @ " + event.getLogTime());
                        if (event.getMessage().contains("Mgt Console URL  : ")) {
                            log.info("Server restarted successfully");
                            Assert.assertTrue(true);
                        }
                    }
                } catch (RemoteException | LogViewerLogViewerException e) {
                    log.error("Error reading logs. \n" + e.getMessage());
                    Assert.assertTrue(false);
                }
            }
        };
        Future<?> f = service.submit(r);
        f.get(Constants.IOT_RESTART_THREAD_TIMEOUT, TimeUnit.MINUTES);
    } catch (final InterruptedException e) {
        log.error("Interrupted " + e.getMessage());
        Assert.assertTrue(false);
    } catch (final TimeoutException e) {
        log.error("Timeout " + e.getMessage());
        Assert.assertTrue(false);
    } catch (final ExecutionException e) {
        log.error("Execution failed " + e.getMessage());
        Assert.assertTrue(false);
    } finally {
        service.shutdown();
    }
}
Also used : LogEvent(org.wso2.carbon.logging.view.stub.types.carbon.LogEvent) LogViewerLogViewerException(org.wso2.carbon.logging.view.stub.LogViewerLogViewerException) ExecutorService(java.util.concurrent.ExecutorService) RemoteException(java.rmi.RemoteException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

RemoteException (java.rmi.RemoteException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1 LogViewerLogViewerException (org.wso2.carbon.logging.view.stub.LogViewerLogViewerException)1 LogEvent (org.wso2.carbon.logging.view.stub.types.carbon.LogEvent)1