func TestRestore(t *testing.T) { f, err := ioutil.TempFile("", "j") if err != nil { t.Fatal(err) } j := f.Name() f.Close() defer os.Remove(j) journal, err := persistence.NewJournal(j) if err != nil { t.Fatal(err) } for k, v := range testData { m := store.MustEncodeSet("/ken/"+strconv.Itoa(k), v, int64(k)) journal.WriteMutation(m) } journal.Close() c := NewCluster(t, fmt.Sprintf("-j=%s", j), "-r") defer c.Close() for k, v := range testData { v1, _, err := c.conn.Get("/ken/"+strconv.Itoa(k), nil) if err != nil { t.Fatal(err) } v2 := string(v1) if v != v2 { t.Fatalf("restored data is not what is expected: %s != %s", v, v2) } } }
func TestSave(t *testing.T) { c := NewCluster(t) defer c.Close() for k, v := range testData { c.conn.Set("/ken/"+strconv.Itoa(k), -1, []byte(v)) } j, err := persistence.NewJournal(c.j) if err != nil { t.Fatal(err) } defer j.Close() for k, v := range testData { m, err := j.ReadMutation() if err != nil { t.Fatalf("bad journal file: %v", err) } k1, v1, err := decode(m) if err != nil { t.Fatalf("bad journal file: %v", err) } if k != k1 { t.Fatalf("bad journal file: %s != %s", k1, k) } if v != v1 { t.Fatalf("bad journal file: %s != %s", v1, v) } } _, err = j.ReadMutation() if err != io.EOF { t.Fatal("bad journal file: expected EOF") } }
func main() { flag.Usage = usage flag.Parse() var err error journal, err = persistence.NewJournal(*j) if err != nil { fatal(err) } dial() if *r { restore() } go Store() go Notify() monitor() }