From 9d759c9bc987965fae8b0c16c000772c546bf3a2 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Wed, 8 Jun 2022 15:06:14 +0200 Subject: 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. --- .../org/opendc/trace/gwf/GwfTaskTableReader.kt | 25 ++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'opendc-trace/opendc-trace-gwf/src/main') 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 getSet(index: Int, elementType: Class): Set? { + checkActive() return when (index) { COL_DEPS -> TYPE_DEPS.convertTo(dependencies, elementType) else -> throw IllegalArgumentException("Invalid column") @@ -157,6 +171,13 @@ internal class GwfTaskTableReader(private val parser: CsvParser) : TableReader { parser.close() } + /** + * 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. */ -- cgit v1.2.3