forked from p93542168/wheat-cache
test(middle): add test worker
This commit is contained in:
parent
623373f7ac
commit
576a7bbd41
|
@ -2,30 +2,41 @@ package middle
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitee.com/timedb/wheatCache/pkg/event"
|
||||
middleMsg "gitee.com/timedb/wheatCache/pkg/middle-msg"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_middleware_driver(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
middleware := NewMiddleWare()
|
||||
require.Equal(t, middleware.plugins["logcontext"][0].Name(), "logMiddle")
|
||||
event := event.NewEvent("logcontext")
|
||||
event.SetValue(middleMsg.MiddleMsgKey, "123")
|
||||
middleware.eventProduce.Call(ctx, event)
|
||||
require.Equal(t, middleware.consumerCount, 5)
|
||||
time.Sleep(1 * time.Second)
|
||||
func Test_middleware_loadPlugins(t *testing.T) {
|
||||
m := NewMiddleWare()
|
||||
m.loadPlugins()
|
||||
|
||||
fmt.Println(m.plugins)
|
||||
}
|
||||
|
||||
func TestWorker(t *testing.T) {
|
||||
// ctx := context.Background()
|
||||
event := event.NewEvent("logcontext")
|
||||
|
||||
ctx := context.Background()
|
||||
m := NewMiddleWare()
|
||||
m.eventDriver.Put(event)
|
||||
|
||||
product := event.NewProduce(m.GetEventDriver())
|
||||
middleMsg.SendMiddleMsg(ctx, product, &middleMsg.LogContext{
|
||||
Msg: "debug msg",
|
||||
})
|
||||
|
||||
middleMsg.SendMiddleMsg(ctx, product, &middleMsg.PulginsInfos{
|
||||
Infos: []*middleMsg.PulginsInfo{
|
||||
{
|
||||
Desc: "miss",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
middleMsg.SendMiddleMsg(ctx, product, &middleMsg.LruTTlContext{
|
||||
Keys: []string{"1", "2", "3"},
|
||||
})
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue