From a3c72bf85f9682b77af2b48e26aea9f414fd3461 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Sat, 28 Aug 2021 01:26:37 +0800 Subject: [PATCH 01/23] feat:Add utils and readdir test Signed-off-by: bokket <3100563328@qq.com> --- go.mod | 1 + go.sum | 1 + readdir_test.go | 95 +++++++++++++++++++++++++++++++++++++++++++++++++ utils.go | 2 +- utils_test.go | 74 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 readdir_test.go create mode 100644 utils_test.go diff --git a/go.mod b/go.mod index 850ef60..007f606 100644 --- a/go.mod +++ b/go.mod @@ -14,4 +14,5 @@ require ( github.com/jcmturner/goidentity v6.0.1+incompatible // indirect github.com/jcmturner/gokrb5 v8.4.2+incompatible // indirect github.com/jcmturner/rpc v1.1.1 // indirect + github.com/stretchr/testify v1.7.0 // indirect ) diff --git a/go.sum b/go.sum index 27bf842..7349607 100644 --- a/go.sum +++ b/go.sum @@ -84,6 +84,7 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykE github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/readdir_test.go b/readdir_test.go new file mode 100644 index 0000000..3e3a207 --- /dev/null +++ b/readdir_test.go @@ -0,0 +1,95 @@ +package hdfs + +import ( + "fmt" + "math/rand" + "path" + "testing" + + "github.com/beyondstorage/go-endpoint" + ps "github.com/beyondstorage/go-storage/v4/pairs" + "github.com/beyondstorage/go-storage/v4/types" + "github.com/google/uuid" + "github.com/stretchr/testify/assert" +) + +func TestHdfsDirerWithFiles(t *testing.T) { + for i := 0; i < 100; i++ { + numbers := 1000 + rand.Intn(1000) + + t.Run(fmt.Sprintf("list %d files", numbers), func(t *testing.T) { + testHdfsReaddir(t, numbers) + }) + } +} + +func testHdfsReaddir(t *testing.T, numbers int) { + tmpDir := t.TempDir() + host := "127.0.0.1" + port := 9000 + + s, err := newStorager( + ps.WithEndpoint(endpoint.NewTCP(host, port).String()), + ps.WithWorkDir(tmpDir), + ) + if err != nil { + t.Errorf("new storager: %v", err) + } + + err = s.hdfs.MkdirAll(tmpDir, 0666) + if err != nil { + t.Error(err) + } + + for i := 0; i < numbers; i++ { + + filename := uuid.New().String() + + f, err := s.hdfs.Create(path.Join(s.workDir, filename)) + if err != nil { + t.Error(err) + } + + defer func() { + closeErr := f.Close() + if err == nil { + err = closeErr + } + }() + + if err != nil { + t.Error(err) + } + } + + expected := make(map[string]string) + fi, err := s.hdfs.ReadDir(tmpDir) + if err != nil { + t.Error(err) + } + for _, v := range fi { + expected[v.Name()] = tmpDir + } + + actual := make(map[string]string) + it, err := s.List(s.workDir) + if err != nil { + t.Error(err) + } + + for { + o, err := it.Next() + if err == types.IterateDone { + break + } + _, exist := actual[o.Path] + if exist { + t.Errorf("file %s exists already", o.Path) + return + } + + actual[o.Path] = o.ID + } + assert.Equal(t, expected, actual) + +} diff --git a/utils.go b/utils.go index c1f8860..dea6763 100644 --- a/utils.go +++ b/utils.go @@ -98,7 +98,7 @@ func (s *Storage) getAbsPath(path string) string { if filepath.IsAbs(path) { return path } - return s.workDir + path + return filepath.Join(s.workDir, path) } func (s *Storage) formatError(op string, err error, path ...string) error { diff --git a/utils_test.go b/utils_test.go new file mode 100644 index 0000000..ea480d5 --- /dev/null +++ b/utils_test.go @@ -0,0 +1,74 @@ +package hdfs + +import ( + "errors" + "os" + "testing" + + "github.com/beyondstorage/go-endpoint" + "github.com/beyondstorage/go-storage/v4/pairs" + "github.com/beyondstorage/go-storage/v4/services" + "github.com/stretchr/testify/assert" +) + +func TestNewClient(t *testing.T) { + host := "127.0.0.1" + port := 9000 + c, err := NewStorager( + pairs.WithEndpoint(endpoint.NewTCP(host, port).String()), + ) + assert.NotNil(t, c) + assert.NoError(t, err) +} + +func TestFormatOsError(t *testing.T) { + testErr := errors.New("test error") + tests := []struct { + name string + input error + expected error + }{ + { + "not found", + os.ErrNotExist, + services.ErrObjectNotExist, + }, + { + "not supported error", + testErr, + services.ErrUnexpected, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := formatError(tt.input) + assert.True(t, errors.Is(err, tt.expected)) + }) + } +} + +func TestGetAbsPath(t *testing.T) { + cases := []struct { + name string + base string + path string + expectedPath string + }{ + {"direct path", "", "abc", "abc"}, + {"under direct path", "", "root/abc", "root/abc"}, + {"under direct path", "", "root/abc/", "root/abc"}, + {"under root", "/", "abc", "/abc"}, + {"under exist dir", "/root", "abc", "/root/abc"}, + {"under new dir", "/root", "abc/", "/root/abc"}, + } + + for _, tt := range cases { + t.Run(tt.name, func(t *testing.T) { + client := Storage{workDir: tt.base} + + getPath := client.getAbsPath(tt.path) + assert.Equal(t, tt.expectedPath, getPath) + }) + } +} From d8af26d6095e24b623ddd3e65b4dc36618564422 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Sat, 28 Aug 2021 10:32:44 +0800 Subject: [PATCH 02/23] fix error return assertion Signed-off-by: bokket <3100563328@qq.com> --- readdir_test.go | 38 ++++++++++++++------------------------ utils_test.go | 7 ++----- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/readdir_test.go b/readdir_test.go index 3e3a207..f13d0ef 100644 --- a/readdir_test.go +++ b/readdir_test.go @@ -3,18 +3,19 @@ package hdfs import ( "fmt" "math/rand" + "os" "path" "testing" - "github.com/beyondstorage/go-endpoint" ps "github.com/beyondstorage/go-storage/v4/pairs" "github.com/beyondstorage/go-storage/v4/types" "github.com/google/uuid" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestHdfsDirerWithFiles(t *testing.T) { - for i := 0; i < 100; i++ { + for i := 0; i < 10; i++ { numbers := 1000 + rand.Intn(1000) t.Run(fmt.Sprintf("list %d files", numbers), func(t *testing.T) { @@ -25,30 +26,24 @@ func TestHdfsDirerWithFiles(t *testing.T) { func testHdfsReaddir(t *testing.T, numbers int) { tmpDir := t.TempDir() - host := "127.0.0.1" - port := 9000 s, err := newStorager( - ps.WithEndpoint(endpoint.NewTCP(host, port).String()), + ps.WithEndpoint(os.Getenv("STORAGE_HDFS_ENDPOINT")), ps.WithWorkDir(tmpDir), ) - if err != nil { - t.Errorf("new storager: %v", err) - } + require.NoError(t, err) err = s.hdfs.MkdirAll(tmpDir, 0666) - if err != nil { - t.Error(err) - } + + require.NoError(t, err) for i := 0; i < numbers; i++ { filename := uuid.New().String() f, err := s.hdfs.Create(path.Join(s.workDir, filename)) - if err != nil { - t.Error(err) - } + + require.NoError(t, err) defer func() { closeErr := f.Close() @@ -57,25 +52,20 @@ func testHdfsReaddir(t *testing.T, numbers int) { } }() - if err != nil { - t.Error(err) - } + require.NoError(t, err) } expected := make(map[string]string) fi, err := s.hdfs.ReadDir(tmpDir) - if err != nil { - t.Error(err) - } + require.NoError(t, err) + for _, v := range fi { expected[v.Name()] = tmpDir } actual := make(map[string]string) it, err := s.List(s.workDir) - if err != nil { - t.Error(err) - } + require.NoError(t, err) for { o, err := it.Next() @@ -84,7 +74,7 @@ func testHdfsReaddir(t *testing.T, numbers int) { } _, exist := actual[o.Path] if exist { - t.Errorf("file %s exists already", o.Path) + require.True(t, exist) return } diff --git a/utils_test.go b/utils_test.go index ea480d5..26983ba 100644 --- a/utils_test.go +++ b/utils_test.go @@ -5,17 +5,14 @@ import ( "os" "testing" - "github.com/beyondstorage/go-endpoint" - "github.com/beyondstorage/go-storage/v4/pairs" + ps "github.com/beyondstorage/go-storage/v4/pairs" "github.com/beyondstorage/go-storage/v4/services" "github.com/stretchr/testify/assert" ) func TestNewClient(t *testing.T) { - host := "127.0.0.1" - port := 9000 c, err := NewStorager( - pairs.WithEndpoint(endpoint.NewTCP(host, port).String()), + ps.WithEndpoint(os.Getenv("STORAGE_HDFS_ENDPOINT")), ) assert.NotNil(t, c) assert.NoError(t, err) From 63e35e63c413e71eab6634bbf3e93fa8f5b525d9 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Sat, 28 Aug 2021 11:42:47 +0800 Subject: [PATCH 03/23] fix action CI Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/unit-test.yml | 14 ++++++++++++++ go.mod | 9 ++------- go.sum | 23 ++--------------------- readdir_test.go | 8 ++++++-- 4 files changed, 24 insertions(+), 30 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index eeb0bc8..a5a0539 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -24,5 +24,19 @@ jobs: - name: Build run: make build + steps: + - uses: actions/setup-python@v2 + with: + python-version: '3.8' + - uses: actions/setup-java@v1 + with: + java-version: '11' + + - uses: beyondstorage/setup-hdfs@master + with: + hdfs-version: '3.3.1' + + - run: curl ${namenode-addr} + - name: Test run: make test diff --git a/go.mod b/go.mod index 007f606..c1fac14 100644 --- a/go.mod +++ b/go.mod @@ -6,13 +6,8 @@ require ( github.com/beyondstorage/go-endpoint v1.1.0 github.com/beyondstorage/go-integration-test/v4 v4.2.0 github.com/beyondstorage/go-storage/v4 v4.4.0 - github.com/colinmarc/hdfs/v2 v2.2.0 // indirect + github.com/colinmarc/hdfs/v2 v2.2.0 github.com/golang/protobuf v1.5.2 // indirect github.com/google/uuid v1.3.0 - github.com/jcmturner/aescts v2.0.0+incompatible // indirect - github.com/jcmturner/dnsutils v2.0.0+incompatible // indirect - github.com/jcmturner/goidentity v6.0.1+incompatible // indirect - github.com/jcmturner/gokrb5 v8.4.2+incompatible // indirect - github.com/jcmturner/rpc v1.1.1 // indirect - github.com/stretchr/testify v1.7.0 // indirect + github.com/stretchr/testify v1.7.0 ) diff --git a/go.sum b/go.sum index 7349607..4caa0b8 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,6 @@ github.com/beyondstorage/go-integration-test/v4 v4.2.0/go.mod h1:jLyYWSGUjQRH7U1 github.com/beyondstorage/go-storage/v4 v4.3.0/go.mod h1:0fdcRCzLKMQe7Ve4zPlyTGgoPYwuINiV79Gx9tCt9tQ= github.com/beyondstorage/go-storage/v4 v4.4.0 h1:sWURraKFjNR4qpwthr45cAGOIx6EOLrrJcz6su4Je30= github.com/beyondstorage/go-storage/v4 v4.4.0/go.mod h1:mc9VzBImjXDg1/1sLfta2MJH79elfM6m47ZZvZ+q/Uw= -github.com/colinmarc/hdfs v1.1.3 h1:662salalXLFmp+ctD+x0aG+xOg62lnVnOJHksXYpFBw= -github.com/colinmarc/hdfs v1.1.3/go.mod h1:0DumPviB681UcSuJErAbDIOx6SIaJWj463TymfZG02I= github.com/colinmarc/hdfs/v2 v2.2.0 h1:4AaIlTq+/sWmeqYhI0dX8bD4YrMQM990tRjm636FkGM= github.com/colinmarc/hdfs/v2 v2.2.0/go.mod h1:Wss6n3mtaZyRwWaqtSH+6ge01qT0rw9dJJmvoUnIQ/E= github.com/dave/dst v0.26.2 h1:lnxLAKI3tx7MgLNVDirFCsDTlTG9nKTk7GcptKcWSwY= @@ -35,31 +33,23 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= +github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ= github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE= github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/jcmturner/aescts v2.0.0+incompatible h1:NADOdvG7ba6APDycsRnElB5PGKPo1RYS0R9SPuH8uDI= -github.com/jcmturner/aescts v2.0.0+incompatible/go.mod h1:k9gJoDUf1GH5r2IBtBjwjDCoLELYxOcEhitdP8RL7qQ= github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8= github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= -github.com/jcmturner/dnsutils v2.0.0+incompatible h1:OncvQxiEJbkPrG9UL/25GmHtvs6w4IvcpYT0+FBpP6M= -github.com/jcmturner/dnsutils v2.0.0+incompatible/go.mod h1:tqMo38L01jO8AKxT0S9OQVlGZu3dkEt+z5CA+LOhwB0= github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo= github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM= github.com/jcmturner/gofork v1.0.0 h1:J7uCkflzTEhUZ64xqKnkDxq3kzc96ajM1Gli5ktUem8= github.com/jcmturner/gofork v1.0.0/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o= -github.com/jcmturner/goidentity v6.0.1+incompatible h1:I+jJ9JbbrqUAiMB8sNLXlginFJ2lPrxst/N3kb67Dko= -github.com/jcmturner/goidentity v6.0.1+incompatible/go.mod h1:1L/Wdvsh7UG1LqY2/yh6gzL7v/+3y7lXPHOAIlTaYio= github.com/jcmturner/goidentity/v6 v6.0.1 h1:VKnZd2oEIMorCTsFBnJWbExfNN7yZr3EhJAxwOkZg6o= github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg= -github.com/jcmturner/gokrb5 v8.4.2+incompatible h1:MQW70Fbazv31g6URAXCjO2bGenIL0wVt3wqcpc0EjHI= -github.com/jcmturner/gokrb5 v8.4.2+incompatible/go.mod h1:0Q5eFyVvYsEsZ8xl1A/jUqhXvxUp/X9ELrJm+zieq5E= github.com/jcmturner/gokrb5/v8 v8.4.1 h1:IGSJfqBzMS6TA0oJ7DxXdyzPK563QHa8T2IqER2ggyQ= github.com/jcmturner/gokrb5/v8 v8.4.1/go.mod h1:T1hnNppQsBtxW0tCHMHTkAt8n/sABdzZgZdoFrZaZNM= -github.com/jcmturner/rpc v1.1.1 h1:QStZbZ/rHemt0CZuZCBCFHA2Ez60qVIXBPpa6dzLKvc= -github.com/jcmturner/rpc v1.1.1/go.mod h1:6LzLUsxSQz8DjmFJ/6oxXY2LFB5F1yi0Sp01Ano39sQ= github.com/jcmturner/rpc/v2 v2.0.2 h1:gMB4IwRXYsWw4Bc6o/az2HJgFUA1ffSh90i26ZJ6Xl0= github.com/jcmturner/rpc/v2 v2.0.2/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= @@ -84,10 +74,8 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykE github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -105,7 +93,6 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0= @@ -126,7 +113,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190726230722-1bd56024c620/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs= @@ -142,11 +128,6 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/jcmturner/aescts.v1 v1.0.1/go.mod h1:nsR8qBOg+OucoIW+WMhB3GspUQXq9XorLnQb9XtvcOo= -gopkg.in/jcmturner/dnsutils.v1 v1.0.1/go.mod h1:m3v+5svpVOhtFAP/wSz+yzh4Mc0Fg7eRhxkJMWSIz9Q= -gopkg.in/jcmturner/goidentity.v3 v3.0.0/go.mod h1:oG2kH0IvSYNIu80dVAyu/yoefjq1mNfM5bm88whjWx4= -gopkg.in/jcmturner/gokrb5.v7 v7.3.0/go.mod h1:l8VISx+WGYp+Fp7KRbsiUuXTTOnxIc3Tuvyavf11/WM= -gopkg.in/jcmturner/rpc.v1 v1.1.0/go.mod h1:YIdkC4XfD6GXbzje11McwsDuOlZQSb9W4vfLvuNnlv8= gopkg.in/src-d/go-billy.v4 v4.3.0 h1:KtlZ4c1OWbIs4jCv5ZXrTqG8EQocr0g/d4DjNg70aek= gopkg.in/src-d/go-billy.v4 v4.3.0/go.mod h1:tm33zBoOwxjYHZIE+OV8bxTWFMJLrconzFMd38aARFk= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/readdir_test.go b/readdir_test.go index f13d0ef..9e0c09f 100644 --- a/readdir_test.go +++ b/readdir_test.go @@ -2,8 +2,8 @@ package hdfs import ( "fmt" + "github.com/beyondstorage/go-endpoint" "math/rand" - "os" "path" "testing" @@ -27,10 +27,14 @@ func TestHdfsDirerWithFiles(t *testing.T) { func testHdfsReaddir(t *testing.T, numbers int) { tmpDir := t.TempDir() + host:="127.0.0.1" + port:=9000 + s, err := newStorager( - ps.WithEndpoint(os.Getenv("STORAGE_HDFS_ENDPOINT")), + ps.WithEndpoint(endpoint.NewTCP(host,port).String()), ps.WithWorkDir(tmpDir), ) + require.NoError(t, err) err = s.hdfs.MkdirAll(tmpDir, 0666) From 8a9c46a03f3ca30e676e11700a23ccc9c4349c37 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Sat, 28 Aug 2021 11:45:03 +0800 Subject: [PATCH 04/23] fix CI Coverage Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/unit-test.yml | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index a5a0539..cfecd77 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -23,20 +23,19 @@ jobs: - name: Build run: make build + + - uses: actions/setup-python@v2 + with: + python-version: '3.8' + - uses: actions/setup-java@v1 + with: + java-version: '11' - steps: - - uses: actions/setup-python@v2 - with: - python-version: '3.8' - - uses: actions/setup-java@v1 - with: - java-version: '11' - - - uses: beyondstorage/setup-hdfs@master - with: - hdfs-version: '3.3.1' + - uses: beyondstorage/setup-hdfs@master + with: + hdfs-version: '3.3.1' - - run: curl ${namenode-addr} + - run: curl ${namenode-addr} - name: Test run: make test From 11dc2fd3c83f9fff633f912c50bd424167b41d82 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Sat, 28 Aug 2021 13:58:32 +0800 Subject: [PATCH 05/23] fix CI steps Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/unit-test.yml | 19 ++++++++++++------- readdir_test.go | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index cfecd77..ca76332 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -21,21 +21,26 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - - name: Build - run: make build - - - uses: actions/setup-python@v2 + - name: Checkout python env + uses: actions/setup-python@v2 with: python-version: '3.8' - - uses: actions/setup-java@v1 + + - name: Checkout java env + uses: actions/setup-java@v1 with: java-version: '11' - - uses: beyondstorage/setup-hdfs@master + - name: Setup-hdfs env + uses: beyondstorage/setup-hdfs@master with: hdfs-version: '3.3.1' - - run: curl ${namenode-addr} + - name: Get namenode-addr + run: curl ${namenode-addr} + + - name: Build + run: make build - name: Test run: make test diff --git a/readdir_test.go b/readdir_test.go index 9e0c09f..5c21956 100644 --- a/readdir_test.go +++ b/readdir_test.go @@ -2,11 +2,11 @@ package hdfs import ( "fmt" - "github.com/beyondstorage/go-endpoint" "math/rand" "path" "testing" + "github.com/beyondstorage/go-endpoint" ps "github.com/beyondstorage/go-storage/v4/pairs" "github.com/beyondstorage/go-storage/v4/types" "github.com/google/uuid" From fec8b4dac141eacef8b1757f7d17b1dbb1f04055 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Sat, 28 Aug 2021 22:09:05 +0800 Subject: [PATCH 06/23] fix curl namenode addr error Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/unit-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index ca76332..a3def84 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -37,7 +37,7 @@ jobs: hdfs-version: '3.3.1' - name: Get namenode-addr - run: curl ${namenode-addr} + run: curl ${{ env.HDFS_NAMENODE_ADDR }} - name: Build run: make build From 963abcfa0028b7c56478b1cb42375dda03ffa1c1 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Sat, 28 Aug 2021 22:19:01 +0800 Subject: [PATCH 07/23] remove windows and macos platform Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/unit-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index a3def84..5f6d79b 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: go: [ "1.15", "1.16" ] - os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-latest] steps: - name: Set up Go 1.x @@ -36,7 +36,7 @@ jobs: with: hdfs-version: '3.3.1' - - name: Get namenode-addr + - name: Get namenode addr run: curl ${{ env.HDFS_NAMENODE_ADDR }} - name: Build From 077aacc678cbb795718498fadadbd609adae6e4c Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Sat, 28 Aug 2021 22:26:39 +0800 Subject: [PATCH 08/23] fix utils error Signed-off-by: bokket <3100563328@qq.com> --- readdir_test.go | 6 +++--- utils_test.go | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/readdir_test.go b/readdir_test.go index 5c21956..9a200f5 100644 --- a/readdir_test.go +++ b/readdir_test.go @@ -27,11 +27,11 @@ func TestHdfsDirerWithFiles(t *testing.T) { func testHdfsReaddir(t *testing.T, numbers int) { tmpDir := t.TempDir() - host:="127.0.0.1" - port:=9000 + host := "127.0.0.1" + port := 9000 s, err := newStorager( - ps.WithEndpoint(endpoint.NewTCP(host,port).String()), + ps.WithEndpoint(endpoint.NewTCP(host, port).String()), ps.WithWorkDir(tmpDir), ) diff --git a/utils_test.go b/utils_test.go index 26983ba..8324c49 100644 --- a/utils_test.go +++ b/utils_test.go @@ -5,14 +5,18 @@ import ( "os" "testing" + "github.com/beyondstorage/go-endpoint" ps "github.com/beyondstorage/go-storage/v4/pairs" "github.com/beyondstorage/go-storage/v4/services" "github.com/stretchr/testify/assert" ) func TestNewClient(t *testing.T) { + host := "127.0.0.1" + port := 9000 + c, err := NewStorager( - ps.WithEndpoint(os.Getenv("STORAGE_HDFS_ENDPOINT")), + ps.WithEndpoint(endpoint.NewTCP(host, port).String()), ) assert.NotNil(t, c) assert.NoError(t, err) From 16d6a447a5855a42677eb0444b13fd754cbfaf79 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Sun, 29 Aug 2021 18:09:58 +0800 Subject: [PATCH 09/23] Add storager test Signed-off-by: bokket <3100563328@qq.com> --- readdir_test.go | 48 +++++++---------- storage.go | 5 +- storager_test.go | 135 +++++++++++++++++++++++++++++++++++++++++++++++ utils_test.go | 14 +++-- 4 files changed, 167 insertions(+), 35 deletions(-) create mode 100644 storager_test.go diff --git a/readdir_test.go b/readdir_test.go index 9a200f5..bc232f6 100644 --- a/readdir_test.go +++ b/readdir_test.go @@ -6,12 +6,9 @@ import ( "path" "testing" - "github.com/beyondstorage/go-endpoint" - ps "github.com/beyondstorage/go-storage/v4/pairs" "github.com/beyondstorage/go-storage/v4/types" "github.com/google/uuid" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestHdfsDirerWithFiles(t *testing.T) { @@ -25,21 +22,11 @@ func TestHdfsDirerWithFiles(t *testing.T) { } func testHdfsReaddir(t *testing.T, numbers int) { - tmpDir := t.TempDir() + s := NewClient(t) - host := "127.0.0.1" - port := 9000 + err := s.hdfs.MkdirAll(s.workDir, 0666) - s, err := newStorager( - ps.WithEndpoint(endpoint.NewTCP(host, port).String()), - ps.WithWorkDir(tmpDir), - ) - - require.NoError(t, err) - - err = s.hdfs.MkdirAll(tmpDir, 0666) - - require.NoError(t, err) + assert.NoError(t, err) for i := 0; i < numbers; i++ { @@ -47,38 +34,39 @@ func testHdfsReaddir(t *testing.T, numbers int) { f, err := s.hdfs.Create(path.Join(s.workDir, filename)) - require.NoError(t, err) - - defer func() { - closeErr := f.Close() - if err == nil { - err = closeErr - } - }() + assert.NoError(t, err) + assert.NotNil(t, f) - require.NoError(t, err) + err = f.Close() + assert.NoError(t, err) } expected := make(map[string]string) - fi, err := s.hdfs.ReadDir(tmpDir) - require.NoError(t, err) + fi, err := s.hdfs.ReadDir(s.workDir) + assert.NoError(t, err) + assert.NotNil(t, fi) for _, v := range fi { - expected[v.Name()] = tmpDir + expected[v.Name()] = s.workDir } actual := make(map[string]string) it, err := s.List(s.workDir) - require.NoError(t, err) + assert.NoError(t, err) + assert.NotNil(t, it) for { o, err := it.Next() + if err == types.IterateDone { break } + + assert.NotNil(t, o) + _, exist := actual[o.Path] if exist { - require.True(t, exist) + assert.True(t, exist) return } diff --git a/storage.go b/storage.go index 0b6e441..c38e58e 100644 --- a/storage.go +++ b/storage.go @@ -138,7 +138,7 @@ func (s *Storage) read(ctx context.Context, path string, w io.Writer, opt pairSt return 0, err } if opt.HasOffset { - _, err = f.Seek(opt.Offset, 0) + _, err := f.Seek(opt.Offset, 0) if err != nil { return 0, err } @@ -150,6 +150,9 @@ func (s *Storage) read(ctx context.Context, path string, w io.Writer, opt pairSt if opt.HasIoCallback { rc = iowrap.CallbackReader(rc, opt.IoCallback) } + if opt.HasSize { + return io.CopyN(w, f, opt.Size) + } return io.Copy(w, f) } diff --git a/storager_test.go b/storager_test.go new file mode 100644 index 0000000..3c2d2b6 --- /dev/null +++ b/storager_test.go @@ -0,0 +1,135 @@ +package hdfs + +import ( + "bytes" + "io" + "path" + "testing" + + ps "github.com/beyondstorage/go-storage/v4/pairs" + "github.com/stretchr/testify/assert" +) + +func TestStorage_String(t *testing.T) { + s := NewClient(t) + assert.NotEmpty(t, s.String()) +} + +func TestStorage_Metadata(t *testing.T) { + s := NewClient(t) + m := s.Metadata() + assert.NotNil(t, m) + assert.Equal(t, s.workDir, m.WorkDir) +} + +func TestStorage_Stat(t *testing.T) { + s := NewClient(t) + + err := s.hdfs.MkdirAll(s.workDir, 0666) + assert.NoError(t, err) + + t.Run("statDir", func(t *testing.T) { + stat, err := s.Stat(s.workDir) + assert.NoError(t, err) + assert.True(t, stat.Mode.IsDir()) + }) + + fname := "TestFileStat.txt" + f1, err := s.hdfs.Create(path.Join(s.workDir + fname)) + assert.NoError(t, err) + assert.NotNil(t, f1) + + stat2, err := s.hdfs.Stat(path.Join(s.workDir + fname)) + assert.NoError(t, err) + assert.NotNil(t, stat2) + + t.Run("statRegular", func(t *testing.T) { + stat1, err := s.Stat(path.Join(s.workDir + fname)) + assert.NoError(t, err) + assert.True(t, stat1.Mode.IsRead()) + + size, ok := stat1.GetContentLength() + assert.True(t, ok) + assert.Equal(t, size, stat2.Size()) + + time, ok := stat1.GetLastModified() + assert.True(t, ok) + assert.Equal(t, time, stat2.ModTime()) + }) +} + +func TestStorage_Read(t *testing.T) { + s := NewClient(t) + + fname := "TestFileSeek.txt" + + err := s.hdfs.MkdirAll(s.workDir, 0666) + assert.NoError(t, err) + + f1, err := s.hdfs.Create(path.Join(s.workDir + fname)) + assert.NoError(t, err) + + n, err := f1.Write([]byte("storager")) + assert.NoError(t, err) + assert.EqualValues(t, 8, n) + + err = f1.Close() + assert.NoError(t, err) + + t.Run("validSeek", func(t *testing.T) { + buf := new(bytes.Buffer) + o, err := s.Read(path.Join(s.workDir+fname), buf, + ps.WithOffset(2), + ) + assert.NoError(t, err) + assert.EqualValues(t, 6, o) + assert.Equal(t, "orager", string(buf.Bytes())) + + }) + + t.Run("invalidSeek", func(t *testing.T) { + buf := new(bytes.Buffer) + o, err := s.Read(path.Join(s.workDir+fname), buf, + ps.WithOffset(8), + ) + assert.NoError(t, err) + assert.EqualValues(t, 0, o) + assert.Equal(t, "", string(buf.Bytes())) + }) + + t.Run("validSeekSet", func(t *testing.T) { + buf := new(bytes.Buffer) + o, err := s.Read(path.Join(s.workDir+fname), buf, + ps.WithOffset(2), + ps.WithSize(5), + ) + assert.NoError(t, err) + assert.EqualValues(t, 5, o) + assert.Equal(t, "orage", string(buf.Bytes())) + }) + + t.Run("invalidSeekSet", func(t *testing.T) { + buf := new(bytes.Buffer) + o, err := s.Read(path.Join(s.workDir+fname), buf, + ps.WithOffset(2), + ps.WithSize(8), + ) + assert.EqualValues(t, s.formatError("read", io.EOF, path.Join(s.workDir+fname)), err) + assert.EqualValues(t, 6, o) + assert.Equal(t, "orager", string(buf.Bytes())) + }) + + t.Run("readWithCallBack", func(t *testing.T) { + buf := new(bytes.Buffer) + + cur := int64(0) + fn := func(b []byte) { + cur += int64(len(b)) + } + + o, err := s.Read(path.Join(s.workDir+fname), buf, ps.WithIoCallback(fn)) + assert.NoError(t, err) + assert.EqualValues(t, 8, o) + assert.Equal(t, "storager", string(buf.Bytes())) + }) +} diff --git a/utils_test.go b/utils_test.go index 8324c49..c0bbac6 100644 --- a/utils_test.go +++ b/utils_test.go @@ -9,17 +9,23 @@ import ( ps "github.com/beyondstorage/go-storage/v4/pairs" "github.com/beyondstorage/go-storage/v4/services" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) -func TestNewClient(t *testing.T) { +func NewClient(t *testing.T) *Storage { + tmpDir := t.TempDir() + host := "127.0.0.1" port := 9000 - c, err := NewStorager( + c, err := newStorager( ps.WithEndpoint(endpoint.NewTCP(host, port).String()), + ps.WithWorkDir(tmpDir), ) - assert.NotNil(t, c) - assert.NoError(t, err) + require.NotNil(t, c) + require.NoError(t, err) + + return c } func TestFormatOsError(t *testing.T) { From 31ec7d643317843e320d3d3dc68fedd99378bb76 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Sun, 29 Aug 2021 20:45:40 +0800 Subject: [PATCH 10/23] Add integration test Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/intergration-test.yml | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/intergration-test.yml diff --git a/.github/workflows/intergration-test.yml b/.github/workflows/intergration-test.yml new file mode 100644 index 0000000..73b0117 --- /dev/null +++ b/.github/workflows/intergration-test.yml @@ -0,0 +1,28 @@ +name: "Integration Test" + +on: [push, pull_request] + +jobs: + integration_test: + name: "Integration Test" + runs-on: ${{ matrix.os }} + + strategy: + matrix: + go: [ "1.15", "1.16" ] + os: [ubuntu-latest, windows-latest, macos-latest] + + steps: + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Test + env: + STORAGE_HDFS_INTEGRATION_TEST: "on" + STORAGE_HDFS_ENDPOINT: "tcp:127.0.0.1:9000" + run: make integration_test \ No newline at end of file From fc91db04a61049e17eb3287bce920e9b31083465 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Sun, 29 Aug 2021 20:54:05 +0800 Subject: [PATCH 11/23] fix CI error Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/intergration-test.yml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/intergration-test.yml b/.github/workflows/intergration-test.yml index 73b0117..9bf66c7 100644 --- a/.github/workflows/intergration-test.yml +++ b/.github/workflows/intergration-test.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: go: [ "1.15", "1.16" ] - os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-latest] steps: - name: Set up Go 1.x @@ -21,6 +21,24 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 + - name: Checkout python env + uses: actions/setup-python@v2 + with: + python-version: '3.8' + + - name: Checkout java env + uses: actions/setup-java@v1 + with: + java-version: '11' + + - name: Setup-hdfs env + uses: beyondstorage/setup-hdfs@master + with: + hdfs-version: '3.3.1' + + - name: Get namenode addr + run: curl ${{ env.HDFS_NAMENODE_ADDR }} + - name: Test env: STORAGE_HDFS_INTEGRATION_TEST: "on" From 0d3914993c0930491a95db48ab462122b0714179 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Sun, 29 Aug 2021 20:59:41 +0800 Subject: [PATCH 12/23] remove some unwanted context Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/unit-test.yml | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 5f6d79b..de4ecd4 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -21,26 +21,8 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - - name: Checkout python env - uses: actions/setup-python@v2 - with: - python-version: '3.8' - - - name: Checkout java env - uses: actions/setup-java@v1 - with: - java-version: '11' - - - name: Setup-hdfs env - uses: beyondstorage/setup-hdfs@master - with: - hdfs-version: '3.3.1' - - - name: Get namenode addr - run: curl ${{ env.HDFS_NAMENODE_ADDR }} - - name: Build run: make build - name: Test - run: make test + run: make test \ No newline at end of file From 204023dd7971a13f2dfc176c6960eaab46cb0c3b Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Sun, 29 Aug 2021 21:04:24 +0800 Subject: [PATCH 13/23] fix unit test error Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/unit-test.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index de4ecd4..3358bd8 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -21,6 +21,24 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 + - name: Checkout python env + uses: actions/setup-python@v2 + with: + python-version: '3.8' + + - name: Checkout java env + uses: actions/setup-java@v1 + with: + java-version: '11' + + - name: Setup-hdfs env + uses: beyondstorage/setup-hdfs@master + with: + hdfs-version: '3.3.1' + + - name: Get namenode addr + run: curl ${{ env.HDFS_NAMENODE_ADDR }} + - name: Build run: make build From 35d41614037235f89e7c1dd0214fdf07e9682d6f Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Sun, 29 Aug 2021 21:20:45 +0800 Subject: [PATCH 14/23] fix connect refused Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/intergration-test.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/intergration-test.yml b/.github/workflows/intergration-test.yml index 9bf66c7..cdbc0d3 100644 --- a/.github/workflows/intergration-test.yml +++ b/.github/workflows/intergration-test.yml @@ -36,11 +36,8 @@ jobs: with: hdfs-version: '3.3.1' - - name: Get namenode addr - run: curl ${{ env.HDFS_NAMENODE_ADDR }} - - name: Test env: STORAGE_HDFS_INTEGRATION_TEST: "on" - STORAGE_HDFS_ENDPOINT: "tcp:127.0.0.1:9000" + STORAGE_HDFS_ENDPOINT: ${{ env.HDFS_NAMENODE_ADDR }} run: make integration_test \ No newline at end of file From 58c034252a9419ac9334f3401b126193981d86b6 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Sun, 29 Aug 2021 21:25:09 +0800 Subject: [PATCH 15/23] fix endpoint error Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/intergration-test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/intergration-test.yml b/.github/workflows/intergration-test.yml index cdbc0d3..0f286ee 100644 --- a/.github/workflows/intergration-test.yml +++ b/.github/workflows/intergration-test.yml @@ -36,8 +36,11 @@ jobs: with: hdfs-version: '3.3.1' + - name: Get namenode addr + run: curl ${{ env.HDFS_NAMENODE_ADDR }} + - name: Test env: STORAGE_HDFS_INTEGRATION_TEST: "on" - STORAGE_HDFS_ENDPOINT: ${{ env.HDFS_NAMENODE_ADDR }} + STORAGE_HDFS_ENDPOINT: ${{ secrets.STORAGE_HDFS_ENDPOINT }} run: make integration_test \ No newline at end of file From 4d2fddb9310ecfa1cca857f8e12eacd50b4aff6f Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Sun, 29 Aug 2021 21:29:15 +0800 Subject: [PATCH 16/23] fix hdfs addr error Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/intergration-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/intergration-test.yml b/.github/workflows/intergration-test.yml index 0f286ee..9bf66c7 100644 --- a/.github/workflows/intergration-test.yml +++ b/.github/workflows/intergration-test.yml @@ -42,5 +42,5 @@ jobs: - name: Test env: STORAGE_HDFS_INTEGRATION_TEST: "on" - STORAGE_HDFS_ENDPOINT: ${{ secrets.STORAGE_HDFS_ENDPOINT }} + STORAGE_HDFS_ENDPOINT: "tcp:127.0.0.1:9000" run: make integration_test \ No newline at end of file From c8b6adc99884d8fb3b7645452bcc257e840bf61d Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Mon, 30 Aug 2021 17:58:00 +0800 Subject: [PATCH 17/23] fix some issue Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/intergration-test.yml | 6 +- .github/workflows/unit-test.yml | 18 ---- readdir_test.go | 77 -------------- storage.go | 2 +- storager_test.go | 135 ------------------------ tests/storage_test.go | 2 +- tests/utils_test.go | 2 +- utils.go | 2 +- utils_test.go | 21 +--- 9 files changed, 7 insertions(+), 258 deletions(-) delete mode 100644 readdir_test.go delete mode 100644 storager_test.go diff --git a/.github/workflows/intergration-test.yml b/.github/workflows/intergration-test.yml index 9bf66c7..e5969de 100644 --- a/.github/workflows/intergration-test.yml +++ b/.github/workflows/intergration-test.yml @@ -10,6 +10,7 @@ jobs: strategy: matrix: go: [ "1.15", "1.16" ] + hdfs: [ "2.10.1", "2.2.2", "3.3.0", "3.3.1"] os: [ubuntu-latest] steps: @@ -34,10 +35,7 @@ jobs: - name: Setup-hdfs env uses: beyondstorage/setup-hdfs@master with: - hdfs-version: '3.3.1' - - - name: Get namenode addr - run: curl ${{ env.HDFS_NAMENODE_ADDR }} + hdfs-version: ${{ matrix.hdfs }} - name: Test env: diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 3358bd8..de4ecd4 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -21,24 +21,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - - name: Checkout python env - uses: actions/setup-python@v2 - with: - python-version: '3.8' - - - name: Checkout java env - uses: actions/setup-java@v1 - with: - java-version: '11' - - - name: Setup-hdfs env - uses: beyondstorage/setup-hdfs@master - with: - hdfs-version: '3.3.1' - - - name: Get namenode addr - run: curl ${{ env.HDFS_NAMENODE_ADDR }} - - name: Build run: make build diff --git a/readdir_test.go b/readdir_test.go deleted file mode 100644 index bc232f6..0000000 --- a/readdir_test.go +++ /dev/null @@ -1,77 +0,0 @@ -package hdfs - -import ( - "fmt" - "math/rand" - "path" - "testing" - - "github.com/beyondstorage/go-storage/v4/types" - "github.com/google/uuid" - "github.com/stretchr/testify/assert" -) - -func TestHdfsDirerWithFiles(t *testing.T) { - for i := 0; i < 10; i++ { - numbers := 1000 + rand.Intn(1000) - - t.Run(fmt.Sprintf("list %d files", numbers), func(t *testing.T) { - testHdfsReaddir(t, numbers) - }) - } -} - -func testHdfsReaddir(t *testing.T, numbers int) { - s := NewClient(t) - - err := s.hdfs.MkdirAll(s.workDir, 0666) - - assert.NoError(t, err) - - for i := 0; i < numbers; i++ { - - filename := uuid.New().String() - - f, err := s.hdfs.Create(path.Join(s.workDir, filename)) - - assert.NoError(t, err) - assert.NotNil(t, f) - - err = f.Close() - assert.NoError(t, err) - } - - expected := make(map[string]string) - fi, err := s.hdfs.ReadDir(s.workDir) - assert.NoError(t, err) - assert.NotNil(t, fi) - - for _, v := range fi { - expected[v.Name()] = s.workDir - } - - actual := make(map[string]string) - it, err := s.List(s.workDir) - assert.NoError(t, err) - assert.NotNil(t, it) - - for { - o, err := it.Next() - - if err == types.IterateDone { - break - } - - assert.NotNil(t, o) - - _, exist := actual[o.Path] - if exist { - assert.True(t, exist) - return - } - - actual[o.Path] = o.ID - } - assert.Equal(t, expected, actual) - -} diff --git a/storage.go b/storage.go index c38e58e..ceea3bb 100644 --- a/storage.go +++ b/storage.go @@ -228,4 +228,4 @@ func (s *Storage) writeAppend(ctx context.Context, o *Object, r io.Reader, size }() return io.CopyN(f, r, size) -} +} \ No newline at end of file diff --git a/storager_test.go b/storager_test.go deleted file mode 100644 index 3c2d2b6..0000000 --- a/storager_test.go +++ /dev/null @@ -1,135 +0,0 @@ -package hdfs - -import ( - "bytes" - "io" - "path" - "testing" - - ps "github.com/beyondstorage/go-storage/v4/pairs" - "github.com/stretchr/testify/assert" -) - -func TestStorage_String(t *testing.T) { - s := NewClient(t) - assert.NotEmpty(t, s.String()) -} - -func TestStorage_Metadata(t *testing.T) { - s := NewClient(t) - m := s.Metadata() - assert.NotNil(t, m) - assert.Equal(t, s.workDir, m.WorkDir) -} - -func TestStorage_Stat(t *testing.T) { - s := NewClient(t) - - err := s.hdfs.MkdirAll(s.workDir, 0666) - assert.NoError(t, err) - - t.Run("statDir", func(t *testing.T) { - stat, err := s.Stat(s.workDir) - assert.NoError(t, err) - assert.True(t, stat.Mode.IsDir()) - }) - - fname := "TestFileStat.txt" - f1, err := s.hdfs.Create(path.Join(s.workDir + fname)) - assert.NoError(t, err) - assert.NotNil(t, f1) - - stat2, err := s.hdfs.Stat(path.Join(s.workDir + fname)) - assert.NoError(t, err) - assert.NotNil(t, stat2) - - t.Run("statRegular", func(t *testing.T) { - stat1, err := s.Stat(path.Join(s.workDir + fname)) - assert.NoError(t, err) - assert.True(t, stat1.Mode.IsRead()) - - size, ok := stat1.GetContentLength() - assert.True(t, ok) - assert.Equal(t, size, stat2.Size()) - - time, ok := stat1.GetLastModified() - assert.True(t, ok) - assert.Equal(t, time, stat2.ModTime()) - }) -} - -func TestStorage_Read(t *testing.T) { - s := NewClient(t) - - fname := "TestFileSeek.txt" - - err := s.hdfs.MkdirAll(s.workDir, 0666) - assert.NoError(t, err) - - f1, err := s.hdfs.Create(path.Join(s.workDir + fname)) - assert.NoError(t, err) - - n, err := f1.Write([]byte("storager")) - assert.NoError(t, err) - assert.EqualValues(t, 8, n) - - err = f1.Close() - assert.NoError(t, err) - - t.Run("validSeek", func(t *testing.T) { - buf := new(bytes.Buffer) - o, err := s.Read(path.Join(s.workDir+fname), buf, - ps.WithOffset(2), - ) - assert.NoError(t, err) - assert.EqualValues(t, 6, o) - assert.Equal(t, "orager", string(buf.Bytes())) - - }) - - t.Run("invalidSeek", func(t *testing.T) { - buf := new(bytes.Buffer) - o, err := s.Read(path.Join(s.workDir+fname), buf, - ps.WithOffset(8), - ) - assert.NoError(t, err) - assert.EqualValues(t, 0, o) - assert.Equal(t, "", string(buf.Bytes())) - }) - - t.Run("validSeekSet", func(t *testing.T) { - buf := new(bytes.Buffer) - o, err := s.Read(path.Join(s.workDir+fname), buf, - ps.WithOffset(2), - ps.WithSize(5), - ) - assert.NoError(t, err) - assert.EqualValues(t, 5, o) - assert.Equal(t, "orage", string(buf.Bytes())) - }) - - t.Run("invalidSeekSet", func(t *testing.T) { - buf := new(bytes.Buffer) - o, err := s.Read(path.Join(s.workDir+fname), buf, - ps.WithOffset(2), - ps.WithSize(8), - ) - assert.EqualValues(t, s.formatError("read", io.EOF, path.Join(s.workDir+fname)), err) - assert.EqualValues(t, 6, o) - assert.Equal(t, "orager", string(buf.Bytes())) - }) - - t.Run("readWithCallBack", func(t *testing.T) { - buf := new(bytes.Buffer) - - cur := int64(0) - fn := func(b []byte) { - cur += int64(len(b)) - } - - o, err := s.Read(path.Join(s.workDir+fname), buf, ps.WithIoCallback(fn)) - assert.NoError(t, err) - assert.EqualValues(t, 8, o) - assert.Equal(t, "storager", string(buf.Bytes())) - }) -} diff --git a/tests/storage_test.go b/tests/storage_test.go index 8784bbb..3d2cf0c 100644 --- a/tests/storage_test.go +++ b/tests/storage_test.go @@ -33,4 +33,4 @@ func TestAppender(t *testing.T) { t.Skipf("STORAGE_HDFS_INTEGRATION_TEST is not 'on', skipped") } tests.TestAppender(t, setupTest(t)) -} +} \ No newline at end of file diff --git a/tests/utils_test.go b/tests/utils_test.go index 058cfab..8ac5a60 100644 --- a/tests/utils_test.go +++ b/tests/utils_test.go @@ -23,4 +23,4 @@ func setupTest(t *testing.T) types.Storager { } return store -} +} \ No newline at end of file diff --git a/utils.go b/utils.go index dea6763..ae23e1b 100644 --- a/utils.go +++ b/utils.go @@ -115,4 +115,4 @@ func (s *Storage) formatError(op string, err error, path ...string) error { func (s *Storage) newObject(done bool) *types.Object { return types.NewObject(s, done) -} +} \ No newline at end of file diff --git a/utils_test.go b/utils_test.go index c0bbac6..cdbecde 100644 --- a/utils_test.go +++ b/utils_test.go @@ -5,29 +5,10 @@ import ( "os" "testing" - "github.com/beyondstorage/go-endpoint" - ps "github.com/beyondstorage/go-storage/v4/pairs" "github.com/beyondstorage/go-storage/v4/services" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) -func NewClient(t *testing.T) *Storage { - tmpDir := t.TempDir() - - host := "127.0.0.1" - port := 9000 - - c, err := newStorager( - ps.WithEndpoint(endpoint.NewTCP(host, port).String()), - ps.WithWorkDir(tmpDir), - ) - require.NotNil(t, c) - require.NoError(t, err) - - return c -} - func TestFormatOsError(t *testing.T) { testErr := errors.New("test error") tests := []struct { @@ -78,4 +59,4 @@ func TestGetAbsPath(t *testing.T) { assert.Equal(t, tt.expectedPath, getPath) }) } -} +} \ No newline at end of file From 0953d7223d27dbcc992b0bf08e6fe1aab40cd8c8 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Mon, 30 Aug 2021 18:02:07 +0800 Subject: [PATCH 18/23] Add run daemon Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/intergration-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/intergration-test.yml b/.github/workflows/intergration-test.yml index e5969de..dbaa59e 100644 --- a/.github/workflows/intergration-test.yml +++ b/.github/workflows/intergration-test.yml @@ -36,6 +36,7 @@ jobs: uses: beyondstorage/setup-hdfs@master with: hdfs-version: ${{ matrix.hdfs }} + run_daemon: true - name: Test env: From 7215251afafe602d28c6d45b1e876497a94e35b9 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Mon, 30 Aug 2021 20:32:25 +0800 Subject: [PATCH 19/23] fix hdfs version error Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/intergration-test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/intergration-test.yml b/.github/workflows/intergration-test.yml index dbaa59e..5bd673e 100644 --- a/.github/workflows/intergration-test.yml +++ b/.github/workflows/intergration-test.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: go: [ "1.15", "1.16" ] - hdfs: [ "2.10.1", "2.2.2", "3.3.0", "3.3.1"] + hdfs: [ "2.10.1", "3.2.2", "3.3.0", "3.3.1"] os: [ubuntu-latest] steps: @@ -36,7 +36,6 @@ jobs: uses: beyondstorage/setup-hdfs@master with: hdfs-version: ${{ matrix.hdfs }} - run_daemon: true - name: Test env: From e3a97ea1aef4b1126850bcbf2f89d85f763f836a Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Mon, 30 Aug 2021 20:35:33 +0800 Subject: [PATCH 20/23] add curl addr Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/intergration-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/intergration-test.yml b/.github/workflows/intergration-test.yml index 5bd673e..8df1107 100644 --- a/.github/workflows/intergration-test.yml +++ b/.github/workflows/intergration-test.yml @@ -37,6 +37,8 @@ jobs: with: hdfs-version: ${{ matrix.hdfs }} + - run: curl ${{ env.HDFS_NAMENODE_ADDR }} + - name: Test env: STORAGE_HDFS_INTEGRATION_TEST: "on" From 231c2ceb4ec5807b1aafdb49a71f00b6f30313f2 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Mon, 30 Aug 2021 20:42:33 +0800 Subject: [PATCH 21/23] fix connection refused Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/intergration-test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/intergration-test.yml b/.github/workflows/intergration-test.yml index 8df1107..1a826d2 100644 --- a/.github/workflows/intergration-test.yml +++ b/.github/workflows/intergration-test.yml @@ -37,7 +37,8 @@ jobs: with: hdfs-version: ${{ matrix.hdfs }} - - run: curl ${{ env.HDFS_NAMENODE_ADDR }} + - name: Get namenode addr + run: curl ${{ env.HDFS_NAMENODE_ADDR }} - name: Test env: From 643a2ed0495a1604bb6c49985734159811dc1586 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Mon, 30 Aug 2021 20:51:38 +0800 Subject: [PATCH 22/23] fix connection error Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/intergration-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/intergration-test.yml b/.github/workflows/intergration-test.yml index 1a826d2..3d37c65 100644 --- a/.github/workflows/intergration-test.yml +++ b/.github/workflows/intergration-test.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: go: [ "1.15", "1.16" ] - hdfs: [ "2.10.1", "3.2.2", "3.3.0", "3.3.1"] + hdfs-version: [ "2.10.1", "3.2.2", "3.3.0", "3.3.1"] os: [ubuntu-latest] steps: @@ -35,7 +35,7 @@ jobs: - name: Setup-hdfs env uses: beyondstorage/setup-hdfs@master with: - hdfs-version: ${{ matrix.hdfs }} + hdfs-version: ${{ matrix.hdfs-version }} - name: Get namenode addr run: curl ${{ env.HDFS_NAMENODE_ADDR }} From a4a67d59e37e8a50f0773596ced4c00a81bb92b9 Mon Sep 17 00:00:00 2001 From: bokket <3100563328@qq.com> Date: Tue, 31 Aug 2021 17:27:00 +0800 Subject: [PATCH 23/23] remove hdfs version '2.10.1' Signed-off-by: bokket <3100563328@qq.com> --- .github/workflows/intergration-test.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/intergration-test.yml b/.github/workflows/intergration-test.yml index 3d37c65..542c7bd 100644 --- a/.github/workflows/intergration-test.yml +++ b/.github/workflows/intergration-test.yml @@ -10,7 +10,10 @@ jobs: strategy: matrix: go: [ "1.15", "1.16" ] - hdfs-version: [ "2.10.1", "3.2.2", "3.3.0", "3.3.1"] + hdfs-version: + - 3.2.2 + - 3.3.0 + - 3.3.1 os: [ubuntu-latest] steps: @@ -37,8 +40,7 @@ jobs: with: hdfs-version: ${{ matrix.hdfs-version }} - - name: Get namenode addr - run: curl ${{ env.HDFS_NAMENODE_ADDR }} + - run: curl ${{ env.HDFS_NAMENODE_ADDR }} - name: Test env: