SimpleExecutionState extends ExecutionState { @VisibleForTesting public String getLullMessage(Thread trackedThread, Duration millis) { String userStepName = this.labelsMetadata.getOrDefault(MonitoringInfoConstants.Labels.PTRANSFORM, null); StringBuilder message = new StringBuilder(); message.append("Operation ongoing"); if (userStepName != null) { message.append(" in step ").append(userStepName); } message .append(" for at least ") .append(formatDuration(millis)) .append(" without outputting or completing in state ") .append(getStateName()); message.append("\n"); StackTraceElement[] fullTrace = trackedThread.getStackTrace(); for (StackTraceElement e : fullTrace) { message.append(" at ").append(e).append("\n"); } return message.toString(); } SimpleExecutionState(
      String stateName, String urn, HashMap<String, String> labelsMetadata); void reset(); String getUrn(); Map<String, String> getLabels(); @Override void takeSample(long millisSinceLastSample); long getTotalMillis(); @VisibleForTesting String getLullMessage(Thread trackedThread, Duration millis); @Override void reportLull(Thread trackedThread, long millis);  }
@Test public void testGetLullReturnsARelevantMessageWithStepName() { HashMap<String, String> labelsMetadata = new HashMap<String, String>(); labelsMetadata.put(MonitoringInfoConstants.Labels.PTRANSFORM, "myPTransform"); SimpleExecutionState testObject = new SimpleExecutionState("myState", null, labelsMetadata); String message = testObject.getLullMessage(new Thread(), Duration.millis(100_000)); assertThat(message, containsString("myState")); assertThat(message, containsString("myPTransform")); }
@Test public void testGetLullReturnsARelevantMessageWithoutStepNameWithNullLabels() { SimpleExecutionState testObject = new SimpleExecutionState("myState", null, null); String message = testObject.getLullMessage(new Thread(), Duration.millis(100_000)); assertThat(message, containsString("myState")); }
@Test public void testGetLullReturnsARelevantMessageWithoutStepName() { HashMap<String, String> labelsMetadata = new HashMap<String, String>(); SimpleExecutionState testObject = new SimpleExecutionState("myState", null, labelsMetadata); String message = testObject.getLullMessage(new Thread(), Duration.millis(100_000)); assertThat(message, containsString("myState")); }