contact_bind_log_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package service
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "encoding/json"
  7. "go-common/app/job/main/passport/model"
  8. "go-common/library/queue/databus"
  9. xtime "go-common/library/time"
  10. )
  11. var (
  12. pCfg = &databus.Config{
  13. Key: "dbe67e6a4c36f877",
  14. Secret: "8c775ea242caa367ba5c876c04576571",
  15. Group: "Test1-MainCommonArch-P",
  16. Topic: "test1",
  17. Action: "pub",
  18. Name: "databus",
  19. Proto: "tcp",
  20. Addr: "172.18.33.50:6205",
  21. Active: 10,
  22. Idle: 5,
  23. DialTimeout: xtime.Duration(time.Second),
  24. WriteTimeout: xtime.Duration(time.Second),
  25. ReadTimeout: xtime.Duration(time.Second),
  26. IdleTimeout: xtime.Duration(time.Minute),
  27. }
  28. )
  29. func testPub(t *testing.T, d *databus.Databus) {
  30. tel := model.TelBindLog{ID: 2, Mid: 88883, Tel: "18817352650", Timestamp: 1500022511}
  31. da, _ := json.Marshal(&tel)
  32. c := &model.BMsg{Action: "insert", Table: "aso_telephone_bind_log", New: da}
  33. if err := d.Send(context.Background(), "test", c); err != nil {
  34. t.Errorf("d.Send(test) error(%v)", err)
  35. }
  36. }
  37. func TestDatabus(t *testing.T) {
  38. d := databus.New(pCfg)
  39. testPub(t, d)
  40. testPub(t, d)
  41. testPub(t, d)
  42. d.Close()
  43. }
  44. //var aesBlock, _ = aes.NewCipher([]byte("1234567890abcdef"))
  45. //func TestEncode(t *testing.T) {
  46. // for a := 0; a < 1000; a++ {
  47. // go enconde()
  48. // }
  49. // time.Sleep(10000 * time.Second)
  50. //
  51. //}
  52. //
  53. //func enconde() {
  54. // for i := 0; i < 100; i++ {
  55. // key := []byte("1234567890abcdef")
  56. // origData := []byte(strconv.Itoa(rand.Intn(100)))
  57. // blockSize := aesBlock.BlockSize()
  58. // origData = PKCS7Padding(origData, blockSize)
  59. // blockMode := cipher.NewCBCEncrypter(aesBlock, key[:blockSize])
  60. // crypted := make([]byte, len(origData))
  61. // blockMode.CryptBlocks(crypted, origData)
  62. // fmt.Println(base64.StdEncoding.EncodeToString(crypted))
  63. // }
  64. //}
  65. //func TestDeode(t *testing.T) {
  66. // key := []byte("1234567890abcdef")
  67. // b,_:=base64.StdEncoding.DecodeString("29YQhqBb/J2XiBAj6bP3Zg==");
  68. // s,_:=AesDecrypt(b,key)
  69. // fmt.Print(string(s))
  70. //}
  71. //
  72. //
  73. //func AesDecrypt(crypted, key []byte) ([]byte, error) {
  74. // block, err := aes.NewCipher(key)
  75. // if err != nil {
  76. // return nil, err
  77. // }
  78. // blockSize := block.BlockSize()
  79. // blockMode := cipher.NewCBCDecrypter(block, key[:blockSize])
  80. // origData := make([]byte, len(crypted))
  81. // blockMode.CryptBlocks(origData, crypted)
  82. // origData = PKCS7UnPadding(origData)
  83. // return origData, nil
  84. //}
  85. //
  86. //
  87. //func PKCS7UnPadding(origData []byte) []byte {
  88. // length := len(origData)
  89. // unpadding := int(origData[length-1])
  90. // return origData[:(length - unpadding)]
  91. //}