How to use Center method of proto Package

Best Rod code snippet using proto.Center

cluster_test.go

Source:cluster_test.go Github

copy

Full Screen

1package cluster2//go test -covermode=count -v -coverprofile=coverage.out -run=.3//go tool cover -html=coverage.out4import (5 "errors"6 "fmt"7 "github.com/golang/protobuf/proto"8 fnet "github.com/sniperHW/flyfish/pkg/net"9 "github.com/stretchr/testify/assert"10 center "initialthree/center"11 center_proto "initialthree/center/protocol"12 "initialthree/cluster/addr"13 cluster_proto "initialthree/cluster/proto"14 "initialthree/cluster/rpcerr"15 "initialthree/common"16 "initialthree/pkg/rpc"17 "initialthree/pkg/timer"18 "initialthree/protocol/cmdEnum"19 _ "initialthree/protocol/ss" //触发pb注册20 ss_rpc "initialthree/protocol/ss/rpc"21 ss_msg "initialthree/protocol/ss/ssmessage"22 "initialthree/zaplogger"23 "math/rand"24 "testing"25 "time"26)27var centerAddr string = "127.0.0.1:8000"28func init() {29 logger := zaplogger.NewZapLogger("test_cluster.log", "log", "debug", 100, 14, 10, true)30 InitLogger(logger)31 rand.Seed(time.Now().Unix())32}33func TestDiff2(t *testing.T) {34 {35 a := []uint32{uint32(1), uint32(2)}36 b := []uint32{}37 add, remove := diff2(a, b)38 assert.Equal(t, 0, len(remove))39 assert.Equal(t, 2, len(add))40 }41 {42 a := []uint32{}43 b := []uint32{uint32(1), uint32(2)}44 add, remove := diff2(a, b)45 assert.Equal(t, 0, len(add))46 assert.Equal(t, 2, len(remove))47 }48 {49 a := []uint32{1, 3, 4}50 b := []uint32{uint32(1), uint32(2)}51 add, remove := diff2(a, b)52 assert.Equal(t, 3, len(add))53 assert.Equal(t, 1, len(remove))54 assert.Equal(t, uint32(1), add[0])55 assert.Equal(t, uint32(3), add[1])56 assert.Equal(t, uint32(4), add[2])57 assert.Equal(t, uint32(2), remove[0])58 }59 {60 a := []uint32{1, 2}61 b := []uint32{1, 3, 4}62 add, remove := diff2(a, b)63 assert.Equal(t, 2, len(add))64 assert.Equal(t, 2, len(remove))65 assert.Equal(t, uint32(1), add[0])66 assert.Equal(t, uint32(2), add[1])67 assert.Equal(t, uint32(3), remove[0])68 assert.Equal(t, uint32(4), remove[1])69 }70}71func TestDiff(t *testing.T) {72 {73 a := []*center_proto.NodeInfo{74 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(1))},75 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(2))},76 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(3))},77 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(4))},78 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(5))},79 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(6))},80 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(7))},81 }82 b := []*center_proto.NodeInfo{83 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(3))},84 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(5))},85 }86 addI := []uint32{1, 2, 3, 4, 5, 6, 7}87 add, remove := diff(a, b)88 assert.Equal(t, len(add), len(addI))89 for k, v := range add {90 assert.Equal(t, v.GetLogicAddr(), addI[k])91 }92 assert.Equal(t, len(remove), 0)93 }94 {95 a := []*center_proto.NodeInfo{}96 b := []*center_proto.NodeInfo{97 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(3))},98 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(5))},99 }100 removeI := []uint32{3, 5}101 add, remove := diff(a, b)102 assert.Equal(t, len(add), 0)103 assert.Equal(t, len(remove), len(removeI))104 for k, v := range remove {105 assert.Equal(t, v.GetLogicAddr(), removeI[k])106 }107 }108 {109 a := []*center_proto.NodeInfo{110 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(1))},111 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(3))},112 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(5))},113 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(7))},114 }115 b := []*center_proto.NodeInfo{116 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(5))},117 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(3))},118 &center_proto.NodeInfo{LogicAddr: proto.Uint32(uint32(6))},119 }120 add, remove := diff(a, b)121 addI := []uint32{1, 3, 5, 7}122 removeI := []uint32{6}123 assert.Equal(t, len(add), len(addI))124 for k, v := range add {125 assert.Equal(t, v.GetLogicAddr(), addI[k])126 }127 assert.Equal(t, len(remove), len(removeI))128 for k, v := range remove {129 assert.Equal(t, v.GetLogicAddr(), removeI[k])130 }131 }132}133type uniLocker struct {134 lockReturnFalse bool135}136func (this uniLocker) Lock(_ addr.Addr) bool {137 if this.lockReturnFalse {138 return false139 } else {140 return true141 }142}143func (this uniLocker) Unlock() {144}145func TestMsgManager(t *testing.T) {146 node1 := NewCluster()147 node1.Register(uint16(1), nil)148 node1.Register(uint16(1), func(from addr.LogicAddr, msg proto.Message) {149 fmt.Println("1 func")150 })151 node1.Register(uint16(1), func(from addr.LogicAddr, msg proto.Message) {})152 node1.SetPeerDisconnected(func(addr.LogicAddr, error) { panic("test error") })153 node1.onPeerDisconnected(addr.LogicAddr(0), nil)154 node1.dispatch(addr.LogicAddr(0), nil, uint16(1), nil)155 node1.Register(uint16(2), func(from addr.LogicAddr, msg proto.Message) {156 panic("test error")157 })158 node1.msgMgr.dispatch(addr.LogicAddr(0), uint16(2), nil)159 node1.msgMgr.dispatch(addr.LogicAddr(0), uint16(3), nil)160}161func TestEndPoint(t *testing.T) {162 {163 center1 := center.New()164 go func() {165 center1.Start(centerAddr, logger)166 fmt.Println("center1 stop")167 }()168 back := common.HeartBeat_Timeout169 common.HeartBeat_Timeout = time.Second * 6170 //测试连接通道空闲超时关闭171 node1 := NewCluster()172 node1.Register(cmdEnum.SS_Echo, func(from addr.LogicAddr, msg proto.Message) {173 fmt.Println("get echo from", from)174 })175 node2 := NewCluster()176 {177 addr_, _ := addr.MakeAddr("1.1.1", "127.0.0.1:8001")178 assert.Equal(t, nil, node1.Start([]string{centerAddr}, addr_, uniLocker{}))179 }180 {181 addr_, _ := addr.MakeAddr("1.2.2", "127.0.0.1:8002")182 assert.Equal(t, nil, node2.Start([]string{centerAddr}, addr_, uniLocker{}))183 }184 node1Addr, _ := addr.MakeLogicAddr("1.1.1")185 //等待从center接收到node1的信息186 for nil == node2.serviceMgr.getEndPoint(node1Addr) {187 time.Sleep(time.Second)188 }189 node2.PostMessage(node1Addr, &ss_msg.Echo{190 Message: proto.String("hello"),191 })192 time.Sleep((common.HeartBeat_Timeout * 2))193 var s *fnet.Socket194 e := node2.serviceMgr.getEndPoint(node1Addr)195 e.Lock()196 s = e.session197 e.Unlock()198 assert.Nil(t, s)199 node1.Stop(nil)200 node1 = NewCluster()201 fmt.Println("---------------------- test1 -------------------------")202 {203 //用一个不同的物理地址启动实例204 addr_, _ := addr.MakeAddr("1.1.1", "127.0.0.1:8003")205 assert.Equal(t, nil, node1.Start([]string{centerAddr}, addr_, uniLocker{}))206 }207 time.Sleep(time.Second)208 fmt.Println("---------------------- test2 -------------------------")209 common.HeartBeat_Timeout = back210 back = delayRemoveEndPointTime211 delayRemoveEndPointTime = time.Second * 2212 center1.Stop()213 time.Sleep(time.Second * 2)214 //重启center215 center1 = center.New()216 go func() {217 center1.Start(centerAddr, logger)218 }()219 time.Sleep(delayRemoveEndPointTime * 3)220 fmt.Println("---------------------- test3 -------------------------")221 center1.Stop()222 node1.Stop(nil)223 time.Sleep(time.Second * 2)224 //再次重启center225 center1 = center.New()226 go func() {227 center1.Start(centerAddr, logger)228 }()229 time.Sleep(delayRemoveEndPointTime * 3)230 node2.Stop(nil)231 center1.Stop()232 delayRemoveEndPointTime = back233 }234}235func TestBothConnect(t *testing.T) {236 center1 := center.New()237 go func() {238 center1.Start(centerAddr, logger)239 }()240 node1 := NewCluster()241 node2 := NewCluster()242 cc1 := make(chan struct{})243 cc2 := make(chan struct{})244 node1.RegisterMethod(&ss_rpc.EchoReq{}, func(replyer *rpc.RPCReplyer, arg interface{}) {245 echoResp := &ss_rpc.EchoResp{}246 echoResp.Message = proto.String("world")247 replyer.Reply(echoResp, nil)248 })249 node2.RegisterMethod(&ss_rpc.EchoReq{}, func(replyer *rpc.RPCReplyer, arg interface{}) {250 echoResp := &ss_rpc.EchoResp{}251 echoResp.Message = proto.String("world")252 replyer.Reply(echoResp, nil)253 })254 {255 addr_, _ := addr.MakeAddr("1.1.1", "127.0.0.1:8001")256 assert.Equal(t, nil, node1.Start([]string{centerAddr}, addr_, uniLocker{}))257 }258 {259 addr_, _ := addr.MakeAddr("1.2.2", "127.0.0.1:8002")260 assert.Equal(t, nil, node2.Start([]string{centerAddr}, addr_, uniLocker{}))261 }262 for {263 _, err := node2.Random(1)264 if nil != err {265 time.Sleep(time.Second)266 } else {267 break268 }269 }270 for {271 _, err := node1.Random(2)272 if nil != err {273 time.Sleep(time.Second)274 } else {275 break276 }277 }278 go func() {279 nodeAddr, _ := addr.MakeLogicAddr("1.2.2")280 node1.AsynCall(nodeAddr, &ss_rpc.EchoReq{Message: proto.String("hello")}, time.Second, func(result interface{}, err error) {281 fmt.Println(err)282 if nil != result {283 close(cc1)284 }285 })286 }()287 go func() {288 nodeAddr, _ := addr.MakeLogicAddr("1.1.1")289 node2.AsynCall(nodeAddr, &ss_rpc.EchoReq{Message: proto.String("hello")}, time.Second, func(result interface{}, err error) {290 fmt.Println(err)291 if nil != result {292 close(cc2)293 }294 })295 }()296 <-cc1297 <-cc2298 node1.Stop(nil)299 node2.Stop(nil)300 center1.Stop()301}302func TestPostMessage(t *testing.T) {303 center1 := center.New()304 go func() {305 center1.Start(centerAddr, logger)306 }()307 node1 := NewCluster()308 cc := make(chan struct{})309 node1.Register(cmdEnum.SS_Echo, func(from addr.LogicAddr, msg proto.Message) {310 if from != node1.SelfAddr().Logic {311 fmt.Println("get echo from", from)312 echo := &ss_msg.Echo{}313 echo.Message = proto.String("world")314 node1.PostMessage(from, echo)315 }316 })317 node2 := NewCluster()318 node2.Register(cmdEnum.SS_Echo, func(from addr.LogicAddr, msg proto.Message) {319 fmt.Println("get echo resp from", from)320 cc <- struct{}{}321 })322 {323 n := NewCluster()324 addr_, _ := addr.MakeAddr("1.1.1", "127.0.0.1:8001")325 assert.NotNil(t, n.Start([]string{centerAddr}, addr_, uniLocker{lockReturnFalse: true}))326 }327 {328 assert.Equal(t, ERR_SERVERADDR_ZERO, node1.Start([]string{centerAddr}, addr.Addr{}, uniLocker{}))329 addr_, _ := addr.MakeAddr("1.1.1", "127.0.0.1:8001")330 assert.Equal(t, nil, node1.Start([]string{centerAddr}, addr_, uniLocker{}))331 assert.Equal(t, ERR_STARTED, node1.Start([]string{centerAddr}, addr_, uniLocker{}))332 node1.GetEventQueue()333 node1.PostTask(func() { fmt.Println("test") })334 node1.SelfAddr()335 }336 node2.PostMessage(addr.LogicAddr(0), &ss_msg.Echo{337 Message: proto.String("hello"),338 })339 {340 addr1, _ := addr.MakeLogicAddr("1.1.10")341 node1.PostMessage(addr1, &ss_msg.Echo{342 Message: proto.String("hello"),343 })344 addr2, _ := addr.MakeLogicAddr("2.1.10")345 node1.PostMessage(addr2, &ss_msg.Echo{346 Message: proto.String("hello"),347 })348 }349 {350 addr_, _ := addr.MakeAddr("1.2.2", "127.0.0.1:8002")351 assert.Equal(t, nil, node2.Start([]string{centerAddr}, addr_, uniLocker{}))352 }353 node2.PostMessage(addr.LogicAddr(0), &ss_msg.Echo{354 Message: proto.String("hello"),355 })356 node1Addr, _ := addr.MakeLogicAddr("1.1.1")357 //等待从center接收到node1的信息358 for nil == node2.serviceMgr.getEndPoint(node1Addr) {359 time.Sleep(time.Second)360 }361 node2.PostMessage(node1Addr, &ss_msg.Echo{362 Message: proto.String("hello"),363 })364 //向自己发365 node1.PostMessage(node1Addr, &ss_msg.Echo{366 Message: proto.String("hello"),367 })368 _ = <-cc369 node1Addr, err := node2.Random(1)370 assert.Equal(t, nil, err)371 node2.PostMessage(node1Addr, &ss_msg.Echo{372 Message: proto.String("hello"),373 })374 _ = <-cc375 node1Addr, err = node2.Mod(1, 10)376 assert.Equal(t, nil, err)377 node2.PostMessage(node1Addr, &ss_msg.Echo{378 Message: proto.String("hello"),379 })380 _ = <-cc381 addrs, err := node1.Select(1)382 assert.Equal(t, nil, err)383 node2.PostMessage(addrs[0], &ss_msg.Echo{384 Message: proto.String("hello"),385 })386 _ = <-cc387 node2.Brocast(1, &ss_msg.Echo{388 Message: proto.String("hello"),389 })390 _ = <-cc391 node2.BrocastToAll(&ss_msg.Echo{392 Message: proto.String("hello"),393 }, 2)394 _ = <-cc395 node1.Stop(func() {396 fmt.Println("test stop func")397 })398 node2.Stop(nil)399 center1.Stop()400}401func TestExportMethod(t *testing.T) {402 center1 := center.New()403 go func() {404 center1.Start(centerAddr, logger)405 }()406 node1 := NewCluster()407 cc := make(chan struct{})408 node1.RegisterMethod(&ss_rpc.EchoReq{}, func(replyer *rpc.RPCReplyer, arg interface{}) {409 echo := arg.(*ss_rpc.EchoReq)410 logger.Sugar().Infof("echo message:%s\n", echo.GetMessage())411 echoResp := &ss_rpc.EchoResp{}412 echoResp.Message = proto.String("world")413 replyer.Reply(echoResp, nil)414 })415 node1.Register(cmdEnum.SS_Echo, func(from addr.LogicAddr, msg proto.Message) {416 if from != node1.SelfAddr().Logic {417 fmt.Println("get echo from", from)418 echo := &ss_msg.Echo{}419 echo.Message = proto.String("world")420 node1.PostMessage(from, echo)421 }422 })423 Register(cmdEnum.SS_Echo, func(from addr.LogicAddr, msg proto.Message) {424 fmt.Println("get echo resp from", from)425 cc <- struct{}{}426 })427 RegisterMethod(&ss_rpc.EchoReq{}, func(replyer *rpc.RPCReplyer, arg interface{}) {428 echo := arg.(*ss_rpc.EchoReq)429 logger.Sugar().Infof("echo message:%s\n", echo.GetMessage())430 echoResp := &ss_rpc.EchoResp{}431 echoResp.Message = proto.String("world")432 replyer.Reply(echoResp, nil)433 })434 node1Addr, _ := addr.MakeLogicAddr("1.1.1")435 AsynCall(node1Addr, &ss_rpc.EchoReq{Message: proto.String("hello")}, time.Second, func(result interface{}, err error) {436 })437 {438 addr_, _ := addr.MakeAddr("1.1.1", "127.0.0.1:8001")439 assert.Equal(t, nil, node1.Start([]string{centerAddr}, addr_, uniLocker{}))440 }441 {442 addr_, _ := addr.MakeAddr("1.2.2", "127.0.0.1:8002")443 assert.Equal(t, nil, Start([]string{centerAddr}, addr_, uniLocker{}))444 }445 SelfAddr()446 GetEventQueue()447 assert.Equal(t, false, IsStoped())448 AsynCall(addr.LogicAddr(0), &ss_rpc.EchoReq{Message: proto.String("hello")}, time.Second, func(result interface{}, err error) {449 cc <- struct{}{}450 })451 _ = <-cc452 //等待从center接收到node1的信息453 for {454 _, err := Random(1)455 if nil != err {456 time.Sleep(time.Second)457 } else {458 break459 }460 }461 _, err := Mod(1, 1)462 assert.Equal(t, nil, err)463 e, _ := Select(1)464 assert.Equal(t, 1, len(e))465 fmt.Println("test 1")466 PostMessage(node1Addr, &cluster_proto.Heartbeat{})467 PostMessage(node1Addr, &ss_msg.Echo{468 Message: proto.String("hello"),469 })470 _ = <-cc471 Brocast(1, &ss_msg.Echo{472 Message: proto.String("hello"),473 })474 _ = <-cc475 BrocastToAll(&ss_msg.Echo{476 Message: proto.String("hello"),477 }, 2)478 _ = <-cc479 fmt.Println("test 2")480 //异步调用481 AsynCall(node1Addr, &ss_rpc.EchoReq{Message: proto.String("hello")}, time.Second, func(result interface{}, err error) {482 assert.Equal(t, result.(*ss_rpc.EchoResp).GetMessage(), "world")483 cc <- struct{}{}484 })485 _ = <-cc486 fmt.Println("test 21")487 {488 nodeAddr, _ := addr.MakeLogicAddr("2.1.1")489 AsynCall(nodeAddr, &ss_rpc.EchoReq{Message: proto.String("hello")}, time.Second, func(result interface{}, err error) {490 cc <- struct{}{}491 })492 _ = <-cc493 }494 fmt.Println("test 22")495 {496 nodeAddr, _ := addr.MakeLogicAddr("1.1.2")497 AsynCall(nodeAddr, &ss_rpc.EchoReq{Message: proto.String("hello")}, time.Second, func(result interface{}, err error) {498 cc <- struct{}{}499 })500 _ = <-cc501 }502 fmt.Println("test 23")503 PostTask(func() {504 cc <- struct{}{}505 })506 fmt.Println("test 24")507 _ = <-cc508 RegisterTimerOnce(time.Second, func(*timer.Timer, interface{}) {509 cc <- struct{}{}510 }, nil)511 _ = <-cc512 fmt.Println("test 25")513 RegisterTimer(time.Second, func(t *timer.Timer, _ interface{}) {514 t.Cancel()515 cc <- struct{}{}516 }, nil)517 fmt.Println("test 26")518 _ = <-cc519 node1.Stop(nil)520 SetPeerDisconnected(func(addr.LogicAddr, error) {521 cc <- struct{}{}522 })523 _ = <-cc524 Stop(nil)525 center1.Stop()526}527func TestRPC(t *testing.T) {528 center1 := center.New()529 go func() {530 center1.Start(centerAddr, logger)531 }()532 node1 := NewCluster()533 cc := make(chan struct{})534 c := 0535 node1.RegisterMethod(&ss_rpc.EchoReq{}, func(replyer *rpc.RPCReplyer, arg interface{}) {536 c++537 if c == 2 {538 //断掉连接,测试SendResponse中如连接中断尝试建立再发response的功能539 node2Addr, _ := addr.MakeLogicAddr("1.2.2")540 //等待从center接收到node1的信息541 end := node1.serviceMgr.getEndPoint(node2Addr)542 end.closeSession(errors.New("test"))543 }544 echo := arg.(*ss_rpc.EchoReq)545 logger.Sugar().Infof("echo message:%s\n", echo.GetMessage())546 echoResp := &ss_rpc.EchoResp{}547 echoResp.Message = proto.String("world")548 replyer.Reply(echoResp, nil)549 })550 node2 := NewCluster()551 {552 addr_, _ := addr.MakeAddr("1.1.1", "127.0.0.1:8001")553 assert.Equal(t, nil, node1.Start([]string{centerAddr}, addr_, uniLocker{}))554 }555 {556 addr_, _ := addr.MakeAddr("1.2.2", "127.0.0.1:8002")557 assert.Equal(t, nil, node2.Start([]string{centerAddr}, addr_, uniLocker{}))558 }559 node1Addr, _ := addr.MakeLogicAddr("1.1.1")560 //等待从center接收到node1的信息561 for nil == node2.serviceMgr.getEndPoint(node1Addr) {562 time.Sleep(time.Second)563 }564 //异步调用565 node2.AsynCall(node1Addr, &ss_rpc.EchoReq{Message: proto.String("hello")}, time.Second, func(result interface{}, err error) {566 assert.Equal(t, result.(*ss_rpc.EchoResp).GetMessage(), "world")567 cc <- struct{}{}568 })569 _ = <-cc570 //异步调用571 node2.AsynCall(node1Addr, &ss_rpc.EchoReq{Message: proto.String("hello")}, time.Second, func(result interface{}, err error) {572 assert.Equal(t, rpc.ErrChannelDisconnected, err)573 cc <- struct{}{}574 })575 _ = <-cc576 node1.Stop(nil)577 node2.Stop(nil)578 center1.Stop()579}580func TestHarbor(t *testing.T) {581 testRPCTimeout = true582 center1 := center.New() //harbor center583 center2 := center.New() //group 1 center584 center3 := center.New() //group 2 center585 go func() {586 center1.Start("127.0.0.1:8000", logger)587 }()588 go func() {589 center2.Start("127.0.0.1:8001", logger)590 }()591 go func() {592 center3.Start("127.0.0.1:8002", logger)593 }()594 harbor1 := NewCluster()595 harbor2 := NewCluster()596 harbor3 := NewCluster()597 harbor1Addr, _ := addr.MakeHarborAddr("1.255.1", "127.0.0.1:8011")598 harbor2Addr, _ := addr.MakeHarborAddr("2.255.1", "127.0.0.1:8012")599 harbor3Addr, _ := addr.MakeHarborAddr("2.255.2", "127.0.0.1:8013")600 assert.Equal(t, nil, harbor1.Start([]string{"127.0.0.1:8000", "127.0.0.1:8001"}, harbor1Addr, uniLocker{}))601 assert.Equal(t, nil, harbor2.Start([]string{"127.0.0.1:8000", "127.0.0.1:8002"}, harbor2Addr, uniLocker{}))602 assert.Equal(t, nil, harbor3.Start([]string{"127.0.0.1:8000", "127.0.0.1:8002"}, harbor3Addr, uniLocker{}))603 node1 := NewCluster()604 node2 := NewCluster()605 node3 := NewCluster()606 node1.RegisterMethod(&ss_rpc.EchoReq{}, func(replyer *rpc.RPCReplyer, arg interface{}) {607 echo := arg.(*ss_rpc.EchoReq)608 logger.Sugar().Infof("echo message:%s\n", echo.GetMessage())609 echoResp := &ss_rpc.EchoResp{}610 echoResp.Message = proto.String("world")611 replyer.Reply(echoResp, nil)612 })613 node1.Register(cmdEnum.SS_Echo, func(from addr.LogicAddr, msg proto.Message) {614 fmt.Println("get echo from", from)615 echo := &ss_msg.Echo{}616 echo.Message = proto.String("world")617 node1.PostMessage(from, echo)618 })619 cc := make(chan struct{})620 node2.Register(cmdEnum.SS_Echo, func(from addr.LogicAddr, msg proto.Message) {621 fmt.Println("get echo resp from", from)622 cc <- struct{}{}623 })624 //time.Sleep(time.Second * 2)625 node1Addr, _ := addr.MakeAddr("1.1.1", "127.0.0.1:8111")626 node2Addr, _ := addr.MakeAddr("2.2.1", "127.0.0.1:8112")627 assert.Equal(t, nil, node1.Start([]string{"127.0.0.1:8001"}, node1Addr, uniLocker{}, EXPORT))628 assert.Equal(t, nil, node2.Start([]string{"127.0.0.1:8002"}, node2Addr, uniLocker{}))629 var peer addr.LogicAddr630 for {631 peer, _ = node2.Random(1)632 if peer.Empty() {633 time.Sleep(time.Second)634 } else {635 break636 }637 }638 node2.AsynCall(peer, &ss_rpc.EchoReq{Message: proto.String("hello")}, time.Second, func(result interface{}, err error) {639 assert.Equal(t, result.(*ss_rpc.EchoResp).GetMessage(), "world")640 cc <- struct{}{}641 })642 fmt.Println("test1------------------------")643 _ = <-cc644 node2.PostMessage(peer, &ss_msg.Echo{645 Message: proto.String("hello"),646 })647 _ = <-cc648 peer, _ = addr.MakeLogicAddr("1.1.0")649 node2.PostMessage(peer, &ss_msg.Echo{650 Message: proto.String("hello"),651 })652 fmt.Println("test2------------------------")653 _ = <-cc654 node1.Stop(nil, true)655 fmt.Println("test3------------------------")656 for {657 _, err := node2.Random(1)658 if nil == err {659 time.Sleep(time.Second)660 } else {661 assert.Equal(t, err, ERR_NO_AVAILABLE_SERVICE)662 break663 }664 }665 fmt.Println("test4------------------------")666 node2.AsynCall(peer, &ss_rpc.EchoReq{Message: proto.String("hello")}, time.Second, func(result interface{}, err error) {667 assert.Equal(t, rpcerr.Err_RPC_RelayError, err)668 cc <- struct{}{}669 })670 fmt.Println("test5------------------------")671 _ = <-cc672 fmt.Println("test6------------------------")673 node3Addr, _ := addr.MakeAddr("1.2.1", "127.0.0.1:8113")674 assert.Equal(t, nil, node3.Start([]string{"127.0.0.1:8001"}, node3Addr, uniLocker{}, EXPORT))675 time.Sleep(time.Second * 2)676 fmt.Println("test7------------------------")677 node3.Stop(nil, true)678 fmt.Println("test8------------------------")679 time.Sleep(time.Second * 2)680 fmt.Println("test9------------------------")681 harbor3.Stop(nil, true)682 time.Sleep(time.Second * 2)683 fmt.Println("test10------------------------")684 node2.Stop(nil)685 fmt.Println("test11------------------------")686 harbor1.Stop(nil)687 fmt.Println("test12------------------------")688 harbor2.Stop(nil)689 fmt.Println("test13------------------------")690 center1.Stop()691 fmt.Println("test14------------------------")692 center2.Stop()693 fmt.Println("test15------------------------")694 center3.Stop()695 testRPCTimeout = false696}...

