Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle units in some YAML settings (post CASSANDRA-15234) #10

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,21 +31,36 @@ 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
fun testIsEmpty() {
Assertions.assertThat(yamlNoFile.isEmpty())
Assertions.assertThat(!yamlWithFile.isEmpty())
}
}

@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())
}
}
2 changes: 2 additions & 0 deletions montecristo/src/test/resources/helpers/rowCacheDisabled.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
row_cache_size: 0MiB
key: "value"
2 changes: 2 additions & 0 deletions montecristo/src/test/resources/helpers/rowCacheEnabled.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
row_cache_size: 1
key: "value"
Loading