feat: incr sync version.

This commit is contained in:
Gordon
2024-06-24 17:48:33 +08:00
parent e8ccae6349
commit 88b8043224
308 changed files with 55952 additions and 59 deletions

View File

@@ -0,0 +1,234 @@
// Copyright © 2023 OpenIM SDK. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"context"
"encoding/json"
"errors"
"github.com/openimsdk/openim-sdk-core/v3/pkg/network"
"github.com/openimsdk/openim-sdk-core/v3/pkg/server_api_params"
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
"github.com/openimsdk/openim-sdk-core/v3/test"
"github.com/openimsdk/tools/log"
"time"
)
var (
//APIADDR = "http://43.155.69.205:10002"
//WSADDR = "ws://43.155.69.205:10001"
//APIADDR = "https://chat-api-dev.opencord.so"
//WSADDR = "wss://chat-ws-dev.opencord.so"
APIADDR = "http://14.29.168.56:10002"
WSADDR = "ws://14.29.168.56:10001"
//APIADDR = "http://113.108.8.93:10002"
//WSADDR = "ws://113.108.8.93:10001"
REGISTERADDR = APIADDR + "/user_register"
ACCOUNTCHECK = APIADDR + "/manager/account_check"
TOKENADDR = APIADDR + "/auth/user_token"
SECRET = "openIM123"
//SECRET = "4zbF9Y6Fs1QJ0hsmpC3B676txZcCnjcZ"
SENDINTERVAL = 20
)
var ctx context.Context
const PlatformID = 3
type ResToken struct {
Data struct {
ExpiredTime int64 `json:"expiredTime"`
Token string `json:"token"`
Uid string `json:"uid"`
}
ErrCode int `json:"errCode"`
ErrMsg string `json:"errMsg"`
}
func ggetToken(uid string) string {
url := TOKENADDR
var req server_api_params.UserTokenReq
req.Platform = PlatformID
req.UserID = uid
req.Secret = SECRET
req.OperationID = utils.OperationIDGenerator()
r, err := network.Post2Api(url, req, "a")
if err != nil {
log.ZError(ctx, "Post2Api failed ", errors.New("Post2Api failed "), "operationID", req.OperationID, "url", url, "req", req)
return ""
}
var stcResp ResToken
err = json.Unmarshal(r, &stcResp)
if stcResp.ErrCode != 0 {
log.ZError(ctx, "ErrCode failed ", errors.New("ErrCode failed "), "operationID", req.OperationID,
"errorCode", stcResp.ErrCode, "errMsg", stcResp.ErrMsg, "url", url, "req", req)
return ""
}
log.ZInfo(ctx, "get token: ", "operationID", req.OperationID, "token", stcResp.Data.Token)
return stcResp.Data.Token
}
func gRunGetToken(strMyUid string) string {
var token string
for true {
token = ggetToken(strMyUid)
if token == "" {
time.Sleep(time.Duration(100) * time.Millisecond)
continue
} else {
break
}
}
return token
}
func main() {
uid := "1695766238"
//Gordon
//uid:="1554321956297519104"
//Gordon2
//uid := "1583984945064968192"
//uid := "3734595565"
tokenx := gRunGetToken(uid)
//tokenx := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVSUQiOiI3MDcwMDgxNTMiLCJQbGF0Zm9ybSI6IkFuZHJvaWQiLCJleHAiOjE5NjY0MTJ1XjJZGWj5fB3mqC7p6ytxSarvxZfsABwIjoxNjUxMDU1MDU2fQ.aWvmJ_sQxXmT5nKwiM5QsF9-tfkldzOYZtRD3nrUuko"
test.InOutDoTest(uid, tokenx, WSADDR, APIADDR)
time.Sleep(time.Second * 30)
// test.DoTestSendMsg2("7789", "7788")
//test.DoTestGetAdvancedHistoryMessageList()
//test.DoTestGetSelfUserInfo()
//test.DoTestSendMsg2GroupWithMessage(uid, "1623878302774460418", "2")
//test.DoTestAddMessageReactionExtensions(1,"special handle")
//time.Sleep(time.Second*5)
//test.DoTestAddMessageReactionExtensions(2,"special handle")
//time.Sleep(time.Second*5)
//test.DoTestGetMessageListReactionExtensions("special handle")
//test.DoTestSetAppBadge()
//test.DoTestSearchLocalMessages()
//test.DoTestGetAdvancedHistoryMessageList()
println("start")
//test.DoTestGetUserInDepartment()
//test.DoTestGetDepartmentMemberAndSubDepartment()
//test.DoTestDeleteAllMsgFromLocalAndSvr()
// test.DoTestGetDepartmentMemberAndSubDepartment()
//test.DotestUploadFile()
//test.DotestMinio()
//test.DotestSearchFriends()
//if *senderNum == 0 {
// test.RegisterAccounts(*onlineNum)
// return
//}
//
//test.OnlineTest(*onlineNum)
////test.TestSendCostTime()
//test.ReliabilityTest(*singleSenderMsgNum, *intervalTime, 10, *senderNum)
//test.DoTestSearchLocalMessages()
//println("start")
//test.DoTestSendImageMsg(strMyUidx, "17726378428")
//test.DoTestSearchGroups()
//test.DoTestGetHistoryMessage("")
//test.DoTestGetHistoryMessageReverse("")
//test.DoTestInviteInGroup()
//test.DoTestCancel()
//test.DoTestSendMsg2(strMyUidx, friendID)
//test.DoTestGetAllConversation()
//test.DoTestGetOneConversation("17726378428")
//test.DoTestGetConversations(`["single_17726378428"]`)
//test.DoTestGetConversationListSplit()
//test.DoTestGetConversationRecvMessageOpt(`["single_17726378428"]`)
//set batch
//test.DoTestSetConversationRecvMessageOpt([]string{"single_17726378428"}, constant.NotReceiveMessage)
//set one
////set batch
//test.DoTestSetConversationRecvMessageOpt([]string{"single_17726378428"}, constant.ReceiveMessage)
////set one
//test.DoTestSetConversationPinned("single_17726378428", false)
//test.DoTestSetOneConversationRecvMessageOpt("single_17726378428", constant.NotReceiveMessage)
//test.DoTestSetOneConversationPrivateChat("single_17726378428", false)
//test.DoTestReject()
//test.DoTestAccept()
//test.DoTestMarkGroupMessageAsRead()
//test.DoTestGetGroupHistoryMessage()
//test.DoTestGetHistoryMessage("17396220460")
time.Sleep(250000 * time.Millisecond)
//b := utils.GetCurrentTimestampBySecond()
i := 0
for {
//test.DoTestSendMsg2Group(strMyUidx, "42c9f515cb84ee0e82b3f3ce71eb14d6", i)
i++
time.Sleep(250 * time.Millisecond)
//if i == 100 {
// break
//}
//log.Warn("", "10 * time.Millisecond ###################waiting... msg: ", i)
}
//
//log.Warn("", "cost time: ", utils.GetCurrentTimestampBySecond()-b)
//return
//i = 0
//for {
// //test.DoTestSendMsg2Group(strMyUidx, "42c9f515cb84ee0e82b3f3ce71eb14d6", i)
// i++
// time.Sleep(1000 * time.Millisecond)
// if i == 10 {
// break
// }
// log.Warn("", "1000 * time.Millisecond ###################waiting... msg: ", i)
//}
//
//i = 0
//for {
// test.DoTestSendMsg2Group(strMyUidx, "42c9f515cb84ee0e82b3f3ce71eb14d6", i)
// i++
// time.Sleep(10000 * time.Millisecond)
// log.Warn("", "10000 * time.Millisecond ###################waiting... msg: ", i)
//}
//reliabilityTest()
// test.PressTest(testClientNum, intervalSleep, imIP)
}
//
//funcation main() {
// testClientNum := 100
// intervalSleep := 2
// imIP := "43.128.5.63"
//
// msgNum := 1000
// test.ReliabilityTest(msgNum, intervalSleep, imIP)
// for i := 0; i < 6; i++ {
// test.Msgwg.Wait()
// }
//
// for {
//
// if test.CheckReliabilityResult() {
// log.Warn("CheckReliabilityResult ok, again")
//
// } else {
// log.Warn("CheckReliabilityResult failed , wait.... ")
// }
//
// time.Sleep(time.Duration(10) * time.Second)
// }
//
//}
//funcation printCallerNameAndLine() string {
// pc, _, line, _ := runtime.Caller(2)
// return runtime.FuncForPC(pc).Name() + "()@" + strconv.Itoa(line) + ": "
//}
// myuid, maxuid, msgnum

View File

@@ -0,0 +1,61 @@
// Copyright © 2023 OpenIM SDK. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"fmt"
"github.com/openimsdk/openim-sdk-core/v3/test"
"time"
)
func main() {
APIADDR := "http://59.36.173.89:10002"
WSADDR := "ws://59.36.173.89:10001"
REGISTERADDR := APIADDR + "/user_register"
ACCOUNTCHECK := APIADDR + "/manager/account_check"
TOKENADDR := APIADDR + "/auth/user_token"
SECRET := "openIM123"
SENDINTERVAL := 20
test.REGISTERADDR = REGISTERADDR
test.TOKENADDR = TOKENADDR
test.SECRET = SECRET
test.SENDINTERVAL = SENDINTERVAL
test.WSADDR = WSADDR
test.ACCOUNTCHECK = ACCOUNTCHECK
strMyUidx := "5284951719"
tokenx := test.RunGetToken(strMyUidx)
fmt.Println(tokenx)
test.InOutDoTest(strMyUidx, tokenx, WSADDR, APIADDR)
time.Sleep(time.Second * 10)
// test.DoTestGetUsersInfo()
// test.DoTestSetMsgDestructTime("sg_1012596513")
// test.DoTestRevoke()
// test.DotestDeleteFriend("8303492153")
// test.TestMarkGroupMessageAsRead()
// test.DoTestRevoke()
// time.Sleep(time.Second * 5)
// test.DoTestAddToBlackList("9169012630")
// test.DoTestDeleteFromBlackList("9169012630")
// test.DotestDeleteFriend("9169012630")
// test.DoTestSetConversationPinned("si_2456093263_9169012630", true)
// test.DoTestSetOneConversationRecvMessageOpt("si_2456093263_9169012630", 2)
// test.DoTestGetConversationRecvMessageOpt("si_2456093263_9169012630")
// test.DoTestDeleteConversationMsgFromLocalAndSvr("sg_537415520")
for {
time.Sleep(10000 * time.Millisecond)
}
}

View File

@@ -0,0 +1,25 @@
// Copyright © 2023 OpenIM SDK. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
func main() {
// var onlineNum *int //Number of online users
// onlineNum = flag.Int("on", 10, "online num")
// flag.Parse()
// log.Warn("", "online test start, online num: ", *onlineNum)
// test.OnlineTest(*onlineNum)
// log.Warn("", "online test finish, online num: ", *onlineNum)
// select {}
}

View File

@@ -0,0 +1,67 @@
// Copyright © 2023 OpenIM SDK. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"go/types"
)
func main() {
//filePath, err := filepath.Abs(".\test.go")
//if err != nil {
// panic(err)
//}
// 解析Go文件
fset := token.NewFileSet()
node, err := parser.ParseFile(fset, "D:\\Goland\\workspace\\Open-IM-SDK-Core\\main\\test.go", nil, parser.AllErrors)
if err != nil {
panic(err)
}
//myImporter := importer.Default()
// 创建类型检查器
//conf := types.Config{Importer: myImporter}
info := &types.Info{
Defs: make(map[*ast.Ident]types.Object),
}
//// 类型检查
//_, err = conf.Check("", fset, []*ast.File{node}, info)
//if err != nil {
// panic(err)
//}
// 遍历文件中所有函数
fn := func(pkg *types.Package) string {
return pkg.Name()
}
for _, decl := range node.Decls {
if f, ok := decl.(*ast.FuncDecl); ok {
// 打印函数名
fmt.Println("Function Name: ", f.Name.Name)
// 打印参数名和类型
for _, param := range f.Type.Params.List {
for _, name := range param.Names {
obj := info.ObjectOf(name)
typ := obj.Type()
fmt.Printf("Parameter Name: %s, Type: %s\n", name.Name, types.TypeString(typ, fn))
}
}
}
}
}

View File

