Example #1
0
func BenchmarkRemotingServer(t *testing.B) {

	//初始化存储

	var kiteClient *client.KiteQClient
	var kiteQServer *KiteQServer
	var c int32 = 0
	var lc int32 = 0

	rc := turbo.NewRemotingConfig(
		"remoting-localhost:13800",
		2000, 16*1024,
		16*1024, 10000, 10000,
		10*time.Second, 160000)

	kc := NewKiteQConfig("kiteq-localhost:13800", "localhost:13800", "localhost:2181", true, 1*time.Second, 10, 1*time.Minute, []string{"trade"}, "memory://", rc)

	kiteQServer = NewKiteQServer(kc)
	kiteQServer.Start()
	log.Println("KiteQServer START....")

	kiteClient = client.NewKiteQClient("localhost:2181", "s-trade-a", "123456", &defualtListener{})
	kiteClient.SetTopics([]string{"trade"})
	kiteClient.SetBindings([]*binding.Binding{
		binding.Bind_Direct("s-trade-a", "trade", "pay-succ", 1000, true),
	})
	kiteClient.Start()

	go func() {
		for {
			time.Sleep(1 * time.Second)
			log.Printf("%d\n", (c - lc))
			lc = c
		}
	}()

	t.SetParallelism(4)
	t.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			err := kiteClient.SendStringMessage(buildStringMessage("1"))
			if nil != err {
				t.Logf("SEND MESSAGE |FAIL|%s\n", err)
			}
		}
	})

	kiteClient.Destory()
	kiteQServer.Shutdown()
}
Example #2
0
func TestRemotingServer(t *testing.T) {

	//初始化存储
	var kiteClient *client.KiteQClient
	var kiteQServer *KiteQServer
	var c int32 = 0
	var lc int32 = 0

	rc := turbo.NewRemotingConfig(
		"remoting-localhost:13800",
		2000, 16*1024,
		16*1024, 10000, 10000,
		10*time.Second, 160000)

	kc := NewKiteQConfig("kiteq-localhost:13800", "localhost:13800", "localhost:2181", true, 1*time.Second, 10, 1*time.Minute, []string{"trade"}, "memory://", rc)

	kiteQServer = NewKiteQServer(kc)
	kiteQServer.Start()
	log.Println("KiteQServer START....")

	kiteClient = client.NewKiteQClient("localhost:2181", "s-trade-a", "123456", &defualtListener{})
	kiteClient.SetTopics([]string{"trade"})
	kiteClient.SetBindings([]*binding.Binding{
		binding.Bind_Direct("s-trade-a", "trade", "pay-succ", 1000, true),
	})
	kiteClient.Start()

	go func() {
		for {
			time.Sleep(1 * time.Second)
			log.Printf("%d\n", (c - lc))
			lc = c
		}
	}()

	err := kiteClient.SendStringMessage(buildStringMessage("1"))
	if nil != err {
		t.Logf("SEND MESSAGE |FAIL|%s\n", err)
		t.Fail()

	}

	err = kiteClient.SendStringMessage(buildStringMessage("2"))
	if nil != err {
		t.Logf("SEND MESSAGE |FAIL|%s\n", err)
		t.Fail()

	}

	err = kiteClient.SendStringMessage(buildStringMessage("3"))
	if nil != err {
		t.Logf("SEND MESSAGE |FAIL|%s\n", err)
		t.Fail()

	}

	msg := buildStringMessage("4")
	msg.GetHeader().Commit = proto.Bool(false)

	err = kiteClient.SendStringMessage(msg)
	if nil != err {
		t.Logf("SEND MESSAGE |FAIL|%s\n", err)
		t.Fail()

	}

	time.Sleep(10 * time.Second)

	kiteClient.Destory()
	kiteQServer.Shutdown()
}