diff --git a/test/mongo/cmd/main.go b/test/mongo/cmd/main.go deleted file mode 100644 index 7873fee90..000000000 --- a/test/mongo/cmd/main.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright © 2023 OpenIM. 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 ( - "Open_IM/pkg/common/config" - mongo2 "Open_IM/test/mongo" - "context" - "flag" - "fmt" - - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" -) - -func init() { - uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority" - if config.Config.Mongo.DBUri != "" { - // example: - // mongodb://$user:$password@mongo1.mongo:27017,mongo2.mongo:27017,mongo3.mongo:27017/$DBDatabase/?replicaSet=rs0&readPreference=secondary&authSource=admin&maxPoolSize=$DBMaxPoolSize - uri = config.Config.Mongo.DBUri - } else { - if config.Config.Mongo.DBPassword != "" && config.Config.Mongo.DBUserName != "" { - uri = fmt.Sprintf("mongodb://%s:%s@%s/%s?maxPoolSize=%d", config.Config.Mongo.DBUserName, config.Config.Mongo.DBPassword, config.Config.Mongo.DBAddress[0], - config.Config.Mongo.DBDatabase, config.Config.Mongo.DBMaxPoolSize) - } else { - uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d", - config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase, - config.Config.Mongo.DBMaxPoolSize) - } - } - var err error - mongo2.Client, err = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) - if err != nil { - panic(err) - } - err = mongo2.Client.Ping(context.TODO(), nil) - if err != nil { - panic(err) - } - fmt.Println("Connected to MongoDB!") -} - -func main() { - userID := flag.String("userID", "", "userID") - flag.Parse() - fmt.Println("userID:", *userID) - mongo2.GetUserAllChat(*userID) -} diff --git a/test/mongo/mongo_utils.go b/test/mongo/mongo_utils.go deleted file mode 100644 index 18cdcbea3..000000000 --- a/test/mongo/mongo_utils.go +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright © 2023 OpenIM. 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 mongo - -import ( - "Open_IM/pkg/common/config" - server_api_params "Open_IM/pkg/proto/sdk_ws" - "context" - "fmt" - "time" - - "github.com/golang/protobuf/proto" - "go.mongodb.org/mongo-driver/mongo" - "gopkg.in/mgo.v2/bson" -) - -var ( - Client *mongo.Client -) - -type MsgInfo struct { - SendTime int64 - Msg []byte -} - -type UserChat struct { - UID string - Msg []MsgInfo -} - -func GetUserAllChat(uid string) { - ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second) - collection := Client.Database(config.Config.Mongo.DBDatabase).Collection("msg") - var userChatList []UserChat - uid = uid + ":" - filter := bson.M{"uid": bson.M{"$regex": uid}} - //filter := bson.M{"uid": "17726378428:0"} - result, err := collection.Find(context.Background(), filter) - if err != nil { - fmt.Println("find error", err.Error()) - return - } - if err := result.All(ctx, &userChatList); err != nil { - fmt.Println(err.Error()) - } - for _, userChat := range userChatList { - for _, msg := range userChat.Msg { - msgData := &server_api_params.MsgData{} - err := proto.Unmarshal(msg.Msg, msgData) - if err != nil { - fmt.Println(err.Error(), msg) - continue - } - fmt.Println("seq: ", msgData.Seq, "status: ", msgData.Status, - "sendID: ", msgData.SendID, "recvID: ", msgData.RecvID, - "sendTime: ", msgData.SendTime, - "clientMsgID: ", msgData.ClientMsgID, - "serverMsgID: ", msgData.ServerMsgID, - "content: ", string(msgData.Content)) - } - } -} diff --git a/test/mysql/cmd/main.go b/test/mysql/cmd/main.go deleted file mode 100644 index b3d73b8db..000000000 --- a/test/mysql/cmd/main.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright © 2023 OpenIM. 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 ( - "Open_IM/test/mysql" -) - -func main() { - mysql.ImportUserToSuperGroup() -} diff --git a/test/mysql/importuser.go b/test/mysql/importuser.go deleted file mode 100644 index 07d97340d..000000000 --- a/test/mysql/importuser.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright © 2023 OpenIM. 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 mysql - -import ( - "Open_IM/pkg/common/db" - "Open_IM/pkg/common/db/mysql_model/im_mysql_model" - "Open_IM/pkg/common/log" - "strconv" - "time" -) - -func ImportUserToSuperGroup() { - for i := 18000000700; i <= 18000000800; i++ { - user := db.User{ - UserID: strconv.Itoa(i), - Nickname: strconv.Itoa(i), - FaceURL: "", - Gender: 0, - PhoneNumber: strconv.Itoa(i), - Birth: time.Time{}, - Email: "", - Ex: "", - CreateTime: time.Time{}, - AppMangerLevel: 0, - GlobalRecvMsgOpt: 0, - } - err := im_mysql_model.UserRegister(user) - if err != nil { - log.NewError("", err.Error(), user) - continue - } - - groupMember := db.GroupMember{ - GroupID: "3907826375", - UserID: strconv.Itoa(i), - Nickname: strconv.Itoa(i), - FaceURL: "", - RoleLevel: 0, - JoinTime: time.Time{}, - JoinSource: 0, - InviterUserID: "openIMAdmin", - OperatorUserID: "openIMAdmin", - MuteEndTime: time.Time{}, - Ex: "", - } - - err = im_mysql_model.InsertIntoGroupMember(groupMember) - if err != nil { - log.NewError("", err.Error(), user) - continue - } - - log.NewInfo("success", i) - - } - -}