Skip to content

Instantly share code, notes, and snippets.

@schrepfler
Last active June 16, 2019 00:29
Show Gist options
  • Save schrepfler/c40088c086664df502029002e518c032 to your computer and use it in GitHub Desktop.
Save schrepfler/c40088c086664df502029002e518c032 to your computer and use it in GitHub Desktop.
Scala testcontainers Cassandra wrapper
import com.dimafeng.testcontainers.SingleContainer
import org.testcontainers.containers.{CassandraContainer => OTCCassandraContainer, GenericContainer => OTCGenericContainer}
class CassandraContainer(dockerImageNameOverride: Option[String] = None,
configurationOverride: Option[String] = None,
initScript: Option[String] = None,
jmxReporting: Boolean = false) extends SingleContainer[OTCCassandraContainer[_]] {
type OTCContainer = OTCGenericContainer[T] forSome {type T <: OTCCassandraContainer[T]}
var cassandraContainer: OTCCassandraContainer[Nothing] = null
if (dockerImageNameOverride.isEmpty) {
cassandraContainer = new OTCCassandraContainer()
} else {
cassandraContainer = new OTCCassandraContainer(dockerImageNameOverride.get)
}
if (configurationOverride.isDefined) cassandraContainer.withConfigurationOverride(configurationOverride.get)
if (initScript.isDefined) cassandraContainer.withConfigurationOverride(initScript.get)
if (jmxReporting) cassandraContainer.withJmxReporting(jmxReporting)
override val container: OTCCassandraContainer[_] = cassandraContainer
}
object CassandraContainer {
def apply(dockerImageNameOverride: String = null,
configurationOverride: String = null,
initScript: String = null,
jmxReporting: Boolean = false) = new CassandraContainer(
Option(dockerImageNameOverride),
Option(configurationOverride),
Option(initScript),
jmxReporting
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment