本文整理匯總了Golang中github.com/juju/txn.NewRunner函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewRunner函數的具體用法?Golang NewRunner怎麽用?Golang NewRunner使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewRunner函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestRunTransactionObserver
func (s *txnSuite) TestRunTransactionObserver(c *gc.C) {
type args struct {
ops []txn.Op
err error
}
var calls []args
runner := jujutxn.NewRunner(jujutxn.RunnerParams{
RunTransactionObserver: func(ops []txn.Op, err error) {
calls = append(calls, args{ops, err})
},
})
fake := &fakeRunner{errors: []error{
txn.ErrAborted,
nil,
}}
jujutxn.SetRunnerFunc(runner, fake.new)
ops := []txn.Op{{}}
buildTxn := func(attempt int) ([]txn.Op, error) {
return ops, nil
}
err := runner.Run(buildTxn)
c.Check(err, gc.IsNil)
c.Check(calls, gc.HasLen, 2)
c.Check(calls[0].ops, gc.DeepEquals, ops)
c.Check(calls[0].err, gc.Equals, txn.ErrAborted)
c.Check(calls[1].ops, gc.DeepEquals, ops)
c.Check(calls[1].err, gc.IsNil)
}
示例2: newMultiEnvRunner
func newMultiEnvRunner(envUUID string, db *mgo.Database, assertEnvAlive bool) jujutxn.Runner {
return &multiEnvRunner{
rawRunner: jujutxn.NewRunner(jujutxn.RunnerParams{Database: db}),
envUUID: envUUID,
assertEnvAlive: assertEnvAlive,
}
}
示例3: SetUpTest
func (s *txnSuite) SetUpTest(c *gc.C) {
s.IsolationSuite.SetUpTest(c)
s.MgoSuite.SetUpTest(c)
db := s.Session.DB("juju")
s.collection = db.C("test")
s.txnRunner = jujutxn.NewRunner(jujutxn.RunnerParams{Database: db})
}
示例4: rawTxnRunner
// rawTxnRunner returns a transaction runner that won't perform
// automatic addition of environment UUIDs into transaction
// operations, even for collections that contain documents for
// multiple environments. It should be used rarely.
func (st *State) rawTxnRunner(session *mgo.Session) jujutxn.Runner {
if st.transactionRunner != nil {
return getRawRunner(st.transactionRunner)
}
return jujutxn.NewRunner(jujutxn.RunnerParams{
Database: st.db.With(session),
})
}
示例5: NewTestMongo
func NewTestMongo(database *mgo.Database) *TestMongo {
return &TestMongo{
database: database,
runner: txn.NewRunner(txn.RunnerParams{
Database: database,
}),
}
}
示例6: NewMongo
// NewMongo returns a *Mongo backed by the supplied database.
func NewMongo(database *mgo.Database) *Mongo {
return &Mongo{
database: database,
runner: jujutxn.NewRunner(jujutxn.RunnerParams{
Database: database,
}),
}
}
示例7: newStorage
func newStorage(st *State, uuid, metadataCollection string) binarystorage.StorageCloser {
session := st.session.Clone()
rs := blobstore.NewGridFS(blobstoreDB, uuid, session)
db := session.DB(jujuDB)
c := db.C(metadataCollection)
txnRunner := jujutxn.NewRunner(jujutxn.RunnerParams{Database: db})
managedStorage := blobstore.NewManagedStorage(db, rs)
storage := binarystorageNew(uuid, managedStorage, c, txnRunner)
return &storageCloser{storage, session}
}
示例8: ToolsStorage
// ToolsStorage returns a new toolstorage.StorageCloser
// that stores tools metadata in the "juju" database''
// "toolsmetadata" collection.
//
// TODO(axw) remove this, add a constructor function in toolstorage.
func (st *State) ToolsStorage() (toolstorage.StorageCloser, error) {
uuid := st.EnvironUUID()
session := st.session.Copy()
rs := blobstore.NewGridFS(blobstoreDB, uuid, session)
db := session.DB(jujuDB)
metadataCollection := db.C(toolsmetadataC)
txnRunner := jujutxn.NewRunner(jujutxn.RunnerParams{Database: db})
managedStorage := blobstore.NewManagedStorage(db, rs)
storage := toolstorageNewStorage(uuid, managedStorage, metadataCollection, txnRunner)
return &toolsStorageCloser{storage, session}, nil
}
示例9: SetUpTest
func (s *ImageSuite) 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, gc.IsNil)
s.storage = imagestorage.NewStorage(s.session, "my-uuid")
s.metadataCollection = imagestorage.MetadataCollection(s.storage)
s.txnRunner = jujutxn.NewRunner(jujutxn.RunnerParams{Database: s.metadataCollection.Database})
s.patchTransactionRunner()
}
示例10: SetUpTest
func (s *managedStorageSuite) SetUpTest(c *gc.C) {
s.IsolationSuite.SetUpTest(c)
s.MgoSuite.SetUpTest(c)
s.db = s.Session.DB("blobstore")
s.resourceStorage = blobstore.NewGridFS("storage", "test", s.Session)
s.managedStorage = blobstore.NewManagedStorage(s.db, s.resourceStorage)
// For testing, we need to ensure there's a single txnRunner for all operations.
s.txnRunner = jujutxn.NewRunner(jujutxn.RunnerParams{Database: s.db})
txnRunnerFunc := func(db *mgo.Database) jujutxn.Runner {
return s.txnRunner
}
s.PatchValue(blobstore.TxnRunner, txnRunnerFunc)
}
示例11: TestRunFailureIntermittentUnexpectedMessage
func (s *txnSuite) TestRunFailureIntermittentUnexpectedMessage(c *gc.C) {
runner := jujutxn.NewRunner(jujutxn.RunnerParams{})
fake := &fakeRunner{errors: []error{errors.New("unexpected message")}}
jujutxn.SetRunnerFunc(runner, fake.new)
tries := 0
// Doesn't matter what this returns as long as it isn't an error.
buildTxn := func(attempt int) ([]txn.Op, error) {
tries++
return nil, nil
}
err := runner.Run(buildTxn)
c.Check(err, gc.Equals, nil)
c.Check(tries, gc.Equals, 2)
}
示例12: SetUpTest
func (s *resourceCatalogSuite) SetUpTest(c *gc.C) {
s.IsolationSuite.SetUpTest(c)
s.MgoSuite.SetUpTest(c)
db := s.Session.DB("blobstore")
s.collection = db.C("storedResources")
s.rCatalog = blobstore.NewResourceCatalog(db)
// For testing, we need to ensure there's a single txnRunner for all operations.
s.txnRunner = txn.NewRunner(txn.RunnerParams{Database: db})
txnRunnerFunc := func(db *mgo.Database) txn.Runner {
return s.txnRunner
}
s.PatchValue(blobstore.TxnRunner, txnRunnerFunc)
}
示例13: SetUpTest
func (s *ToolsSuite) 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("toolsmetadata")
s.txnRunner = jujutxn.NewRunner(jujutxn.RunnerParams{Database: catalogue})
s.storage = toolstorage.NewStorage("my-uuid", s.managedStorage, s.metadataCollection, s.txnRunner)
}
示例14: newStorageDBWrapper
// newStorageDBWrapper returns a DB operator for the , with its own session.
func newStorageDBWrapper(db *mgo.Database, metaColl, envUUID string) *storageDBWrapper {
session := db.Session.Copy()
db = db.With(session)
coll := db.C(metaColl)
txnRunner := jujutxn.NewRunner(jujutxn.RunnerParams{Database: db})
dbWrap := storageDBWrapper{
session: session,
db: db,
metaColl: coll,
txnRunner: txnRunner,
envUUID: envUUID,
}
return &dbWrap
}
示例15: Copy
// Copy returns a copy of the operator.
func (b *storageDBWrapper) Copy() *storageDBWrapper {
session := b.session.Copy()
coll := b.metaColl.With(session)
db := coll.Database
txnRunner := jujutxn.NewRunner(jujutxn.RunnerParams{Database: db})
dbWrap := storageDBWrapper{
session: session,
db: db,
metaColl: coll,
txnRunner: txnRunner,
envUUID: b.envUUID,
}
return &dbWrap
}