Skip to content

Commit

Permalink
optimize(undo): change default parser name to json from jackson
Browse files Browse the repository at this point in the history
  • Loading branch information
106umao committed Mar 18, 2023
1 parent 27cba64 commit 277d89f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pkg/datasource/sql/undo/parser/const.go
Expand Up @@ -18,5 +18,5 @@
package parser

const (
DefaultSerializer = "jackson"
DefaultSerializer = "json"
)
2 changes: 1 addition & 1 deletion pkg/datasource/sql/undo/parser/parser_cache.go
Expand Up @@ -38,7 +38,7 @@ func initCache() {
serializerNameToParser: make(map[string]UndoLogParser, 0),
}

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

func GetCache() *UndoLogParserCache {
Expand Down
4 changes: 2 additions & 2 deletions pkg/datasource/sql/undo/parser/parser_cache_test.go
Expand Up @@ -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)
}
Expand Up @@ -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
Expand All @@ -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
Expand Down
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 277d89f

Please sign in to comment.