@Test public void shouldNotGenerateMessageWhenOwnTimeWithinThresholds() { final List<SFinishedBuild> builds = Arrays.asList(myBuild1, myBuild2); final List<HistoryElement> historyElements = Arrays.asList(myHistoryElement1, myHistoryElement2); final StatisticMessage statisticMessage = new StatisticMessage("method1", "L10", "F20", "12", "34"); final Statistic statistic = new Statistic(new BigDecimal(1), new BigDecimal(2), new ThresholdValue(ThresholdValueType.LAST, new BigDecimal(3)), new ThresholdValue(ThresholdValueType.LAST, new BigDecimal(4)), new BigDecimal(5), new BigDecimal(6)); myCtx.checking(new Expectations() {{ oneOf(myServerExtensionHolder).registerExtension(with(ServiceMessageTranslator.class), with(DotTraceStatisticTranslator.class.getName()), with(any(ServiceMessageTranslator.class))); oneOf(myRunningBuild).getBuildType(); will(returnValue(myBuildType)); oneOf(myBuildType).getHistory(); will(returnValue(builds)); oneOf(myHistory).getElements(builds); will(returnValue(historyElements)); oneOf(myStatisticProvider).tryCreateStatistic(statisticMessage, historyElements); will(returnValue(statistic)); oneOf(myMetricComparer).isMeasuredValueWithinThresholds(new BigDecimal(5), new BigDecimal(1), new ThresholdValue(ThresholdValueType.LAST, new BigDecimal(3))); will(returnValue(true)); oneOf(myMetricComparer).isMeasuredValueWithinThresholds(new BigDecimal(6), new BigDecimal(2), new ThresholdValue(ThresholdValueType.LAST, new BigDecimal(4))); will(returnValue(false)); oneOf(myMetricComparer).tryGetThresholdValue(new BigDecimal(6), new ThresholdValue(ThresholdValueType.LAST, new BigDecimal(4))); will(returnValue(new BigDecimal(10))); oneOf(myStatisticKeyFactory).createTotalTimeKey("method1"); will(returnValue("TotalTimeKey")); oneOf(myStatisticKeyFactory).createOwnTimeKey("method1"); will(returnValue("OwnTimeKey")); oneOf(myRunningBuild).getBuildId(); will(returnValue(33L)); oneOf(myBuildDataStorage).publishValue("TotalTimeKey", 33L, new BigDecimal(1)); oneOf(myBuildDataStorage).publishValue("OwnTimeKey", 33L, new BigDecimal(2)); }}); final ServiceMessageTranslator instance = createInstance(); final List<BuildMessage1> messages = instance.translate(myRunningBuild, buildMessage1, statisticMessage); myCtx.assertIsSatisfied(); then(messages.size()).isEqualTo(2); }
@NotNull @Override public List<BuildMessage1> translate(@NotNull final SRunningBuild runningBuild, @NotNull final BuildMessage1 buildMessage, @NotNull final ServiceMessage serviceMessage) { List<BuildMessage1> messages = new Vector<BuildMessage1>(Collections.singleton(buildMessage)); final StatisticMessage statisticMessage = StatisticMessage.tryParse(serviceMessage); if(statisticMessage == null) { return messages; } final SBuildType buildType = runningBuild.getBuildType(); if(buildType == null) { return messages; } final String methodName = statisticMessage.getMethodName(); final Statistic statistic = myStatisticProvider.tryCreateStatistic(statisticMessage, myHistory.getElements(buildType.getHistory())); if(statistic != null) { final BigDecimal prevTotalTime = statistic.getPrevTotalTime(); if (prevTotalTime != null && !myMetricComparer.isMeasuredValueWithinThresholds(prevTotalTime, statistic.getMeasuredTotalTime(), statistic.getTotalTimeThreshold())) { final BigDecimal expectedValue = myMetricComparer.tryGetThresholdValue(prevTotalTime, statistic.getTotalTimeThreshold()); if(expectedValue != null) { messages.add( new BuildMessage1( buildMessage.getSourceId(), buildMessage.getTypeId(), Status.FAILURE, buildMessage.getTimestamp(), createBuildMessageText(expectedValue, statistic.getMeasuredTotalTime(), methodName, TOTAL_TIME_THRESHOLD_NAME))); } } final BigDecimal prevOwnTime = statistic.getPrevOwnTime(); if (prevOwnTime != null && !myMetricComparer.isMeasuredValueWithinThresholds(prevOwnTime, statistic.getMeasuredOwnTime(), statistic.getOwnTimeThreshold())) { final BigDecimal expectedValue = myMetricComparer.tryGetThresholdValue(prevOwnTime, statistic.getOwnTimeThreshold()); if(expectedValue != null) { messages.add( new BuildMessage1( buildMessage.getSourceId(), buildMessage.getTypeId(), Status.FAILURE, buildMessage.getTimestamp(), createBuildMessageText(expectedValue, statistic.getMeasuredOwnTime(), methodName, OWN_TIME_THRESHOLD_NAME))); } } final long buildId = runningBuild.getBuildId(); myStorage.publishValue(myStatisticKeyFactory.createTotalTimeKey(methodName), buildId, statistic.getMeasuredTotalTime()); myStorage.publishValue(myStatisticKeyFactory.createOwnTimeKey(methodName), buildId, statistic.getMeasuredOwnTime()); } return messages; }
DotTraceStatisticTranslator implements ServiceMessageTranslator { @NotNull @Override public List<BuildMessage1> translate(@NotNull final SRunningBuild runningBuild, @NotNull final BuildMessage1 buildMessage, @NotNull final ServiceMessage serviceMessage) { List<BuildMessage1> messages = new Vector<BuildMessage1>(Collections.singleton(buildMessage)); final StatisticMessage statisticMessage = StatisticMessage.tryParse(serviceMessage); if(statisticMessage == null) { return messages; } final SBuildType buildType = runningBuild.getBuildType(); if(buildType == null) { return messages; } final String methodName = statisticMessage.getMethodName(); final Statistic statistic = myStatisticProvider.tryCreateStatistic(statisticMessage, myHistory.getElements(buildType.getHistory())); if(statistic != null) { final BigDecimal prevTotalTime = statistic.getPrevTotalTime(); if (prevTotalTime != null && !myMetricComparer.isMeasuredValueWithinThresholds(prevTotalTime, statistic.getMeasuredTotalTime(), statistic.getTotalTimeThreshold())) { final BigDecimal expectedValue = myMetricComparer.tryGetThresholdValue(prevTotalTime, statistic.getTotalTimeThreshold()); if(expectedValue != null) { messages.add( new BuildMessage1( buildMessage.getSourceId(), buildMessage.getTypeId(), Status.FAILURE, buildMessage.getTimestamp(), createBuildMessageText(expectedValue, statistic.getMeasuredTotalTime(), methodName, TOTAL_TIME_THRESHOLD_NAME))); } } final BigDecimal prevOwnTime = statistic.getPrevOwnTime(); if (prevOwnTime != null && !myMetricComparer.isMeasuredValueWithinThresholds(prevOwnTime, statistic.getMeasuredOwnTime(), statistic.getOwnTimeThreshold())) { final BigDecimal expectedValue = myMetricComparer.tryGetThresholdValue(prevOwnTime, statistic.getOwnTimeThreshold()); if(expectedValue != null) { messages.add( new BuildMessage1( buildMessage.getSourceId(), buildMessage.getTypeId(), Status.FAILURE, buildMessage.getTimestamp(), createBuildMessageText(expectedValue, statistic.getMeasuredOwnTime(), methodName, OWN_TIME_THRESHOLD_NAME))); } } final long buildId = runningBuild.getBuildId(); myStorage.publishValue(myStatisticKeyFactory.createTotalTimeKey(methodName), buildId, statistic.getMeasuredTotalTime()); myStorage.publishValue(myStatisticKeyFactory.createOwnTimeKey(methodName), buildId, statistic.getMeasuredOwnTime()); } return messages; } }
DotTraceStatisticTranslator implements ServiceMessageTranslator { @NotNull @Override public List<BuildMessage1> translate(@NotNull final SRunningBuild runningBuild, @NotNull final BuildMessage1 buildMessage, @NotNull final ServiceMessage serviceMessage) { List<BuildMessage1> messages = new Vector<BuildMessage1>(Collections.singleton(buildMessage)); final StatisticMessage statisticMessage = StatisticMessage.tryParse(serviceMessage); if(statisticMessage == null) { return messages; } final SBuildType buildType = runningBuild.getBuildType(); if(buildType == null) { return messages; } final String methodName = statisticMessage.getMethodName(); final Statistic statistic = myStatisticProvider.tryCreateStatistic(statisticMessage, myHistory.getElements(buildType.getHistory())); if(statistic != null) { final BigDecimal prevTotalTime = statistic.getPrevTotalTime(); if (prevTotalTime != null && !myMetricComparer.isMeasuredValueWithinThresholds(prevTotalTime, statistic.getMeasuredTotalTime(), statistic.getTotalTimeThreshold())) { final BigDecimal expectedValue = myMetricComparer.tryGetThresholdValue(prevTotalTime, statistic.getTotalTimeThreshold()); if(expectedValue != null) { messages.add( new BuildMessage1( buildMessage.getSourceId(), buildMessage.getTypeId(), Status.FAILURE, buildMessage.getTimestamp(), createBuildMessageText(expectedValue, statistic.getMeasuredTotalTime(), methodName, TOTAL_TIME_THRESHOLD_NAME))); } } final BigDecimal prevOwnTime = statistic.getPrevOwnTime(); if (prevOwnTime != null && !myMetricComparer.isMeasuredValueWithinThresholds(prevOwnTime, statistic.getMeasuredOwnTime(), statistic.getOwnTimeThreshold())) { final BigDecimal expectedValue = myMetricComparer.tryGetThresholdValue(prevOwnTime, statistic.getOwnTimeThreshold()); if(expectedValue != null) { messages.add( new BuildMessage1( buildMessage.getSourceId(), buildMessage.getTypeId(), Status.FAILURE, buildMessage.getTimestamp(), createBuildMessageText(expectedValue, statistic.getMeasuredOwnTime(), methodName, OWN_TIME_THRESHOLD_NAME))); } } final long buildId = runningBuild.getBuildId(); myStorage.publishValue(myStatisticKeyFactory.createTotalTimeKey(methodName), buildId, statistic.getMeasuredTotalTime()); myStorage.publishValue(myStatisticKeyFactory.createOwnTimeKey(methodName), buildId, statistic.getMeasuredOwnTime()); } return messages; } DotTraceStatisticTranslator(
    @NotNull final ServerExtensionHolder server,
    @NotNull final BuildDataStorage storage,
    @NotNull final MetricComparer metricComparer,
    @NotNull final StatisticKeyFactory statisticKeyFactory,
    @NotNull final StatisticProvider statisticProvider,
    @NotNull final History history); }
DotTraceStatisticTranslator implements ServiceMessageTranslator { @NotNull @Override public List<BuildMessage1> translate(@NotNull final SRunningBuild runningBuild, @NotNull final BuildMessage1 buildMessage, @NotNull final ServiceMessage serviceMessage) { List<BuildMessage1> messages = new Vector<BuildMessage1>(Collections.singleton(buildMessage)); final StatisticMessage statisticMessage = StatisticMessage.tryParse(serviceMessage); if(statisticMessage == null) { return messages; } final SBuildType buildType = runningBuild.getBuildType(); if(buildType == null) { return messages; } final String methodName = statisticMessage.getMethodName(); final Statistic statistic = myStatisticProvider.tryCreateStatistic(statisticMessage, myHistory.getElements(buildType.getHistory())); if(statistic != null) { final BigDecimal prevTotalTime = statistic.getPrevTotalTime(); if (prevTotalTime != null && !myMetricComparer.isMeasuredValueWithinThresholds(prevTotalTime, statistic.getMeasuredTotalTime(), statistic.getTotalTimeThreshold())) { final BigDecimal expectedValue = myMetricComparer.tryGetThresholdValue(prevTotalTime, statistic.getTotalTimeThreshold()); if(expectedValue != null) { messages.add( new BuildMessage1( buildMessage.getSourceId(), buildMessage.getTypeId(), Status.FAILURE, buildMessage.getTimestamp(), createBuildMessageText(expectedValue, statistic.getMeasuredTotalTime(), methodName, TOTAL_TIME_THRESHOLD_NAME))); } } final BigDecimal prevOwnTime = statistic.getPrevOwnTime(); if (prevOwnTime != null && !myMetricComparer.isMeasuredValueWithinThresholds(prevOwnTime, statistic.getMeasuredOwnTime(), statistic.getOwnTimeThreshold())) { final BigDecimal expectedValue = myMetricComparer.tryGetThresholdValue(prevOwnTime, statistic.getOwnTimeThreshold()); if(expectedValue != null) { messages.add( new BuildMessage1( buildMessage.getSourceId(), buildMessage.getTypeId(), Status.FAILURE, buildMessage.getTimestamp(), createBuildMessageText(expectedValue, statistic.getMeasuredOwnTime(), methodName, OWN_TIME_THRESHOLD_NAME))); } } final long buildId = runningBuild.getBuildId(); myStorage.publishValue(myStatisticKeyFactory.createTotalTimeKey(methodName), buildId, statistic.getMeasuredTotalTime()); myStorage.publishValue(myStatisticKeyFactory.createOwnTimeKey(methodName), buildId, statistic.getMeasuredOwnTime()); } return messages; } DotTraceStatisticTranslator(
    @NotNull final ServerExtensionHolder server,
    @NotNull final BuildDataStorage storage,
    @NotNull final MetricComparer metricComparer,
    @NotNull final StatisticKeyFactory statisticKeyFactory,
    @NotNull final StatisticProvider statisticProvider,
    @NotNull final History history); @NotNull @Override String getServiceMessageName(); @NotNull @Override List<BuildMessage1> translate(@NotNull final SRunningBuild runningBuild, @NotNull final BuildMessage1 buildMessage, @NotNull final ServiceMessage serviceMessage); }
