Beispiel #1
0
func TestConsulNodeRedeclaresOnStart(t *testing.T) {
	dir, err := ioutil.TempDir("", "mailbox")
	if err != nil {
		panic(err)
	}

	defer os.RemoveAll(dir)

	cn1, err := NewConsulClusterNode(
		&ConsulNodeConfig{
			AdvertiseAddr: "127.0.0.1",
			ListenPort:    8899,
			DataPath:      dir})

	if err != nil {
		panic(err)
	}

	// defer cn1.Close()
	go cn1.Accept()

	cl, err := vega.NewClient(":8899")

	cn1.Declare("a")

	// propagation delay
	time.Sleep(1000 * time.Millisecond)

	msg := vega.Msg([]byte("hello"))

	// debugf("pushing...\n")
	err = cl.Push("a", msg)
	if err != nil {
		panic(err)
	}

	cl.Close()
	cn1.Cleanup()
	cn1.Close()

	cn1, err = NewConsulClusterNode(
		&ConsulNodeConfig{
			AdvertiseAddr: "127.0.0.1",
			ListenPort:    8899,
			DataPath:      dir})

	if err != nil {
		panic(err)
	}

	defer cn1.Close()
	go cn1.Accept()

	cl, _ = vega.NewClient(":8899")

	err = cl.Push("a", msg)
	assert.NoError(t, err, "routes were not readded")
}
Beispiel #2
0
func (cp *consulPusher) Connect() error {
	c, err := vega.NewClient(cp.target)
	if err != nil {
		return err
	}

	cp.client = vega.NewReliableStorage(c)

	return nil
}
Beispiel #3
0
func TestClusterPubSubBetweenNodes(t *testing.T) {
	dir, err := ioutil.TempDir("", "mailbox")
	if err != nil {
		panic(err)
	}

	defer os.RemoveAll(dir)

	cn, err := NewMemClusterNode(dir)
	if err != nil {
		panic(err)
	}

	defer cn.Close()

	dir2, err := ioutil.TempDir("", "mailbox")
	if err != nil {
		panic(err)
	}

	defer os.RemoveAll(dir2)

	cn2, err := NewMemClusterNode(dir2)
	if err != nil {
		panic(err)
	}

	defer cn2.Close()

	// Setup 2 service objects

	s1, err := vega.NewService(cPort, cn)
	if err != nil {
		panic(err)
	}

	defer s1.Close()
	go s1.Accept()

	s2, err := vega.NewService(cPort2, cn2)
	if err != nil {
		panic(err)
	}

	defer s2.Close()
	go s2.Accept()

	// Wire up a client going to s1

	toS1, err := vega.NewClient(cPort)
	if err != nil {
		panic(err)
	}

	toS1.Declare("a")
	err = toS1.Push(":subscribe", &vega.Message{ReplyTo: "a", CorrelationId: "foo"})
	require.NoError(t, err)

	cn2.AddRoute(":publish", toS1)

	// Push data into cn2 and see it show up in cn

	toS2, err := vega.NewClient(cPort2)
	if err != nil {
		panic(err)
	}

	msg := &vega.Message{CorrelationId: "foo", Body: []byte("between nodes")}

	err = toS2.Push(":publish", msg)
	require.NoError(t, err)

	// debugf("polling\n")

	ret, err := toS1.Poll("a")
	if err != nil {
		panic(err)
	}

	require.NotNil(t, ret)

	assert.True(t, msg.Equal(ret.Message), "message did not route properly")
}
Beispiel #4
0
func TestClusterRoutesViaNetwork(t *testing.T) {
	dir, err := ioutil.TempDir("", "mailbox")
	if err != nil {
		panic(err)
	}

	defer os.RemoveAll(dir)

	cn, err := NewMemClusterNode(dir)
	if err != nil {
		panic(err)
	}

	defer cn.Close()

	dir2, err := ioutil.TempDir("", "mailbox")
	if err != nil {
		panic(err)
	}

	defer os.RemoveAll(dir2)

	cn2, err := NewMemClusterNode(dir2)
	if err != nil {
		panic(err)
	}

	defer cn2.Close()

	// Setup 2 service objects

	s1, err := vega.NewService(cPort, cn)
	if err != nil {
		panic(err)
	}

	defer s1.Close()
	go s1.Accept()

	s2, err := vega.NewService(cPort2, cn2)
	if err != nil {
		panic(err)
	}

	defer s2.Close()
	go s2.Accept()

	// Wire up a client going to s1

	toS1, err := vega.NewClient(cPort)
	if err != nil {
		panic(err)
	}

	toS1.Declare("a")
	cn2.AddRoute("a", toS1)

	// Push data into cn2 and see it show up in cn

	toS2, err := vega.NewClient(cPort2)
	if err != nil {
		panic(err)
	}

	msg := vega.Msg([]byte("between nodes"))

	err = toS2.Push("a", msg)
	if err != nil {
		panic(err)
	}

	// debugf("polling\n")

	ret, err := toS1.Poll("a")
	if err != nil {
		panic(err)
	}

	assert.True(t, msg.Equal(ret.Message), "message did not route properly")
}