コード例 #1
0
func startKeeper(t *testing.T, addr string) {
	readyk := make(chan bool)
	addrk := randaddr.Local()
	for addrk == addr {
		addrk = randaddr.Local()
	}

	go func() {
		e := triblab.ServeKeeper(&trib.KeeperConfig{
			Backs: []string{addr},
			Addrs: []string{addrk},
			This:  0,
			Id:    0,
			Ready: readyk,
		})
		if e != nil {
			t.Fatal(e)
		}
	}()

	if !<-readyk {
		t.Fatal("keeper not ready")
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: ymqytw/cse223_distFileSys
func main() {
	flag.Parse()

	rc, e := trib.LoadRC(*frc)
	noError(e)

	run := func(i int) {
		if i > len(rc.Keepers) {
			noError(fmt.Errorf("keeper index out of range: %d", i))
		}

		keeperConfig := rc.KeeperConfig(i)
		c := make(chan bool)
		keeperConfig.Ready = c
		go func() {
			noError(triblab.ServeKeeper(keeperConfig))
		}()

		b := <-c
		if b {
			log.Printf("bin storage keeper serving on %s",
				keeperConfig.Addr())
			if *readyAddr != "" {
				ready.Notify(*readyAddr, keeperConfig.Addr())
			}
		} else {
			log.Printf("bin storage keeper on %s init failed",
				keeperConfig.Addr())
			if *readyAddr != "" {
				ready.NotifyFail(*readyAddr, keeperConfig.Addr())
			}
		}
	}

	args := flag.Args()
	n := 0
	if len(args) == 0 {
		for i, k := range rc.Keepers {
			if local.Check(k) {
				go run(i)
				n++
			}
		}

		if n == 0 {
			log.Fatal("no keeper found for this host")
		}
	} else {
		for _, a := range args {
			i, e := strconv.Atoi(a)
			noError(e)

			go run(i)
			n++
		}
	}

	if n > 0 {
		select {}
	}
}
コード例 #3
0
func TestBinStorage(t *testing.T) {
	if os.Getenv("TRIB_LAB") == "lab1" {
		t.SkipNow()
	}

	addr1 := randaddr.Local()
	addr2 := randaddr.Local()
	for addr2 == addr1 {
		addr2 = randaddr.Local()
	}

	ready1 := make(chan bool)
	ready2 := make(chan bool)

	run := func(addr string, ready chan bool) {
		e := entries.ServeBackSingle(addr,
			store.NewStorage(), ready)
		if e != nil {
			t.Fatal(e)
		}
	}

	go run(addr1, ready1)
	go run(addr2, ready2)

	r := <-ready1 && <-ready2
	if !r {
		t.Fatal("not ready")
	}

	readyk := make(chan bool)
	addrk := randaddr.Local()
	for addrk == addr1 || addrk == addr2 {
		addrk = randaddr.Local()
	}
	go func() {
		e := triblab.ServeKeeper(&trib.KeeperConfig{
			Backs: []string{addr1, addr2},
			Addrs: []string{addrk},
			This:  0,
			Id:    0,
			Ready: readyk,
		})
		if e != nil {
			t.Fatal(e)
		}
	}()

	if !<-readyk {
		t.Fatal("keeper not ready")
	}

	bc := triblab.NewBinClient(
		[]string{addr1, addr2},
	)

	done := make(chan bool, 10)

	for i := 0; i < 10; i++ {
		c := bc.Bin(fmt.Sprintf("b%d", i))
		go func(s trib.Storage) {
			tribtest.CheckStorage(t, s)
			done <- true
		}(c)
	}

	for i := 0; i < 10; i++ {
		<-done
	}
}