-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheasycall_test.go
180 lines (139 loc) · 3.08 KB
/
easycall_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package easycall
import (
"bytes"
"encoding/binary"
"encoding/json"
"errors"
"flag"
"fmt"
"math/rand"
"reflect"
"runtime"
"testing"
"github.com/starjiang/elog"
"github.com/vmihailenco/msgpack"
)
func TestBinary(t *testing.T) {
var data = make([]byte, 100)
buffer := bytes.NewBuffer(data)
var a int16 = 10
var b uint32 = 200
var c uint64 = 23
var d int16 = 10
err := binary.Write(buffer, binary.BigEndian, a)
if err != nil {
fmt.Println(err)
}
binary.Write(buffer, binary.BigEndian, b)
binary.Write(buffer, binary.BigEndian, c)
binary.Write(buffer, binary.BigEndian, d)
var a1 int8 = 20
err1 := binary.Read(buffer, binary.BigEndian, &a1)
if err1 != nil {
fmt.Println(err1)
}
fmt.Printf("%v,%v\n", data, a1)
}
func TestReflect(t *testing.T) {
pkg := &EasyPackage{}
info := reflect.ValueOf(pkg)
m := info.MethodByName("SetHead")
head := &EasyHead{}
head.Service = "profile"
args := []reflect.Value{
reflect.ValueOf(head),
}
m.Call(args)
fmt.Println(pkg.GetHead().Service)
}
func TestJsonTag(t *testing.T) {
head := &EasyHead{Service: "abc"}
var buf bytes.Buffer
encode := msgpack.NewEncoder(&buf).UseJSONTag(true)
err := encode.Encode(head)
if err != nil {
fmt.Println(err)
return
}
head.Service = ""
fmt.Println(string(buf.Bytes()))
decode := msgpack.NewDecoder(bytes.NewReader(buf.Bytes())).UseJSONTag(true)
decode.Decode(head)
fmt.Println(head)
}
func TestGetLocalIp(t *testing.T) {
fmt.Println(GetLocalIp())
}
func TestRandIntn(t *testing.T) {
for i := 0; i < 100; i++ {
fmt.Println(rand.Intn(10))
}
}
func TestFuncCaller(t *testing.T) {
_, file, line, ok := runtime.Caller(0)
fmt.Println(file, line, ok)
}
func TestEasyLog(t *testing.T) {
defer elog.Flush()
flag.Parse()
elog.Info(111, "sdsdsdsd")
}
func TestJsonByteBuffer(t *testing.T) {
head := NewEasyHead().SetService("profile").SetMethod("getProfile")
var buf bytes.Buffer
json.NewEncoder(&buf).Encode(head)
json.NewEncoder(&buf).Encode(head)
fmt.Println(string(buf.Bytes()))
}
func TestFloat(t *testing.T) {
f := float32(1) / float32(3)
fmt.Println(f)
}
var count = 0
func getUserName() error {
if count > 15 {
return nil
}
count++
return errors.New("invalid params")
}
func fail() error {
fmt.Println("fall")
return nil
}
func TestCircuitBreaker(t *testing.T) {
for i := 0; i < 100; i++ {
err := CbCall("hello", getUserName, nil)
fmt.Println(err)
}
}
type TConfig struct {
ThreadNum int
Name string
Port int
IsExsit bool
FailRate float32
UserList []int64
UserMap map[string]int64
UserMap1 map[string]bool
UserMap2 map[string]float64
UserMap3 map[string]string
}
func TestEasyConfig(t *testing.T) {
config := NewEasyConfig()
err := config.Load("./config.ini")
if err != nil {
fmt.Println(err)
}
tconfig := &TConfig{}
fmt.Println(config.GetInt64("easycall.port", 10))
config.GetConfig("easycall.", tconfig)
fmt.Println(tconfig)
tconfig1 := &TConfig{}
config = GetConfig()
fmt.Println(config.GetInt64("easycall.port", 10))
config.GetConfig("easycall.", tconfig1)
fmt.Println(tconfig1)
}
func TestSyncMap(t *testing.T) {
}