本文整理汇总了Golang中github.com/cockroachdb/cockroach/server.TestServer.DB方法的典型用法代码示例。如果您正苦于以下问题:Golang TestServer.DB方法的具体用法?Golang TestServer.DB怎么用?Golang TestServer.DB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/server.TestServer
的用法示例。
在下文中一共展示了TestServer.DB方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: acquire
func acquire(s server.TestServer, descID sqlbase.ID, version sqlbase.DescriptorVersion) (*csql.LeaseState, error) {
var lease *csql.LeaseState
err := s.DB().Txn(func(txn *client.Txn) error {
var err error
lease, err = s.LeaseManager().(*csql.LeaseManager).Acquire(txn, descID, version)
return err
})
return lease, err
}
示例2: forceNewConfig
// forceNewConfig forces a system config update by writing a bogus descriptor with an
// incremented value inside. It then repeatedly fetches the gossip config until the
// just-written descriptor is found.
func forceNewConfig(t *testing.T, s *server.TestServer) (*config.SystemConfig, error) {
configID++
configDesc := sql.DatabaseDescriptor{
Name: "sentinel",
ID: configID,
Privileges: &sql.PrivilegeDescriptor{},
}
// This needs to be done in a transaction with the system trigger set.
if err := s.DB().Txn(func(txn *client.Txn) error {
txn.SetSystemDBTrigger()
return txn.Put(configDescKey, &configDesc)
}); err != nil {
t.Fatal(err)
}
return waitForConfigChange(t, s)
}
示例3: TestDB_Put_insecure
func TestDB_Put_insecure(t *testing.T) {
defer leaktest.AfterTest(t)()
ctx := server.MakeTestContext()
ctx.Insecure = true
s := server.TestServer{
Ctx: &ctx,
}
if err := s.Start(); err != nil {
log.Fatalf("Could not start server: %v", err)
}
defer s.Stop()
db := s.DB()
if err := db.Put("aa", "1"); err != nil {
panic(err)
}
result, err := db.Get("aa")
if err != nil {
panic(err)
}
checkResult(t, []byte("1"), result.ValueBytes())
}
示例4: ExampleDB_Put_insecure
func ExampleDB_Put_insecure() {
ctx := server.MakeTestContext()
ctx.Insecure = true
s := server.TestServer{
Ctx: &ctx,
}
if err := s.Start(); err != nil {
log.Fatalf("Could not start server: %v", err)
}
defer s.Stop()
db := s.DB()
if err := db.Put("aa", "1"); err != nil {
panic(err)
}
result, err := db.Get("aa")
if err != nil {
panic(err)
}
fmt.Printf("aa=%s\n", result.ValueBytes())
// Output:
// aa=1
}