@@ -0,0 +1,38 @@
// Copyright © 2023 OpenIM SDK. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"errors"
"flag"
"github.com/openimsdk/openim-sdk-core/v3/test"
"github.com/openimsdk/tools/log"
)
func main() {
var senderNum *int //Number of users sending messages
var singleSenderMsgNum *int //Number of single user send messages
var intervalTime *int //Sending time interval, in millisecond
senderNum = flag.Int("sn", 100, "sender num")
singleSenderMsgNum = flag.Int("mn", 1000, "single sender msg num")
intervalTime = flag.Int("t", 0, "interval time mill second")
flag.Parse()
// test.InitMgr(*senderNum)
log.ZInfo(ctx, "logLevel", uint32(test.LogLevel))
log.ZWarn(ctx, "press test begin ", errors.New(""), "sender num", *senderNum, " single sender msg num", *singleSenderMsgNum, " send msg total num ", *senderNum**singleSenderMsgNum)
test.PressTest(*singleSenderMsgNum, *intervalTime, *senderNum)
select {}
}

View File

@@ -0,0 +1,38 @@
// Copyright © 2023 OpenIM SDK. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"errors"
"flag"
"github.com/openimsdk/openim-sdk-core/v3/test"
"github.com/openimsdk/tools/log"
)
func main() {
var senderNum *int //Number of users sending messages
var singleSenderMsgNum *int //Number of single user send messages
var intervalTime *int //Sending time interval, in millisecond
senderNum = flag.Int("sn", 200, "sender num")
singleSenderMsgNum = flag.Int("mn", 100, "single sender msg num")
intervalTime = flag.Int("t", 10, "interval time mill second")
flag.Parse()
test.InitMgr(*senderNum)
log.ZInfo(ctx, "logName", test.LogName, "logLevel", uint32(test.LogLevel))
log.ZWarn(ctx, "reliability test start ", errors.New(""), "sender num", *senderNum, " single sender msg num", *singleSenderMsgNum, " send msg total num ", *senderNum**singleSenderMsgNum)
test.ReliabilityTest(*singleSenderMsgNum, *intervalTime, 10, *senderNum)
}

View File

