2017-11-20 16:21:40 +00:00
|
|
|
package redis
|
2016-12-04 08:08:06 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"gopkg.in/redis.v5"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var defaultAddr = "127.0.0.1:6379"
|
|
|
|
|
|
|
|
|
|
func Test_CheckpointLifecycle(t *testing.T) {
|
|
|
|
|
client := redis.NewClient(&redis.Options{Addr: defaultAddr})
|
|
|
|
|
|
2017-11-20 16:21:40 +00:00
|
|
|
c := &Checkpoint{
|
2017-11-21 16:58:16 +00:00
|
|
|
appName: "app",
|
|
|
|
|
streamName: "stream",
|
2016-12-04 08:08:06 +00:00
|
|
|
client: client,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set checkpoint
|
2017-11-21 16:58:16 +00:00
|
|
|
c.Set("shard_id", "testSeqNum")
|
2016-12-04 08:08:06 +00:00
|
|
|
|
2017-11-21 16:58:16 +00:00
|
|
|
// get checkpoint
|
|
|
|
|
val, err := c.Get("shard_id")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("get checkpoint error: %v", err)
|
2016-12-04 08:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
2017-11-21 16:58:16 +00:00
|
|
|
if val != "testSeqNum" {
|
2016-12-04 08:08:06 +00:00
|
|
|
t.Fatalf("checkpoint exists expected %s, got %s", "testSeqNum", val)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-21 16:58:16 +00:00
|
|
|
client.Del(c.key("shard_id"))
|
2016-12-04 08:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_key(t *testing.T) {
|
|
|
|
|
client := redis.NewClient(&redis.Options{Addr: defaultAddr})
|
|
|
|
|
|
2017-11-20 16:21:40 +00:00
|
|
|
c := &Checkpoint{
|
2017-11-21 16:58:16 +00:00
|
|
|
appName: "app",
|
|
|
|
|
streamName: "stream",
|
2016-12-04 08:08:06 +00:00
|
|
|
client: client,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expected := "app:checkpoint:stream:shard"
|
|
|
|
|
|
|
|
|
|
if val := c.key("shard"); val != expected {
|
|
|
|
|
t.Fatalf("checkpoint exists expected %s, got %s", expected, val)
|
|
|
|
|
}
|
|
|
|
|
}
|