2023-07-10 10:29:16 +09:00
|
|
|
package rpc
|
|
|
|
|
|
2023-07-10 10:53:49 +09:00
|
|
|
import (
|
|
|
|
|
"context"
|
2023-07-10 12:28:32 +09:00
|
|
|
"math/rand"
|
2023-07-10 10:53:49 +09:00
|
|
|
"testing"
|
2023-07-10 12:13:51 +09:00
|
|
|
"time"
|
2023-07-10 10:53:49 +09:00
|
|
|
|
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
|
|
"repositories.action2quare.com/ayo/gocommon"
|
|
|
|
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type testReceiver struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (tr *testReceiver) TargetExists(tid primitive.ObjectID) bool {
|
2023-07-10 12:13:51 +09:00
|
|
|
logger.Println(tid.Hex())
|
2023-07-10 10:53:49 +09:00
|
|
|
return tid[0] >= 10
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-10 12:13:51 +09:00
|
|
|
func (tr *testReceiver) TestFunc(a string, b string, c int) {
|
2023-07-10 10:53:49 +09:00
|
|
|
target := primitive.NewObjectID()
|
2023-07-10 12:28:32 +09:00
|
|
|
target[0] = byte(rand.Intn(2) * 20)
|
2023-07-10 14:30:24 +09:00
|
|
|
if Make(tr).To(target).Call(a, b, c) != ErrCanExecuteHere {
|
2023-07-10 10:53:49 +09:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-10 12:28:32 +09:00
|
|
|
logger.Println(" ", a, b, target[0])
|
2023-07-10 10:53:49 +09:00
|
|
|
}
|
2023-07-10 10:29:16 +09:00
|
|
|
|
|
|
|
|
func TestRpc(t *testing.T) {
|
2023-07-10 10:53:49 +09:00
|
|
|
var tr testReceiver
|
|
|
|
|
RegistReceiver(&tr)
|
|
|
|
|
myctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
|
|
|
|
|
redisClient, _ := gocommon.NewRedisClient("redis://192.168.8.94:6379", 0)
|
2023-07-10 12:13:51 +09:00
|
|
|
go func() {
|
|
|
|
|
for {
|
|
|
|
|
tr.TestFunc("aaaa", "bbbb", 333)
|
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
|
}
|
|
|
|
|
}()
|
2023-07-10 10:29:16 +09:00
|
|
|
|
2023-07-10 12:13:51 +09:00
|
|
|
Start(myctx, redisClient)
|
2023-07-10 10:53:49 +09:00
|
|
|
<-myctx.Done()
|
|
|
|
|
cancel()
|
2023-07-10 10:29:16 +09:00
|
|
|
}
|