summaryrefslogtreecommitdiff
path: root/opendc-trace/opendc-trace-calcite/src/test
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-06-06 16:21:21 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-06-07 15:46:53 +0200
commit2358257c1080b7ce78270535f82f0b960d48261a (patch)
treebced69c02698e85f995aa9935ddcfb54df23a64f /opendc-trace/opendc-trace-calcite/src/test
parent61b6550d7a476ab1aae45a5b9385dfd6ca4f6b6f (diff)
refactor(trace/api): Introduce type system for trace API
This change updates the trace API by introducing a limited type system for the table columns. Previously, the table columns could have any possible type representable by the JVM. With this change, we limit the available types to a small type system.
Diffstat (limited to 'opendc-trace/opendc-trace-calcite/src/test')
-rw-r--r--opendc-trace/opendc-trace-calcite/src/test/kotlin/org/opendc/trace/calcite/CalciteTest.kt96
1 files changed, 91 insertions, 5 deletions
diff --git a/opendc-trace/opendc-trace-calcite/src/test/kotlin/org/opendc/trace/calcite/CalciteTest.kt b/opendc-trace/opendc-trace-calcite/src/test/kotlin/org/opendc/trace/calcite/CalciteTest.kt
index d2877d7c..d8729034 100644
--- a/opendc-trace/opendc-trace-calcite/src/test/kotlin/org/opendc/trace/calcite/CalciteTest.kt
+++ b/opendc-trace/opendc-trace-calcite/src/test/kotlin/org/opendc/trace/calcite/CalciteTest.kt
@@ -22,16 +22,24 @@
package org.opendc.trace.calcite
+import io.mockk.every
+import io.mockk.mockk
import org.apache.calcite.jdbc.CalciteConnection
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
+import org.opendc.trace.TableColumn
+import org.opendc.trace.TableColumnType
+import org.opendc.trace.TableReader
import org.opendc.trace.Trace
+import org.opendc.trace.conv.TABLE_RESOURCES
import java.nio.file.Files
import java.nio.file.Paths
import java.sql.DriverManager
import java.sql.ResultSet
import java.sql.Statement
import java.sql.Timestamp
+import java.time.Duration
+import java.time.Instant
import java.util.*
/**
@@ -41,11 +49,11 @@ class CalciteTest {
/**
* The trace to experiment with.
*/
- private val trace = Trace.open(Paths.get("src/test/resources/trace"), format = "opendc-vm")
+ private val odcTrace = Trace.open(Paths.get("src/test/resources/trace"), format = "opendc-vm")
@Test
fun testResources() {
- runQuery(trace, "SELECT * FROM trace.resources") { rs ->
+ runQuery(odcTrace, "SELECT * FROM trace.resources") { rs ->
assertAll(
{ assertTrue(rs.next()) },
{ assertEquals("1019", rs.getString("id")) },
@@ -65,7 +73,7 @@ class CalciteTest {
@Test
fun testResourceStates() {
- runQuery(trace, "SELECT * FROM trace.resource_states") { rs ->
+ runQuery(odcTrace, "SELECT * FROM trace.resource_states") { rs ->
assertAll(
{ assertTrue(rs.next()) },
{ assertEquals("1019", rs.getString("id")) },
@@ -80,7 +88,7 @@ class CalciteTest {
@Test
fun testInterferenceGroups() {
- runQuery(trace, "SELECT * FROM trace.interference_groups") { rs ->
+ runQuery(odcTrace, "SELECT * FROM trace.interference_groups") { rs ->
assertAll(
{ assertTrue(rs.next()) },
{ assertArrayEquals(arrayOf("1019", "1023", "1052"), rs.getArray("members").array as Array<*>) },
@@ -92,7 +100,7 @@ class CalciteTest {
@Test
fun testComplexQuery() {
- runQuery(trace, "SELECT max(cpu_usage) as max_cpu_usage, avg(cpu_usage) as avg_cpu_usage FROM trace.resource_states") { rs ->
+ runQuery(odcTrace, "SELECT max(cpu_usage) as max_cpu_usage, avg(cpu_usage) as avg_cpu_usage FROM trace.resource_states") { rs ->
assertAll(
{ assertTrue(rs.next()) },
{ assertEquals(249.59993808, rs.getDouble("max_cpu_usage")) },
@@ -128,6 +136,84 @@ class CalciteTest {
}
}
+ @Test
+ fun testUUID() {
+ val trace = mockk<Trace>()
+ every { trace.tables } returns listOf(TABLE_RESOURCES)
+ every { trace.getTable(TABLE_RESOURCES)!!.columns } returns listOf(
+ TableColumn("id", TableColumnType.UUID)
+ )
+ every { trace.getTable(TABLE_RESOURCES)!!.newReader() } answers {
+ object : TableReader {
+ override fun nextRow(): Boolean = true
+
+ override fun resolve(name: String): Int {
+ return when (name) {
+ "id" -> 0
+ else -> -1
+ }
+ }
+
+ override fun isNull(index: Int): Boolean = false
+
+ override fun getBoolean(index: Int): Boolean {
+ TODO("not implemented")
+ }
+
+ override fun getInt(index: Int): Int {
+ TODO("not implemented")
+ }
+
+ override fun getLong(index: Int): Long {
+ TODO("not implemented")
+ }
+
+ override fun getFloat(index: Int): Float {
+ TODO("not implemented")
+ }
+
+ override fun getDouble(index: Int): Double {
+ TODO("not implemented")
+ }
+
+ override fun getString(index: Int): String? {
+ TODO("not implemented")
+ }
+
+ override fun getUUID(index: Int): UUID = UUID(1, 2)
+
+ override fun getInstant(index: Int): Instant? {
+ TODO("not implemented")
+ }
+
+ override fun getDuration(index: Int): Duration? {
+ TODO("not implemented")
+ }
+
+ override fun <T> getList(index: Int, elementType: Class<T>): List<T>? {
+ TODO("not implemented")
+ }
+
+ override fun <T> getSet(index: Int, elementType: Class<T>): Set<T>? {
+ TODO("not implemented")
+ }
+
+ override fun <K, V> getMap(index: Int, keyType: Class<K>, valueType: Class<V>): Map<K, V>? {
+ TODO("not implemented")
+ }
+
+ override fun close() {}
+ }
+ }
+
+ runQuery(trace, "SELECT id FROM trace.resources") { rs ->
+ assertAll(
+ { assertTrue(rs.next()) },
+ { assertArrayEquals(byteArrayOf(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2), rs.getBytes("id")) },
+ )
+ }
+ }
+
/**
* Helper function to run statement for the specified trace.
*/