Commit d57b099b authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Implement embedded kafka as extension

Makes it easier to use the embedded kafka container.
parent deaed694
/*
* sftp-reader
* Copyright (C) 2020 Memoriav
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.memobase
import org.junit.jupiter.api.extension.BeforeAllCallback
import org.junit.jupiter.api.extension.ExtensionContext
class EmbeddedKafkaExtension : BeforeAllCallback {
lateinit var kafka: KafkaEmbedded
private val testTopic: String = "test"
private val port: Int = 12345
override fun beforeAll(context: ExtensionContext?) {
kafka = KafkaEmbedded(port, testTopic)
val wrapper = KafkaWrapper(kafka)
if (context != null) {
context.getStore(ExtensionContext.Namespace.create(EmbeddedKafkaExtension::class.java))
.put("redis", wrapper)
Runtime.getRuntime().addShutdownHook(Thread(Runnable {
wrapper.close()
}))
}
}
class KafkaWrapper(private val embedded: KafkaEmbedded) : ExtensionContext.Store.CloseableResource {
override fun close() {
embedded.close()
}
}
}
/*
* sftp-reader
* Copyright (C) 2020 Memoriav
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.memobase
import org.junit.jupiter.api.extension.BeforeAllCallback
import org.junit.jupiter.api.extension.ExtensionContext
class SftpServerExtension : BeforeAllCallback {
override fun beforeAll(context: ExtensionContext?) {
TODO("Not yet implemented")
}
class SftpServerWrapper(private val embedded: KafkaEmbedded) : ExtensionContext.Store.CloseableResource {
override fun close() {
embedded.close()
}
}
}
......@@ -17,24 +17,15 @@
*/
package org.memobase
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.assertAll
import org.junit.jupiter.api.extension.ExtendWith
@ExtendWith(EmbeddedKafkaExtension::class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class Tests {
private val kafkaEmbedded = KafkaEmbedded(12301, "test")
private val testResourceCsv = ClassLoader.getSystemResourceAsStream("test.csv")
@Test
fun testValidCsvSend() {
kafkaEmbedded.use {
assertAll("test case 1",
{ assertEquals("null", "null") },
{ assertEquals("null", "null") }
)
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment