Exemple #1
0
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
}
// 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)
}
Exemple #3
0
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())
}
Exemple #4
0
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
}