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

undo_test.go 3.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package sql
  18. import (
  19. "context"
  20. "database/sql"
  21. "testing"
  22. "github.com/seata/seata-go/pkg/datasource/sql/undo/base"
  23. "github.com/seata/seata-go/pkg/datasource/sql/undo/mysql"
  24. "github.com/stretchr/testify/assert"
  25. )
  26. // TestBatchDeleteUndoLogs
  27. func TestBatchDeleteUndoLogs(t *testing.T) {
  28. // local test can annotation t.SkipNow()
  29. t.SkipNow()
  30. testBatchDeleteUndoLogs := func() {
  31. db, err := sql.Open(SeataATMySQLDriver, "root:12345678@tcp(127.0.0.1:3306)/seata_order?multiStatements=true")
  32. assert.Nil(t, err)
  33. sqlConn, err := db.Conn(context.Background())
  34. assert.Nil(t, err)
  35. undoLogManager := new(base.BaseUndoLogManager)
  36. err = undoLogManager.BatchDeleteUndoLog([]string{"1"}, []int64{1}, sqlConn)
  37. assert.Nil(t, err)
  38. }
  39. t.Run("test_batch_delete_undo_logs", func(t *testing.T) {
  40. testBatchDeleteUndoLogs()
  41. })
  42. }
  43. func TestDeleteUndoLogs(t *testing.T) {
  44. // local test can annotation t.SkipNow()
  45. t.SkipNow()
  46. testDeleteUndoLogs := func() {
  47. /*db, err := sql.Open(SeataATMySQLDriver, "root:12345678@tcp(127.0.0.1:3306)/seata_order?multiStatements=true")
  48. assert.Nil(t, err)
  49. ctx := context.Background()
  50. sqlConn, err := db.Conn(ctx)
  51. assert.Nil(t, err)
  52. undoLogManager := new(base.BaseUndoLogManager)
  53. err = undoLogManager.DeleteUndoLog(ctx, "1", 1, sqlConn)
  54. assert.Nil(t, err)*/
  55. }
  56. t.Run("test_delete_undo_logs", func(t *testing.T) {
  57. testDeleteUndoLogs()
  58. })
  59. }
  60. // TestHasUndoLogTable
  61. func TestHasUndoLogTable(t *testing.T) {
  62. // local test can annotation t.SkipNow()
  63. t.SkipNow()
  64. testHasUndoLogTable := func() {
  65. db, err := sql.Open(SeataATMySQLDriver, "root:12345678@tcp(127.0.0.1:3306)/seata_order?multiStatements=true")
  66. assert.Nil(t, err)
  67. ctx := context.Background()
  68. sqlConn, err := db.Conn(ctx)
  69. assert.Nil(t, err)
  70. undoLogManager := new(base.BaseUndoLogManager)
  71. res, err := undoLogManager.HasUndoLogTable(ctx, sqlConn)
  72. assert.Nil(t, err)
  73. assert.True(t, res)
  74. }
  75. t.Run("test_has_undo_log_table", func(t *testing.T) {
  76. testHasUndoLogTable()
  77. })
  78. }
  79. func TestUndo(t *testing.T) {
  80. // Todo TestUndo update
  81. // Todo TestUndo delete
  82. // local test can annotation t.SkipNow()
  83. t.SkipNow()
  84. testUndoLog := func() {
  85. manager := mysql.NewUndoLogManager()
  86. db, err := sql.Open(SeataATMySQLDriver, "root:123456@tcp(127.0.0.1:3306)/seata_order?multiStatements=true")
  87. assert.Nil(t, err)
  88. ctx := context.Background()
  89. sqlConn, err := db.Conn(ctx)
  90. assert.Nil(t, err)
  91. defer func() {
  92. _ = sqlConn.Close()
  93. }()
  94. if err = manager.RunUndo(ctx, "1", 1, nil, ""); err != nil {
  95. t.Logf("%+v", err)
  96. }
  97. assert.Nil(t, err)
  98. }
  99. t.Run("test_undo_log", func(t *testing.T) {
  100. testUndoLog()
  101. })
  102. }