Skip to content

Commit

Permalink
Move the shared code in fs/decomposed to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Feb 16, 2021
1 parent bdc9ced commit 1768fc4
Show file tree
Hide file tree
Showing 29 changed files with 251 additions and 171 deletions.
6 changes: 3 additions & 3 deletions pkg/storage/fs/ocis/ocis.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"path"

"github.com/cs3org/reva/pkg/storage"
"github.com/cs3org/reva/pkg/storage/fs/decomposed"
"github.com/cs3org/reva/pkg/storage/fs/decomposed/options"
"github.com/cs3org/reva/pkg/storage/fs/ocis/blobstore"
"github.com/cs3org/reva/pkg/storage/fs/registry"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/options"
)

func init() {
Expand All @@ -45,5 +45,5 @@ func New(m map[string]interface{}) (storage.FS, error) {
return nil, err
}

return decomposed.NewDefault(m, bs)
return decomposedfs.NewDefault(m, bs)
}
119 changes: 11 additions & 108 deletions pkg/storage/fs/ocis/ocis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,11 @@
package ocis_test

import (
"context"
"fmt"
"io/ioutil"
"os"
"path"
"sync"
"strings"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/storage"
"github.com/cs3org/reva/pkg/storage/fs/ocis"
"github.com/cs3org/reva/pkg/user"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -39,114 +32,24 @@ import (
var _ = Describe("Ocis", func() {
var (
options map[string]interface{}
ctx context.Context
tmpDir string
fs storage.FS
tmpRoot string
)

BeforeEach(func() {
tmpDir, _ = ioutil.TempDir("", "ocis_fs_unittests")
tmpRoot, err := ioutil.TempDir("", "reva-unit-tests-*-root")
Expect(err).ToNot(HaveOccurred())

options = map[string]interface{}{
"root": tmpDir,
"enable_home": false,
"user_layout": "{{.Id.OpaqueId}}",
"owner": "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c",
"root": tmpRoot,
"enable_home": true,
"share_folder": "/Shares",
}
u := &userpb.User{
Id: &userpb.UserId{
OpaqueId: "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c",
},
Username: "test",
Mail: "marie@example.org",
DisplayName: "Marie Curie",
Groups: []string{
"radium-lovers",
"polonium-lovers",
"physics-lovers",
},
}
ctx = user.ContextSetUser(context.Background(), u)

var err error
fs, err = ocis.New(options)
Expect(err).ToNot(HaveOccurred())
})

Describe("concurrent", func() {
Describe("Upload", func() {
var (
f, f1 *os.File
)

BeforeEach(func() {
// Prepare two test files for upload
err := ioutil.WriteFile(fmt.Sprintf("%s/%s", tmpDir, "f.lol"), []byte("test"), 0644)
Expect(err).ToNot(HaveOccurred())
f, err = os.Open(fmt.Sprintf("%s/%s", tmpDir, "f.lol"))
Expect(err).ToNot(HaveOccurred())

err = ioutil.WriteFile(fmt.Sprintf("%s/%s", tmpDir, "f1.lol"), []byte("another run"), 0644)
Expect(err).ToNot(HaveOccurred())
f1, err = os.Open(fmt.Sprintf("%s/%s", tmpDir, "f1.lol"))
Expect(err).ToNot(HaveOccurred())
})

PIt("generates two revisions", func() {
//runtime.GOMAXPROCS(1) // uncomment to remove concurrency and see revisions working.
wg := &sync.WaitGroup{}
wg.Add(2)

// upload file with contents: "test"
go func(wg *sync.WaitGroup) {
fs.Upload(ctx, &provider.Reference{
Spec: &provider.Reference_Path{Path: "uploaded.txt"},
}, f)
wg.Done()
}(wg)

// upload file with contents: "another run"
go func(wg *sync.WaitGroup) {
fs.Upload(ctx, &provider.Reference{
Spec: &provider.Reference_Path{Path: "uploaded.txt"},
}, f1)
wg.Done()
}(wg)

// this test, by the way the oCIS storage is implemented, is non-deterministic, and the contents
// of uploaded.txt will change on each run depending on which of the 2 routines above makes it
// first into the scheduler. In order to make it deterministic, we have to consider the Upload impl-
// ementation and we can leverage concurrency and add locks only when the destination path are the
// same for 2 uploads.

wg.Wait()
revisions, err := fs.ListRevisions(ctx, &provider.Reference{
Spec: &provider.Reference_Path{Path: "uploaded.txt"},
})
Expect(err).ToNot(HaveOccurred())
Expect(len(revisions)).To(Equal(1))

_, err = ioutil.ReadFile(path.Join(tmpDir, "nodes", "root", "uploaded.txt"))
Expect(err).ToNot(HaveOccurred())
})
})

Describe("CreateDir", func() {
It("handle already existing directories", func() {
for i := 0; i < 10; i++ {
go func() {
err := fs.CreateDir(ctx, "fightforit")
if err != nil {
rinfo, err := fs.GetMD(ctx, &provider.Reference{
Spec: &provider.Reference_Path{Path: "fightforit"},
}, nil)
Expect(err).ToNot(HaveOccurred())
Expect(rinfo).ToNot(BeNil())
}
}()
}
})
})
AfterEach(func() {
if strings.HasPrefix(tmpRoot, os.TempDir()) {
os.RemoveAll(tmpRoot)
}
})

Describe("New", func() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/fs/s3ng/s3ng.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"fmt"

"github.com/cs3org/reva/pkg/storage"
"github.com/cs3org/reva/pkg/storage/fs/decomposed"
"github.com/cs3org/reva/pkg/storage/fs/registry"
"github.com/cs3org/reva/pkg/storage/fs/s3ng/blobstore"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs"
)

func init() {
Expand All @@ -48,5 +48,5 @@ func New(m map[string]interface{}) (storage.FS, error) {
return nil, err
}

return decomposed.NewDefault(m, bs)
return decomposedfs.NewDefault(m, bs)
}
15 changes: 15 additions & 0 deletions pkg/storage/fs/s3ng/s3ng_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
package s3ng_test

import (
"io/ioutil"
"os"
"strings"

"github.com/cs3org/reva/pkg/storage/fs/s3ng"

. "github.com/onsi/ginkgo"
Expand All @@ -28,10 +32,15 @@ import (
var _ = Describe("S3ng", func() {
var (
options map[string]interface{}
tmpRoot string
)

BeforeEach(func() {
tmpRoot, err := ioutil.TempDir("", "reva-unit-tests-*-root")
Expect(err).ToNot(HaveOccurred())

options = map[string]interface{}{
"root": tmpRoot,
"enable_home": true,
"share_folder": "/Shares",
"s3.endpoint": "http://1.2.3.4:5000",
Expand All @@ -42,6 +51,12 @@ var _ = Describe("S3ng", func() {
}
})

AfterEach(func() {
if strings.HasPrefix(tmpRoot, os.TempDir()) {
os.RemoveAll(tmpRoot)
}
})

Describe("New", func() {
It("fails on missing s3 configuration", func() {
_, err := s3ng.New(map[string]interface{}{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package decomposed
package decomposedfs

//go:generate mockery -name PermissionsChecker
//go:generate mockery -name Tree
Expand All @@ -34,11 +34,11 @@ import (
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/logger"
"github.com/cs3org/reva/pkg/storage"
"github.com/cs3org/reva/pkg/storage/fs/decomposed/node"
"github.com/cs3org/reva/pkg/storage/fs/decomposed/options"
"github.com/cs3org/reva/pkg/storage/fs/decomposed/tree"
"github.com/cs3org/reva/pkg/storage/fs/decomposed/xattrs"
"github.com/cs3org/reva/pkg/storage/utils/chunking"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/node"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/options"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/tree"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/xattrs"
"github.com/cs3org/reva/pkg/storage/utils/templates"
"github.com/cs3org/reva/pkg/user"
"github.com/pkg/errors"
Expand Down
Loading

0 comments on commit 1768fc4

Please sign in to comment.