Skip to content

Commit

Permalink
alternative fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Bdegraaf1234 committed Apr 2, 2024
1 parent ae98a17 commit 2758139
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
5 changes: 4 additions & 1 deletion src/main/java/org/radarbase/output/config/PathConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ data class PathConfig(
else -> null
}

val pathFormatterConfig = path.copy(properties = properties)
val pathConfig = copy(bucket = bucketConfig, path = pathFormatterConfig)

pathFactory.init(
extension = extension,
config = copy(bucket = bucketConfig),
config = pathConfig,
topics = topics,
)

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/radarbase/output/path/RecordPathFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ abstract class RecordPathFactory {
},
path = config.path.copy(
properties = buildMap {
putAll(config.properties)
putAll(config.path.properties)
putIfAbsent("extension", extension)
},
),
)
val props = config.path.properties == config.properties
logger.warn("This should be false imo but it is not in the unit test: $props")

this.addTopicConfiguration(topics)
}

Expand Down
33 changes: 17 additions & 16 deletions src/test/java/org/radarbase/output/path/RecordPathFactoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,43 @@ import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.radarbase.output.config.PathConfig
import org.radarbase.output.config.PathFormatterConfig
import org.radarbase.output.config.TopicConfig
import org.radarbase.output.config.ResourceConfig
import org.radarbase.output.config.S3Config

internal class RecordPathFactoryTest {

@Test
fun testInit() {
var properties = mapOf("key1" to "value1", "key2" to "value2")

val pathConfig = PathConfig(
factory = "org.radarbase.output.path.FormattedPathFactory",
properties = properties,
path = PathFormatterConfig(
format = "\${topic}/\${projectId}/\${userId}/\${sourceId}/\${time:yyyyMM}/\${time:dd}/\${filename}",
format = "\${topic}/\${projectId}/\${userId}/\${sourceId}/\${filename}",
plugins = "fixed",
properties = properties,
),
)

val topics = mapOf<String, TopicConfig>()

val recordPathFactory = object : RecordPathFactory() {
override suspend fun bucket(pathParameters: PathFormatParameters?): String? {
return null
}

override suspend fun relativePath(pathParameters: PathFormatParameters): String {
return ""
}
}
val targetConfig = S3Config(
endpoint = "http://localhost:9000",
accessToken = "minioadmin",
secretKey = "minioadmin",
bucket = "target",
)

recordPathFactory.init("test-extension", pathConfig, topics)
val factory = pathConfig.createFactory(
ResourceConfig("s3", s3 = targetConfig),
"test-extension",
topics = mapOf(),
)

properties = buildMap {
putAll(properties)
putIfAbsent("extension", "test-extension")
}

assertEquals(properties, recordPathFactory.pathConfig.path.properties)
assertEquals(properties, factory.pathConfig.path.properties)
assertEquals(properties, factory.pathConfig.path.properties)
}
}

0 comments on commit 2758139

Please sign in to comment.