Skip to content

Commit

Permalink
Merge pull request #202 from dskrvk/remove_pubsub0204
Browse files Browse the repository at this point in the history
Remove PubSubServer and dependency on Akka
  • Loading branch information
debasishg authored Apr 22, 2018
2 parents 9ba10dd + 083a4df commit e14ed08
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 325 deletions.
59 changes: 59 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name := "RedisClient"

lazy val redisClient = (project in file(".")).settings(coreSettings : _*)

lazy val commonSettings: Seq[Setting[_]] = Seq(
organization := "net.debasishg",
version := "3.6",
scalaVersion := "2.11.12",
crossScalaVersions := Seq("2.12.4", "2.11.12", "2.10.7"),

scalacOptions in Compile ++= Seq( "-unchecked", "-feature", "-language:postfixOps", "-deprecation" ),

resolvers ++= Seq(
"typesafe repo" at "http://repo.typesafe.com/typesafe/releases/"
)
)

lazy val coreSettings = commonSettings ++ Seq(
name := "RedisClient",
libraryDependencies ++= Seq(
"commons-pool" % "commons-pool" % "1.6",
"org.slf4j" % "slf4j-api" % "1.7.25",
"org.slf4j" % "slf4j-log4j12" % "1.7.25" % "provided",
"log4j" % "log4j" % "1.2.17" % "provided",
"junit" % "junit" % "4.12" % "test",
"org.scalatest" %% "scalatest" % "3.0.4" % "test"),

parallelExecution in Test := false,
publishTo := version { (v: String) =>
val nexus = "https://oss.sonatype.org/"
if (v.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots")
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
}.value,
credentials += Credentials(Path.userHome / ".sbt" / "sonatype.credentials"),
publishMavenStyle := true,
publishArtifact in Test := false,
pomIncludeRepository := { repo => false },
pomExtra := (
<url>https://github.com/debasishg/scala-redis</url>
<licenses>
<license>
<name>Apache 2.0 License</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>git@github.com:debasishg/scala-redis.git</url>
<connection>scm:git:git@github.com:debasishg/scala-redis.git</connection>
</scm>
<developers>
<developer>
<id>debasishg</id>
<name>Debasish Ghosh</name>
<url>http://debasishg.blogspot.com</url>
</developer>
</developers>),
unmanagedResources in Compile += baseDirectory.map( _ / "LICENSE" ).value
)
72 changes: 0 additions & 72 deletions project/ScalaRedisProject.scala

This file was deleted.

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.17
sbt.version=1.1.0
44 changes: 0 additions & 44 deletions src/main/scala/com/redis/PubSubServer.scala

This file was deleted.

45 changes: 0 additions & 45 deletions src/test/resources/application.conf

This file was deleted.

20 changes: 9 additions & 11 deletions src/test/scala/com/redis/Patterns.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.redis

import serialization._
import scala.concurrent.{ ExecutionContext, Await, Future }
import scala.concurrent.{ Await, Future }
import scala.concurrent.duration._
import akka.actor.ActorSystem

/**
* Implementing some of the common patterns like scatter/gather, which can benefit from
Expand All @@ -25,25 +24,24 @@ object Patterns {
def listPush(count: Int, key: String)(implicit clients: RedisClientPool) = {
clients.withClient { client =>
(1 to count) foreach {i => client.rpush(key, i)}
assert(client.llen(key) == Some(count))
assert(client.llen(key).contains(count))
}
key
}

def listPop(count: Int, key: String)(implicit clients: RedisClientPool) = {
implicit val parseInt = Parse[Long](new String(_).toLong)
implicit val parseInt: Parse[Long] = Parse[Long](new String(_).toLong)
clients.withClient { client =>
val list = (1 to count) map {i => client.lpop[Long](key).get}
assert(client.llen(key) == Some(0))
val list = (1 to count) map {_ => client.lpop[Long](key).get}
assert(client.llen(key).contains(0))
list.sum
}
}

// set up Executors
val system = ActorSystem("ScatterGatherSystem")
import system.dispatcher
import scala.concurrent.ExecutionContext.Implicits.global

val timeout = 5 minutes
val timeout: Duration = 5 minutes

private[this] def flow[A](noOfRecipients: Int, opsPerClient: Int, keyPrefix: String,
fn: (Int, String) => A) = {
Expand All @@ -69,7 +67,7 @@ object Patterns {
val allPops = Future.sequence(futurePops)
allPops map {members => members.sum}
}
Await.result(allSum, timeout).asInstanceOf[Long]
Await.result(allSum, timeout)
}

// scatter across clietns and gather the first future to complete
Expand All @@ -84,6 +82,6 @@ object Patterns {
val firstSum = firstPush map {key =>
listPop(opsPerClient, key)
}
Await.result(firstSum, timeout).asInstanceOf[Int]
Await.result(firstSum, timeout)
}
}
Loading

0 comments on commit e14ed08

Please sign in to comment.