Ejemplo n.º 1
0
func newExport(desc *servicedescriptor.ServiceDescriptor, cfg *config.Config) (n int) {
	n = getNextExport()
	e := aursir4go.NewExport(desc, cfg)
	exports[n] = e
	request[n] = map[string]*messages.Request{}
	waiting_request[n] = []string{}
	e.Requests().Listen(getRequest(n))
	e.Run()
	return
}
Ejemplo n.º 2
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)
		}
	}
}
Ejemplo n.º 3
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)
}
Ejemplo n.º 4
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)
		}
	}

}