func BenchmarkDeliveryRegistry(t *testing.B) {
	t.StopTimer()
	registry := NewDeliveryRegistry(10 * 10000)

	t.SetParallelism(8)
	t.StartTimer()
	t.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			msgId := store.MessageId()
			succ := registry.Registe(msgId, 5*time.Second)
			if !succ {
				t.Fail()
			}
		}
	})
}
func buildBytesMessage(commit bool) *protocol.BytesMessage {
	//创建消息
	entity := &protocol.BytesMessage{}
	entity.Header = &protocol.Header{
		MessageId:    proto.String(store.MessageId()),
		Topic:        proto.String("trade"),
		MessageType:  proto.String("pay-succ"),
		ExpiredTime:  proto.Int64(time.Now().Add(10 * time.Minute).Unix()),
		DeliverLimit: proto.Int32(-1),
		GroupId:      proto.String("ps-trade-a"),
		Commit:       proto.Bool(commit),
		Fly:          proto.Bool(false)}
	entity.Body = []byte("helloworld")

	return entity
}
func buildStringMessage(commit bool) *protocol.StringMessage {
	//创建消息
	entity := &protocol.StringMessage{}
	entity.Header = &protocol.Header{
		MessageId:    proto.String(store.MessageId()),
		Topic:        proto.String("trade"),
		MessageType:  proto.String("pay-succ"),
		ExpiredTime:  proto.Int64(-1),
		DeliverLimit: proto.Int32(100),
		GroupId:      proto.String("go-kite-test"),
		Commit:       proto.Bool(commit),
		Fly:          proto.Bool(false)}

	entity.Body = proto.String("hello world")

	return entity
}
func buildBytesMessage(commit bool) *protocol.BytesMessage {
	//创建消息
	entity := &protocol.BytesMessage{}
	entity.Header = &protocol.Header{
		MessageId:    proto.String(store.MessageId()),
		Topic:        proto.String("trade"),
		MessageType:  proto.String("pay-succ"),
		ExpiredTime:  proto.Int64(time.Now().Add(24 * time.Hour).Unix()),
		DeliverLimit: proto.Int32(100),
		GroupId:      proto.String("go-kite-test"),
		Commit:       proto.Bool(commit),
		Fly:          proto.Bool(false)}

	entity.Body = body

	return entity
}
示例#5
0
func buildStringMessage(id string) *protocol.StringMessage {
	//创建消息
	entity := &protocol.StringMessage{}
	mid := store.MessageId()
	mid = string(mid[:len(mid)-1]) + id
	// mid[len(mid)-1] = id[0]
	entity.Header = &protocol.Header{
		MessageId:    proto.String(mid),
		Topic:        proto.String("trade"),
		MessageType:  proto.String("pay-succ"),
		ExpiredTime:  proto.Int64(time.Now().Add(10 * time.Minute).Unix()),
		DeliverLimit: proto.Int32(100),
		GroupId:      proto.String("go-kite-test"),
		Commit:       proto.Bool(true),
		Fly:          proto.Bool(false)}
	entity.Body = proto.String("hello go-kite")

	return entity
}
func TestDeliveryRegistry(t *testing.T) {
	registry := NewDeliveryRegistry(10 * 10000)

	msgId := store.MessageId()
	succ := registry.Registe(msgId, 5*time.Second)
	if !succ {
		t.Fail()
		t.Logf("TestDeliveryRegistry|FirstRegist|FAIL|%s", msgId)
	}

	succ = registry.Registe(msgId, 5*time.Second)
	if succ {
		t.Fail()
		t.Logf("TestDeliveryRegistry|SecondRegist|FAIL|%s", msgId)
	}

	time.Sleep(5 * time.Second)
	succ = registry.Registe(msgId, 5*time.Second)
	if !succ {
		t.Fail()
		t.Logf("TestDeliveryRegistry|ThirdRegist|FAIL|%s", msgId)
	}
}
示例#7
0
func TestRecoverManager(t *testing.T) {

	pipeline := NewDefaultPipeline()

	kitedb := memory.NewKiteMemoryStore(100, 100)

	messageid := store.MessageId()
	t.Logf("messageid:%s\b", messageid)
	entity := store.NewMessageEntity(protocol.NewQMessage(buildStringMessage(messageid)))
	kitedb.Save(entity)
	go func() {
		for {
			log.Println(kitedb.Monitor())
			time.Sleep(1 * time.Second)
		}
	}()

	fs := stat.NewFlowStat("recover")
	fs.Start()
	ch := make(chan bool, 1)

	// 临时在这里创建的BindExchanger
	exchanger := binding.NewBindExchanger("localhost:2181", "127.0.0.1:13800")
	pipeline.RegisteHandler("deliverpre", handler.NewDeliverPreHandler("deliverpre", kitedb, exchanger, fs, 100))
	pipeline.RegisteHandler("deliver", newmockDeliverHandler("deliver", ch))
	hostname, _ := os.Hostname()
	rm := NewRecoverManager(hostname, 16*time.Second, pipeline, kitedb)
	rm.Start()
	select {
	case succ := <-ch:
		log.Printf("--------------recover %s\n", succ)
	case <-time.After(5 * time.Second):
		t.Fail()
		log.Println("waite recover  deliver timeout\n")
	}

}