Skip to content

Instantly share code, notes, and snippets.

@ioleo
Created January 18, 2017 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ioleo/cb490d7f379e5f9b4b0db13ee0a51e33 to your computer and use it in GitHub Desktop.
Save ioleo/cb490d7f379e5f9b4b0db13ee0a51e33 to your computer and use it in GitHub Desktop.
Quill CassandraAsyncContext with stubbed underlaying Cluster - does not try to connect on init. Useful as a mock in tests.
// this is a disabled version of CassandraAsyncContext which does not connect to Cassandra DB on init
package loostro.scala.gist
import collection.JavaConverters._
import com.datastax.driver.core.Cluster
import com.datastax.driver.core.Configuration.Builder
import io.getquill.{CassandraAsyncContext, SnakeCase}
import java.net.InetSocketAddress
import org.scalatest.{FlatSpec, Matchers}
import org.scalamock.scalatest.MockFactory
import scala.collection.mutable._
trait CassandraDbSpec extends FlatSpec with Matchers with MockFactory { spec =>
class CassandraClusterTest extends Cluster("none", ArrayBuffer[InetSocketAddress]().asJava, new Builder().build())
val clusterStub = stub[CassandraClusterTest]
// any class requireing CassandraAsyncContext (eg. repositories) will consume this implicit mock
implicit val db: CassandraAsyncContext[SnakeCase] = new CassandraAsyncContext[SnakeCase](clusterStub, "none", 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment