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{
|
2016-12-04 08:08:06 +00:00
|
|
|
AppName: "app",
|
|
|
|
|
StreamName: "stream",
|
|
|
|
|
client: client,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set checkpoint
|
|
|
|
|
c.SetCheckpoint("shard_id", "testSeqNum")
|
|
|
|
|
|
|
|
|
|
// checkpoint exists
|
|
|
|
|
if val := c.CheckpointExists("shard_id"); val != true {
|
|
|
|
|
t.Fatalf("checkpoint exists expected true, got %t", val)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// get checkpoint
|
|
|
|
|
if val := c.SequenceNumber(); val != "testSeqNum" {
|
|
|
|
|
t.Fatalf("checkpoint exists expected %s, got %s", "testSeqNum", val)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client.Del("app:checkpoint:stream:shard_id")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_key(t *testing.T) {
|
|
|
|
|
client := redis.NewClient(&redis.Options{Addr: defaultAddr})
|
|
|
|
|
|
2017-11-20 16:21:40 +00:00
|
|
|
c := &Checkpoint{
|
2016-12-04 08:08:06 +00:00
|
|
|
AppName: "app",
|
|
|
|
|
StreamName: "stream",
|
|
|
|
|
client: client,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expected := "app:checkpoint:stream:shard"
|
|
|
|
|
|
|
|
|
|
if val := c.key("shard"); val != expected {
|
|
|
|
|
t.Fatalf("checkpoint exists expected %s, got %s", expected, val)
|
|
|
|
|
}
|
|
|
|
|
}
|