From e2c5c505322a3fcf814beb3777e1daef3176ff1a Mon Sep 17 00:00:00 2001
From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de>
Date: Wed, 5 Jan 2022 11:40:13 +0100
Subject: [PATCH] Enhance tests and code quality

---
 .../theodolite/benchmark/ActionCommand.kt     | 22 +++++++++++++------
 .../theodolite/benchmark/ActionCommandTest.kt |  2 +-
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/ActionCommand.kt b/theodolite/src/main/kotlin/theodolite/benchmark/ActionCommand.kt
index 82bfdf7fd..966fa5632 100644
--- a/theodolite/src/main/kotlin/theodolite/benchmark/ActionCommand.kt
+++ b/theodolite/src/main/kotlin/theodolite/benchmark/ActionCommand.kt
@@ -22,7 +22,7 @@ class ActionCommand(val client: NamespacedKubernetesClient) {
     var out: ByteArrayOutputStream = ByteArrayOutputStream()
     var error: ByteArrayOutputStream = ByteArrayOutputStream()
     var errChannelStream: ByteArrayOutputStream = ByteArrayOutputStream()
-    private val execLatch = CountDownLatch(1);
+    private val execLatch = CountDownLatch(1)
 
     /**
      * Executes an action command.
@@ -57,22 +57,22 @@ class ActionCommand(val client: NamespacedKubernetesClient) {
                 .usingListener(ActionCommandListener(execLatch))
                 .exec(*command)
 
-            val latchTerminationStatus = execLatch.await(timeout, TimeUnit.SECONDS);
+            val latchTerminationStatus = execLatch.await(timeout, TimeUnit.SECONDS)
             if (!latchTerminationStatus) {
                 throw ActionCommandFailedException("Latch could not terminate within specified time")
             }
-            execWatch.close();
+            execWatch.close()
         } catch (e: Exception) {
             when (e) {
                 is InterruptedException -> {
-                    Thread.currentThread().interrupt();
+                    Thread.currentThread().interrupt()
                     throw ActionCommandFailedException("Interrupted while waiting for the exec", e)
                 }
                 is KubernetesClientException -> {
                     throw ActionCommandFailedException("Error while executing command", e)
                 }
                 else -> {
-                    throw  e
+                    throw e
                 }
             }
         }
@@ -105,7 +105,15 @@ class ActionCommand(val client: NamespacedKubernetesClient) {
             }.toInt()
     }
 
-    private fun getPodName(matchLabels: MutableMap<String, String>, tries: Int): String {
+    /**
+     * Find pod with matching labels. The matching pod must have the status `Running`.
+     *
+     * @param matchLabels the match labels
+     * @param tries specifies the number of times to look for a  matching pod. When pods are newly created,
+     * it can take a while until the status is ready and the pod can be selected.
+     * @return the name of the pod or throws [ActionCommandFailedException]
+     */
+    fun getPodName(matchLabels: MutableMap<String, String>, tries: Int): String {
         for (i in 1..tries) {
 
             try {
@@ -118,7 +126,7 @@ class ActionCommand(val client: NamespacedKubernetesClient) {
         throw ActionCommandFailedException("Couldn't find any pod that matches the specified labels.")
     }
 
-    fun getPodName(matchLabels: MutableMap<String, String>): String {
+    private fun getPodName(matchLabels: MutableMap<String, String>): String {
         return try {
             val podNames = this.client
                 .pods()
diff --git a/theodolite/src/test/kotlin/theodolite/benchmark/ActionCommandTest.kt b/theodolite/src/test/kotlin/theodolite/benchmark/ActionCommandTest.kt
index 71001ac6f..0e40fca5c 100644
--- a/theodolite/src/test/kotlin/theodolite/benchmark/ActionCommandTest.kt
+++ b/theodolite/src/test/kotlin/theodolite/benchmark/ActionCommandTest.kt
@@ -94,7 +94,7 @@ class ActionCommandTest {
 
     @Test
     fun testGetPodName() {
-        assertEquals("pod1", ActionCommand(client = server.client).getPodName(mutableMapOf("app" to "pod")))
+        assertEquals("pod1", ActionCommand(client = server.client).getPodName(mutableMapOf("app" to "pod"), 1))
     }
 
     @Test
-- 
GitLab