@Test public void testWaitUnitAgentConnected() { SingleConsole singleConsole = new SingleConsole(11113) { @Override public boolean isCanceled() { return cancelded; } }; ProcessReports report = mock(ProcessReports.class); WorkerProcessReport workerProcessReport = mock(WorkerProcessReport.class); WorkerProcessReport workerProcessReport2 = mock(WorkerProcessReport.class); WorkerProcessReport[] workerProcessReports = new WorkerProcessReport[] {workerProcessReport, workerProcessReport2}; when(workerProcessReport.getNumberOfRunningThreads()).thenReturn(new Short((short) 3)); when(workerProcessReport2.getNumberOfRunningThreads()).thenReturn(new Short((short) 2)); when(report.getWorkerProcessReports()).thenReturn(workerProcessReports); ProcessReports[] processReports = new ProcessReports[] {report}; singleConsole.update(processReports); assertThat(singleConsole.getRunningProcess(), is(2)); assertThat(singleConsole.getRunningThread(), is(5)); processReports = new ProcessReports[] {}; singleConsole.waitUntilAgentConnected(1); singleConsole.update(processReports); try { singleConsole.waitUntilAgentConnected(1); fail("Shoule throw Exception"); } catch (NGrinderRuntimeException e) { // } singleConsole.waitUntilAllAgentDisconnected(); processReports = new ProcessReports[] {report}; singleConsole.update(processReports); try { singleConsole.waitUntilAllAgentDisconnected(); fail("Shoule throw Exception"); } catch (NGrinderRuntimeException e) { // } }
/** * Update the count of current processes and threads. * * @param processReports ProcessReports array. */ private void updateCurrentProcessAndThread(ProcessReports[] processReports) { int notFinishedWorkerCount = 0; int processCount = 0; int threadCount = 0; // Per agents for (ProcessReports agentReport : processReports) { // Per process for (WorkerProcessReport processReport : agentReport.getWorkerProcessReports()) { // There might be the processes which is not finished but no // running thread in it. if (processReport.getState() != 3) { notFinishedWorkerCount++; } processCount++; threadCount += processReport.getNumberOfRunningThreads(); } } synchronized (this) { this.runningProcess = processCount; this.runningThread = threadCount; this.currentNotFinishedProcessCount = notFinishedWorkerCount; } }