DotTraceStatisticTranslator implements ServiceMessageTranslator { @NotNull @Override public List<BuildMessage1> translate(@NotNull final SRunningBuild runningBuild, @NotNull final BuildMessage1 buildMessage, @NotNull final ServiceMessage serviceMessage) { List<BuildMessage1> messages = new Vector<BuildMessage1>(Collections.singleton(buildMessage)); final StatisticMessage statisticMessage = StatisticMessage.tryParse(serviceMessage); if(statisticMessage == null) { return messages; } final SBuildType buildType = runningBuild.getBuildType(); if(buildType == null) { return messages; } final String methodName = statisticMessage.getMethodName(); final Statistic statistic = myStatisticProvider.tryCreateStatistic(statisticMessage, myHistory.getElements(buildType.getHistory())); if(statistic != null) { final BigDecimal prevTotalTime = statistic.getPrevTotalTime(); if (prevTotalTime != null && !myMetricComparer.isMeasuredValueWithinThresholds(prevTotalTime, statistic.getMeasuredTotalTime(), statistic.getTotalTimeThreshold())) { final BigDecimal expectedValue = myMetricComparer.tryGetThresholdValue(prevTotalTime, statistic.getTotalTimeThreshold()); if(expectedValue != null) { messages.add( new BuildMessage1( buildMessage.getSourceId(), buildMessage.getTypeId(), Status.FAILURE, buildMessage.getTimestamp(), createBuildMessageText(expectedValue, statistic.getMeasuredTotalTime(), methodName, TOTAL_TIME_THRESHOLD_NAME))); } } final BigDecimal prevOwnTime = statistic.getPrevOwnTime(); if (prevOwnTime != null && !myMetricComparer.isMeasuredValueWithinThresholds(prevOwnTime, statistic.getMeasuredOwnTime(), statistic.getOwnTimeThreshold())) { final BigDecimal expectedValue = myMetricComparer.tryGetThresholdValue(prevOwnTime, statistic.getOwnTimeThreshold()); if(expectedValue != null) { messages.add( new BuildMessage1( buildMessage.getSourceId(), buildMessage.getTypeId(), Status.FAILURE, buildMessage.getTimestamp(), createBuildMessageText(expectedValue, statistic.getMeasuredOwnTime(), methodName, OWN_TIME_THRESHOLD_NAME))); } } final long buildId = runningBuild.getBuildId(); myStorage.publishValue(myStatisticKeyFactory.createTotalTimeKey(methodName), buildId, statistic.getMeasuredTotalTime()); myStorage.publishValue(myStatisticKeyFactory.createOwnTimeKey(methodName), buildId, statistic.getMeasuredOwnTime()); } return messages; } DotTraceStatisticTranslator(
    @NotNull final ServerExtensionHolder server,
    @NotNull final BuildDataStorage storage,
    @NotNull final MetricComparer metricComparer,
    @NotNull final StatisticKeyFactory statisticKeyFactory,
    @NotNull final StatisticProvider statisticProvider,
    @NotNull final History history); @NotNull @Override String getServiceMessageName(); @NotNull @Override List<BuildMessage1> translate(@NotNull final SRunningBuild runningBuild, @NotNull final BuildMessage1 buildMessage, @NotNull final ServiceMessage serviceMessage); static final String TOTAL_TIME_THRESHOLD_NAME; static final String OWN_TIME_THRESHOLD_NAME; }