Beispiel #1
0
func TestCallOne2One(t *testing.T) {
	i := aurarath.NewImport(TEST_APP_DESCRIPTOR, config.DefaultLocalhost())
	defer i.Remove()
	e := aurarath.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("SeyHello", 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())
		}
		if !bytes.Equal(r.Parameter(), 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())
		}
		if !bytes.Equal(r.Parameter(), params) {
			t.Error("Wrong Params", r.Parameter(), params)
		}
	}
}
Beispiel #2
0
func TestCallMany2One(t *testing.T) {
	i1 := aurarath.NewImport(TEST_APP_DESCRIPTOR, config.DefaultLocalhost())
	defer i1.Remove()
	i2 := aurarath.NewImport(TEST_APP_DESCRIPTOR, config.DefaultLocalhost())
	defer i2.Remove()
	e := aurarath.NewExport(TEST_APP_DESCRIPTOR, config.DefaultLocalhost())
	defer e.Remove()
	c := e.Requests().AsChan()

	c1 := i1.Results().AsChan()
	c2 := i2.Results().AsChan()

	e.Run()
	i2.Run()
	i1.Run()

	i1.Connected().WaitUntilComplete()
	i2.Connected().WaitUntilComplete()
	e.Connected().WaitUntilComplete()

	i1.Listen("SayHello")
	i2.Listen("SayHello")
	time.Sleep(1 * time.Second)

	params := []byte{4, 5, 63, 4}
	i1.Trigger("SayHello", params)

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

	select {
	case <-time.After(5 * time.Second):
		t.Fatal("Didnt Got Result 1")
	case d := <-c1:
		r := d.(*messages.Result)
		if r.Exporter != e.UUID() {
			t.Error("Wrong Export UUID", r.Exporter, e.UUID())
		}
		if !bytes.Equal(r.Parameter(), params) {
			t.Error("Wrong Params", r.Parameter(), params)
		}
	}
	select {
	case <-time.After(2 * time.Second):
		t.Fatal("Didnt Got Result 2")
	case d := <-c2:
		r := d.(*messages.Result)
		if r.Exporter != e.UUID() {
			t.Error("Wrong Export UUID", r.Exporter, e.UUID())
		}
		if !bytes.Equal(r.Parameter(), params) {
			t.Error("Wrong Params", r.Parameter(), params)
		}
	}

}
Beispiel #3
0
func TestCallOne2Many(t *testing.T) {
	i := aurarath.NewImport(TEST_APP_DESCRIPTOR, config.DefaultLocalhost())
	defer i.Remove()
	i.Run()
	e1 := aurarath.NewExport(TEST_APP_DESCRIPTOR, config.DefaultLocalhost())
	defer e1.Remove()
	c1 := e1.Requests().AsChan()
	e1.Run()
	e2 := aurarath.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())
		}
		if !bytes.Equal(r.Parameter(), 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())
		}
		if !bytes.Equal(r.Parameter(), 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())
		}
		if !bytes.Equal(r.Parameter(), 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())
		}
		if !bytes.Equal(r.Parameter(), params2) {
			t.Error("Wrong Params", r.Parameter(), params2)
		}
	}

}