From 866c39e4fee4781a48914ff81158ed2f41b70fcd Mon Sep 17 00:00:00 2001
From: Marcel Becker <stu117960@mail.uni-kiel.de>
Date: Thu, 24 Feb 2022 15:58:49 +0100
Subject: [PATCH] Added CRDExecution Parsing Test

---
 docs/api-reference/crds.md                    |  2 +-
 .../benchmark/BenchmarkExecution.kt           |  7 +-
 .../theodolite/model/crd/CRDExecutionTest.kt  | 90 +++++++++++++++++++
 3 files changed, 95 insertions(+), 4 deletions(-)
 create mode 100644 theodolite/src/test/kotlin/theodolite/model/crd/CRDExecutionTest.kt

diff --git a/docs/api-reference/crds.md b/docs/api-reference/crds.md
index f7a3185f5..9ee24e17c 100644
--- a/docs/api-reference/crds.md
+++ b/docs/api-reference/crds.md
@@ -1784,7 +1784,7 @@ Contains the Kafka configuration.
         <td>
           Specifies the load values that are benchmarked.<br/>
         </td>
-        <td>false</td>
+        <td>true</td>
       </tr><tr>
         <td><b>name</b></td>
         <td>string</td>
diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt b/theodolite/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt
index 66f20e94b..1010a8a34 100644
--- a/theodolite/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt
+++ b/theodolite/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt
@@ -35,7 +35,7 @@ class BenchmarkExecution : KubernetesResource {
     lateinit var configOverrides: MutableList<ConfigurationOverride?>
 
     /**
-     * This execution encapsulates the [strategy], the [duration], the [repetitions], and the [restrictions]
+     * This execution encapsulates the [strategy], the [duration], and the [repetitions],
      *  which are used for the concrete benchmark experiments.
      */
     @JsonDeserialize
@@ -51,8 +51,9 @@ class BenchmarkExecution : KubernetesResource {
 
     /**
      * This Strategy encapsulates the [restrictions], [guessStrategy] and [searchStrategy],
-     * which are used for restricting the resources, the guess Strategy for the [InitialGuessSearchStrategy] and
-     * the actual [SearchStrategy] which is used.
+     * which are used for restricting the resources, the guess Strategy for the
+     * [theodolite.strategies.searchstrategy.InitialGuessSearchStrategy] and the name of the actual
+     * [theodolite.strategies.searchstrategy.SearchStrategy] which is used.
      */
     @JsonDeserialize
     @RegisterForReflection
diff --git a/theodolite/src/test/kotlin/theodolite/model/crd/CRDExecutionTest.kt b/theodolite/src/test/kotlin/theodolite/model/crd/CRDExecutionTest.kt
new file mode 100644
index 000000000..1150141ec
--- /dev/null
+++ b/theodolite/src/test/kotlin/theodolite/model/crd/CRDExecutionTest.kt
@@ -0,0 +1,90 @@
+package theodolite.model.crd
+
+import io.fabric8.kubernetes.api.model.KubernetesResourceList
+import io.fabric8.kubernetes.client.dsl.MixedOperation
+import io.fabric8.kubernetes.client.dsl.Resource
+import io.fabric8.kubernetes.client.server.mock.KubernetesServer
+import io.quarkus.test.junit.QuarkusTest
+import io.quarkus.test.kubernetes.client.KubernetesTestServer
+import io.quarkus.test.kubernetes.client.WithKubernetesTestServer
+import org.junit.jupiter.api.AfterEach
+import org.junit.jupiter.api.Assertions.*
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.Test
+import org.mockito.internal.matchers.apachecommons.ReflectionEquals
+import org.apache.commons.lang3.builder.EqualsBuilder
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers.instanceOf
+import org.mockito.kotlin.isA
+import org.mockito.kotlin.mock
+import theodolite.benchmark.BenchmarkExecution
+import theodolite.execution.operator.*
+import theodolite.util.ConfigurationOverride
+import java.io.FileInputStream
+
+
+// TODO move somewhere else
+typealias ExecutionClient = MixedOperation<ExecutionCRD, KubernetesResourceList<ExecutionCRD>, Resource<ExecutionCRD>>
+
+@WithKubernetesTestServer
+@QuarkusTest
+internal class CRDExecutionTest {
+
+     @KubernetesTestServer
+     private lateinit var server: KubernetesServer
+
+     lateinit var executionClient: ExecutionClient
+
+     lateinit var controller: TheodoliteController
+
+     lateinit var stateHandler: ExecutionStateHandler
+
+     lateinit var eventHandler: ExecutionEventHandler
+
+     @BeforeEach
+     fun setUp() {
+          server.before()
+
+          this.server.client
+                  .apiextensions().v1()
+                  .customResourceDefinitions()
+                  .load(FileInputStream("crd/crd-execution.yaml"))
+                  .create()
+
+          this.executionClient = this.server.client.resources(ExecutionCRD::class.java)
+
+          this.controller = mock()
+          this.stateHandler = ExecutionStateHandler(server.client)
+          this.eventHandler = ExecutionEventHandler(this.controller, this.stateHandler)
+     }
+
+     @AfterEach
+     fun tearDown() {
+          server.after()
+     }
+
+     @Test
+     fun checkParsingCRDTest(){
+          // BenchmarkExecution from yaml
+          val execution = executionClient.load(ClassLoader.getSystemResourceAsStream("k8s-resource-files/test-execution.yaml")).create().spec
+
+          assertEquals(0, execution.executionId)
+          assertEquals("test", execution.name)
+          assertEquals("uc1-kstreams", execution.benchmark)
+          assertEquals(mutableListOf<ConfigurationOverride?>(), execution.configOverrides)
+
+          assertEquals("NumSensors", execution.loads.loadType)
+          assertEquals(listOf(25000, 50000, 75000, 100000, 125000, 150000),execution.loads.loadValues)
+
+          assertEquals("Instances", execution.resources.resourceType)
+          assertEquals(listOf(1, 2, 3, 4, 5), execution.resources.resourceValues)
+
+          assertEquals("demand", execution.execution.metric)
+          assertEquals(300, execution.execution.duration)
+          assertEquals(1, execution.execution.repetitions)
+
+          assertEquals("RestrictionSearch", execution.execution.strategy.name)
+          assertEquals("LinearSearch", execution.execution.strategy.searchStrategy)
+          assertEquals(listOf("LowerBound"), execution.execution.strategy.restrictions)
+     }
+}
\ No newline at end of file
-- 
GitLab