-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test for failures in integration tests instead (#131)
- Loading branch information
Showing
8 changed files
with
101 additions
and
101 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
persistence-cassandra/src/it/scala/com/evolutiongaming/kafka/flow/CassandraSessionStub.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.evolutiongaming.kafka.flow | ||
|
||
import cats.effect.concurrent.Ref | ||
import cats.syntax.all._ | ||
import com.datastax.driver.core.Statement | ||
import com.evolutiongaming.catshelper.MonadThrowable | ||
import com.evolutiongaming.kafka.journal.eventual.cassandra.CassandraSession | ||
import com.evolutiongaming.sstream.Stream | ||
|
||
object CassandraSessionStub { | ||
|
||
def alwaysFails[F[_]: MonadThrowable]: CassandraSession[F] = new CassandraSession[F] { | ||
def fail[T]: F[T] = MonadThrowable[F].raiseError { | ||
new RuntimeException("CassandraSessionStub: always fails") | ||
} | ||
def prepare(query: String) = fail | ||
def execute(statement: Statement) = Stream.lift(fail) | ||
def unsafe = sys.error("CassandraSessionStub: no unsafe session") | ||
} | ||
|
||
def injectFailures[F[_]: MonadThrowable]( | ||
session: CassandraSession[F], | ||
failAfter: Ref[F, Int] | ||
): CassandraSession[F] = new CassandraSession[F] { | ||
|
||
def fail[T]: F[T] = MonadThrowable[F].raiseError { | ||
new RuntimeException("CassandraSessionStub: failing after proper calls exhausted") | ||
} | ||
|
||
val failed = failAfter modify { failAfter => | ||
(failAfter - 1, failAfter <= 0) | ||
} | ||
|
||
def prepare(query: String) = failed.ifM(fail, session.prepare(query)) | ||
|
||
def execute(statement: Statement) = Stream.lift(failed) flatMap { failed => | ||
if (failed) Stream.lift(fail) else session.execute(statement) | ||
} | ||
|
||
def unsafe = sys.error("CassandraSessionStub: no unsafe session") | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
...stence-cassandra/src/test/scala/com/evolutiongaming/kafka/flow/CassandraSessionStub.scala
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
persistence-cassandra/src/test/scala/com/evolutiongaming/kafka/flow/CassandraSyncStub.scala
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
...ssandra/src/test/scala/com/evolutiongaming/kafka/flow/journal/CassandraJournalsSpec.scala
This file was deleted.
Oops, something went wrong.