ledisdb/rpl/rpl_test.go

46 lines
701 B
Go
Raw Normal View History

2014-09-22 13:50:51 +04:00
package rpl
import (
"io/ioutil"
"os"
"testing"
2015-05-04 17:42:28 +03:00
2020-04-24 09:10:03 +03:00
"github.com/ledisdb/ledisdb/config"
2014-09-22 13:50:51 +04:00
)
func TestReplication(t *testing.T) {
dir, err := ioutil.TempDir("", "rpl")
if err != nil {
t.Fatalf("err: %v ", err)
}
defer os.RemoveAll(dir)
2014-10-11 12:00:59 +04:00
c := config.NewConfigDefault()
2014-09-22 13:50:51 +04:00
c.Replication.Path = dir
r, err := NewReplication(c)
if err != nil {
t.Fatal(err)
}
if l1, err := r.Log([]byte("hello world")); err != nil {
t.Fatal(err)
} else if l1.ID != 1 {
t.Fatal(l1.ID)
}
if b, _ := r.CommitIDBehind(); !b {
t.Fatal("must backward")
}
if err := r.UpdateCommitID(1); err != nil {
t.Fatal(err)
}
if b, _ := r.CommitIDBehind(); b {
t.Fatal("must not backward")
}
r.Close()
}