示例#1
0
func TestFakeSwitchCenter(t *testing.T) {
	printIndicate()

	groups := make(map[uint64]bool)
	groups[uint64(1)] = true
	groups[uint64(2)] = true
	groups[uint64(3)] = true

	fcenter := NewFakeSwitchCenter(groups)
	assert(nil != fcenter)

	for id, _ := range groups {
		fswitch := fcenter.Get(id)
		assert(nil != fswitch)
		assert(fswitch.id == id)
	}

	go fcenter.Run()
	defer fcenter.Stop()

	msg := pb.Message{From: 1, To: 2}
	fswitch := fcenter.Get(1)
	fswitch.GetSendChan() <- msg

	rmsg := <-fcenter.Get(2).GetRecvChan()
	assert(rmsg.From == 1)
	assert(rmsg.To == 2)

	msg.From = 3
	msg.To = 1
	fcenter.Get(3).GetSendChan() <- msg
	rmsg = <-fcenter.Get(1).GetRecvChan()
	assert(rmsg.From == 3)
	assert(rmsg.To == 1)
}