Browse Source

optimize(undo): change default parser name to json from jackson (#525)

tags/v1.2.0
juzimao GitHub 2 years ago
parent
commit
c43f4792c5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 14 deletions
  1. +1
    -1
      pkg/datasource/sql/undo/parser/const.go
  2. +1
    -1
      pkg/datasource/sql/undo/parser/parser_cache.go
  3. +2
    -2
      pkg/datasource/sql/undo/parser/parser_cache_test.go
  4. +6
    -6
      pkg/datasource/sql/undo/parser/parser_json.go
  5. +4
    -4
      pkg/datasource/sql/undo/parser/parser_json_test.go

+ 1
- 1
pkg/datasource/sql/undo/parser/const.go View File

@@ -18,5 +18,5 @@
package parser

const (
DefaultSerializer = "jackson"
DefaultSerializer = "json"
)

+ 1
- 1
pkg/datasource/sql/undo/parser/parser_cache.go View File

@@ -38,7 +38,7 @@ func initCache() {
serializerNameToParser: make(map[string]UndoLogParser, 0),
}

cache.store(&JacksonParser{})
cache.store(&JsonParser{})
}

func GetCache() *UndoLogParserCache {


+ 2
- 2
pkg/datasource/sql/undo/parser/parser_cache_test.go View File

@@ -41,7 +41,7 @@ func TestGetDefault(t *testing.T) {
}

func TestLoad(t *testing.T) {
jacksonParser, err := GetCache().Load("jackson")
jsonParser, err := GetCache().Load("json")
assert.Nil(t, err)
assert.NotNil(t, jacksonParser)
assert.NotNil(t, jsonParser)
}

pkg/datasource/sql/undo/parser/parser_jackson.go → pkg/datasource/sql/undo/parser/parser_json.go View File

@@ -23,25 +23,25 @@ import (
"github.com/seata/seata-go/pkg/datasource/sql/undo"
)

type JacksonParser struct {
type JsonParser struct {
}

// Get the name of parser;
// return the name of parser
func (j *JacksonParser) GetName() string {
return "jackson"
func (j *JsonParser) GetName() string {
return "json"
}

// Get default context of this parser
// return the default content if undo log is empty
func (j *JacksonParser) GetDefaultContent() []byte {
func (j *JsonParser) GetDefaultContent() []byte {
return []byte("{}")
}

// Encode branch undo log to byte array.
// param branchUndoLog the branch undo log
// return the byte array
func (j *JacksonParser) Encode(branchUndoLog *undo.BranchUndoLog) ([]byte, error) {
func (j *JsonParser) Encode(branchUndoLog *undo.BranchUndoLog) ([]byte, error) {
bytes, err := json.Marshal(branchUndoLog)
if err != nil {
return nil, err
@@ -53,7 +53,7 @@ func (j *JacksonParser) Encode(branchUndoLog *undo.BranchUndoLog) ([]byte, error
// Decode byte array to branch undo log.
// param bytes the byte array
// return the branch undo log
func (j *JacksonParser) Decode(bytes []byte) (*undo.BranchUndoLog, error) {
func (j *JsonParser) Decode(bytes []byte) (*undo.BranchUndoLog, error) {
var branchUndoLog *undo.BranchUndoLog
if err := json.Unmarshal(bytes, &branchUndoLog); err != nil {
return nil, err

pkg/datasource/sql/undo/parser/parser_jackson_test.go → pkg/datasource/sql/undo/parser/parser_json_test.go View File

@@ -25,11 +25,11 @@ import (
)

func TestGetName(t *testing.T) {
assert.Equal(t, "jackson", (&JacksonParser{}).GetName())
assert.Equal(t, "json", (&JsonParser{}).GetName())
}

func TestGetDefaultContext(t *testing.T) {
assert.Equal(t, []byte("{}"), (&JacksonParser{}).GetDefaultContent())
assert.Equal(t, []byte("{}"), (&JsonParser{}).GetDefaultContent())
}

func TestEncode(t *testing.T) {
@@ -53,7 +53,7 @@ func TestEncode(t *testing.T) {

for _, Case := range TestCases {
t.Run(Case.CaseName, func(t *testing.T) {
logParser := &JacksonParser{}
logParser := &JsonParser{}
bytes, err := logParser.Encode(Case.UndoLog)
if Case.ExpectErr {
assert.NotNil(t, err)
@@ -87,7 +87,7 @@ func TestDecode(t *testing.T) {

for _, Case := range TestCases {
t.Run(Case.CaseName, func(t *testing.T) {
logParser := &JacksonParser{}
logParser := &JsonParser{}
undoLog, err := logParser.Decode([]byte(Case.InputBytes))
if Case.ExpectErr {
assert.NotNil(t, err)

Loading…
Cancel
Save