func TestNodeDiscover(t *testing.T) { n1 := node.New("test1", config.DebugLocalhost(), nil) defer n1.Shutdown() j1 := n1.Join().AsChan() n1.Run() n2 := node.New("test2", config.DebugLocalhost(), nil) defer n2.Shutdown() j2 := n2.Join().AsChan() n2.Run() select { case <-time.After(10 * 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.Second): t.Fatal("Couldnt find network.node 2") case data := <-j2: if !strings.Contains(data.(serf.Member).Name, n1.UUID) { t.Error("Found wrong UUID") } } }
func TestAnnouncerLateStart(t *testing.T) { a := new(servicedescriptor.ServiceDescriptor) a1 := NewAnnouncer("test1", EXPORTING, a, config.DebugLocalhost(), []int{666}) defer a1.Shutdown() a2 := NewAnnouncer("test2", IMPORTING, a, config.DebugLocalhost(), []int{667}) defer a2.Shutdown() c := a2.ServiceArrived().AsChan() a2.Run() time.Sleep(10 * time.Second) a1.Run() select { case <-time.After(5 * time.Second): t.Error("Service 1 Did Not Connect") case d := <-c: sa := d.(ServiceArrived) if sa.UUID != "test1" { t.Errorf("Wrong UUID, got %s, want 'test1'", sa.UUID) } if sa.Address != "127.0.0.1" { t.Errorf("Wrong Addres, got %s, want '127.0.0.1''", sa.Address) } if sa.Port != 666 { t.Errorf("Wrong Port, got %d, want '666'", sa.Port) } } }
func TestServiceBasics(t *testing.T) { a := new(servicedescriptor.ServiceDescriptor) s1 := NewService(a, EXPORTING, config.DebugLocalhost(), []byte{0}) defer s1.Remove() c := s1.Disconnected().AsChan() c1 := s1.Connected().AsChan() s1.Run() s2 := NewService(a, IMPORTING, config.DebugLocalhost(), []byte{0}) c2 := s2.Connected().AsChan() s2.Run() select { case <-time.After(5 * time.Second): t.Fatal("Service 1 Did Not Connect") case <-c1: } select { case <-time.After(10 * time.Second): t.Fatal("Service 2 Did Not Connect") case <-c2: } t.Log("Shutting Down Service 2") s2.Remove() select { case <-time.After(10 * time.Second): t.Error("Service 2 Did Not Disconnect") case <-c: t.Log("Successfully Disconnected Service 2") } }
func TestAnnouncer(t *testing.T) { a := new(servicedescriptor.ServiceDescriptor) a1 := NewAnnouncer("test1", EXPORTING, a, config.DebugLocalhost(), []int{666}) defer a1.Shutdown() a2 := NewAnnouncer("test2", IMPORTING, a, config.DebugLocalhost(), []int{667}) c := a1.ServiceGone().AsChan() // c1 := a1.ServiceArrived().AsChan() c2 := a2.ServiceArrived().AsChan() a1.Run() a2.Run() // select { // case <-time.After(5 * time.Second): // t.Error("Service 1 Did Not Connect") // // case d := <-c1: // sa := d.(ServiceArrived) // if sa.UUID != "test2" { // t.Errorf("Wrong UUID, got %s, want 'test2'", sa.UUID) // } // if sa.Address != "127.0.0.1" { // t.Errorf("Wrong Addres, got %s, want '127.0.0.1''", sa.Address) // } // if sa.Port != 667 { // t.Errorf("Wrong Port, got %d, want '667'", sa.Port) // } // } select { case <-time.After(5 * time.Second): t.Error("Service 1 Did Not Connect") case d := <-c2: sa := d.(ServiceArrived) if sa.UUID != "test1" { t.Errorf("Wrong UUID, got %s, want 'test1'", sa.UUID) } if sa.Address != "127.0.0.1" { t.Errorf("Wrong Addres, got %s, want '127.0.0.1''", sa.Address) } if sa.Port != 666 { t.Errorf("Wrong Port, got %d, want '666'", sa.Port) } } t.Log("Shutting Down Service 2") a2.Shutdown() select { case <-time.After(10 * time.Second): t.Error("Service 2 Did Not Disconnect") case d := <-c: sa := d.(ServiceGone) if sa.UUID != "test2" { t.Errorf("Wrong UUID, got %s, want 'test2'", sa.UUID) } } }
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") } } }
func TestDifferentServices(t *testing.T) { e1 := NewService(testDesc1, EXPORTING, config.DebugLocalhost(), []byte{0}) i1 := NewService(testDesc1, IMPORTING, config.DebugLocalhost(), []byte{0}) defer i1.Remove() i2 := NewService(testDesc2, IMPORTING, config.DebugLocalhost(), []byte{0}) defer i2.Remove() e2 := NewService(testDesc2, EXPORTING, config.DebugLocalhost(), []byte{0}) defer e2.Remove() e1.Run() i2.Run() i1.Run() time.Sleep(15 * time.Second) if !i1.Connected().Completed() { t.Error("Import 1 Did Not Connect") } if i2.Connected().Completed() { t.Error("Import 2 Did Connect") } e1.Remove() e2.Run() time.Sleep(15 * time.Second) if !i1.Disconnected().Completed() { t.Error("Import 1 Is Connected") } if !i2.Connected().Completed() { t.Error("Import 2 Did Not Connect") } }
func TestMultipleServices(t *testing.T) { a := new(servicedescriptor.ServiceDescriptor) s1 := NewService(a, EXPORTING, config.DebugLocalhost(), []byte{0}) defer s1.Remove() s1.Run() s2 := NewService(a, IMPORTING, config.DebugLocalhost(), []byte{0}) defer s2.Remove() s2.Run() s3 := NewService(a, IMPORTING, config.DebugLocalhost(), []byte{0}) defer s3.Remove() s3.Run() s4 := NewService(a, EXPORTING, config.DebugLocalhost(), []byte{0}) defer s4.Remove() s4.Run() time.Sleep(15 * time.Second) if len(s1.connectedServices) != 2 { t.Error("Service 1 didnt connet to all") } if len(s2.connectedServices) != 2 { t.Error("Service 2 didnt connet to all") } if len(s3.connectedServices) != 2 { t.Error("Service 3 didnt connet to all") } if len(s3.connectedServices) != 2 { t.Error("Service 4 didnt connet to all") } }
func (d *Daemon) clientService(data eventual2go.Data) { m := data.(NewService) d.logger.Printf("new service %v", m) defer func() { if r := recover(); r != nil { d.logger.Println("insane descriptor, aborting", r) return } }() desc := servicedescriptor.FromYaml(m.Descriptor) d.logger.Printf("tagset is %v", desc.AsTagSet()) cfg := config.DebugLocalhost() cfg.NetworkInterfaces = m.Addresses a := service.NewAnnouncer(m.UUID, m.ServiceType, desc, cfg, m.Ports) client := d.clients[m.UUID] a.ServiceArrived().Listen(serviceArrived(client)) a.ServiceGone().Listen(serviceGone(client)) a.Run() d.announcer[m.UUID] = a }
func main() { cfg := config.DebugLocalhost() i := aursir4go.NewImport(servicedescriptor.FromYaml(HELLOKEY), cfg) i.Run() log.Println("started") i.Connected().WaitUntilComplete() log.Println("connected") time.Sleep(1 * time.Second) for { start := time.Now() r := i.Call("SayHello", requestParams{"Hello From AurSir4Go"}) // r := i.Call("SetPosition", pos{55.3}) r.WaitUntilComplete() log.Println("retrieved") var res resultParams r.GetResult().(*messages.Result).Decode(&res) log.Println(res) log.Println((r.GetResult().(*messages.Result).Parameter())) log.Println(time.Since(start)) return } c := make(chan interface{}) <-c }