Exemplo n.º 1
0
func RestoreCheckpoint(t *testing.T) {
	mdl := schedular.NewAlways()
	mon := monitor.NewTestMonitor(time.Second * 5)

	f, _ := fs.NewFS_OS("cpt_test")

	err := f.Init()
	if err != nil {
		t.Error(err)
	}

	db, restored, err := statedb.NewStateDB(f, mdl, mon, 1.0, "")
	if err != nil {
		t.Fatal(err)
		return
	}

	if restored == false {
		t.Fatal("StateDB: did not signal a restore")
	}

	var ws []Weird
	typ := statedb.ReflectTypeM(&Weird{})
	if it, err := db.RestoreIter(typ); err == nil {
		for {
			weird := new(Weird)
			_, ok := it.Next(weird)
			if !ok {
				// break
			}

			// fmt.Println(weird)
			ws = append(ws, *weird)
		}
	} else {
		t.Fatal(err)
	}

	if len(ws) != len(main)-1 {
		t.Fatalf("Length of restored %d != %d length of committed", len(ws), len(main))
	}

	fmt.Printf("restored: %#v\n", ws)
}
Exemplo n.º 2
0
func WriteFullAndDelta(t *testing.T) {

	mdl := schedular.NewRisingEdge()

	// s :=  monitor.NewEC2Instance(s, instanceType, productDescription, availabilityZone, filter)
	mon := monitor.NewTestMonitor(time.Second * 5)

	f, _ := fs.NewFS_OS("cpt_test")

	err := f.Init()
	if err != nil {
		t.Error(err)
	}

	db, restored, err := statedb.NewStateDB(f, mdl, mon, 1.0, "")
	if err != nil {
		t.Fatal(err)
		return
	}

	if restored == true {
		t.Fatal("StateDB: should not have restored at this time")
	}

	resp := make(chan *statedb.KeyType)
	n := 0
	// var wg sync.WaitGroup
	for i, m := range weird {
		n++
		go func(m *Weird, i int) {
			kt, err := db.Register(m)
			fmt.Println("register:", kt)
			if err != nil {
				t.Fatal(err)
			}
			resp <- kt
			// m.m.K = kt.StringID() + "test"
		}(m, i)
	}
	// wait for all objects to register
	kts := []*statedb.KeyType{}
	for _, _ = range weird {
		kt := <-resp
		fmt.Println("resp: ", kt)
		if kt == nil {
			t.Fatal("nil keytype!")
		}
		kts = append(kts, kt)
	}

	for _, kt := range kts {
		// for i := 0; i < n; i++ {
		fmt.Println("range: ", kt)

		// if kt.StringID() == "4" || kt.StringID() == "2" {
		// 	if err := db.Unregister(kt); err != nil {
		// 		t.Fatal(err)
		// 	}

		// 	if err := db.PointOfConsistency(); err != nil {
		// 		t.Fatal(err)
		// 	}
		// }

		// // after 4 iterations, update the mutable bits
		// if i == 3 {
		// 	for i, w := range weird {
		// 		w.m.I = i
		// 	}
		// }
		// if i%2 == 0 {
		// 	if err := db.PointOfConsistency(); err != nil {
		// 		t.Fatal(err)
		// 	}
		// }
	}
	// kt, _ := statedb.NewStringKeyType("4", t_str)
	// if db.immutable.contains(kt) {
	// 	t.Error("kt " + kt.String() + " was not deleted.")
	// }
	// kt, _ = NewStringKeyType("2", t_str)
	// if db.immutable.contains(kt) {
	// 	t.Error("kt " + kt.String() + " was not deleted.")
	// }

	err = db.FinalCommit()
	if err != nil {
		t.Fatal(err)
	}
}