You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.4 KiB
Go
70 lines
1.4 KiB
Go
package starmap
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
type Miaomiao struct {
|
|
Sakura string
|
|
Fuck int
|
|
Mimi bool
|
|
}
|
|
|
|
func Test_Remote(t *testing.T) {
|
|
Store("nmb", 22222)
|
|
server, err := NewServer("127.0.0.1:45678")
|
|
server.Register(&Miaomiao{})
|
|
fmt.Println(err)
|
|
client, err := NewClient("127.0.0.1:45678")
|
|
client.SetKeepAlive(false)
|
|
fmt.Println(err)
|
|
_ = server
|
|
fmt.Println(client.Get("nmb"))
|
|
fmt.Println(client.Store("maio", Miaomiao{"sss", 222, true}))
|
|
fmt.Println(client.Get("maio"))
|
|
}
|
|
|
|
func (cat *Miaomiao) GetName() string {
|
|
return "miaomiao"
|
|
}
|
|
func Test_Remote2(t *testing.T) {
|
|
server, err := NewServer("127.0.0.1:45678")
|
|
server.Register(&Miaomiao{})
|
|
fmt.Println(err)
|
|
client, err := NewClient("127.0.0.1:45678")
|
|
//client.SetKeepAlive(false)
|
|
fmt.Println(err)
|
|
_ = server
|
|
fmt.Println(client.StoreMap(&Miaomiao{"suki", 1127, false}))
|
|
fmt.Println(client.GetMap("miaomiao"))
|
|
}
|
|
|
|
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)
|
|
}
|