Full Screen

Full Screen

merchant_center_link_status.pb.go

Source:merchant_center_link_status.pb.go Github

copy

Full Screen

...34// This is a compile-time assertion that a sufficiently up-to-date version35// of the legacy proto package is being used.36const _ = proto.ProtoPackageIsVersion437// Describes the possible statuses for a link between a Google Ads customer38// and a Google Merchant Center account.39type MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus int3240const (41 // Not specified.42 MerchantCenterLinkStatusEnum_UNSPECIFIED MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus = 043 // Used for return value only. Represents value unknown in this version.44 MerchantCenterLinkStatusEnum_UNKNOWN MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus = 145 // The link is enabled.46 MerchantCenterLinkStatusEnum_ENABLED MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus = 247 // The link has no effect. It was proposed by the Merchant Center Account48 // owner and hasn't been confirmed by the customer.49 MerchantCenterLinkStatusEnum_PENDING MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus = 350)51// Enum value maps for MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus.52var (53 MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus_name = map[int32]string{54 0: "UNSPECIFIED",55 1: "UNKNOWN",56 2: "ENABLED",57 3: "PENDING",58 }59 MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus_value = map[string]int32{60 "UNSPECIFIED": 0,61 "UNKNOWN": 1,62 "ENABLED": 2,63 "PENDING": 3,64 }65)66func (x MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus) Enum() *MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus {67 p := new(MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus)68 *p = x69 return p70}71func (x MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus) String() string {72 return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x))73}74func (MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus) Descriptor() protoreflect.EnumDescriptor {75 return file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_enumTypes[0].Descriptor()76}77func (MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus) Type() protoreflect.EnumType {78 return &file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_enumTypes[0]79}80func (x MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus) Number() protoreflect.EnumNumber {81 return protoreflect.EnumNumber(x)82}83// Deprecated: Use MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus.Descriptor instead.84func (MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus) EnumDescriptor() ([]byte, []int) {85 return file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_rawDescGZIP(), []int{0, 0}86}87// Container for enum describing possible statuses of a Google Merchant Center88// link.89type MerchantCenterLinkStatusEnum struct {90 state protoimpl.MessageState91 sizeCache protoimpl.SizeCache92 unknownFields protoimpl.UnknownFields93}94func (x *MerchantCenterLinkStatusEnum) Reset() {95 *x = MerchantCenterLinkStatusEnum{}96 if protoimpl.UnsafeEnabled {97 mi := &file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_msgTypes[0]98 ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))99 ms.StoreMessageInfo(mi)100 }101}102func (x *MerchantCenterLinkStatusEnum) String() string {103 return protoimpl.X.MessageStringOf(x)104}105func (*MerchantCenterLinkStatusEnum) ProtoMessage() {}106func (x *MerchantCenterLinkStatusEnum) ProtoReflect() protoreflect.Message {107 mi := &file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_msgTypes[0]108 if protoimpl.UnsafeEnabled && x != nil {109 ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))110 if ms.LoadMessageInfo() == nil {111 ms.StoreMessageInfo(mi)112 }113 return ms114 }115 return mi.MessageOf(x)116}117// Deprecated: Use MerchantCenterLinkStatusEnum.ProtoReflect.Descriptor instead.118func (*MerchantCenterLinkStatusEnum) Descriptor() ([]byte, []int) {119 return file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_rawDescGZIP(), []int{0}120}121var File_google_ads_googleads_v4_enums_merchant_center_link_status_proto protoreflect.FileDescriptor122var file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_rawDesc = []byte{123 0x0a, 0x3f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x64, 0x73, 0x2f, 0x67, 0x6f, 0x6f,124 0x67, 0x6c, 0x65, 0x61, 0x64, 0x73, 0x2f, 0x76, 0x34, 0x2f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x2f,125 0x6d, 0x65, 0x72, 0x63, 0x68, 0x61, 0x6e, 0x74, 0x5f, 0x63, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x5f,126 0x6c, 0x69, 0x6e, 0x6b, 0x5f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74,127 0x6f, 0x12, 0x1d, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x64, 0x73, 0x2e, 0x67, 0x6f,128 0x6f, 0x67, 0x6c, 0x65, 0x61, 0x64, 0x73, 0x2e, 0x76, 0x34, 0x2e, 0x65, 0x6e, 0x75, 0x6d, 0x73,129 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e,130 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x72,131 0x0a, 0x1c, 0x4d, 0x65, 0x72, 0x63, 0x68, 0x61, 0x6e, 0x74, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72,132 0x4c, 0x69, 0x6e, 0x6b, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x45, 0x6e, 0x75, 0x6d, 0x22, 0x52,133 0x0a, 0x18, 0x4d, 0x65, 0x72, 0x63, 0x68, 0x61, 0x6e, 0x74, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72,134 0x4c, 0x69, 0x6e, 0x6b, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x4e,135 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x55,136 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x45, 0x4e, 0x41, 0x42,137 0x4c, 0x45, 0x44, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x45, 0x4e, 0x44, 0x49, 0x4e, 0x47,138 0x10, 0x03, 0x42, 0xf2, 0x01, 0x0a, 0x21, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c,139 0x65, 0x2e, 0x61, 0x64, 0x73, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x61, 0x64, 0x73, 0x2e,140 0x76, 0x34, 0x2e, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x42, 0x1d, 0x4d, 0x65, 0x72, 0x63, 0x68, 0x61,141 0x6e, 0x74, 0x43, 0x65, 0x6e, 0x74, 0x65, 0x72, 0x4c, 0x69, 0x6e, 0x6b, 0x53, 0x74, 0x61, 0x74,142 0x75, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x42, 0x67, 0x6f, 0x6f, 0x67, 0x6c,143 0x65, 0x2e, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x67, 0x65, 0x6e,144 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x61, 0x70, 0x69, 0x73,145 0x2f, 0x61, 0x64, 0x73, 0x2f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x61, 0x64, 0x73, 0x2f, 0x76,146 0x34, 0x2f, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x3b, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0xa2, 0x02, 0x03,147 0x47, 0x41, 0x41, 0xaa, 0x02, 0x1d, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x41, 0x64, 0x73,148 0x2e, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x41, 0x64, 0x73, 0x2e, 0x56, 0x34, 0x2e, 0x45, 0x6e,149 0x75, 0x6d, 0x73, 0xca, 0x02, 0x1d, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x5c, 0x41, 0x64, 0x73,150 0x5c, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x41, 0x64, 0x73, 0x5c, 0x56, 0x34, 0x5c, 0x45, 0x6e,151 0x75, 0x6d, 0x73, 0xea, 0x02, 0x21, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x3a, 0x3a, 0x41, 0x64,152 0x73, 0x3a, 0x3a, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x41, 0x64, 0x73, 0x3a, 0x3a, 0x56, 0x34,153 0x3a, 0x3a, 0x45, 0x6e, 0x75, 0x6d, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,154}155var (156 file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_rawDescOnce sync.Once157 file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_rawDescData = file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_rawDesc158)159func file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_rawDescGZIP() []byte {160 file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_rawDescOnce.Do(func() {161 file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_rawDescData = protoimpl.X.CompressGZIP(file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_rawDescData)162 })163 return file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_rawDescData164}165var file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_enumTypes = make([]protoimpl.EnumInfo, 1)166var file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_msgTypes = make([]protoimpl.MessageInfo, 1)167var file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_goTypes = []interface{}{168 (MerchantCenterLinkStatusEnum_MerchantCenterLinkStatus)(0), // 0: google.ads.googleads.v4.enums.MerchantCenterLinkStatusEnum.MerchantCenterLinkStatus169 (*MerchantCenterLinkStatusEnum)(nil), // 1: google.ads.googleads.v4.enums.MerchantCenterLinkStatusEnum170}171var file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_depIdxs = []int32{172 0, // [0:0] is the sub-list for method output_type173 0, // [0:0] is the sub-list for method input_type174 0, // [0:0] is the sub-list for extension type_name175 0, // [0:0] is the sub-list for extension extendee176 0, // [0:0] is the sub-list for field type_name177}178func init() { file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_init() }179func file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_init() {180 if File_google_ads_googleads_v4_enums_merchant_center_link_status_proto != nil {181 return182 }183 if !protoimpl.UnsafeEnabled {184 file_google_ads_googleads_v4_enums_merchant_center_link_status_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {185 switch v := v.(*MerchantCenterLinkStatusEnum); i {186 case 0:187 return &v.state188 case 1:189 return &v.sizeCache190 case 2:191 return &v.unknownFields192 default:193 return nil194 }195 }196 }197 type x struct{}198 out := protoimpl.TypeBuilder{199 File: protoimpl.DescBuilder{...

