Skip to content

Commit

Permalink
Add equal lz4 decompress test case and format code by goimports.
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattJia committed Oct 22, 2022
1 parent 0e4dfae commit bf140c1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
12 changes: 8 additions & 4 deletions pkg/compressor/lz4_compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,24 @@ type Lz4 struct {
}

func (l *Lz4) Compress(data []byte) ([]byte, error) {
buffer := make([]byte, len(data))
ht := make([]int, 64<<10)
n, err := lz4.CompressBlock(data, buffer, ht)

buffer := make([]byte, lz4.CompressBlockBound(len(data)))

var compressor lz4.Compressor

n, err := compressor.CompressBlock(data, buffer)
if err != nil {
return nil, err
}
if n >= len(data) {
return nil, fmt.Errorf("`%s` is not compressible", string(data))
}

return buffer[:n], nil
}

func (l *Lz4) Decompress(in []byte) ([]byte, error) {
out := make([]byte, 10*len(in))
out := make([]byte, 100*len(in))
n, err := lz4.UncompressBlock(in, out)
if err != nil {
return nil, err
Expand Down
6 changes: 4 additions & 2 deletions pkg/compressor/lz4_compress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,23 @@
package compressor

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func TestLz4Compress(t *testing.T) {
sample := "test"
sample := strings.Repeat("hello world", 100)

lz4 := new(Lz4)
lz4 := Lz4{}

compressResult, err := lz4.Compress([]byte(sample))
assert.NoError(t, err)
t.Logf("Compressed result: %v", string(compressResult))

decompressResult, err := lz4.Decompress(compressResult)
assert.NoError(t, err)
assert.Equal(t, sample, string(decompressResult))
t.Logf("Decompressed result: %v", string(decompressResult))
}
3 changes: 2 additions & 1 deletion pkg/datasource/sql/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ func (c *Conn) Begin() (driver.Tx, error) {
}

// BeginTx Open a transaction and judge whether the current transaction needs to open a
// global transaction according to ctx. If so, it needs to be included in the transaction management of seata
//
// global transaction according to ctx. If so, it needs to be included in the transaction management of seata
func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
if conn, ok := c.targetConn.(driver.ConnBeginTx); ok {
tx, err := conn.BeginTx(ctx, opts)
Expand Down
4 changes: 2 additions & 2 deletions pkg/datasource/sql/datasource/datasource_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (dm *BasicSourceManager) BranchRegister(ctx context.Context, clientId strin
return 0, nil
}

// Branch report
// Branch report
func (dm *BasicSourceManager) BranchReport(ctx context.Context, req message.BranchReportRequest) error {
return nil
}
Expand All @@ -138,7 +138,7 @@ func (dm *BasicSourceManager) RegisterResource(resource rm.Resource) error {
return nil
}

// Unregister a model.Resource from the model.Resource Manager
// Unregister a model.Resource from the model.Resource Manager
func (dm *BasicSourceManager) UnregisterResource(resource rm.Resource) error {
return errors.New("unsupport unregister resource")
}
Expand Down
1 change: 1 addition & 0 deletions pkg/datasource/sql/types/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package types
import "github.com/arana-db/parser/ast"

// ExecutorType
//
//go:generate stringer -type=ExecutorType
type ExecutorType int32

Expand Down

0 comments on commit bf140c1

Please sign in to comment.