SingleConsole extends AbstractSingleConsole implements Listener, SampleListener, AcceptDistFilesDigestListener { @Override public void update(final StatisticsSet intervalStatistics, final StatisticsSet cumulativeStatistics) { try { if (!capture) { return; } samplingCount++; long currentPeriod = cumulativeStatistics.getValue(getSampleModel().getPeriodIndex()); setTpsValue(sampleModel.getTPSExpression().getDoubleValue(intervalStatistics)); checkTooLowTps(getTpsValues()); updateStatistics(intervalStatistics, cumulativeStatistics); writeIntervalCsvData(intervalStatistics); int interval = getSampleModel().getSampleInterval(); long gap = 1; if (samplingCount == 1) { lastSamplingPeriod = currentPeriod; } else { lastSamplingPeriod = lastSamplingPeriod + interval; gap = ((currentPeriod - lastSamplingPeriod) / interval); } samplingLifeCycleListener.apply(new Informer<SamplingLifeCycleListener>() { @Override public void inform(SamplingLifeCycleListener listener) { listener.onSampling(getReportPath(), intervalStatistics, cumulativeStatistics); } }); for (long index = 0, repeatCounts = gap + 1; index < repeatCounts; index++) { final boolean lastCall = (samplingCount == 1 && index == 0) || (samplingCount != 1 && index == gap); writeIntervalSummaryData(intervalStatistics, lastCall); if (interval >= (MIN_SAMPLING_INTERVAL_TO_ACTIVATE_TPS_PER_TEST)) { writeIntervalSummaryDataPerTest(intervalStatisticMapPerTest, lastCall); } samplingLifeCycleFollowupListener.apply(new Informer<SamplingLifeCycleFollowUpListener>() { @Override public void inform(SamplingLifeCycleFollowUpListener listener) { listener.onSampling(getReportPath(), intervalStatistics, cumulativeStatistics, lastCall); } }); } lastSamplingPeriod = lastSamplingPeriod + (interval * gap); } catch (RuntimeException e) { LOGGER.error("Error occurred while updating the statistics : {}", e.getMessage()); LOGGER.debug("Details : ", e); throw e; } } SingleConsole(int port);  SingleConsole(String ip, int port, ConsoleCommunicationSetting consoleCommunicationSetting,
						 ConsoleProperties consoleProperties); int getConsolePort(); void start(); void shutdown(); int getAllAttachedAgentsCount(); List<AgentIdentity> getAllAttachedAgents(); T getConsoleComponent(Class<T> componentType); ConsoleProperties getConsoleProperties(); long startTest(GrinderProperties properties); void setDistributionDirectory(File filePath); @Override void cancel(); void distributeFiles(File filePath, ListenerSupport<FileDistributionListener> listener, boolean safe); String getConsoleIP(); @Override void onAcceptDistFilesDigestListener(Set<String> distFilesDigest); void sendDistFilesDigestToAgents(Set<String> distFilesDigest); void distributeFiles(ListenerSupport<FileDistributionListener> listener, final boolean safe); void waitUntilAgentPrepared(int size); void waitUntilAllAgentDisconnected(); boolean isAllTestFinished(); void setTpsValue(double newValue); double getTpsValues(); @Override long getCurrentRunningTime(); StatisticsIndexMap getStatisticsIndexMap(); ExpressionView[] getExpressionView(); Set<Entry<String, StatisticExpression>> getExpressionEntrySet(); @Override void update(final StatisticsSet intervalStatistics, final StatisticsSet cumulativeStatistics); void writeIntervalSummaryData(StatisticsSet intervalStatistics, boolean firstCall); void writeIntervalCsvData(StatisticsSet intervalStatistics); static boolean isPerfTestInterestingStatistics(String key); static boolean isInterestingStatistics(String key); @Override long getCurrentExecutionCount(); ListenerSupport<ConsoleShutdownListener> getListeners(); void addListener(ConsoleShutdownListener listener); void addSamplingLifeCycleListener(SamplingLifeCycleListener listener); @Override void update(ProcessReports[] processReports); Map<String, Object> getStatisticsData(); @Override File getReportPath(); void setReportPath(File reportPath); void sendStopMessageToAgents(); void startSampling(); void unregisterSampling(); GrinderProperties getGrinderProperties(); boolean hasTooManyError(); boolean hasNoPerformedTest(); boolean isCanceled(); boolean isCurrentRunningTimeOverDuration(long duration); @Override double getPeakTpsForGraph(); SampleModelImplementationEx getSampleModel(); void setSampleModel(SampleModel sampleModel); @Override int getRunningThread(); @Override int getRunningProcess(); List<Set<String>> getAgentCachedDistFilesDigestList(); @SuppressWarnings("UnusedDeclaration") void addSamplingLifeCycleFollowUpCycleListener(SamplingLifeCycleFollowUpListener listener); void setCsvSeparator(String csvSeparator); static final Resources RESOURCE; static final Logger LOGGER; static final String REPORT_DATA; static final int MIN_SAMPLING_INTERVAL_TO_ACTIVATE_TPS_PER_TEST; }
@Test public void testUpdate() { SingleConsole singleConsole = new SingleConsole(getFreePort()) { @Override public long getCurrentRunningTime() { return 2000; } @Override public Map<String, Object> getStatisticsData() { Map<String, Object> newMap = new HashMap<String, Object>(); Map<Object, Object> errorMap = new HashMap<Object, Object>(); errorMap.put("Tests", testCount); errorMap.put("Errors", errorCount); newMap.put("totalStatistics", errorMap); return newMap; } @Override protected void updateStatistics(StatisticsSet intervalStatisticsSnapshot, StatisticsSet accumulatedStatisticsSnapshot) { } }; singleConsole.update(null, null); singleConsole.startSampling(); SampleModelImplementationEx sampleModelMock = mock(SampleModelImplementationEx.class); singleConsole.setSampleModel(sampleModelMock); StatisticExpression exp = mock(StatisticExpression.class); StatisticsSet statisticMock = mock(StatisticsSet.class); StatisticsSet statisticAccumulatedMock = mock(StatisticsSet.class); when(statisticMock.snapshot()).thenReturn(statisticMock); when(statisticAccumulatedMock.snapshot()).thenReturn(statisticAccumulatedMock); when(exp.getDoubleValue(any(StatisticsSet.class))).thenReturn(3D); when(sampleModelMock.getTPSExpression()).thenReturn(exp); singleConsole.update(statisticMock, statisticAccumulatedMock); singleConsole.update(statisticMock, statisticAccumulatedMock); }