Ejemplo n.º 1
0
func TestNodeDiscover(t *testing.T) {
	n1 := node.New("test1", config.DefaultLocalhost(), nil)
	defer n1.Shutdown()
	j1 := n1.Join().AsChan()
	n1.Run()

	n2 := node.New("test2", config.DefaultLocalhost(), nil)
	defer n2.Shutdown()
	j2 := n2.Join().AsChan()
	n2.Run()
	select {
	case <-time.After(5 * time.Second):
		t.Fatal("Couldnt find network.node 1")
	case data := <-j1:
		if !strings.Contains(data.(serf.Member).Name, n2.UUID) {
			t.Error("Found wrong UUID")
		}
	}

	select {
	case <-time.After(5 * time.Minute):
		t.Fatal("Couldnt find network.node 2")
	case data := <-j2:
		if !strings.Contains(data.(serf.Member).Name, n1.UUID) {
			t.Error("Found wrong UUID")
		}
	}
}
Ejemplo n.º 2
0
func NewAnnouncer(uuid string, addresses []string, servicetype string, desc *appdescriptor.AppDescriptor) (a *Announcer) {

	cfg := config.DefaultLocalhost()

	a = new(Announcer)
	a.announced = eventual2go.NewCompleter()
	a.logger = log.New(cfg.Logger(), fmt.Sprintf("announcer %s ", uuid), log.Lshortfile)

	a.new = eventual2go.NewStreamController()
	a.servicetype = servicetype
	addrs := []string{}
	a.clientPorts = map[string]int{}

	for _, addr := range addresses {
		as := strings.Split(addr, ":")
		addrs = append(addrs, as[0])
		p, _ := strconv.ParseInt(as[1], 0, 0)
		a.clientPorts[as[0]] = int(p)
		a.logger.Println("adding address", as[0], int(p))
	}

	cfg.NetworkInterfaces = addrs
	a.node = node.New(uuid, cfg, desc.AsTagSet())

	a.r = eventual2go.NewReactor()
	a.r.React("first_join", a.announce)
	a.r.AddFuture("first_join", a.node.Join().First())
	a.r.React("service_found", a.replyToServiceQuery)
	a.r.AddStream("service_found", a.node.Queries().WhereNot(isService(a.servicetype)))
	a.logger.Println("setup finished")
	return
}
Ejemplo n.º 3
0
func TestNodeLeave(t *testing.T) {
	n1 := node.New("test1", config.DebugLocalhost(), nil)
	defer n1.Shutdown()
	c := n1.Leave().AsChan()
	n1.Run()

	n2 := node.New("test2", config.DebugLocalhost(), nil)
	n2.Run()

	time.Sleep(3 * time.Second)

	n2.Shutdown()

	select {
	case <-time.After(30 * time.Second):
		t.Fatal("network.node didnt leave")
	case data := <-c:
		if !strings.Contains(data.(node.LeaveEvent).Name, n2.UUID) {
			t.Error("Found wrong UUID")
		}
	}
}
Ejemplo n.º 4
0
func NewAnnouncer(uuid string, servicetype string, desc *servicedescriptor.ServiceDescriptor, cfg *config.Config, ports []int) (a *Announcer) {

	a = &Announcer{
		announced:   eventual2go.NewCompleter(),
		clientPorts: map[string]int{},
		logger:      log.New(cfg.Logger(), fmt.Sprintf("announcer %s ", uuid), log.Lshortfile),
		new:         eventual2go.NewStreamController(),
		node:        node.New(uuid, cfg, desc.AsTagSet()),
		servicetype: servicetype,
	}

	a.setPorts(cfg, ports)

	a.initReactor()

	return
}