func TestExportReactor(t *testing.T) {
	i := aursir4go.NewImport(TEST_APP_DESCRIPTOR, config.DefaultLocalhost())
	defer i.Remove()
	e := patterns.NewExportReactor(TEST_APP_DESCRIPTOR, config.DefaultLocalhost())
	defer e.Stop()
	i.Run()
	params := []byte{4, 5, 63, 4}
	e.React("SayHello", func(r *messages.Request) interface{} {
		return params
	})
	e.Start()
	i.Connected().WaitUntilComplete()
	f := i.Call("SayHello", params)

	select {
	case <-time.After(2 * time.Second):
		t.Fatal("Didnt Got Request")
	case d := <-f.AsChan():
		r := d.(*messages.Result)

		var res []byte
		r.Decode(&res)
		if !bytes.Equal(res, params) {
			t.Error("Wrong Params", r.Parameter(), params)
		}
	}
}
Пример #2
0
func newImport(desc *servicedescriptor.ServiceDescriptor, cfg *config.Config) (n int) {
	n = getNextImport()
	i := aursir4go.NewImport(desc, cfg)
	imports[n] = i
	request[n] = map[string]*eventual2go.Future{}
	listen_results[n] = eventual2go.NewCollector()
	listen_results[n].AddStream(i.Results())
	i.Run()
	return
}
Пример #3
0
func TestCallOne2One(t *testing.T) {
	i := aursir4go.NewImport(TEST_APP_DESCRIPTOR, config.DefaultLocalhost())
	defer i.Remove()
	e := aursir4go.NewExport(TEST_APP_DESCRIPTOR, config.DefaultLocalhost())
	defer e.Remove()
	c := e.Requests().AsChan()
	i.Run()

	e.Run()
	i.Connected().WaitUntilComplete()
	e.Connected().WaitUntilComplete()
	params := []byte{4, 5, 63, 4}
	f := i.Call("SayHello", params)

	select {
	case <-time.After(5 * time.Second):
		t.Fatal("Didnt Got Request")
	case d := <-c:
		r := d.(*messages.Request)
		if r.Importer != i.UUID() {
			t.Error("Wrong Import UUID", r.Importer, i.UUID())
		}
		var res []byte
		r.Decode(&res)
		if !bytes.Equal(res, params) {
			t.Error("Wrong Params", r.Parameter(), params)
		}
		e.Reply(r, params)
	}

	select {
	case <-time.After(2 * time.Second):
		t.Fatal("Didnt Got Request")
	case d := <-f.AsChan():
		r := d.(*messages.Result)
		if r.Exporter != e.UUID() {
			t.Error("Wrong Export UUID", r.Exporter, e.UUID())
		}

		var res []byte
		r.Decode(&res)
		if !bytes.Equal(res, params) {
			t.Error("Wrong Params", r.Parameter(), params)
		}
	}
}
Пример #4
0
func TestEmit(t *testing.T) {
	i := aursir4go.NewImport(TEST_APP_DESCRIPTOR, config.DefaultLocalhost())
	e := aursir4go.NewExport(TEST_APP_DESCRIPTOR, config.DefaultLocalhost())
	defer e.Remove()
	c := i.Results().AsChan()
	i.Listen("SayHello")
	i.Run()

	e.Run()
	i.Connected().WaitUntilComplete()
	e.Connected().WaitUntilComplete()

	params := []byte{4, 5, 63, 4}
	e.Emit("SayHello", nil, params)

	select {
	case <-time.After(2 * time.Second):
		t.Fatal("Didnt Got Result")
	case d := <-c:
		r := d.(*messages.Result)
		if r.Exporter != e.UUID() {
			t.Error("Wrong Export UUID", r.Exporter, e.UUID())
		}

		var res []byte
		r.Decode(&res)
		if !bytes.Equal(res, params) {
			t.Error("Wrong Params", r.Parameter(), params)
		}
	}
	i.StopListen("SayHello")
	time.Sleep(100 * time.Millisecond)
	e.Emit("SayHello", nil, params)

	select {
	case <-time.After(2 * time.Microsecond):
	case <-c:
		t.Fatal("Got Result")
	}
	i.Remove()
	time.Sleep(1 * time.Second)
	//testing if it not crashes due to uncomplete removal
	e.Emit("SayHello", nil, params)
}
Пример #5
0
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
}
Пример #6
0
func TestCallOne2Many(t *testing.T) {
	i := aursir4go.NewImport(TEST_APP_DESCRIPTOR, config.DefaultLocalhost())
	defer i.Remove()
	i.Run()
	e1 := aursir4go.NewExport(TEST_APP_DESCRIPTOR, config.DefaultLocalhost())
	defer e1.Remove()
	c1 := e1.Requests().AsChan()
	e1.Run()
	e2 := aursir4go.NewExport(TEST_APP_DESCRIPTOR, config.DefaultLocalhost())
	defer e2.Remove()
	c2 := e2.Requests().AsChan()
	e2.Run()

	i.Connected().WaitUntilComplete()
	e1.Connected().WaitUntilComplete()
	e2.Connected().WaitUntilComplete()

	params := []byte{4, 5, 63, 4}
	params1 := []byte{3}
	params2 := []byte{6}
	s := eventual2go.NewStreamController()
	s1, s2 := s.Split(func(d eventual2go.Data) bool { return d.(*messages.Result).Exporter == e1.UUID() })
	rc1 := s1.AsChan()
	rc2 := s2.AsChan()
	i.CallAll("SayHello", params, s)
	select {
	case <-time.After(5 * time.Second):
		t.Fatal("Didnt Got Request 1")
	case d := <-c1:
		r := d.(*messages.Request)
		if r.Importer != i.UUID() {
			t.Error("Wrong Import UUID 1", r.Importer, i.UUID())
		}

		var res []byte
		r.Decode(&res)
		if !bytes.Equal(res, params) {
			t.Error("Wrong Params 1", r.Parameter(), params)
		}
		e1.Reply(r, params1)
	}

	select {
	case <-time.After(2 * time.Second):
		t.Fatal("Didnt Got Request 2")
	case d := <-c2:
		r := d.(*messages.Request)
		if r.Importer != i.UUID() {
			t.Error("Wrong Import UUID 2", r.Importer, i.UUID())
		}

		var res []byte
		r.Decode(&res)
		if !bytes.Equal(res, params) {
			t.Error("Wrong Params 2", r.Parameter(), params)
		}
		e2.Reply(r, params2)
	}

	select {
	case <-time.After(2 * time.Second):
		t.Fatal("Didnt Got Result 1")
	case d := <-rc1:
		r := d.(*messages.Result)
		if r.Exporter != e1.UUID() {
			t.Error("Wrong Export UUID", r.Exporter, e1.UUID())
		}

		var res []byte
		r.Decode(&res)
		if !bytes.Equal(res, params1) {
			t.Error("Wrong Params", r.Parameter(), params1)
		}
	}
	select {
	case <-time.After(2 * time.Second):
		t.Fatal("Didnt Got Result 2")
	case d := <-rc2:
		r := d.(*messages.Result)
		if r.Exporter != e2.UUID() {
			t.Error("Wrong Export UUID", r.Exporter, e2.UUID())
		}

		var res []byte
		r.Decode(&res)
		if !bytes.Equal(res, params2) {
			t.Error("Wrong Params", r.Parameter(), params2)
		}
	}

}