@@ -0,0 +1,192 @@
// Copyright © 2023 OpenIM SDK. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"errors"
"github.com/openimsdk/openim-sdk-core/v3/pkg/db"
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
"github.com/openimsdk/openim-sdk-core/v3/test"
"github.com/openimsdk/tools/log"
"time"
)
var allDB []*db.DataBase
//funcation TestDB(loginUserID string) {
// operationID := utils.OperationIDGenerator()
// dbUser, err := db.NewDataBase(loginUserID, "/data/test/Open-IM-Server/db/sdk/", operationID)
// if err != nil {
// log.Error(operationID, "NewDataBase failed ", err.Error(), loginUserID)
// return
// }
// conversationList, err := dbUser.GetAllConversationList()
// if err != nil {
// log.Error(operationID, "GetAllConversationList failed ", err.Error())
// }
// log.Info(operationID, "GetAllConversationList len: ", len(conversationList))
//
// groupIDList, err := dbUser.GetJoinedGroupList()
// if err != nil {
// log.Error(operationID, "GetJoinedGroupList failed ", err.Error())
// }
// log.Info(operationID, "GetJoinedGroupList len: ", len(groupIDList))
//
// groupMemberList, err := dbUser.GetAllGroupMemberList()
// if err != nil {
// log.Error(operationID, "GetAllGroupMemberList failed ", err.Error())
// }
// log.Info(operationID, "GetAllGroupMemberList len: ", len(groupMemberList))
// //GetAllMessageForTest
// msgList, err := dbUser.GetAllMessageForTest()
// if err != nil {
// log.Error(operationID, "GetAllMessageForTest failed ", err.Error())
// }
// log.Info(operationID, "GetAllMessageForTest len: ", len(msgList))
// allDB = append(allDB, dbUser)
//
// dbUser.CloseDB(operationID)
// log.Info(operationID, "close db finished ")
//
//}
func main() {
//var userIDList []string
//f, err := os.Open("/data/test/Open-IM-Server/db/sdk")
//if err != nil {
// log.Error("", "open failed ", err.Error())
// return
//}
//files, err := f.Readdir(-1)
//f.Close()
//if err != nil {
// log.Error("", "Readdir failed ", err.Error())
// return
//}
//
//for _, file := range files {
// begin := strings.Index(file.Name(), "OpenIM_v2_")
// end := strings.Index(file.Name(), ".db")
// userID := file.Name()[begin+len("OpenIM_v2_") : end]
// // OpenIM_v2_3380999461.db
// log.Info("", "file name: ", file.Name(), userID)
// TestDB(userID)
//}
//log.Info("", "files: ", len(allDB))
////for _, v := range allDB {
//// v.CloseDB("aa")
////}
//
//log.Info("", "gc begin ")
//runtime.GC()
//log.Info("", "gc end ")
//time.Sleep(100000 * time.Second)
//return
strMyUidx := "3370431052"
tokenx := test.RunGetToken(strMyUidx)
//tokenx := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVSUQiOiI3MDcwMDgxNTMiLCJQbGF0Zm9ybSI6IkFuZHJvaWQiLCJleHAiOjE5NjY0MTJ1XjJZGWj5fB3mqC7p6ytxSarvxZfsABwIjoxNjUxMDU1MDU2fQ.aWvmJ_sQxXmT5nKwiM5QsF9-tfkldzOYZtRD3nrUuko"
//go funcation() {
// time.Sleep(2 * time.Second)
// test.InOutLogou()
//}()
test.InOutDoTest(strMyUidx, tokenx, test.WSADDR, test.APIADDR)
// test.InOutDoTest(strMyUidx, tokenx, test.WSADDR, test.APIADDR)
// time.Sleep(5 * time.Second)
// test.SetListenerAndLogin(strMyUidx, tokenx)
//test.DoTestSetGroupMemberInfo("1104164664", "3188816039", "set ex")
// test.DotestGetGroupMemberList()
//time.Sleep(100000 * time.Second)
// test.DoTestCreateGroup()
// test.DoTestJoinGroup()
// test.DoTestGetGroupsInfo()
// test.DoTestDeleteAllMsgFromLocalAndSvr()
// println("token ", tokenx)
time.Sleep(100000 * time.Second)
b := utils.GetCurrentTimestampBySecond()
i := 0
for {
test.DoTestSendMsg2c2c(strMyUidx, "3380999461", i)
i++
time.Sleep(100 * time.Millisecond)
if i == 10000 {
break
}
log.ZWarn(ctx, "", errors.New(""), "10 * time.Millisecond ###################waiting... msg: ", i)
}
//log.Warn("", "cost time: ", utils.GetCurrentTimestampBySecond()-b)
time.Sleep(100000 * time.Second)
return
i = 0
for {
test.DoTestSendMsg2Group(strMyUidx, "42c9f515cb84ee0e82b3f3ce71eb14d6", i)
i++
time.Sleep(1000 * time.Millisecond)
if i == 10 {
break
}
log.ZWarn(ctx, "", errors.New(""), "1000 * time.Millisecond ###################waiting... msg: ", i)
}
i = 0
for {
test.DoTestSendMsg2Group(strMyUidx, "42c9f515cb84ee0e82b3f3ce71eb14d6", i)
i++
time.Sleep(10000 * time.Millisecond)
log.ZWarn(ctx, "", errors.New(""), "10000 * time.Millisecond ###################waiting... msg: ", i)
}
//reliabilityTest()
// test.PressTest(testClientNum, intervalSleep, imIP)
}
//
//funcation main() {
// testClientNum := 100
// intervalSleep := 2
// imIP := "43.128.5.63"
//
// msgNum := 1000
// test.ReliabilityTest(msgNum, intervalSleep, imIP)
// for i := 0; i < 6; i++ {
// test.Msgwg.Wait()
// }
//
// for {
//
// if test.CheckReliabilityResult() {
// log.Warn("CheckReliabilityResult ok, again")
//
// } else {
// log.Warn("CheckReliabilityResult failed , wait.... ")
// }
//
// time.Sleep(time.Duration(10) * time.Second)
// }
//
//}
//funcation printCallerNameAndLine() string {
// pc, _, line, _ := runtime.Caller(2)
// return runtime.FuncForPC(pc).Name() + "()@" + strconv.Itoa(line) + ": "
//}
// myuid, maxuid, msgnum