Full Screen

Full Screen

center.go

Source:center.go Github

copy

Full Screen

...9 "initialthree/cluster/addr"10 "sort"11 "strings"12)13func (this *Cluster) connectCenter(centerAddrs []string) {14 this.centerClient.ConnectCenter(centerAddrs, this.serverState.selfAddr)15}16func diff(a, b []*center_proto.NodeInfo) ([]*center_proto.NodeInfo, []*center_proto.NodeInfo) {17 if len(a) == 0 {18 return nil, b19 }20 if len(b) == 0 {21 return a, nil22 }23 sort.Slice(a, func(i, j int) bool {24 return a[i].GetLogicAddr() < a[j].GetLogicAddr()25 })26 sort.Slice(b, func(i, j int) bool {27 return b[i].GetLogicAddr() < b[j].GetLogicAddr()28 })29 add := []*center_proto.NodeInfo{}30 remove := []*center_proto.NodeInfo{}31 i := 032 j := 033 for i < len(a) && j < len(b) {34 if a[i].GetLogicAddr() == b[j].GetLogicAddr() {35 add = append(add, a[i])36 i++37 j++38 } else if a[i].GetLogicAddr() > b[j].GetLogicAddr() {39 remove = append(remove, b[j])40 j++41 } else {42 add = append(add, a[i])43 i++44 }45 }46 if len(a[i:]) > 0 {47 add = append(add, a[i:]...)48 }49 if len(b[j:]) > 0 {50 remove = append(remove, b[j:]...)51 }52 return add, remove53}54func (this *Cluster) centerInit(export ...bool) {55 exportService := uint32(0)56 if len(export) > 0 && export[0] {57 exportService = 158 }59 this.centerClient = center_client.New(this.queue, logger, exportService)60 this.centerClient.RegisterCenterMsgHandler(center_proto.CENTER_HeartbeatToNode, func(session *fnet.Socket, msg proto.Message) {61 //心跳响应暂时不处理62 //kendynet.Infof("HeartbeatToNode\n")63 })64 nodes2Str := func(nodes []*center_proto.NodeInfo) string {65 s := []string{}66 for _, v := range nodes {67 t := addr.LogicAddr(v.GetLogicAddr())68 s = append(s, t.String())69 }70 return strings.Join(s, ",")71 }72 this.centerClient.RegisterCenterMsgHandler(center_proto.CENTER_NotifyNodeAdd, func(session *fnet.Socket, msg proto.Message) {73 NodeAdd := msg.(*center_proto.NodeAdd)74 logger.Sugar().Infof("%s CENTER_NotifyNodeAdd %v\n", this.serverState.selfAddr.Logic.String(), nodes2Str(NodeAdd.Nodes))75 for _, v := range NodeAdd.Nodes {76 this.serviceMgr.addEndPoint(session.RemoteAddr(), v)77 }78 })79 this.centerClient.RegisterCenterMsgHandler(center_proto.CENTER_NotifyNodeInfo, func(session *fnet.Socket, msg proto.Message) {80 currentEndPoints := this.serviceMgr.getAllNodeInfo()81 NotifyNodeInfo := msg.(*center_proto.NotifyNodeInfo)82 logger.Sugar().Infof("%s CENTER_NotifyNodeInfo %v\n", this.serverState.selfAddr.Logic.String(), nodes2Str(NotifyNodeInfo.Nodes))83 add, remove := diff(NotifyNodeInfo.Nodes, currentEndPoints)84 for _, v := range add {85 this.serviceMgr.addEndPoint(session.RemoteAddr(), v)86 }87 /*88 * 在单一center的配置下,如果center crash之后重启,节点重新连接center,此时原集群中可能尚有部分节点未连接上center89 * 此时,NotifyNodeInfo将只包含部分节点。例如集群中原有1,2,3,4,4个节点,center崩溃重启后,1先连上center,此时收到的NotifyNodeInfo只有1。90 * diff将把2,3,4计算到remove中。91 *92 * 如果直接将2,3,4删除,将导致到1与这些节点的通信暂时中断,直到2,3,4连上center并把信息发送到1。93 *94 * 为了避免这个中断,endpoint中添加了timestamp,当调用addEndPoint将更新timestamp。95 * 然后调用delayRemove,把本次要remove的end和时间记录下来,延迟到一定时间之后再执行。如果在延迟执行之前,2,3,4连上center并通告到1,1中对应的96 * end将会更新timestamp,延迟执行时会比较end.timestamp和记录下的timestamp,如果end.timestamp更新将放弃删除。97 *98 */99 this.serviceMgr.delayRemove(session.RemoteAddr(), remove)100 })101 this.centerClient.RegisterCenterMsgHandler(center_proto.CENTER_NodeLeave, func(session *fnet.Socket, msg proto.Message) {102 NodeLeave := msg.(*center_proto.NodeLeave)103 //logger.Infoln("CENTER_NodeLeave", pretty.Sprint(msg))104 for _, v := range NodeLeave.Nodes {105 this.serviceMgr.removeEndPoint(session.RemoteAddr(), addr.LogicAddr(v))106 }107 })108}...

Full Screen

Full Screen

Center

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := proto.Point{1, 2}4 q := proto.Point{4, 6}5 fmt.Println(r.Distance(q))6 fmt.Println(origin.Distance(q))7 fmt.Println(proto.Point{1, 2}.ScaleBy(2))8 fmt.Println(proto.Point{1, 2}.ScaleBy(2).ScaleBy(3))9 fmt.Println((&proto.Point{1, 2}).ScaleBy(2))10}11import (12func main() {13 p := proto.Point{1, 2}14 q := proto.Point{4, 6}15 fmt.Println(r.Distance(q))16 fmt.Println(origin.Distance(q))17 fmt.Println(proto.Point{1, 2}.ScaleBy(2))18 fmt.Println(proto.Point{1, 2}.ScaleBy(2).ScaleBy(3))19 fmt.Println((&proto.Point{1, 2}).ScaleBy(2))20}21import (22func main() {23 p := proto.Point{1, 2}24 q := proto.Point{4, 6}25 fmt.Println(r.Distance(q))26 fmt.Println(origin.Distance(q))27 fmt.Println(proto.Point{1, 2}.ScaleBy(2))28 fmt.Println(proto.Point{1, 2}.ScaleBy(2).ScaleBy(3))29 fmt.Println((&proto.Point

Full Screen

Full Screen

Center

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Geometrical shape properties")4 rectArea := rectangle.Area(rectLen, rectWidth)5 fmt.Printf("area of rectangle %.2f\n", rectArea)6 rectDiagonal := rectangle.Diagonal(rectLen, rectWidth)7 fmt.Printf("diagonal of the rectangle %.2f ", rectDiagonal)8 circle := geometry.Circle{10}9 fmt.Println("\nCircle properties")10 fmt.Printf("area of the circle %.2f ", circle.Area())11 fmt.Printf("diagonal of the circle %.2f ", circle.Diagonal())12 rectangle := geometry.Rectangle{6, 7}13 fmt.Println("\nRectangle properties")14 fmt.Printf("area of the rectangle %.2f ", rectangle.Area())15 fmt.Printf("diagonal of the rectangle %.2f ", rectangle.Diagonal())16}17import (18func init() {19 fmt.Println("main package initialized")20}21func main() {22 fmt.Println("main package started")23 fmt.Println("Geometrical shape properties")24 rectArea := rectangle.Area(rectLen, rectWidth)25 fmt.Printf("area of rectangle %.2f\n", rectArea)26 rectDiagonal := rectangle.Diagonal(rectLen, rectWidth)27 fmt.Printf("diagonal of the rectangle %.2f ", rectDiagonal)28}29import (30func init() {31 fmt.Println("main package initialized")32}33func main() {34 fmt.Println("main package started")35 fmt.Println("Geometrical shape properties")36 rectArea := rectangle.Area(rectLen, rectWidth)37 fmt.Printf("area of rectangle %.2f\n

Full Screen

Full Screen

Center

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 point := &Point{X: proto.Float64(1), Y: proto.Float64(2)}4 fmt.Println(point.GetCenter())5}6&{1 2}7import proto "github.com/golang/protobuf/proto"8import fmt "fmt"9import math "math"10import (11type Point struct {12}13func (m *Point) Reset() { *m = Point{} }14func (m *Point) String() string { return proto.CompactTextString(m) }15func (*Point) ProtoMessage() {}16func (*Point) Descriptor() ([]byte, []int) { return fileDescriptor2, []int{0} }17func (m *Point) GetX() float64 {18 if m != nil && m.X != nil {19 }20}21func (m *Point) GetY() float64 {22 if m != nil && m.Y != nil {23 }24}25func (m *Point) GetCenter() *Point {26 if m != nil {27 return &Point{28 X: proto.Float64(m.GetX()

Full Screen

Full Screen

Center

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := geometry.Point{1, 2}4 c := geometry.Circle{p, 5}5 q := c.Center()6 fmt.Println(q)7}8import (9func main() {10 p := geometry.Point{1, 2}11 c := geometry.Circle{p, 5}12 area := c.Area()13 fmt.Println(area)14}15import (16func main() {17 p := geometry.Point{1, 2}18 c := geometry.Circle{p, 5}19 perimeter := c.Perimeter()20 fmt.Println(perimeter)21}22import (23func main() {24 p := geometry.Point{1, 2}25 c := geometry.Circle{p, 5}26 c.ScaleBy(2)27 fmt.Println(c.Center())28}29import (30func main() {31 p := geometry.Point{1, 2}32 c := geometry.Circle{p, 5}33 c.ScaleBy(2)34 fmt.Println(c.Area())35}36import (

Full Screen

Full Screen

Center

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 p := &Point{X: 1, Y: 2}4 c := &Circle{Radius: 5, Center: p}5 data, err := proto.Marshal(c)6 if err != nil {7 fmt.Println("Marshaling error: ", err)8 }9 newC := &Circle{}10 err = proto.Unmarshal(data, newC)11 if err != nil {12 fmt.Println("Unmarshaling error: ", err)13 }14 if c.GetRadius() == newC.GetRadius() {15 fmt.Println("Radius equals:", c.GetRadius())16 } else {17 fmt.Println("Radius does not equal:", c.GetRadius(), newC.GetRadius())18 }19}20import (21func main() {22 p := &Point{X: 1, Y: 2}23 c := &Circle{Radius: 5, Center: p}24 data, err := proto.Marshal(c)25 if err != nil {26 fmt.Println("Marshaling error: ", err)27 }28 newC := &Circle{}29 err = proto.Unmarshal(data, newC)30 if err != nil {31 fmt.Println("Unmarshaling error: ", err)32 }33 if c.GetRadius() == newC.GetRadius() {34 fmt.Println("Radius equals:", c.GetRadius())35 } else {36 fmt.Println("Radius does not equal:", c.GetRadius(), newC.GetRadius())37 }38}39import (40func main() {41 p := &Point{X: 1, Y: 2}42 c := &Circle{Radius

Full Screen

Full Screen

Center

Using AI Code Generation

copy

Full Screen

1func main() {2 p := proto{}3 p.Center()4}5func main() {6 p := proto{}7 p.Center()8}9func main() {10 p := proto{}11 p.Center()12}13func main() {14 p := proto{}15 p.Center()16}17func main() {18 p := proto{}19 p.Center()20}21func main() {22 p := proto{}23 p.Center()24}25func main() {26 p := proto{}27 p.Center()28}29func main() {30 p := proto{}31 p.Center()32}

Full Screen

Full Screen

Center

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := yourproto.Center{X: 3, Y: 4}4 fmt.Println(c)5 fmt.Println(c.X, c.Y)6}

Full Screen

Full Screen

Center

Using AI Code Generation

copy

Full Screen

1func main() {2 p := proto.NewProto()3 p.Center()4}5func main() {6 p := proto.NewProto()7 p.Center()8}9type Proto struct {10}11func (p *Proto) Center() {12 fmt.Println(p.x)13}14func NewProto() *Proto {15 return &Proto{}16}17func main() {18 p := proto.NewProto()19 p.Center()20}21func main() {22 p := proto.NewProto()23 p.Center()24}25func main() {26 p := proto.NewProto()27 p.Center()28}29import (30func main() {31 p := proto.NewProto()32 p.Center()33}34import (

Full Screen

Full Screen

Center

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("main: 2.go")4 p := &proto.Point{X: 1, Y: 2}5 fmt.Printf("main: point=%v6 c := p.Center()7 fmt.Printf("main: center=%v8}9type Point struct {10}11func (p *Point) Center() *Point {12 return &Point{X: p.X / 2, Y: p.Y / 2}13}14import "testing"15func TestCenter(t *testing.T) {16 p := &Point{X: 4, Y: 6}17 c := p.Center()18 if c.X != 2 || c.Y != 3 {19 t.Fatalf("center not correct: %v", c)20 }21}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Rod automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful