Skip to content

Commit

Permalink
scala 2.12
Browse files Browse the repository at this point in the history
  • Loading branch information
etaty committed Nov 20, 2016
1 parent ffd4f94 commit 3c1bce9
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 63 deletions.
12 changes: 6 additions & 6 deletions project/Rediscala.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ object Resolvers {
}

object Dependencies {
val akkaVersion = "2.3.6"
val akkaVersion = "2.4.12"

import sbt._

val akkaActor = "com.typesafe.akka" %% "akka-actor" % akkaVersion

val akkaTestkit = "com.typesafe.akka" %% "akka-testkit" % akkaVersion

val specs2 = "org.specs2" %% "specs2" % "2.3.13"
val specs2 = "org.specs2" %% "specs2-core" % "3.8.6"

val stm = "org.scala-stm" %% "scala-stm" % "0.7"
val stm = "org.scala-stm" %% "scala-stm" % "0.8"

val scalacheck = "org.scalacheck" %% "scalacheck" % "1.12.5"
val scalacheck = "org.scalacheck" %% "scalacheck" % "1.13.4"

//val scalameter = "com.github.axel22" %% "scalameter" % "0.4"

Expand All @@ -51,8 +51,8 @@ object RediscalaBuild extends Build {
Seq(
name := "rediscala",
organization := "com.github.etaty",
scalaVersion := "2.11.7",
crossScalaVersions := Seq("2.11.7", "2.10.4"),
scalaVersion := "2.11.8",
crossScalaVersions := Seq(scalaVersion.value, "2.12.0"),
licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0.html")),
homepage := Some(url("https://github.com/etaty/rediscala")),
scmInfo := Some(ScmInfo(url("https://github.com/etaty/rediscala"), "scm:git:[email protected]:etaty/rediscala.git")),
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.8
sbt.version=0.13.13
6 changes: 2 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.3.3")

resolvers += Classpaths.sbtPluginReleases

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.0.4")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.3.5")

addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.0.0")

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.1")
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.1.0")

resolvers += Resolver.url(
"bintray-sbt-plugin-releases",
Expand Down
44 changes: 23 additions & 21 deletions src/main/scala/redis/Sentinel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ trait SentinelCommands
case class SentinelClient(var host: String = "localhost",
var port: Int = 26379,
onMasterChange: (String, String, Int) => Unit = (masterName: String, ip: String, port: Int) => {},
onNewSentinel: (String, String, Int) => Unit = (masterName: String, sentinelip: String, sentinelport: Int) => {},
onNewSentinel: (String, String, Int) => Unit = (masterName: String, sentinelip: String, sentinelport: Int) => {},
onSentinelDown: (String, String, Int) => Unit = (masterName: String, sentinelip: String, sentinelport: Int) => {},
onNewSlave: (String, String, Int) => Unit = (masterName: String, sentinelip: String, sentinelport: Int) => {},
onSlaveDown: (String, String, Int) => Unit = (masterName: String, sentinelip: String, sentinelport: Int) => {},
onNewSlave: (String, String, Int) => Unit = (masterName: String, sentinelip: String, sentinelport: Int) => {},
onSlaveDown: (String, String, Int) => Unit = (masterName: String, sentinelip: String, sentinelport: Int) => {},
name: String = "SentinelClient")
(implicit _system: ActorSystem,
redisDispatcher: RedisDispatcher = Redis.dispatcher
Expand All @@ -27,11 +27,11 @@ case class SentinelClient(var host: String = "localhost",

val log = Logging.getLogger(system, this)

val channels = Seq("+switch-master", "+sentinel", "+sdown","-sdown", "+failover-state-send-slaveof-noone","+slave")
val channels = Seq("+switch-master", "+sentinel", "+sdown", "-sdown", "+failover-state-send-slaveof-noone", "+slave")

val onMessage = (message: Message) => {

if (log.isDebugEnabled)
if (log.isDebugEnabled)
log.debug(s"SentinelClient.onMessage: message received:${message.channel} ${message.data.utf8String}")

message match {
Expand Down Expand Up @@ -67,15 +67,15 @@ case class SentinelClient(var host: String = "localhost",
case _ => {}
}
}
case Message("-sdown", data) => {
case Message("-sdown", data) => {
data.utf8String.split(" ") match {
case Array("slave", slaveName, slaveip, slaveport, "@", master, masterip, masterport) =>
onNewSlave(master, slaveip, slaveport.toInt)

case _ => {}
}
}
case Message("+slave", data) => {
case Message("+slave", data) => {
data.utf8String.split(" ") match {
case Array("slave", slaveName, slaveip, slaveport, "@", master, masterip, masterport) =>
onNewSlave(master, slaveip, slaveport.toInt)
Expand All @@ -91,14 +91,14 @@ case class SentinelClient(var host: String = "localhost",

val redisPubSubConnection: ActorRef = system.actorOf(
Props(classOf[RedisSubscriberActorWithCallback],
new InetSocketAddress(host, port), channels, Seq(), onMessage, (pmessage: PMessage) => {}, None,(status:Boolean) => {})
new InetSocketAddress(host, port), channels, Seq(), onMessage, (pmessage: PMessage) => {}, None, (status: Boolean) => {})
.withDispatcher(redisDispatcher.name),
name + '-' + Redis.tempName()
)

/**
* Disconnect from the server (stop the actors)
*/
* Disconnect from the server (stop the actors)
*/
override def stop() {
system stop redisConnection
system stop redisPubSubConnection
Expand Down Expand Up @@ -175,11 +175,13 @@ abstract class SentinelMonitored(system: ActorSystem, redisDispatcher: RedisDisp
import scala.concurrent.duration._

val f = sentinelClients.values.map(_.getMasterAddr(master))
val ff = Future.find(f) { case Some((_: String, _: Int)) => true case _ => false }
.map {
case Some(Some((ip: String, port: Int))) => initFunction(ip, port)
case _ => throw new Exception(s"No such master '$master'")
}
val ff = Future.sequence(f).map { listAddr =>
listAddr.flatten
.headOption
.map {
case (ip: String, port: Int) => initFunction(ip, port)
}.getOrElse(throw new Exception(s"No such master '$master'"))
}

Await.result(ff, 15 seconds)
}
Expand All @@ -206,7 +208,7 @@ abstract class SentinelMonitored(system: ActorSystem, redisDispatcher: RedisDisp
}

abstract class SentinelMonitoredRedisClientLike(system: ActorSystem, redisDispatcher: RedisDispatcher
) extends SentinelMonitored(system, redisDispatcher) with ActorRequest {
) extends SentinelMonitored(system, redisDispatcher) with ActorRequest {
val redisClient: RedisClientActorLike
val onMasterChange = (ip: String, port: Int) => {
log.info(s"onMasterChange: $ip:$port")
Expand All @@ -216,8 +218,8 @@ abstract class SentinelMonitoredRedisClientLike(system: ActorSystem, redisDispat
def redisConnection = redisClient.redisConnection

/**
* Disconnect from the server (stop the actors)
*/
* Disconnect from the server (stop the actors)
*/
def stop() = {
redisClient.stop()
sentinelClients.values.foreach(_.stop())
Expand All @@ -226,7 +228,7 @@ abstract class SentinelMonitoredRedisClientLike(system: ActorSystem, redisDispat
}

abstract class SentinelMonitoredRedisBlockingClientLike(system: ActorSystem, redisDispatcher: RedisDispatcher
) extends SentinelMonitored(system, redisDispatcher) with ActorRequest {
) extends SentinelMonitored(system, redisDispatcher) with ActorRequest {
val redisClient: RedisClientActorLike

val onMasterChange = (ip: String, port: Int) => {
Expand All @@ -235,8 +237,8 @@ abstract class SentinelMonitoredRedisBlockingClientLike(system: ActorSystem, red
}

/**
* Disconnect from the server (stop the actors)
*/
* Disconnect from the server (stop the actors)
*/
def stop() = {
redisClient.stop()
sentinelClients.values.foreach(_.stop())
Expand Down
31 changes: 15 additions & 16 deletions src/test/scala/redis/RedisSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@ package redis

import java.io.{InputStream, OutputStream}
import java.net.Socket
import java.nio.file.{Files, Path}
import java.util.concurrent.TimeUnit
import java.nio.file.Files
import java.util.concurrent.atomic.AtomicInteger

import org.specs2.mutable.{SpecificationLike, Tags}
import akka.util.Timeout
import org.specs2.time.NoTimeConversions
import akka.testkit.TestKit
import org.specs2.specification.{Fragments, Step}
import akka.actor.ActorSystem
import java.util.concurrent.atomic.AtomicInteger
import akka.testkit.TestKit
import akka.util.Timeout
import org.specs2.concurrent.FutureAwait
import org.specs2.mutable.SpecificationLike
import org.specs2.specification.core.Fragments

import scala.io.Source
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
import scala.concurrent.Future
import scala.io.Source
import scala.reflect.io.File
import scala.util.Try
import scala.sys.process.{ProcessIO, _}
import scala.util.Try
import scala.util.control.NonFatal


Expand Down Expand Up @@ -46,7 +45,7 @@ object RedisServerHelper {
}


abstract class RedisHelper extends TestKit(ActorSystem()) with SpecificationLike with Tags with NoTimeConversions {
abstract class RedisHelper extends TestKit(ActorSystem()) with SpecificationLike with FutureAwait {

import scala.concurrent.duration._

Expand All @@ -60,8 +59,8 @@ abstract class RedisHelper extends TestKit(ActorSystem()) with SpecificationLike
override def map(fs: => Fragments) = {
setup()
fs ^
Step({
system.shutdown()
step({
TestKit.shutdownActorSystem(system)
cleanup()
})
}
Expand Down Expand Up @@ -273,13 +272,13 @@ abstract class RedisClusterClients() extends RedisHelper {

def deleteDirectory(): Unit = {
val fileStream = Files.newDirectoryStream(fileDir.toPath)
fileStream.iterator().toSeq.foreach(Files.delete)
fileStream.iterator().asScala.foreach(Files.delete)
Files.delete(fileDir.toPath)
}
}


import RedisServerHelper._
import redis.RedisServerHelper._

class RedisProcess(val port: Int) {
var server: Process = null
Expand Down
3 changes: 2 additions & 1 deletion src/test/scala/redis/SentinelSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package redis
import scala.concurrent._
import scala.concurrent.duration._
import akka.testkit._
import org.specs2.concurrent.ExecutionEnv

class SentinelSpec extends RedisSentinelClients("SentinelSpec") {
class SentinelSpec(implicit ee: ExecutionEnv) extends RedisSentinelClients("SentinelSpec") {

sequential

Expand Down
5 changes: 2 additions & 3 deletions src/test/scala/redis/actors/RedisClientActorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import java.net.InetSocketAddress
import akka.actor._
import akka.testkit._
import akka.util.ByteString
import org.specs2.mutable.{SpecificationLike, Tags}
import org.specs2.time.NoTimeConversions
import org.specs2.mutable.SpecificationLike
import redis.api.connection.Ping
import redis.api.strings.Get
import redis.{RedisDispatcher, Operation, Redis}

import scala.collection.mutable
import scala.concurrent.{Await, Promise}

class RedisClientActorSpec extends TestKit(ActorSystem()) with SpecificationLike with Tags with NoTimeConversions with ImplicitSender {
class RedisClientActorSpec extends TestKit(ActorSystem()) with SpecificationLike with ImplicitSender {

import scala.concurrent.duration._

Expand Down
5 changes: 2 additions & 3 deletions src/test/scala/redis/actors/RedisReplyDecoderSpec.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package redis.actors

import akka.actor._
import org.specs2.mutable.{Tags, SpecificationLike}
import org.specs2.time.NoTimeConversions
import org.specs2.mutable.SpecificationLike
import akka.util.ByteString
import redis.api.hashes.Hgetall
import redis.protocol.MultiBulk
Expand All @@ -16,7 +15,7 @@ import akka.testkit._

class RedisReplyDecoderSpec
extends TestKit(ActorSystem("testsystem", ConfigFactory.parseString( """akka.loggers = ["akka.testkit.TestEventListener"]""")))
with SpecificationLike with Tags with NoTimeConversions with ImplicitSender {
with SpecificationLike with ImplicitSender {

import scala.concurrent.duration._

Expand Down
5 changes: 2 additions & 3 deletions src/test/scala/redis/actors/RedisSubscriberActorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package redis.actors

import akka.testkit._
import akka.actor._
import org.specs2.mutable.{Tags, SpecificationLike}
import org.specs2.time.NoTimeConversions
import org.specs2.mutable.SpecificationLike
import java.net.InetSocketAddress
import akka.util.ByteString
import redis.protocol.RedisProtocolRequest
Expand All @@ -12,7 +11,7 @@ import akka.io.Tcp._
import redis.api.pubsub.Message
import redis.api.pubsub.PMessage

class RedisSubscriberActorSpec extends TestKit(ActorSystem()) with SpecificationLike with Tags with NoTimeConversions with ImplicitSender {
class RedisSubscriberActorSpec extends TestKit(ActorSystem()) with SpecificationLike with ImplicitSender {

import scala.concurrent.duration._

Expand Down
5 changes: 2 additions & 3 deletions src/test/scala/redis/actors/RedisWorkerIOSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package redis.actors

import akka.testkit._
import akka.actor.{ActorRef, Props, ActorSystem}
import org.specs2.mutable.{Tags, SpecificationLike}
import org.specs2.time.NoTimeConversions
import org.specs2.mutable.SpecificationLike
import java.net.InetSocketAddress
import akka.io.Tcp._
import akka.util.ByteString
Expand All @@ -14,7 +13,7 @@ import akka.io.Tcp.Connect
import akka.io.Tcp.CommandFailed
import redis.Redis

class RedisWorkerIOSpec extends TestKit(ActorSystem()) with SpecificationLike with Tags with NoTimeConversions with ImplicitSender {
class RedisWorkerIOSpec extends TestKit(ActorSystem()) with SpecificationLike with ImplicitSender {

import scala.concurrent.duration._

Expand Down
4 changes: 3 additions & 1 deletion src/test/scala/redis/commands/ScriptingSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package redis.commands
import java.io.File

import redis._

import scala.concurrent.Await
import akka.util.ByteString
import org.specs2.concurrent.ExecutionEnv
import redis.protocol.{Bulk, MultiBulk}
import redis.actors.ReplyErrorException
import redis.api.scripting.RedisScript

class ScriptingSpec extends RedisStandaloneServer {
class ScriptingSpec(implicit ee: ExecutionEnv) extends RedisStandaloneServer {

sequential

Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "1.7.0"
version in ThisBuild := "1.8.0-SNAPSHOT"

0 comments on commit 3c1bce9

Please sign in to comment.