golang-im聊天
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 2 години
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package uid
  2. import (
  3. "database/sql"
  4. "fmt"
  5. "testing"
  6. _ "github.com/go-sql-driver/mysql"
  7. )
  8. func TestLid(t *testing.T) {
  9. db, err := sql.Open("mysql", "root:Liu123456@tcp(localhost:3306)/im?charset=utf8")
  10. if err != nil {
  11. fmt.Println(err)
  12. panic(err)
  13. }
  14. lid, err := NewUid(db, "test", 100)
  15. if err != nil {
  16. fmt.Println(err)
  17. return
  18. }
  19. i := 0
  20. for i < 100 {
  21. id, _ := lid.Get()
  22. fmt.Println(id)
  23. i++
  24. }
  25. }
  26. func TestLid_Get(t *testing.T) {
  27. go getLid("one")
  28. go getLid("two")
  29. go getLid("three")
  30. select {}
  31. }
  32. func getLid(index string) {
  33. db, err := sql.Open("mysql", "root:Liu123456@tcp(localhost:3306)/im?charset=utf8")
  34. if err != nil {
  35. fmt.Println(err)
  36. panic(err)
  37. }
  38. lid, err := NewUid(db, "test", 1000)
  39. if err != nil {
  40. fmt.Println(err)
  41. return
  42. }
  43. i := 0
  44. for i < 100 {
  45. id, _ := lid.Get()
  46. fmt.Println(index, id)
  47. i++
  48. }
  49. }
  50. func BenchmarkLeafKey(b *testing.B) {
  51. db, err := sql.Open("mysql", "root:Liu123456@tcp(localhost:3306)/im?charset=utf8")
  52. if err != nil {
  53. fmt.Println(err)
  54. panic(err)
  55. }
  56. lid, err := NewUid(db, "test", 1000)
  57. if err != nil {
  58. fmt.Println(err)
  59. return
  60. }
  61. for i := 0; i < b.N; i++ {
  62. _, _ = lid.Get()
  63. }
  64. }