コード例 #1
0
ファイル: managedstorage_test.go プロジェクト: juju/blobstore
func (s *managedStorageSuite) TestPutRequestSingle(c *gc.C) {
	ch := make(chan struct{})
	s.PatchValue(blobstore.AfterFunc, patchedAfterFunc(ch))
	s.assertPutRequestSingle(c, nil, 1)
	c.Assert(blobstore.RequestQueueLength(s.managedStorage), gc.Equals, 0)
	// Trigger the request timeout.
	ch <- trigger
	<-ch
	c.Assert(blobstore.RequestQueueLength(s.managedStorage), gc.Equals, 0)
}
コード例 #2
0
ファイル: managedstorage_test.go プロジェクト: juju/blobstore
// Run one simple test with the real time.AfterFunc to ensure it works.
func (s *managedStorageSuite) TestPutRequestExpiredWithRealTimeAfter(c *gc.C) {
	s.PatchValue(blobstore.RequestExpiry, 5*time.Millisecond)
	blob, sha384Hash := s.putTestRandomBlob(c, "path/to/blob")
	reqResp, err := s.managedStorage.PutForEnvironmentRequest("env", "path/to/blob", sha384Hash)
	c.Assert(err, gc.IsNil)
	sha384Response := calculateCheckSum(c, reqResp.RangeStart, reqResp.RangeLength, blob)
	// Wait for request timer to trigger.
	time.Sleep(7 * time.Millisecond)
	response := blobstore.NewPutResponse(reqResp.RequestId, sha384Response)
	err = s.managedStorage.ProofOfAccessResponse(response)
	c.Assert(err, gc.Equals, blobstore.ErrRequestExpired)
	c.Assert(blobstore.RequestQueueLength(s.managedStorage), gc.Equals, 0)
	c.Assert(blobstore.RequestQueueLength(s.managedStorage), gc.Equals, 0)
}
コード例 #3
0
ファイル: managedstorage_test.go プロジェクト: juju/blobstore
func (s *managedStorageSuite) TestPutRequestLarge(c *gc.C) {
	ch := make(chan struct{})
	s.PatchValue(blobstore.AfterFunc, patchedAfterFunc(ch))
	// Use a blob size of 4096 which is greater than max range of put response range length.
	blob := make([]byte, 4096)
	for i := 0; i < 4096; i++ {
		blob[i] = byte(rand.Intn(255))
	}
	s.assertPutRequestSingle(c, blob, 1)
	c.Assert(blobstore.RequestQueueLength(s.managedStorage), gc.Equals, 0)
	// Trigger the request timeout.
	ch <- trigger
	<-ch
	c.Assert(blobstore.RequestQueueLength(s.managedStorage), gc.Equals, 0)
}
コード例 #4
0
ファイル: managedstorage_test.go プロジェクト: juju/blobstore
func (s *managedStorageSuite) TestPutRequestMultiRandom(c *gc.C) {
	ch := make(chan struct{})
	s.PatchValue(blobstore.AfterFunc, patchedAfterFunc(ch))
	done := make(chan struct{})
	s.queuePutRequests(c, done)
	select {
	case <-done:
		c.Logf("all done")
	case <-time.After(LongWait):
		c.Fatalf("timed out waiting for put requests to be processed")
	}
	// One request hasn't been processed since we left it to timeout.
	c.Assert(blobstore.RequestQueueLength(s.managedStorage), gc.Equals, 1)
	// Trigger the request timeout.
	ch <- trigger
	<-ch
	c.Assert(blobstore.RequestQueueLength(s.managedStorage), gc.Equals, 0)
}
コード例 #5
0
ファイル: managedstorage_test.go プロジェクト: juju/blobstore
func (s *managedStorageSuite) TestPutRequestResponseHashMismatch(c *gc.C) {
	_, sha384Hash := s.putTestRandomBlob(c, "path/to/blob")
	reqResp, err := s.managedStorage.PutForEnvironmentRequest("env", "path/to/blob", sha384Hash)
	c.Assert(err, gc.IsNil)
	response := blobstore.NewPutResponse(reqResp.RequestId, "notsha384")
	err = s.managedStorage.ProofOfAccessResponse(response)
	c.Assert(err, gc.Equals, blobstore.ErrResponseMismatch)
	c.Assert(blobstore.RequestQueueLength(s.managedStorage), gc.Equals, 0)
}
コード例 #6
0
func (s *managedStorageSuite) TestPutRequestResponseSHA256Mismatch(c *gc.C) {
	blob, md5hash, sha256hash := s.putTestBlob(c, "path/to/blob")
	hash := blobstore.ResourceHash{md5hash, sha256hash}
	reqResp, err := s.managedStorage.PutForEnvironmentRequest("env", "path/to/blob", hash)
	c.Assert(err, gc.IsNil)
	md5Response, _ := calculateCheckSums(c, reqResp.RangeStart, reqResp.RangeLength, blob)
	response := blobstore.NewPutResponse(reqResp.RequestId, md5Response, "notsha256")
	err = s.managedStorage.ProofOfAccessResponse(response)
	c.Assert(err, gc.Equals, blobstore.ErrResponseMismatch)
	c.Assert(blobstore.RequestQueueLength(s.managedStorage), gc.Equals, 0)
}
コード例 #7
0
ファイル: managedstorage_test.go プロジェクト: juju/blobstore
func (s *managedStorageSuite) TestPutRequestExpired(c *gc.C) {
	ch := make(chan struct{})
	s.PatchValue(blobstore.AfterFunc, patchedAfterFunc(ch))
	blob, sha384Hash := s.putTestRandomBlob(c, "path/to/blob")
	reqResp, err := s.managedStorage.PutForEnvironmentRequest("env", "path/to/blob", sha384Hash)
	c.Assert(err, gc.IsNil)
	sha384Response := calculateCheckSum(c, reqResp.RangeStart, reqResp.RangeLength, blob)
	// Trigger the request timeout.
	ch <- trigger
	<-ch
	response := blobstore.NewPutResponse(reqResp.RequestId, sha384Response)
	err = s.managedStorage.ProofOfAccessResponse(response)
	c.Assert(err, gc.Equals, blobstore.ErrRequestExpired)
	c.Assert(blobstore.RequestQueueLength(s.managedStorage), gc.Equals, 0)
}
コード例 #8
0
func (s *managedStorageSuite) TestPutRequestExpiredMulti(c *gc.C) {
	ch := make(chan struct{})
	s.PatchValue(blobstore.AfterFunc, patchedAfterFunc(ch))
	blob, md5hash, sha256hash := s.putTestBlob(c, "path/to/blob")
	hash := blobstore.ResourceHash{md5hash, sha256hash}
	reqResp, err := s.managedStorage.PutForEnvironmentRequest("env", "path/to/blob", hash)
	c.Assert(err, gc.IsNil)
	md5Response, sha256Response := calculateCheckSums(c, reqResp.RangeStart, reqResp.RangeLength, blob)
	reqResp2, err := s.managedStorage.PutForEnvironmentRequest("env", "path/to/blob2", hash)
	c.Assert(err, gc.IsNil)
	md5Response2, sha256Response2 := calculateCheckSums(c, reqResp.RangeStart, reqResp.RangeLength, blob)
	// Trigger the request timeouts.
	ch <- trigger
	<-ch
	ch <- trigger
	<-ch
	c.Assert(blobstore.RequestQueueLength(s.managedStorage), gc.Equals, 0)
	response := blobstore.NewPutResponse(reqResp.RequestId, md5Response, sha256Response)
	response2 := blobstore.NewPutResponse(reqResp2.RequestId, md5Response2, sha256Response2)
	err = s.managedStorage.ProofOfAccessResponse(response)
	c.Assert(err, gc.Equals, blobstore.ErrRequestExpired)
	err = s.managedStorage.ProofOfAccessResponse(response2)
	c.Assert(err, gc.Equals, blobstore.ErrRequestExpired)
}