diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-06-08 15:06:14 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-06-08 15:06:14 +0200 |
| commit | 9d759c9bc987965fae8b0c16c000772c546bf3a2 (patch) | |
| tree | bf20f51b434d56e60ad013568ac1a32b912a3b5e /opendc-trace/opendc-trace-gwf/src/main | |
| parent | f7a5b200e4767213617774a87113d0b56d8d8a59 (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-gwf/src/main')
| -rw-r--r-- | opendc-trace/opendc-trace-gwf/src/main/kotlin/org/opendc/trace/gwf/GwfTaskTableReader.kt | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/opendc-trace/opendc-trace-gwf/src/main/kotlin/org/opendc/trace/gwf/GwfTaskTableReader.kt b/opendc-trace/opendc-trace-gwf/src/main/kotlin/org/opendc/trace/gwf/GwfTaskTableReader.kt index 007ab90a..f9a171e9 100644 --- a/opendc-trace/opendc-trace-gwf/src/main/kotlin/org/opendc/trace/gwf/GwfTaskTableReader.kt +++ b/opendc-trace/opendc-trace-gwf/src/main/kotlin/org/opendc/trace/gwf/GwfTaskTableReader.kt @@ -37,15 +37,24 @@ import java.util.regex.Pattern * A [TableReader] implementation for the GWF format. */ internal class GwfTaskTableReader(private val parser: CsvParser) : TableReader { + /** + * A flag to indicate whether a single row has been read already. + */ + private var isStarted = false + init { parser.schema = schema } override fun nextRow(): Boolean { + if (!isStarted) { + isStarted = true + } + // Reset the row state reset() - if (!nextStart()) { + if (parser.isClosed || !nextStart()) { return false } @@ -84,7 +93,7 @@ internal class GwfTaskTableReader(private val parser: CsvParser) : TableReader { } override fun isNull(index: Int): Boolean { - check(index in 0..COL_DEPS) { "Invalid column" } + require(index in 0..COL_DEPS) { "Invalid column" } return false } @@ -93,6 +102,7 @@ internal class GwfTaskTableReader(private val parser: CsvParser) : TableReader { } override fun getInt(index: Int): Int { + checkActive() return when (index) { COL_REQ_NPROC -> reqNProcs COL_NPROC -> nProcs @@ -113,6 +123,7 @@ internal class GwfTaskTableReader(private val parser: CsvParser) : TableReader { } override fun getString(index: Int): String? { + checkActive() return when (index) { COL_JOB_ID -> jobId COL_WORKFLOW_ID -> workflowId @@ -125,6 +136,7 @@ internal class GwfTaskTableReader(private val parser: CsvParser) : TableReader { } override fun getInstant(index: Int): Instant? { + checkActive() return when (index) { COL_SUBMIT_TIME -> submitTime else -> throw IllegalArgumentException("Invalid column") @@ -132,6 +144,7 @@ internal class GwfTaskTableReader(private val parser: CsvParser) : TableReader { } override fun getDuration(index: Int): Duration? { + checkActive() return when (index) { COL_RUNTIME -> runtime else -> throw IllegalArgumentException("Invalid column") @@ -147,6 +160,7 @@ internal class GwfTaskTableReader(private val parser: CsvParser) : TableReader { } override fun <T> getSet(index: Int, elementType: Class<T>): Set<T>? { + checkActive() return when (index) { COL_DEPS -> TYPE_DEPS.convertTo(dependencies, elementType) else -> throw IllegalArgumentException("Invalid column") @@ -158,6 +172,13 @@ internal class GwfTaskTableReader(private val parser: CsvParser) : TableReader { } /** + * Helper method to check if the reader is active. + */ + private fun checkActive() { + check(isStarted && !parser.isClosed) { "No active row. Did you call nextRow()?" } + } + + /** * The pattern used to parse the parents. */ private val pattern = Pattern.compile("\\s+") |
