diff --git a/montecristo/src/main/kotlin/com/datastax/montecristo/model/application/CassandraYaml.kt b/montecristo/src/main/kotlin/com/datastax/montecristo/model/application/CassandraYaml.kt index 7ca47f1..07ba580 100644 --- a/montecristo/src/main/kotlin/com/datastax/montecristo/model/application/CassandraYaml.kt +++ b/montecristo/src/main/kotlin/com/datastax/montecristo/model/application/CassandraYaml.kt @@ -31,7 +31,9 @@ data class CassandraYaml(val data : JsonNode) : YamlConfig(data) { val partitioner get() = get("partitioner") val memtableAllocationType get() = get("memtable_allocation_type") val authorizer get() = get("authorizer") - private val rowCacheSizeInMB get() = (get("row_cache_size","0")).toInt() + val rowCacheSizeInMB get() = ( + get("row_cache_size", "0").replace("\\D+".toRegex(), "") + ).toInt() fun isRowCacheEnabled(): Boolean { return (rowCacheSizeInMB.toString().toInt() > 0) } diff --git a/montecristo/src/test/kotlin/com/datastax/montecristo/model/application/YamlConfigTest.kt b/montecristo/src/test/kotlin/com/datastax/montecristo/model/application/YamlConfigTest.kt index 73d6e3a..dbea38f 100644 --- a/montecristo/src/test/kotlin/com/datastax/montecristo/model/application/YamlConfigTest.kt +++ b/montecristo/src/test/kotlin/com/datastax/montecristo/model/application/YamlConfigTest.kt @@ -16,10 +16,13 @@ package com.datastax.montecristo.model.application +import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.node.JsonNodeFactory import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import org.assertj.core.api.Assertions +import org.junit.Assert.assertTrue +import org.junit.Assert.assertFalse import org.junit.Before import org.junit.Test import java.io.File @@ -28,16 +31,19 @@ internal class YamlConfigTest { lateinit var yamlNoFile: YamlConfig lateinit var yamlWithFile: YamlConfig - @Before - fun setUp() { - yamlNoFile = YamlConfig(JsonNodeFactory.instance.objectNode()) - - val yamlFile = File(this.javaClass.getResource("/helpers/generic.yaml").path) + private fun openYamlFile(filePath: String): JsonNode { + val yamlFile = File(this.javaClass.getResource(filePath).path) val yamlReader = ObjectMapper(YAMLFactory()) val obj = yamlReader.readValue(yamlFile.readText(), Any::class.java) val jsonWriter = ObjectMapper() val json = jsonWriter.readTree(jsonWriter.writeValueAsString(obj)) - yamlWithFile = YamlConfig(json) + return json + } + + @Before + fun setUp() { + yamlNoFile = YamlConfig(JsonNodeFactory.instance.objectNode()) + yamlWithFile = YamlConfig(openYamlFile("/helpers/generic.yaml")) } @Test @@ -45,4 +51,16 @@ internal class YamlConfigTest { Assertions.assertThat(yamlNoFile.isEmpty()) Assertions.assertThat(!yamlWithFile.isEmpty()) } -} \ No newline at end of file + + @Test + fun testParseRowCache() { + var yamlFile = openYamlFile("/helpers/rowCacheEnabled.yaml") + var cassandraYaml = CassandraYaml(yamlFile) + assertTrue(cassandraYaml.isRowCacheEnabled()) + + yamlFile = openYamlFile("/helpers/rowCacheDisabled.yaml") + cassandraYaml = CassandraYaml(yamlFile) + // this should fail but the Assertions are somehow not effective + assertFalse(cassandraYaml.isRowCacheEnabled()) + } +} diff --git a/montecristo/src/test/resources/helpers/rowCacheDisabled.yaml b/montecristo/src/test/resources/helpers/rowCacheDisabled.yaml new file mode 100644 index 0000000..5e0c802 --- /dev/null +++ b/montecristo/src/test/resources/helpers/rowCacheDisabled.yaml @@ -0,0 +1,2 @@ +row_cache_size: 0MiB +key: "value" diff --git a/montecristo/src/test/resources/helpers/rowCacheEnabled.yaml b/montecristo/src/test/resources/helpers/rowCacheEnabled.yaml new file mode 100644 index 0000000..0511399 --- /dev/null +++ b/montecristo/src/test/resources/helpers/rowCacheEnabled.yaml @@ -0,0 +1,2 @@ +row_cache_size: 1 +key: "value"