-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- I'm just leaving this in here in case I need to debug this scenario again.
- Loading branch information
1 parent
419f7c2
commit 17b0e62
Showing
2 changed files
with
79 additions
and
2 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 |
---|---|---|
@@ -1 +1,13 @@ | ||
package blob_cache | ||
package blob_cache_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"testing" | ||
) | ||
|
||
func TestBlobCache(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Blob Cache Suite") | ||
} |
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 +1,66 @@ | ||
package blob_cache | ||
package blob_cache_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"io/ioutil" | ||
"os" | ||
"github.com/karlseguin/ccache" | ||
"s3proxy/fakes" | ||
"s3proxy/blob_cache" | ||
"golang.org/x/net/context" | ||
"s3proxy/context" | ||
"s3proxy/source" | ||
"time" | ||
"sync" | ||
"io" | ||
"fmt" | ||
) | ||
|
||
var _ = Describe("Testing blob cache", func() { | ||
Context("Sanity", func() { | ||
It("Just works", func() { | ||
cacheDir, err := ioutil.TempDir("", "cached-") | ||
Expect(err).To(BeNil()) | ||
defer os.RemoveAll(cacheDir) | ||
|
||
bc := ccache.Layered(ccache.Configure()) | ||
fus := fakes.NewFakeUpstreamSource(cacheDir, bc) | ||
cache := blob_cache.NewS3Cache(bc, fus, cacheDir, 60) | ||
|
||
meta := &source.Meta { | ||
Size: 1, | ||
Expires: time.Now(), | ||
} | ||
|
||
cache.AddMeta(meta, "/cached/1000000") | ||
|
||
wg := sync.WaitGroup{} | ||
wg.Add(3) | ||
|
||
var i uint64 | ||
for i = 0; i < 3; i++ { | ||
x := i | ||
go func() { | ||
ctx := context.WithValue(context.Background(), 0, &cache_context.Context{x}) | ||
r, _ := cache.Get(ctx, "/cached/1000000") | ||
var err error | ||
buf := make([]byte, 65536) | ||
var total int | ||
var n int | ||
for { | ||
n, err = r.Read(buf) | ||
total += n | ||
if err != nil && err == io.EOF { | ||
fmt.Printf("err: %s\n", err) | ||
break | ||
} | ||
} | ||
fmt.Printf("[%d] --->>> read %d\n", x, total) | ||
wg.Done() | ||
}() | ||
} | ||
wg.Wait() | ||
}) | ||
}) | ||
}) |