Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions phantom-test/src/test/scala/com/newzly/phantom/dsl/BaseTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,39 @@ import scala.concurrent.duration._
import org.scalatest.{ BeforeAndAfterEach, BeforeAndAfterAll, FlatSpec }
import com.newzly.phantom.helper.{ CassandraCluster, TestHelper}
import org.cassandraunit.utils.EmbeddedCassandraServerHelper
import java.util.concurrent.atomic.{AtomicInteger, AtomicBoolean}


object Atomics {
val clusterStarted = new AtomicBoolean(false)
val startedTests = new AtomicInteger(0)
}
class BaseTest extends FlatSpec with BeforeAndAfterEach with BeforeAndAfterAll with CassandraCluster {


override def beforeAll() {
TestHelper.initCluster
if (!Atomics.clusterStarted.get()) {
if (Atomics.clusterStarted.compareAndSet(false,true)) {
TestHelper.initCluster()
}
}
Atomics.startedTests.incrementAndGet()
while (!TestHelper.initialized) {
Thread.sleep(1000)
}
}

override def afterAll() {
cluster.shutdown()
val finished = Atomics.startedTests.decrementAndGet()
if (finished == 0) {
cluster.shutdown()
}
}

implicit class SyncFuture[T](future: Future[T]) {
/*implicit class SyncFuture[T](future: Future[T]) {
def sync(): T = {
Await.result(future, 10 seconds)
}
}
}*/

}
Loading