forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert last 7 reverts (blobstore read and write in chunks)
This reverts commit 688739b. Signed-off-by: Kam Leung <[email protected]>
- Loading branch information
Showing
36 changed files
with
344 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,8 @@ gobin/* | |
*.sublime-workspace | ||
*.sw* | ||
|
||
test/bosh/*.json | ||
test/micro_bosh | ||
|
||
/.idea | ||
/.vagrant | ||
/.vagrant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 71 additions & 21 deletions
92
internal/github.com/cloudfoundry/bosh-utils/blobstore/blob_manager_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,89 @@ | ||
package blobstore_test | ||
|
||
import ( | ||
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/ginkgo" | ||
. "github.com/cloudfoundry/bosh-agent/internal/github.com/onsi/gomega" | ||
|
||
"bytes" | ||
. "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/blobstore" | ||
fakesys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
boshlog "github.com/cloudfoundry/bosh-utils/logger" | ||
boshsys "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system" | ||
boshsysfake "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func createBlobManager() (blobManager BlobManager, fs *fakesys.FakeFileSystem) { | ||
fs = fakesys.NewFakeFileSystem() | ||
blobManager = NewBlobManager(fs, "/var/vcap/micro_bosh/data/cache") | ||
return | ||
} | ||
var _ = Describe("Blob Manager", func() { | ||
var ( | ||
fs boshsys.FileSystem | ||
logger boshlog.Logger | ||
basePath string | ||
blobPath string | ||
blobId string | ||
toWrite io.Reader | ||
) | ||
|
||
BeforeEach(func() { | ||
logger = boshlog.NewLogger(boshlog.LevelNone) | ||
fs = boshsys.NewOsFileSystem(logger) | ||
blobId = "105d33ae-655c-493d-bf9f-1df5cf3ca847" | ||
basePath = "/tmp" | ||
blobPath = filepath.Join(basePath, blobId) | ||
toWrite = bytes.NewReader([]byte("new data")) | ||
}) | ||
|
||
readFile := func(fileIO boshsys.File) []byte { | ||
fileStat, _ := fileIO.Stat() | ||
fileBytes := make([]byte, fileStat.Size()) | ||
fileIO.Read(fileBytes) | ||
return fileBytes | ||
} | ||
|
||
It("fetches", func() { | ||
blobManager := NewBlobManager(fs, basePath) | ||
fs.WriteFileString(blobPath, "some data") | ||
|
||
var _ = Describe("Testing with Ginkgo", func() { | ||
It("fetch", func() { | ||
blobManager, fs := createBlobManager() | ||
fs.WriteFileString("/var/vcap/micro_bosh/data/cache/105d33ae-655c-493d-bf9f-1df5cf3ca847", "some data") | ||
readOnlyFile, err, _ := blobManager.Fetch(blobId) | ||
defer fs.RemoveAll(readOnlyFile.Name()) | ||
|
||
blobBytes, err := blobManager.Fetch("105d33ae-655c-493d-bf9f-1df5cf3ca847") | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(string(blobBytes)).To(Equal("some data")) | ||
}) | ||
fileBytes := readFile(readOnlyFile) | ||
|
||
It("write", func() { | ||
Expect(string(fileBytes)).To(Equal("some data")) | ||
}) | ||
|
||
blobManager, fs := createBlobManager() | ||
fs.WriteFileString("/var/vcap/micro_bosh/data/cache/105d33ae-655c-493d-bf9f-1df5cf3ca847", "some data") | ||
It("writes", func() { | ||
blobManager := NewBlobManager(fs, basePath) | ||
fs.WriteFileString(blobPath, "some data") | ||
defer fs.RemoveAll(blobPath) | ||
|
||
err := blobManager.Write("105d33ae-655c-493d-bf9f-1df5cf3ca847", []byte("new data")) | ||
err := blobManager.Write(blobId, toWrite) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
contents, err := fs.ReadFileString("/var/vcap/micro_bosh/data/cache/105d33ae-655c-493d-bf9f-1df5cf3ca847") | ||
contents, err := fs.ReadFileString(blobPath) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(contents).To(Equal("new data")) | ||
}) | ||
|
||
Context("when it writes", func() { | ||
It("creates and closes the file", func() { | ||
fs_ := boshsysfake.NewFakeFileSystem() | ||
blobManager := NewBlobManager(fs_, basePath) | ||
err := blobManager.Write(blobId, toWrite) | ||
Expect(err).ToNot(HaveOccurred()) | ||
fileStats, err := fs_.FindFileStats(blobPath) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(fileStats.Open).To(BeFalse()) | ||
}) | ||
It("creates file with correct permissions", func() { | ||
fs_ := boshsysfake.NewFakeFileSystem() | ||
blobManager := NewBlobManager(fs_, basePath) | ||
err := blobManager.Write(blobId, toWrite) | ||
fileStats, err := fs_.FindFileStats(blobPath) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(fileStats.FileMode).To(Equal(os.FileMode(0666))) | ||
Expect(fileStats.Flags).To(Equal(os.O_WRONLY | os.O_CREATE | os.O_TRUNC)) | ||
}) | ||
}) | ||
|
||
}) |
4 changes: 2 additions & 2 deletions
4
internal/github.com/cloudfoundry/bosh-utils/blobstore/blobstore_suite_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
internal/github.com/cloudfoundry/bosh-utils/blobstore/provider_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
internal/github.com/cloudfoundry/bosh-utils/blobstore/retryable_blobstore.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
internal/github.com/cloudfoundry/bosh-utils/logger/logger_suite_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.