starmap/starmap_test.go

60 lines
1.2 KiB
Go
Raw Normal View History

2020-07-20 11:24:42 +08:00
package starmap
import (
"fmt"
2020-12-21 17:28:32 +08:00
"math/rand"
2020-07-20 11:24:42 +08:00
"testing"
2020-12-21 17:28:32 +08:00
"time"
2020-07-20 11:24:42 +08:00
)
type Miaomiao struct {
2023-02-11 17:51:30 +08:00
Val1 string
Val2 int
Val3 bool
2020-07-20 11:24:42 +08:00
}
func Test_Remote(t *testing.T) {
2023-02-11 17:51:30 +08:00
Store("test", 22222)
server, _ := NewServer("tcp", "127.0.0.1:45678")
2020-07-20 11:24:42 +08:00
server.Register(&Miaomiao{})
client, _ := NewClient("tcp", "127.0.0.1:45678", time.Second*2)
2020-07-20 11:24:42 +08:00
_ = server
2023-02-11 17:51:30 +08:00
fmt.Println(client.Get("meow"))
fmt.Println(client.Exists("meow"))
fmt.Println(client.Store("meow", Miaomiao{"sss", 222, true}))
fmt.Println(client.Get("meow"))
fmt.Println(client.Exists("meow"))
fmt.Println(client.Delete("meow"))
fmt.Println(client.Exists("meow"))
2020-07-20 11:24:42 +08:00
}
func (cat *Miaomiao) GetName() string {
2023-02-11 17:51:30 +08:00
return "meow"
2020-07-20 11:24:42 +08:00
}
2020-12-21 17:28:32 +08:00
func Test_Math(t *testing.T) {
wg := NewWaitGroup(5000)
rand.Seed(time.Now().UnixNano())
waitfn := func(wg *WaitGroup, num int) {
defer wg.Done()
fmt.Println(num)
time.Sleep(time.Second * time.Duration(2+rand.Intn(3)))
}
for i := 0; i <= 3214670; i++ {
wg.Add(1)
if i == 34567 {
wg.SetMaxWaitNum(50000)
}
if i == 123456 {
wg.SetMaxWaitNum(210456)
}
if i == 323456 {
wg.SetMaxWaitNum(2104562)
}
go waitfn(&wg, i)
}
fmt.Println("Waiting~~~~~~~~~~")
wg.Wait()
fmt.Println(wg.allCount)
}