summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-flow/src/test
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-02-19 11:32:38 +0100
committerGitHub <noreply@github.com>2022-02-19 11:32:38 +0100
commita413367c039e1cbb640cbd7087068d78140b373f (patch)
tree3737158b657c8cb2f102621f90d7f5dedddaba77 /opendc-simulator/opendc-simulator-flow/src/test
parent0cba027933e19254573f2488086db3e4660f93d2 (diff)
parent5a0821e19eed87e91054289051213cb60b4235b4 (diff)
merge: Backport generic changes from Radice branch
This pull request backports changes from the Radice branch that are not related to Radice itself. ## Implementation Notes :hammer_and_pick: * Adjust CPU capacity to number of vCPUs * Fix reporting of CPU time * Flush results before accessing counters * Move logger field out of class * Remove delta parameter from flow callbacks ## Breaking API Changes :warning: * `delta` parameter from callbacks in `FlowSource` is removed.
Diffstat (limited to 'opendc-simulator/opendc-simulator-flow/src/test')
-rw-r--r--opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowConsumerContextTest.kt8
-rw-r--r--opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowForwarderTest.kt38
-rw-r--r--opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowSinkTest.kt12
-rw-r--r--opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt2
4 files changed, 31 insertions, 29 deletions
diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowConsumerContextTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowConsumerContextTest.kt
index fe39eb2c..e7b25554 100644
--- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowConsumerContextTest.kt
+++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowConsumerContextTest.kt
@@ -36,7 +36,7 @@ class FlowConsumerContextTest {
fun testFlushWithoutCommand() = runBlockingSimulation {
val engine = FlowEngineImpl(coroutineContext, clock)
val consumer = object : FlowSource {
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
return if (now == 0L) {
conn.push(1.0)
1000
@@ -57,7 +57,7 @@ class FlowConsumerContextTest {
fun testDoubleStart() = runBlockingSimulation {
val engine = FlowEngineImpl(coroutineContext, clock)
val consumer = object : FlowSource {
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
return if (now == 0L) {
conn.push(0.0)
1000
@@ -82,7 +82,7 @@ class FlowConsumerContextTest {
fun testIdempotentCapacityChange() = runBlockingSimulation {
val engine = FlowEngineImpl(coroutineContext, clock)
val consumer = spyk(object : FlowSource {
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
return if (now == 0L) {
conn.push(1.0)
1000
@@ -99,6 +99,6 @@ class FlowConsumerContextTest {
context.start()
context.capacity = 4200.0
- verify(exactly = 1) { consumer.onPull(any(), any(), any()) }
+ verify(exactly = 1) { consumer.onPull(any(), any()) }
}
}
diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowForwarderTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowForwarderTest.kt
index 12e72b8f..8b090593 100644
--- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowForwarderTest.kt
+++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowForwarderTest.kt
@@ -45,7 +45,7 @@ internal class FlowForwarderTest {
launch { source.consume(forwarder) }
forwarder.consume(object : FlowSource {
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
conn.close()
return Long.MAX_VALUE
}
@@ -66,7 +66,7 @@ internal class FlowForwarderTest {
forwarder.consume(object : FlowSource {
var isFirst = true
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
return if (isFirst) {
isFirst = false
conn.push(1.0)
@@ -87,7 +87,7 @@ internal class FlowForwarderTest {
val engine = FlowEngineImpl(coroutineContext, clock)
val forwarder = FlowForwarder(engine)
val consumer = object : FlowSource {
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
conn.close()
return Long.MAX_VALUE
}
@@ -113,7 +113,7 @@ internal class FlowForwarderTest {
val forwarder = FlowForwarder(engine)
val consumer = spyk(object : FlowSource {
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
conn.close()
return Long.MAX_VALUE
}
@@ -122,7 +122,7 @@ internal class FlowForwarderTest {
forwarder.startConsumer(consumer)
forwarder.cancel()
- verify(exactly = 0) { consumer.onStop(any(), any(), any()) }
+ verify(exactly = 0) { consumer.onStop(any(), any()) }
}
@Test
@@ -140,7 +140,7 @@ internal class FlowForwarderTest {
forwarder.cancel()
verify(exactly = 1) { consumer.onStart(any(), any()) }
- verify(exactly = 1) { consumer.onStop(any(), any(), any()) }
+ verify(exactly = 1) { consumer.onStop(any(), any()) }
}
@Test
@@ -158,7 +158,7 @@ internal class FlowForwarderTest {
source.cancel()
verify(exactly = 1) { consumer.onStart(any(), any()) }
- verify(exactly = 1) { consumer.onStop(any(), any(), any()) }
+ verify(exactly = 1) { consumer.onStop(any(), any()) }
}
@Test
@@ -168,7 +168,7 @@ internal class FlowForwarderTest {
val source = FlowSink(engine, 2000.0)
val consumer = object : FlowSource {
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
conn.close()
return Long.MAX_VALUE
}
@@ -198,7 +198,7 @@ internal class FlowForwarderTest {
}
assertEquals(3000, clock.millis())
- verify(exactly = 1) { source.onPull(any(), any(), any()) }
+ verify(exactly = 1) { source.onPull(any(), any()) }
}
@Test
@@ -214,11 +214,13 @@ internal class FlowForwarderTest {
yield()
- assertEquals(2.0, source.counters.actual)
- assertEquals(source.counters.actual, forwarder.counters.actual) { "Actual work" }
- assertEquals(source.counters.demand, forwarder.counters.demand) { "Work demand" }
- assertEquals(source.counters.remaining, forwarder.counters.remaining) { "Overcommitted work" }
- assertEquals(2000, clock.millis())
+ assertAll(
+ { assertEquals(2.0, source.counters.actual) },
+ { assertEquals(source.counters.actual, forwarder.counters.actual) { "Actual work" } },
+ { assertEquals(source.counters.demand, forwarder.counters.demand) { "Work demand" } },
+ { assertEquals(source.counters.remaining, forwarder.counters.remaining) { "Overcommitted work" } },
+ { assertEquals(2000, clock.millis()) }
+ )
}
@Test
@@ -246,7 +248,7 @@ internal class FlowForwarderTest {
try {
forwarder.consume(object : FlowSource {
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
throw IllegalStateException("Test")
}
})
@@ -269,7 +271,7 @@ internal class FlowForwarderTest {
try {
forwarder.consume(object : FlowSource {
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
return Long.MAX_VALUE
}
@@ -301,11 +303,11 @@ internal class FlowForwarderTest {
conn.shouldSourceConverge = true
}
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
return Long.MAX_VALUE
}
- override fun onConverge(conn: FlowConnection, now: Long, delta: Long) {
+ override fun onConverge(conn: FlowConnection, now: Long) {
throw IllegalStateException("Test")
}
})
diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowSinkTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowSinkTest.kt
index 70c75864..726ddbf7 100644
--- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowSinkTest.kt
+++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/FlowSinkTest.kt
@@ -65,7 +65,7 @@ internal class FlowSinkTest {
provider.capacity = 0.5
}
assertEquals(3000, clock.millis())
- verify(exactly = 3) { consumer.onPull(any(), any(), any()) }
+ verify(exactly = 3) { consumer.onPull(any(), any()) }
}
@Test
@@ -95,7 +95,7 @@ internal class FlowSinkTest {
val provider = FlowSink(engine, capacity)
val consumer = object : FlowSource {
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
conn.close()
return Long.MAX_VALUE
}
@@ -122,7 +122,7 @@ internal class FlowSinkTest {
resCtx = conn
}
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
return if (isFirst) {
isFirst = false
conn.push(1.0)
@@ -154,7 +154,7 @@ internal class FlowSinkTest {
throw IllegalStateException("Hi")
}
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
return Long.MAX_VALUE
}
}
@@ -173,7 +173,7 @@ internal class FlowSinkTest {
val consumer = object : FlowSource {
var isFirst = true
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
return if (isFirst) {
isFirst = false
conn.push(1.0)
@@ -231,7 +231,7 @@ internal class FlowSinkTest {
val provider = FlowSink(engine, capacity)
val consumer = object : FlowSource {
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long = Long.MAX_VALUE
+ override fun onPull(conn: FlowConnection, now: Long): Long = Long.MAX_VALUE
}
provider.consume(consumer)
diff --git a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt
index 187dacd9..ef15f711 100644
--- a/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt
+++ b/opendc-simulator/opendc-simulator-flow/src/test/kotlin/org/opendc/simulator/flow/mux/ForwardingFlowMultiplexerTest.kt
@@ -112,7 +112,7 @@ internal class ForwardingFlowMultiplexerTest {
isFirst = true
}
- override fun onPull(conn: FlowConnection, now: Long, delta: Long): Long {
+ override fun onPull(conn: FlowConnection, now: Long): Long {
return if (isFirst) {
isFirst = false
conn.push(1.0)