diff --git a/theodolite-benchmarks/definitions/install-configmaps.sh b/theodolite-benchmarks/definitions/install-configmaps.sh index a1bbb2c60f0b74eb31ac36628de92174ed1ac910..3f69119cf28b9bebf553f6ae06a57bf28f30429e 100755 --- a/theodolite-benchmarks/definitions/install-configmaps.sh +++ b/theodolite-benchmarks/definitions/install-configmaps.sh @@ -10,7 +10,6 @@ kubectl create configmap benchmark-resources-uc2-hazelcastjet --from-file uc2-ha kubectl create configmap benchmark-resources-uc3-hazelcastjet --from-file uc3-hazelcastjet/resources kubectl create configmap benchmark-resources-uc4-hazelcastjet --from-file uc4-hazelcastjet/resources - # Kafka Streams kubectl create configmap benchmark-resources-uc1-kstreams --from-file uc1-kstreams/resources kubectl create configmap benchmark-resources-uc2-kstreams --from-file uc2-kstreams/resources diff --git a/theodolite/src/main/kotlin/rocks/theodolite/core/Results.kt b/theodolite/src/main/kotlin/rocks/theodolite/core/Results.kt index 16e6b517e1f570fd17a1b9688aff4f41ec8c9884..20b7edfd089c95af7911c72613bb6ca55703173e 100644 --- a/theodolite/src/main/kotlin/rocks/theodolite/core/Results.kt +++ b/theodolite/src/main/kotlin/rocks/theodolite/core/Results.kt @@ -58,13 +58,14 @@ class Results (val metric: Metric) { /** * Get the result for an experiment. * - * @param experiment A pair that identifies the experiment by the Load and Resource. + * @param load Load that identifies the experiment. + * @param resources Resource that identify the experiment. * @return true if the experiment was successful and false otherwise. If the result has not been reported so far, * null is returned. * */ - fun getResult(experiment: Pair<Int, Int>): Boolean? { - return this.results[experiment] + fun getResult(load: Int, resources: Int): Boolean? { + return this.results[Pair(load, resources)] } /** diff --git a/theodolite/src/test/kotlin/rocks/theodolite/core/ResultsHelper.kt b/theodolite/src/test/kotlin/rocks/theodolite/core/ResultsHelper.kt new file mode 100644 index 0000000000000000000000000000000000000000..63b44352cccb3dfc8afe69797a850c781ef46c66 --- /dev/null +++ b/theodolite/src/test/kotlin/rocks/theodolite/core/ResultsHelper.kt @@ -0,0 +1,13 @@ +package rocks.theodolite.core + +import rocks.theodolite.core.strategies.Metric + +fun createResultsFromArray(array: Array<Array<Boolean>>, metric: Metric): Results { + val results = Results(metric) + for (load in array.indices) { + for (resources in array[load].indices) { + results.setResult(Pair(load + 1, resources + 1), array[load][resources]) + } + } + return results +} diff --git a/theodolite/src/test/kotlin/rocks/theodolite/core/strategies/searchstrategy/InitialGuessSearchStrategyTest.kt b/theodolite/src/test/kotlin/rocks/theodolite/core/strategies/searchstrategy/InitialGuessSearchStrategyTest.kt index d98fd4261f709d52904094d7c4a5e8cc35d8424a..40cf803d68382ea380f0afc67adf3afbd70f9960 100644 --- a/theodolite/src/test/kotlin/rocks/theodolite/core/strategies/searchstrategy/InitialGuessSearchStrategyTest.kt +++ b/theodolite/src/test/kotlin/rocks/theodolite/core/strategies/searchstrategy/InitialGuessSearchStrategyTest.kt @@ -5,11 +5,10 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import rocks.theodolite.core.strategies.Metric import mu.KotlinLogging -import rocks.theodolite.kubernetes.TestBenchmarkDeploymentBuilder -import rocks.theodolite.kubernetes.TestExperimentRunnerImpl +import rocks.theodolite.kubernetes.TestExperimentRunner import rocks.theodolite.core.strategies.guessstrategy.PrevInstanceOptGuess import rocks.theodolite.core.Results -import rocks.theodolite.kubernetes.model.KubernetesBenchmark.Slo +import rocks.theodolite.core.createResultsFromArray private val logger = KotlinLogging.logger {} @@ -18,7 +17,7 @@ class InitialGuessSearchStrategyTest { @Test fun testInitialGuessSearch() { - val mockResults = arrayOf( + val mockResults = createResultsFromArray(arrayOf( arrayOf(true, true, true, true, true, true, true), arrayOf(false, false, true, true, true, true, true), arrayOf(false, false, true, true, true, true, true), @@ -26,19 +25,16 @@ class InitialGuessSearchStrategyTest { arrayOf(false, false, false, false, true, true, true), arrayOf(false, false, false, false, false, false, true), arrayOf(false, false, false, false, false, false, false) - ) - val mockLoads: List<Int> = (0..6).toList() - val mockResources: List<Int> = (0..6).toList() + ), Metric.DEMAND) + val mockLoads: List<Int> = (1..7).toList() + val mockResources: List<Int> = (1..7).toList() val results = Results(Metric.DEMAND) - val benchmarkDeploymentBuilder = TestBenchmarkDeploymentBuilder() val guessStrategy = PrevInstanceOptGuess() - val sloChecker = Slo() - val benchmarkExecutor = TestExperimentRunnerImpl(results, mockResults, benchmarkDeploymentBuilder, listOf(sloChecker), 0, 0, 5) + val benchmarkExecutor = TestExperimentRunner(results, mockResults) val strategy = InitialGuessSearchStrategy(benchmarkExecutor,guessStrategy, results) - val actual: ArrayList<Int?> = ArrayList() - val expected: ArrayList<Int?> = ArrayList(listOf(0, 2, 2, 3, 4, 6)) - expected.add(null) + val actual: MutableList<Int?> = mutableListOf() + val expected: List<Int?> = listOf(1, 3, 3, 4, 5, 7, null) for (load in mockLoads) { val returnVal : Int? = strategy.findSuitableResource(load, mockResources) @@ -56,7 +52,7 @@ class InitialGuessSearchStrategyTest { @Test fun testInitialGuessSearchLowerResourceDemandHigherLoad() { - val mockResults = arrayOf( + val mockResults = createResultsFromArray(arrayOf( arrayOf(true, true, true, true, true, true, true), arrayOf(false, false, true, true, true, true, true), arrayOf(false, false, true, true, true, true, true), @@ -64,19 +60,16 @@ class InitialGuessSearchStrategyTest { arrayOf(false, false, false, false, true, true, true), arrayOf(false, false, false, false, false, false, true), arrayOf(false, false, false, false, false, false, false) - ) - val mockLoads: List<Int> = (0..6).toList() - val mockResources: List<Int> = (0..6).toList() + ), Metric.DEMAND) + val mockLoads: List<Int> = (1..7).toList() + val mockResources: List<Int> = (1..7).toList() val results = Results(Metric.DEMAND) - val benchmarkDeploymentBuilder = TestBenchmarkDeploymentBuilder() val guessStrategy = PrevInstanceOptGuess() - val sloChecker = Slo() - val benchmarkExecutor = TestExperimentRunnerImpl(results, mockResults, benchmarkDeploymentBuilder, listOf(sloChecker), 0, 0, 5) + val benchmarkExecutor = TestExperimentRunner(results, mockResults) val strategy = InitialGuessSearchStrategy(benchmarkExecutor,guessStrategy, results) - val actual: ArrayList<Int?> = ArrayList() - val expected: ArrayList<Int?> = ArrayList(listOf(0, 2, 2, 1, 4, 6)) - expected.add(null) + val actual: MutableList<Int?> = mutableListOf() + val expected: List<Int?> = listOf(1, 3, 3, 2, 5, 7, null) for (load in mockLoads) { val returnVal : Int? = strategy.findSuitableResource(load, mockResources) @@ -94,7 +87,7 @@ class InitialGuessSearchStrategyTest { @Test fun testInitialGuessSearchFirstNotDoable() { - val mockResults = arrayOf( + val mockResults = createResultsFromArray(arrayOf( arrayOf(false, false, false, false, false, false, false), arrayOf(false, false, true, true, true, true, true), arrayOf(false, false, false, true, true, true, true), @@ -102,20 +95,16 @@ class InitialGuessSearchStrategyTest { arrayOf(false, false, false, false, true, true, true), arrayOf(false, false, false, false, false, false, true), arrayOf(false, false, false, false, false, false, false) - ) - val mockLoads: List<Int> = (0..6).toList() - val mockResources: List<Int> = (0..6).toList() + ), Metric.DEMAND) + val mockLoads: List<Int> = (1..7).toList() + val mockResources: List<Int> = (1..7).toList() val results = Results(Metric.DEMAND) - val benchmarkDeploymentBuilder = TestBenchmarkDeploymentBuilder() val guessStrategy = PrevInstanceOptGuess() - val sloChecker = Slo() - val benchmarkExecutor = TestExperimentRunnerImpl(results, mockResults, benchmarkDeploymentBuilder, listOf(sloChecker), 0, 0, 5) + val benchmarkExecutor = TestExperimentRunner(results, mockResults) val strategy = InitialGuessSearchStrategy(benchmarkExecutor, guessStrategy, results) val actual: MutableList<Int?> = mutableListOf() - var expected: MutableList<Int?> = ArrayList(listOf(2, 3, 0, 4, 6)) - expected.add(null) - expected = ArrayList(listOf(null) + expected) + val expected: List<Int?> = listOf(null, 3, 4, 1, 5, 7, null) for (load in mockLoads) { val returnVal : Int? = strategy.findSuitableResource(load, mockResources) diff --git a/theodolite/src/test/kotlin/rocks/theodolite/core/strategies/searchstrategy/RestrictionSearchTest.kt b/theodolite/src/test/kotlin/rocks/theodolite/core/strategies/searchstrategy/RestrictionSearchTest.kt index c82f00939da917a3bdce47e644ea50450164f38c..dbd5454fc2e2de1ed433f534915c820b55860eba 100644 --- a/theodolite/src/test/kotlin/rocks/theodolite/core/strategies/searchstrategy/RestrictionSearchTest.kt +++ b/theodolite/src/test/kotlin/rocks/theodolite/core/strategies/searchstrategy/RestrictionSearchTest.kt @@ -2,21 +2,46 @@ package rocks.theodolite.core.strategies.searchstrategy import io.quarkus.test.junit.QuarkusTest import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test -import rocks.theodolite.kubernetes.TestBenchmarkDeploymentBuilder -import rocks.theodolite.kubernetes.TestExperimentRunnerImpl +import rocks.theodolite.kubernetes.TestExperimentRunner import rocks.theodolite.core.strategies.Metric import rocks.theodolite.core.strategies.restrictionstrategy.LowerBoundRestriction import rocks.theodolite.core.Results -import rocks.theodolite.kubernetes.model.KubernetesBenchmark.Slo +import rocks.theodolite.core.createResultsFromArray @QuarkusTest class RestrictionSearchTest { + @Test + @Disabled("Currently failing, has to be fixed") + fun restrictionSearchNoMatch() { + val mockResults = createResultsFromArray(arrayOf( + arrayOf(true, true), + arrayOf(false, false), + arrayOf(true, true), + ), Metric.DEMAND) + val mockLoads: List<Int> = (1..3).toList() + val mockResources: List<Int> = (1..2).toList() + val results = Results(Metric.DEMAND) + val benchmarkExecutor = TestExperimentRunner(results, mockResults) + val linearSearch = LinearSearch(benchmarkExecutor) + val lowerBoundRestriction = LowerBoundRestriction(results) + val strategy = RestrictionSearch(benchmarkExecutor, linearSearch, setOf(lowerBoundRestriction)) + + val actual: MutableList<Int?> = mutableListOf() + val expected: List<Int?> = listOf(1, null, null) + + for (load in mockLoads) { + actual.add(strategy.findSuitableResource(load, mockResources)) + } + + assertEquals(expected, actual) + } @Test fun restrictionSearchTestLinearSearch() { - val mockResults = arrayOf( + val mockResults = createResultsFromArray(arrayOf( arrayOf(true, true, true, true, true, true, true), arrayOf(false, false, true, true, true, true, true), arrayOf(false, false, true, true, true, true, true), @@ -24,32 +49,28 @@ class RestrictionSearchTest { arrayOf(false, false, false, false, true, true, true), arrayOf(false, false, false, false, false, false, true), arrayOf(false, false, false, false, false, false, false) - ) - val mockLoads: List<Int> = (0..6).toList() - val mockResources: List<Int> = (0..6).toList() + ), Metric.DEMAND) + val mockLoads: List<Int> = (1..7).toList() + val mockResources: List<Int> = (1..7).toList() val results = Results(Metric.DEMAND) - val benchmarkDeploymentBuilder = TestBenchmarkDeploymentBuilder() - val sloChecker = Slo() - val benchmarkExecutor = TestExperimentRunnerImpl(results, mockResults, benchmarkDeploymentBuilder, listOf(sloChecker), 0, 0, 5) + val benchmarkExecutor = TestExperimentRunner(results, mockResults) val linearSearch = LinearSearch(benchmarkExecutor) val lowerBoundRestriction = LowerBoundRestriction(results) - val strategy = - RestrictionSearch(benchmarkExecutor, linearSearch, setOf(lowerBoundRestriction)) + val strategy = RestrictionSearch(benchmarkExecutor, linearSearch, setOf(lowerBoundRestriction)) - val actual: ArrayList<Int?> = ArrayList() - val expected: ArrayList<Int?> = ArrayList(listOf(0, 2, 2, 3, 4, 6)) - expected.add(null) + val actual: MutableList<Int?> = mutableListOf() + val expected: List<Int?> = listOf(1, 3, 3, 4, 5, 7, null) for (load in mockLoads) { actual.add(strategy.findSuitableResource(load, mockResources)) } - assertEquals(actual, expected) + assertEquals(expected, actual) } @Test fun restrictionSearchTestFullSearch() { - val mockResults = arrayOf( + val mockResults = createResultsFromArray(arrayOf( arrayOf(true, true, true, true, true, true, true), arrayOf(false, false, true, true, true, true, true), arrayOf(false, false, true, true, true, true, true), @@ -57,32 +78,28 @@ class RestrictionSearchTest { arrayOf(false, false, false, false, true, true, true), arrayOf(false, false, false, false, false, false, true), arrayOf(false, false, false, false, false, false, false) - ) - val mockLoads: List<Int> = (0..6).toList() - val mockResources: List<Int> = (0..6).toList() + ), Metric.DEMAND) + val mockLoads: List<Int> = (1..7).toList() + val mockResources: List<Int> = (1..7).toList() val results = Results(Metric.DEMAND) - val benchmarkDeploymentBuilder = TestBenchmarkDeploymentBuilder() - val sloChecker = Slo() - val benchmarkExecutor = TestExperimentRunnerImpl(results, mockResults, benchmarkDeploymentBuilder, listOf(sloChecker), 0, 0, 5) + val benchmarkExecutor = TestExperimentRunner(results, mockResults) val fullSearch = FullSearch(benchmarkExecutor) val lowerBoundRestriction = LowerBoundRestriction(results) - val strategy = - RestrictionSearch(benchmarkExecutor, fullSearch, setOf(lowerBoundRestriction)) + val strategy = RestrictionSearch(benchmarkExecutor, fullSearch, setOf(lowerBoundRestriction)) - val actual: ArrayList<Int?> = ArrayList() - val expected: ArrayList<Int?> = ArrayList(listOf(0, 2, 2, 3, 4, 6)) - expected.add(null) + val actual: MutableList<Int?> = mutableListOf() + val expected: List<Int?> = listOf(1, 3, 3, 4, 5, 7, null) for (load in mockLoads) { actual.add(strategy.findSuitableResource(load, mockResources)) } - assertEquals(actual, expected) + assertEquals(expected, actual) } @Test fun restrictionSearchTestBinarySearch() { - val mockResults = arrayOf( + val mockResults = createResultsFromArray(arrayOf( arrayOf(true, true, true, true, true, true, true), arrayOf(false, false, true, true, true, true, true), arrayOf(false, false, true, true, true, true, true), @@ -90,32 +107,28 @@ class RestrictionSearchTest { arrayOf(false, false, false, false, true, true, true), arrayOf(false, false, false, false, false, false, true), arrayOf(false, false, false, false, false, false, false) - ) - val mockLoads: List<Int> = (0..6).toList() - val mockResources: List<Int> = (0..6).toList() + ), Metric.DEMAND) + val mockLoads: List<Int> = (1..7).toList() + val mockResources: List<Int> = (1..7).toList() val results = Results(Metric.DEMAND) - val benchmarkDeploymentBuilder = TestBenchmarkDeploymentBuilder() - val sloChecker = Slo() - val benchmarkExecutorImpl = - TestExperimentRunnerImpl(results, mockResults, benchmarkDeploymentBuilder, listOf(sloChecker), 0, 0, 0) + val benchmarkExecutorImpl = TestExperimentRunner(results, mockResults) val binarySearch = BinarySearch(benchmarkExecutorImpl) val lowerBoundRestriction = LowerBoundRestriction(results) val strategy = RestrictionSearch(benchmarkExecutorImpl, binarySearch, setOf(lowerBoundRestriction)) - val actual: ArrayList<Int?> = ArrayList() - val expected: ArrayList<Int?> = ArrayList(listOf(0, 2, 2, 3, 4, 6)) - expected.add(null) + val actual: MutableList<Int?> = mutableListOf() + val expected: List<Int?> = listOf(1, 3, 3, 4, 5, 7, null) for (load in mockLoads) { actual.add(strategy.findSuitableResource(load, mockResources)) } - assertEquals(actual, expected) + assertEquals(expected, actual) } @Test fun restrictionSearchTestBinarySearch2() { - val mockResults = arrayOf( + val mockResults = createResultsFromArray(arrayOf( arrayOf(true, true, true, true, true, true, true, true), arrayOf(false, false, true, true, true, true, true, true), arrayOf(false, false, true, true, true, true, true, true), @@ -123,26 +136,22 @@ class RestrictionSearchTest { arrayOf(false, false, false, false, true, true, true, true), arrayOf(false, false, false, false, false, false, true, true), arrayOf(false, false, false, false, false, false, false, true) - ) - val mockLoads: List<Int> = (0..6).toList() - val mockResources: List<Int> = (0..7).toList() + ), Metric.DEMAND) + val mockLoads: List<Int> = (1..7).toList() + val mockResources: List<Int> = (1..8).toList() val results = Results(Metric.DEMAND) - val benchmarkDeploymentBuilder = TestBenchmarkDeploymentBuilder() - val sloChecker = Slo() - val benchmarkExecutor = TestExperimentRunnerImpl(results, mockResults, benchmarkDeploymentBuilder, listOf(sloChecker), 0, 0, 0) + val benchmarkExecutor = TestExperimentRunner(results, mockResults) val binarySearch = BinarySearch(benchmarkExecutor) val lowerBoundRestriction = LowerBoundRestriction(results) - val strategy = - RestrictionSearch(benchmarkExecutor, binarySearch, setOf(lowerBoundRestriction)) + val strategy = RestrictionSearch(benchmarkExecutor, binarySearch, setOf(lowerBoundRestriction)) - val actual: ArrayList<Int?> = ArrayList() - val expected: ArrayList<Int?> = - ArrayList(listOf(0, 2, 2, 3, 4, 6, 7)) + val actual: MutableList<Int?> = mutableListOf() + val expected: List<Int> = listOf(1, 3, 3, 4, 5, 7, 8) for (load in mockLoads) { actual.add(strategy.findSuitableResource(load, mockResources)) } - assertEquals(actual, expected) + assertEquals(expected, actual) } } diff --git a/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/TestExperimentRunner.kt b/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/TestExperimentRunner.kt new file mode 100644 index 0000000000000000000000000000000000000000..62bb31edee19f960c1affb07579b3de814f12b33 --- /dev/null +++ b/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/TestExperimentRunner.kt @@ -0,0 +1,18 @@ +package rocks.theodolite.kubernetes + +import rocks.theodolite.core.Results +import rocks.theodolite.core.ExperimentRunner + +class TestExperimentRunner( + results: Results, + private val mockResults: Results +) : ExperimentRunner( + results +) { + + override fun runExperiment(load: Int, resource: Int): Boolean { + val result = this.mockResults.getResult(load, resource) ?: throw IllegalStateException("Result is null.") + this.results.setResult(Pair(load, resource), result) + return result + } +} diff --git a/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/TestExperimentRunnerImpl.kt b/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/TestExperimentRunnerImpl.kt deleted file mode 100644 index 896beed83e0c9436c3aadc83b1e395df06b1f5b2..0000000000000000000000000000000000000000 --- a/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/TestExperimentRunnerImpl.kt +++ /dev/null @@ -1,24 +0,0 @@ -package rocks.theodolite.kubernetes - -import rocks.theodolite.core.Results -import rocks.theodolite.kubernetes.model.KubernetesBenchmark.Slo -import rocks.theodolite.core.ExperimentRunner - -class TestExperimentRunnerImpl( - results: Results, - private val mockResults: Array<Array<Boolean>>, - private val benchmarkDeploymentBuilder: TestBenchmarkDeploymentBuilder, - private val slo: List<Slo>, - private val executionId: Int, - private val loadGenerationDelay: Long, - private val afterTeardownDelay: Long -) : ExperimentRunner( - results -) { - - override fun runExperiment(load: Int, resource: Int): Boolean { - val result = this.mockResults[load][resource] - this.results.setResult(Pair(load, resource), result) - return result - } -}