2023-08-30 13:15:44 +09:00
|
|
|
// package main ...
|
|
|
|
|
package session
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
|
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestExpTable(t *testing.T) {
|
2023-08-30 15:43:26 +09:00
|
|
|
// pv, err := NewProviderWithRedis(context.Background(), "redis://192.168.8.94:6380/1", 10*time.Second)
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// t.Error(err)
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// cs, err := NewConsumerWithRedis(context.Background(), "redis://192.168.8.94:6380/1", 10*time.Second)
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// t.Error(err)
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
pv, err := NewProviderWithMongo(context.Background(), "mongodb://192.168.8.94:27017/?replicaSet=repl01&retrywrites=false", "maingate", 10*time.Second)
|
2023-08-30 13:15:44 +09:00
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 15:43:26 +09:00
|
|
|
cs, err := NewConsumerWithMongo(context.Background(), "mongodb://192.168.8.94:27017/?replicaSet=repl01&retrywrites=false", "maingate", 10*time.Second)
|
2023-08-30 13:15:44 +09:00
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 15:43:26 +09:00
|
|
|
sk1 := primitive.NewObjectID().Hex()
|
|
|
|
|
sk2 := primitive.NewObjectID().Hex()
|
2023-08-30 13:15:44 +09:00
|
|
|
go func() {
|
|
|
|
|
for {
|
2023-08-30 18:23:19 +09:00
|
|
|
q1, err := cs.Query(sk1)
|
|
|
|
|
logger.Println("query :", q1, err)
|
|
|
|
|
|
|
|
|
|
q2, err := cs.Query(sk2)
|
|
|
|
|
logger.Println("query :", q2, err)
|
2023-08-30 13:15:44 +09:00
|
|
|
time.Sleep(time.Second)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
time.Sleep(2 * time.Second)
|
2023-08-30 15:43:26 +09:00
|
|
|
pv.Update(sk1, &Authorization{
|
|
|
|
|
Account: primitive.NewObjectID(),
|
2023-08-30 13:15:44 +09:00
|
|
|
Platform: "editor",
|
|
|
|
|
Uid: "uid-1",
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
time.Sleep(2 * time.Second)
|
2023-08-30 15:43:26 +09:00
|
|
|
pv.Update(sk2, &Authorization{
|
|
|
|
|
Account: primitive.NewObjectID(),
|
2023-08-30 13:15:44 +09:00
|
|
|
Platform: "editor",
|
|
|
|
|
Uid: "uid-2",
|
|
|
|
|
})
|
|
|
|
|
|
2023-08-30 15:43:26 +09:00
|
|
|
cs.Touch(sk1)
|
2023-08-30 13:15:44 +09:00
|
|
|
time.Sleep(2 * time.Second)
|
2023-08-30 15:43:26 +09:00
|
|
|
cs.Touch(sk2)
|
2023-08-30 13:15:44 +09:00
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
|
|
|
|
|
|
time.Sleep(2 * time.Second)
|
2023-08-30 15:43:26 +09:00
|
|
|
pv.Delete(sk1)
|
2023-08-30 13:15:44 +09:00
|
|
|
|
2023-08-30 15:43:26 +09:00
|
|
|
cs.Touch(sk1)
|
2023-08-30 13:15:44 +09:00
|
|
|
time.Sleep(2 * time.Second)
|
2023-08-30 15:43:26 +09:00
|
|
|
cs.Touch(sk2)
|
2023-08-30 13:15:44 +09:00
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
|
|
2023-08-30 15:43:26 +09:00
|
|
|
cs2, err := NewConsumerWithRedis(context.Background(), "redis://192.168.8.94:6380/1", 10*time.Second)
|
2023-08-30 13:15:44 +09:00
|
|
|
if err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-30 18:23:19 +09:00
|
|
|
q2, err := cs2.Query(sk2)
|
|
|
|
|
logger.Println("queryf :", q2, err)
|
2023-08-30 13:15:44 +09:00
|
|
|
time.Sleep(20 * time.Second)
|
|
|
|
|
}
|