StatisticsConverter { public StatisticsResponse convert(Statistics stats) { StatisticsResponse response = new StatisticsResponse(); response.queueStatistics.count = stats.queuedStatistics.count; response.queueStatistics.maxAge = stats.queuedStatistics.maxAgeMillis; response.queueStatistics.minAge = stats.queuedStatistics.minAgeMillis; response.executionStatistics.count = stats.executionStatistics.count; response.executionStatistics.maxAge = stats.executionStatistics.maxAgeMillis; response.executionStatistics.minAge = stats.executionStatistics.minAgeMillis; return response; }  StatisticsResponse convert(Statistics stats); WorkflowDefinitionStatisticsResponse convert(Map<String, Map<String, WorkflowDefinitionStatistics>> stats);  }
@Test public void queueStatisticsConvertWorks() { QueueStatistics queuedStatistics = new QueueStatistics(2, 42l, 10l); QueueStatistics executionStatistics = new QueueStatistics(5, null, null); Statistics stats = new Statistics(queuedStatistics, executionStatistics); StatisticsResponse response = converter.convert(stats); io.nflow.rest.v1.msg.QueueStatistics restQueueStats = response.queueStatistics; assertThat(restQueueStats.count, is(2)); assertThat(restQueueStats.maxAge, is(42l)); assertThat(restQueueStats.minAge, is(10l)); io.nflow.rest.v1.msg.QueueStatistics restExecStats = response.executionStatistics; assertThat(restExecStats.count, is(5)); assertThat(restExecStats.maxAge, nullValue()); assertThat(restExecStats.minAge, nullValue()); }
@Test public void workflowDefinitionStatisticsConverterWorks() { Map<String, WorkflowDefinitionStatistics> stateStats = new HashMap<>(); WorkflowDefinitionStatistics created = new WorkflowDefinitionStatistics(); created.allInstances = 1; created.queuedInstances = 2; stateStats.put("created", created); WorkflowDefinitionStatistics inProgress = new WorkflowDefinitionStatistics(); inProgress.allInstances = 3; inProgress.queuedInstances = 4; stateStats.put("inProgress", inProgress); WorkflowDefinitionStatistics executing = new WorkflowDefinitionStatistics(); executing.allInstances = 5; stateStats.put("executing", executing); WorkflowDefinitionStatistics manual = new WorkflowDefinitionStatistics(); manual.allInstances = 8; stateStats.put("manual", manual); WorkflowDefinitionStatistics finished = new WorkflowDefinitionStatistics(); finished.allInstances = 9; stateStats.put("finished", finished); stateStats.put("unknown", new WorkflowDefinitionStatistics()); Map<String, Map<String, WorkflowDefinitionStatistics>> stats = singletonMap("state", stateStats); WorkflowDefinitionStatisticsResponse response = converter.convert(stats); StateStatistics stateStatistics = response.stateStatistics.get("state"); assertThat(stateStatistics.created.allInstances, is(1L)); assertThat(stateStatistics.created.queuedInstances, is(2L)); assertThat(stateStatistics.inProgress.allInstances, is(3L)); assertThat(stateStatistics.inProgress.queuedInstances, is(4L)); assertThat(stateStatistics.executing.allInstances, is(5L)); assertThat(stateStatistics.manual.allInstances, is(8L)); assertThat(stateStatistics.finished.allInstances, is(9L)); }