Skip to content

Commit

Permalink
Fixed Authentication doesn't work chrisdinn#67
Browse files Browse the repository at this point in the history
  • Loading branch information
Deboitemendumenix committed Apr 24, 2016
1 parent efcc20d commit fb1f105
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 78 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ In your build.sbt

resolvers += "chrisdinn" at "http://chrisdinn.github.io/releases/"

libraryDependencies += "com.digital-achiever" %% "brando" % "3.0.3"
libraryDependencies += "com.digital-achiever" %% "brando" % "3.0.4"

### Getting started

Expand Down Expand Up @@ -244,7 +244,7 @@ It's possible to use sharding with Sentinel, to do so you need to use `SentinelS

## Documentation

Read the API documentation here: [http://chrisdinn.github.io/api/brando-3.0.3/](http://chrisdinn.github.io/api/brando-3.0.3/)
Read the API documentation here: [http://chrisdinn.github.io/api/brando-3.0.4/](http://chrisdinn.github.io/api/brando-3.0.4/)

## Mailing list

Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name := "brando"

organization := "com.digital-achiever"

version := "3.0.3"
version := "3.0.4"

scalaVersion := "2.11.4"

Expand Down
7 changes: 3 additions & 4 deletions src/main/scala/Connection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,13 @@ private[brando] class Connection(
case x: Tcp.Connected
socket = sender
socket ! Tcp.Register(self, useResumeWriting = false)
(self ? Request("PING"))(connectionTimeout) map {
(self ? Request("PING"))(connectionTimeout) onComplete {
case scala.util.Failure(_: AskTimeoutException)
listener ! ConnectionFailed(host, port)
case _
listener ! Connected(host, port)
heartbeatDelay map (d
context.system.scheduler.schedule(0.seconds, 1.seconds, self, Heartbeat(d)))
} recover {
case _
listener ! ConnectionFailed(host, port)
}

case Heartbeat(delay)
Expand Down
5 changes: 2 additions & 3 deletions src/test/scala/RedisClientTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,8 @@ class RedisClientTest extends TestKit(ActorSystem("RedisClientTest")) with FunSp
Some(1))))

publisher ! Request("PUBLISH", channel, "test")
expectMsg(Some(1)) //publisher gets back number of subscribers when publishing

expectMsg(PubSubMessage(channel, "test"))
//publisher gets back number of subscribers when publishing
assert(receiveN(2).toSet === Set(Some(1), PubSubMessage(channel, "test")))
}

it("should be able to unsubscribe from a pubsub channel") {
Expand Down
31 changes: 19 additions & 12 deletions src/test/scala/SentinelTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ class SentinelTest extends TestKit(ActorSystem("SentinelTest")) with FunSpecLike
Server("wrong-host", 26379),
Server("localhost", 26379)), Set(probe.ref)))

probe.expectMsg(Connecting("wrong-host", 26379))
probe.expectMsg(Connecting("localhost", 26379))
probe.expectMsg(Connected("localhost", 26379))
val redisNotifications = probe.receiveN(3)
assert(redisNotifications.toSet === Set(
Connecting("wrong-host", 26379),
Connecting("localhost", 26379),
Connected("localhost", 26379)))
}

it("should send a notification to the listeners when connecting") {
Expand Down Expand Up @@ -75,9 +77,11 @@ class SentinelTest extends TestKit(ActorSystem("SentinelTest")) with FunSpecLike
Server("wrong-host", 26379),
Server("localhost", 26379)), Set(probe.ref)))

probe.expectMsg(Connecting("wrong-host", 26379))
probe.expectMsg(Connecting("localhost", 26379))
probe.expectMsg(Connected("localhost", 26379))
val redisNotifications = probe.receiveN(3)
assert(redisNotifications.toSet === Set(
Connecting("wrong-host", 26379),
Connecting("localhost", 26379),
Connected("localhost", 26379)))

sentinel ! Disconnected("localhost", 26379)

Expand Down Expand Up @@ -112,15 +116,18 @@ class SentinelTest extends TestKit(ActorSystem("SentinelTest")) with FunSpecLike

describe("Subscriptions") {
it("should receive pub/sub notifications") {
val probe = TestProbe()
val sentinel = system.actorOf(Sentinel(Seq(
Server("localhost", 26379)), Set(self)))
Server("localhost", 26379)), Set(probe.ref)))
val sentinel2 = system.actorOf(Sentinel(Seq(
Server("localhost", 26379)), Set(self)))
Server("localhost", 26379)), Set(probe.ref)))

expectMsg(Connecting("localhost", 26379))
expectMsg(Connecting("localhost", 26379))
expectMsg(Connected("localhost", 26379))
expectMsg(Connected("localhost", 26379))
val redisNotifications = probe.receiveN(3)
assert(redisNotifications.toSet === Set(
Connecting("localhost", 26379),
Connecting("localhost", 26379),
Connected("localhost", 26379),
Connected("localhost", 26379)))

sentinel ! Request("subscribe", "+failover-end")

Expand Down
94 changes: 38 additions & 56 deletions src/test/scala/ShardManagerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,14 @@ class ShardManagerTest extends TestKit(ActorSystem("ShardManagerTest"))
sentinelProbe.expectMsg(
Connected("localhost", 26379))

