func (s *binaryStorageSuite) TestAddRemovesExistingRemoveFails(c *gc.C) { // Add a metadata doc and a blob at a known path, then // call Add and ensure that Add attempts to remove // the original blob, but does not return an error if it // fails. s.addMetadataDoc(c, current, 3, "hash(abc)", "path") err := s.managedStorage.PutForBucket("my-uuid", "path", strings.NewReader("blah"), 4) c.Assert(err, jc.ErrorIsNil) storage := binarystorage.New( "my-uuid", removeFailsManagedStorage{s.managedStorage}, s.metadataCollection, s.txnRunner, ) addedMetadata := binarystorage.Metadata{ Version: current, Size: 6, SHA256: "hash(xyzzzz)", } err = storage.Add(strings.NewReader("xyzzzz"), addedMetadata) c.Assert(err, jc.ErrorIsNil) // old blob should still be there r, _, err := s.managedStorage.GetForBucket("my-uuid", "path") c.Assert(err, jc.ErrorIsNil) r.Close() s.assertMetadataAndContent(c, addedMetadata, "xyzzzz") }
func (s *binaryStorageSuite) SetUpTest(c *gc.C) { s.BaseSuite.SetUpTest(c) s.mongo = &gitjujutesting.MgoInstance{} s.mongo.Start(nil) var err error s.session, err = s.mongo.Dial() c.Assert(err, jc.ErrorIsNil) rs := blobstore.NewGridFS("blobstore", "my-uuid", s.session) catalogue := s.session.DB("catalogue") s.managedStorage = blobstore.NewManagedStorage(catalogue, rs) s.metadataCollection = catalogue.C("binarymetadata") s.txnRunner = jujutxn.NewRunner(jujutxn.RunnerParams{Database: catalogue}) s.storage = binarystorage.New("my-uuid", s.managedStorage, s.metadataCollection, s.txnRunner) }
func (s *binaryStorageSuite) TestAddRemovesBlobOnFailure(c *gc.C) { storage := binarystorage.New( "my-uuid", s.managedStorage, s.metadataCollection, errorTransactionRunner{s.txnRunner}, ) addedMetadata := binarystorage.Metadata{ Version: current, Size: 6, SHA256: "hash", } err := storage.Add(strings.NewReader("xyzzzz"), addedMetadata) c.Assert(err, gc.ErrorMatches, "cannot store binary metadata: Run fails") path := fmt.Sprintf("tools/%s-%s", addedMetadata.Version, addedMetadata.SHA256) _, _, err = s.managedStorage.GetForBucket("my-uuid", path) c.Assert(err, jc.Satisfies, errors.IsNotFound) }
func (s *binaryStorageSuite) TestAddRemovesBlobOnFailureRemoveFails(c *gc.C) { storage := binarystorage.New( "my-uuid", removeFailsManagedStorage{s.managedStorage}, s.metadataCollection, errorTransactionRunner{s.txnRunner}, ) addedMetadata := binarystorage.Metadata{ Version: current, Size: 6, SHA256: "hash", } err := storage.Add(strings.NewReader("xyzzzz"), addedMetadata) c.Assert(err, gc.ErrorMatches, "cannot store binary metadata: Run fails") // blob should still be there, because the removal failed. path := fmt.Sprintf("tools/%s-%s", addedMetadata.Version, addedMetadata.SHA256) r, _, err := s.managedStorage.GetForBucket("my-uuid", path) c.Assert(err, jc.ErrorIsNil) r.Close() }