forked from gmsec/micro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
micro_test.go
48 lines (40 loc) · 998 Bytes
/
micro_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package micro
import (
"fmt"
"os"
"testing"
"time"
"github.com/gmsec/micro/registry"
)
func TestMain(t *testing.T) {
reg := registry.NewDNSNamingRegistry()
os.Setenv("MICRO_DEBUG_PROFILE", "true")
// 初始化服务
service := NewService(
WithName("lp.srv.eg1"),
WithRegisterTTL(time.Second*30), //指定服务注册时间
WithRegisterInterval(time.Second*15), //让服务在指定时间内重新注册
)
service.Init(WithRegistryNaming(reg))
// server
go func() {
// RegisterHelloServer(service.Server(), &hello{})
// run server
if err := service.Run(); err != nil {
panic(err)
}
fmt.Println("stop service")
}()
// client
SetClientServiceName("proto.Hello", "lp.srv.eg1") // set client group
GetService("lp.srv.eg1")
GetClient("proto.Hello")
service.Options()
service.Client()
service.Server()
service.String()
service.Stop()
// process, _ := os.FindProcess(os.Getpid())
// process.Signal(syscall.SIGTERM)
// time.Sleep(1 * time.Second)
}