redisProbe.expectMsg(
Connecting("127.0.0.1", 6379))
redisProbe.expectMsg(
Connecting("127.0.0.1", 6379))
redisProbe.expectMsg(
Connecting("127.0.0.1", 6379))

redisProbe.expectMsg(
Connected("127.0.0.1", 6379))
redisProbe.expectMsg(
Connected("127.0.0.1", 6379))
redisProbe.expectMsg(
Connected("127.0.0.1", 6379))
val redisNotifications = redisProbe.receiveN(6)
assert(redisNotifications.toSet === Set(
Connecting("127.0.0.1", 6379),
Connecting("127.0.0.1", 6379),
Connecting("127.0.0.1", 6379),
Connected("127.0.0.1", 6379),
Connected("127.0.0.1", 6379),
Connected("127.0.0.1", 6379)))

shardManager ! ("key", Request("SET", "shard_manager_test", "some value"))

Expand All @@ -131,19 +126,14 @@ class ShardManagerTest extends TestKit(ActorSystem("ShardManagerTest"))
val shardManager = TestActorRef[ShardManager](ShardManager(
shards, listeners = Set(redisProbe.ref)))

redisProbe.expectMsg(
Connecting("127.0.0.1", 6379))
redisProbe.expectMsg(
Connecting("127.0.0.1", 6379))
redisProbe.expectMsg(
Connecting("127.0.0.1", 6379))

redisProbe.expectMsg(
Connected("127.0.0.1", 6379))
redisProbe.expectMsg(
Connected("127.0.0.1", 6379))
redisProbe.expectMsg(
Connected("127.0.0.1", 6379))
val redisNotifications = redisProbe.receiveN(6)
assert(redisNotifications.toSet === Set(
Connecting("127.0.0.1", 6379),
Connecting("127.0.0.1", 6379),
Connecting("127.0.0.1", 6379),
Connected("127.0.0.1", 6379),
Connected("127.0.0.1", 6379),
Connected("127.0.0.1", 6379)))

shardManager ! Request("SET", "shard_manager_test", "some value")

Expand All @@ -164,19 +154,14 @@ class ShardManagerTest extends TestKit(ActorSystem("ShardManagerTest"))
val shardManager = TestActorRef[ShardManager](ShardManager(
shards, listeners = Set(redisProbe.ref)))

redisProbe.expectMsg(
Connecting("127.0.0.1", 6379))
redisProbe.expectMsg(
Connecting("127.0.0.1", 6379))
redisProbe.expectMsg(
Connecting("127.0.0.1", 6379))

redisProbe.expectMsg(
Connected("127.0.0.1", 6379))
redisProbe.expectMsg(
Connected("127.0.0.1", 6379))
redisProbe.expectMsg(
Connected("127.0.0.1", 6379))
val redisNotifications = redisProbe.receiveN(6)
assert(redisNotifications.toSet === Set(
Connecting("127.0.0.1", 6379),
Connecting("127.0.0.1", 6379),
Connecting("127.0.0.1", 6379),
Connected("127.0.0.1", 6379),
Connected("127.0.0.1", 6379),
Connected("127.0.0.1", 6379)))

shardManager ! Request("SET")

Expand All @@ -193,19 +178,14 @@ class ShardManagerTest extends TestKit(ActorSystem("ShardManagerTest"))
val shardManager = TestActorRef[ShardManager](ShardManager(
shards, listeners = Set(redisProbe.ref)))

redisProbe.expectMsg(
Connecting("127.0.0.1", 6379))
redisProbe.expectMsg(
Connecting("127.0.0.1", 6379))
redisProbe.expectMsg(
Connecting("127.0.0.1", 6379))

redisProbe.expectMsg(
Connected("127.0.0.1", 6379))
redisProbe.expectMsg(
Connected("127.0.0.1", 6379))
redisProbe.expectMsg(
Connected("127.0.0.1", 6379))
val redisNotifications = redisProbe.receiveN(6)
assert(redisNotifications.toSet === Set(
Connecting("127.0.0.1", 6379),
Connecting("127.0.0.1", 6379),
Connecting("127.0.0.1", 6379),
Connected("127.0.0.1", 6379),
Connected("127.0.0.1", 6379),
Connected("127.0.0.1", 6379)))

val listName = scala.util.Random.nextString(5)

Expand Down Expand Up @@ -276,10 +256,12 @@ class ShardManagerTest extends TestKit(ActorSystem("ShardManagerTest"))
val shardManager = TestActorRef[ShardManager](ShardManager(
shards, Set(probe.ref)))

probe.expectMsg(Connecting("localhost", 6379))
probe.expectMsg(Connecting("localhost", 6379))
probe.expectMsg(Connected("localhost", 6379))
probe.expectMsg(Redis.AuthenticationFailed("localhost", 6379))
val redisNotifications = probe.receiveN(4)
assert(redisNotifications.toSet === Set(
Connecting("localhost", 6379),
Connecting("localhost", 6379),
Connected("localhost", 6379),
Redis.AuthenticationFailed("localhost", 6379)))
}
}
}

0 comments on commit fb1f105

Please sign in to comment.