Skip to content
Snippets Groups Projects
Commit 29066768 authored by Sören Henning's avatar Sören Henning
Browse files

Do some refactoring

parent d528d2b7
No related branches found
No related tags found
No related merge requests found
Pipeline #10028 passed
......@@ -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
......
......@@ -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)]
}
/**
......
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
}
......@@ -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)
......
......@@ -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)
}
}
package rocks.theodolite.kubernetes
import rocks.theodolite.core.Results
import rocks.theodolite.kubernetes.model.KubernetesBenchmark.Slo
import rocks.theodolite.core.ExperimentRunner
class TestExperimentRunnerImpl(
class TestExperimentRunner(
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
private val mockResults: Results
) : ExperimentRunner(
results
) {
override fun runExperiment(load: Int, resource: Int): Boolean {
val result = this.mockResults[load][resource]
val result = this.mockResults.getResult(load, resource) ?: throw IllegalStateException("Result is null.")
this.results.setResult(Pair(load, resource), result)
return result
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment