summaryrefslogtreecommitdiff
path: root/opendc-trace/opendc-trace-wfformat/src
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-06-08 15:06:14 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-06-08 15:06:14 +0200
commit9d759c9bc987965fae8b0c16c000772c546bf3a2 (patch)
treebf20f51b434d56e60ad013568ac1a32b912a3b5e /opendc-trace/opendc-trace-wfformat/src
parentf7a5b200e4767213617774a87113d0b56d8d8a59 (diff)
test(trace): Add conformance suite for OpenDC trace API
This change adds a re-usable test suite for the interface of the OpenDC trace API, so implementors can verify whether they match the specification of the interfaces.
Diffstat (limited to 'opendc-trace/opendc-trace-wfformat/src')
-rw-r--r--opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTaskTableReader.kt17
-rw-r--r--opendc-trace/opendc-trace-wfformat/src/test/kotlin/org/opendc/trace/wfformat/WfFormatTraceFormatTest.kt24
2 files changed, 36 insertions, 5 deletions
diff --git a/opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTaskTableReader.kt b/opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTaskTableReader.kt
index 0be9dec6..ca1a29d0 100644
--- a/opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTaskTableReader.kt
+++ b/opendc-trace/opendc-trace-wfformat/src/main/kotlin/org/opendc/trace/wfformat/WfFormatTaskTableReader.kt
@@ -54,6 +54,7 @@ internal class WfFormatTaskTableReader(private val parser: JsonParser) : TableRe
// Check whether the document is not empty and starts with an object
if (token == null) {
+ parser.close()
break
} else if (token != JsonToken.START_OBJECT) {
throw JsonParseException(parser, "Expected object", parser.currentLocation)
@@ -64,6 +65,7 @@ internal class WfFormatTaskTableReader(private val parser: JsonParser) : TableRe
ParserLevel.TRACE -> {
// Seek for the workflow object in the file
if (!seekWorkflow()) {
+ parser.close()
break
} else if (!parser.isExpectedStartObjectToken) {
throw JsonParseException(parser, "Expected object", parser.currentLocation)
@@ -111,7 +113,7 @@ internal class WfFormatTaskTableReader(private val parser: JsonParser) : TableRe
}
override fun isNull(index: Int): Boolean {
- check(index in 0..COL_CHILDREN) { "Invalid column value" }
+ require(index in 0..COL_CHILDREN) { "Invalid column value" }
return false
}
@@ -120,6 +122,7 @@ internal class WfFormatTaskTableReader(private val parser: JsonParser) : TableRe
}
override fun getInt(index: Int): Int {
+ checkActive()
return when (index) {
COL_NPROC -> cores
else -> throw IllegalArgumentException("Invalid column")
@@ -139,6 +142,7 @@ internal class WfFormatTaskTableReader(private val parser: JsonParser) : TableRe
}
override fun getString(index: Int): String? {
+ checkActive()
return when (index) {
COL_ID -> id
COL_WORKFLOW_ID -> workflowId
@@ -155,6 +159,7 @@ internal class WfFormatTaskTableReader(private val parser: JsonParser) : TableRe
}
override fun getDuration(index: Int): Duration? {
+ checkActive()
return when (index) {
COL_RUNTIME -> runtime
else -> throw IllegalArgumentException("Invalid column")
@@ -166,6 +171,7 @@ internal class WfFormatTaskTableReader(private val parser: JsonParser) : TableRe
}
override fun <T> getSet(index: Int, elementType: Class<T>): Set<T>? {
+ checkActive()
return when (index) {
COL_PARENTS -> TYPE_PARENTS.convertTo(parents, elementType)
COL_CHILDREN -> TYPE_CHILDREN.convertTo(children, elementType)
@@ -182,10 +188,17 @@ internal class WfFormatTaskTableReader(private val parser: JsonParser) : TableRe
}
/**
+ * Helper method to check if the reader is active.
+ */
+ private fun checkActive() {
+ check(level != ParserLevel.TOP && !parser.isClosed) { "No active row. Did you call nextRow()?" }
+ }
+
+ /**
* Parse the trace and seek until the workflow description.
*/
private fun seekWorkflow(): Boolean {
- while (parser.nextValue() != JsonToken.END_OBJECT) {
+ while (parser.nextValue() != JsonToken.END_OBJECT && !parser.isClosed) {
when (parser.currentName) {
"name" -> workflowId = parser.text
"workflow" -> return true
diff --git a/opendc-trace/opendc-trace-wfformat/src/test/kotlin/org/opendc/trace/wfformat/WfFormatTraceFormatTest.kt b/opendc-trace/opendc-trace-wfformat/src/test/kotlin/org/opendc/trace/wfformat/WfFormatTraceFormatTest.kt
index a460c5f6..40506d59 100644
--- a/opendc-trace/opendc-trace-wfformat/src/test/kotlin/org/opendc/trace/wfformat/WfFormatTraceFormatTest.kt
+++ b/opendc-trace/opendc-trace-wfformat/src/test/kotlin/org/opendc/trace/wfformat/WfFormatTraceFormatTest.kt
@@ -22,17 +22,20 @@
package org.opendc.trace.wfformat
-import org.junit.jupiter.api.Assertions
+import org.junit.jupiter.api.*
import org.junit.jupiter.api.Assertions.*
-import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.Assertions.assertAll
import org.junit.jupiter.api.assertDoesNotThrow
-import org.junit.jupiter.api.assertThrows
+import org.opendc.trace.TableColumn
+import org.opendc.trace.TableReader
import org.opendc.trace.conv.*
+import org.opendc.trace.testkit.TableReaderTestKit
import java.nio.file.Paths
/**
* Test suite for the [WfFormatTraceFormat] class.
*/
+@DisplayName("WfFormat TraceFormat")
class WfFormatTraceFormatTest {
private val format = WfFormatTraceFormat()
@@ -98,4 +101,19 @@ class WfFormatTraceFormatTest {
reader.close()
}
}
+
+ @DisplayName("TableReader for Tasks")
+ @Nested
+ inner class TasksTableReaderTest : TableReaderTestKit() {
+ override lateinit var reader: TableReader
+ override lateinit var columns: List<TableColumn>
+
+ @BeforeEach
+ fun setUp() {
+ val path = Paths.get("src/test/resources/trace.json")
+
+ columns = format.getDetails(path, TABLE_TASKS).columns
+ reader = format.newReader(path, TABLE_TASKS, null)
+ }
+ }
}