当前位置: 首页>>代码示例>>Golang>>正文


Golang server.NewTestContext函数代码示例

本文整理汇总了Golang中github.com/cockroachdb/cockroach/server.NewTestContext函数的典型用法代码示例。如果您正苦于以下问题:Golang NewTestContext函数的具体用法?Golang NewTestContext怎么用?Golang NewTestContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewTestContext函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: createTestServerContext

func createTestServerContext() (*server.Context, *CommandFilters) {
	ctx := server.NewTestContext()
	var cmdFilters CommandFilters
	cmdFilters.AppendFilter(checkEndTransactionTrigger, true)
	ctx.TestingKnobs.StoreTestingKnobs.TestingCommandFilter = cmdFilters.runFilters
	return ctx, &cmdFilters
}
开发者ID:bogdanbatog,项目名称:cockroach,代码行数:7,代码来源:main_test.go

示例2: benchmarkSelect1

// benchmarkSelect1 is a benchmark of the simplest SQL query: SELECT 1. This
// query requires no tables, expression analysis, etc. As such, it is measuring
// the overhead of parsing and other non-table processing (e.g. reading
// requests, writing responses).
func benchmarkSelect1(b *testing.B, scheme string) {
	s := &server.TestServer{}
	s.Ctx = server.NewTestContext()
	s.Ctx.Insecure = (scheme == "http" || scheme == "rpc")
	if err := s.Start(); err != nil {
		b.Fatal(err)
	}
	defer s.Stop()

	db, err := sql.Open("cockroach",
		scheme+"://[email protected]"+s.ServingAddr()+"?certs="+s.Ctx.Certs)
	if err != nil {
		b.Fatal(err)
	}
	defer db.Close()

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		rows, err := db.Query(`SELECT 1`)
		if err != nil {
			b.Fatal(err)
		}
		rows.Close()
	}
	b.StopTimer()
}
开发者ID:rissoa,项目名称:cockroach,代码行数:30,代码来源:bench_test.go

示例3: TestProtocols

func TestProtocols(t *testing.T) {
	defer leaktest.AfterTest(t)

	// Test that all of the network protocols work.
	for _, scheme := range []string{"http", "https", "rpc", "rpcs"} {
		func() {
			// Start test server in insecure mode.
			s := &server.TestServer{}
			s.Ctx = server.NewTestContext()
			s.Ctx.Insecure = (scheme == "http" || scheme == "rpc")
			if err := s.Start(); err != nil {
				t.Fatalf("Could not start server: %v", err)
			}
			defer s.Stop()

			db, err := sql.Open("cockroach",
				scheme+"://[email protected]"+s.ServingAddr()+"?certs="+s.Ctx.Certs)
			if err != nil {
				t.Fatal(err)
			}
			defer db.Close()

			if _, err := db.Exec(`SELECT 1`); err != nil {
				t.Fatal(err)
			}
		}()
	}
}
开发者ID:surpass,项目名称:cockroach,代码行数:28,代码来源:driver_test.go

示例4: ExampleDB_Put_insecure

func ExampleDB_Put_insecure() {
	s := &server.TestServer{}
	s.Ctx = server.NewTestContext()
	s.Ctx.Insecure = true
	if pErr := s.Start(); pErr != nil {
		log.Fatalf("Could not start server: %v", pErr)
	}
	defer s.Stop()

	db, err := client.Open(s.Stopper(), "rpc://[email protected]"+s.ServingAddr())
	if err != nil {
		log.Fatal(err)
	}

	if pErr := db.Put("aa", "1"); pErr != nil {
		panic(pErr)
	}
	result, pErr := db.Get("aa")
	if pErr != nil {
		panic(pErr)
	}
	fmt.Printf("aa=%s\n", result.ValueBytes())

	// Output:
	// aa=1
}
开发者ID:eddyzhou,项目名称:cockroach,代码行数:26,代码来源:db_test.go

示例5: ExampleDB_Insecure

func ExampleDB_Insecure() {
	s := &server.TestServer{}
	s.Ctx = server.NewTestContext()
	s.Ctx.Insecure = true
	if err := s.Start(); err != nil {
		log.Fatalf("Could not start server: %v", err)
	}
	log.Printf("Test server listening on %s: %s", s.Ctx.RequestScheme(), s.ServingAddr())
	defer s.Stop()

	db, err := client.Open("http://[email protected]" + s.ServingAddr())
	if err != nil {
		log.Fatal(err)
	}

	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
}
开发者ID:routhcr,项目名称:cockroach,代码行数:27,代码来源:db_test.go

示例6: setup

func (t *parallelTest) setup() {
	ctx := server.NewTestContext()
	ctx.MaxOffset = logicMaxOffset
	ctx.TestingKnobs.ExecutorTestingKnobs.WaitForGossipUpdate = true
	ctx.TestingKnobs.ExecutorTestingKnobs.CheckStmtStringChange = true
	t.srv = setupTestServerWithContext(t.T, ctx)
}
开发者ID:chzyer-dev,项目名称:cockroach,代码行数:7,代码来源:parallel_test.go

示例7: TestInsecure

func TestInsecure(t *testing.T) {
	defer leaktest.AfterTest(t)
	// Start test server in insecure mode.
	s := &server.TestServer{}
	s.Ctx = server.NewTestContext()
	s.Ctx.Insecure = true
	if err := s.Start(); err != nil {
		t.Fatalf("Could not start server: %v", err)
	}
	t.Logf("Test server listening on %s: %s", s.Ctx.RequestScheme(), s.ServingAddr())
	defer s.Stop()

	// We can't attempt a connection through HTTPS since the client just retries forever.
	// DB connection using plain HTTP.
	db, err := sql.Open("cockroach", "http://[email protected]"+s.ServingAddr())
	if err != nil {
		t.Fatal(err)
	}
	defer func() {
		_ = db.Close()
	}()
	if _, err := db.Exec(`SELECT 1`); err != nil {
		t.Fatal(err)
	}
}
开发者ID:nkhuyu,项目名称:cockroach,代码行数:25,代码来源:driver_test.go

示例8: createTestServerContext

func createTestServerContext() (*server.Context, *CommandFilters) {
	ctx := server.NewTestContext()
	var cmdFilters CommandFilters
	cmdFilters.AppendFilter(checkEndTransactionTrigger, true)
	// Disable one phase commits as they otherwise confuse the
	// various bits of machinery in sql tests which inject via
	// the testing command filter and inspect the transaction.
	ctx.TestingKnobs.StoreTestingKnobs.DisableOnePhaseCommits = true
	ctx.TestingKnobs.StoreTestingKnobs.TestingCommandFilter = cmdFilters.runFilters
	return ctx, &cmdFilters
}
开发者ID:petermattis,项目名称:cockroach,代码行数:11,代码来源:main_test.go

示例9: run

func (t *parallelTest) run(dir string) {
	fmt.Printf("Running test %s\n", dir)
	// Set up database
	defer t.close()
	ctx := server.NewTestContext()
	ctx.MaxOffset = logicMaxOffset
	t.srv = setupTestServer(t.T)

	// Add the main client and set up the database.
	t.addClient(true)

	// Open the main faile.
	mainFile := filepath.Join(dir, "main")
	file, err := os.Open(mainFile)
	if err != nil {
		t.Fatal(err)
	}
	defer file.Close()
	s := newLineScanner(file)
	for s.Scan() {
		fields := strings.Fields(s.Text())
		if len(fields) == 0 {
			continue
		}
		cmd := fields[0]
		if strings.HasPrefix(cmd, "#") {
			// Skip comment lines.
			continue
		}
		switch cmd {
		case "run":
			testFiles := fields[1:]
			for len(t.clients) < len(testFiles) {
				t.addClient(false)
			}
			if testing.Verbose() || log.V(1) {
				fmt.Printf("%s:%d: running %s\n", mainFile, s.line, strings.Join(testFiles, ","))
			}
			ch := make(chan bool)
			for i, f := range testFiles {
				go t.processTestFile(filepath.Join(dir, f), t.clients[i].db, ch)
			}
			// Wait for all clients to complete.
			for range testFiles {
				<-ch
			}
		default:
			t.Fatalf("%s:%d: unknown command: %s", mainFile, s.line, cmd)
		}
	}
}
开发者ID:liugangnhm,项目名称:cockroach,代码行数:51,代码来源:parallel_test.go

示例10: TestLeaseManagerReacquire

func TestLeaseManagerReacquire(testingT *testing.T) {
	defer leaktest.AfterTest(testingT)()
	t := newLeaseTest(testingT, server.NewTestContext())
	defer t.cleanup()

	const descID = keys.LeaseTableID

	// Acquire 2 leases from the same node. They should point to the same lease
	// structure.
	l1 := t.mustAcquire(1, descID, 0)
	l2 := t.mustAcquire(1, descID, 0)
	if l1 != l2 {
		t.Fatalf("expected same lease, but found %p != %p", l1, l2)
	}
	if l1.Refcount() != 2 {
		t.Fatalf("expected refcount of 2, but found %d", l1.Refcount())
	}
	t.expectLeases(descID, "/1/1")

	// Set the minimum lease duration such that the next lease acquisition will
	// require the lease to be reacquired.
	savedLeaseDuration, savedMinLeaseDuration := csql.LeaseDuration, csql.MinLeaseDuration
	defer func() {
		csql.LeaseDuration, csql.MinLeaseDuration = savedLeaseDuration, savedMinLeaseDuration
	}()
	csql.MinLeaseDuration = l1.Expiration().Sub(timeutil.Now())
	csql.LeaseDuration = 2 * csql.MinLeaseDuration

	// Another lease acquisition from the same node will result in a new lease.
	l3 := t.mustAcquire(1, descID, 0)
	if l1 == l3 {
		t.Fatalf("expected different leases, but found %p", l1)
	}
	if l3.Refcount() != 1 {
		t.Fatalf("expected refcount of 1, but found %d", l3.Refcount())
	}
	if l3.Expiration().Before(l1.Expiration()) {
		t.Fatalf("expected new lease expiration (%s) to be after old lease expiration (%s)",
			l3.Expiration(), l1.Expiration())
	}
	t.expectLeases(descID, "/1/1 /1/1")

	t.mustRelease(1, l1)
	t.mustRelease(1, l2)
	t.mustRelease(1, l3)
}
开发者ID:GitGoldie,项目名称:cockroach,代码行数:46,代码来源:lease_test.go

示例11: benchmarkSelect1

// benchmarkSelect1 is a benchmark of the simplest SQL query: SELECT 1. This
// query requires no tables, expression analysis, etc. As such, it is measuring
// the overhead of parsing and other non-table processing (e.g. reading
// requests, writing responses).
func benchmarkSelect1(b *testing.B, scheme string) {
	s := &server.TestServer{}
	s.Ctx = server.NewTestContext()
	s.Ctx.Insecure = (scheme == "http" || scheme == "rpc")
	if err := s.Start(); err != nil {
		b.Fatal(err)
	}
	defer s.Stop()

	db, err := sql.Open("cockroach",
		scheme+"://[email protected]"+s.ServingAddr()+"?certs="+s.Ctx.Certs)
	if err != nil {
		b.Fatal(err)
	}
	defer db.Close()

	runBenchmarkSelect1(b, db)
}
开发者ID:Ralkage,项目名称:cockroach,代码行数:22,代码来源:bench_test.go

示例12: setup

func (t *logicTest) setup() {
	// TODO(pmattis): Add a flag to make it easy to run the tests against a local
	// MySQL or Postgres instance.
	ctx := server.NewTestContext()
	ctx.MaxOffset = logicMaxOffset
	t.srv = setupTestServerWithContext(t.T, ctx)

	// db may change over the lifetime of this function, with intermediate
	// values cached in t.clients and finally closed in t.close().
	t.cleanupRootUser = t.setUser(security.RootUser)

	if _, err := t.db.Exec(`
CREATE DATABASE test;
SET DATABASE = test;
`); err != nil {
		t.Fatal(err)
	}
}
开发者ID:liugangnhm,项目名称:cockroach,代码行数:18,代码来源:logic_test.go

示例13: TestErrorOnCommit

// Test that if there's an error on COMMIT that needs to be reported to the user
// the txn will be rolled back. As opposed to an error on a COMMIT in an auto-retry
// txn, where we retry the txn (not tested here).
func TestErrorOnCommit(t *testing.T) {
	defer leaktest.AfterTest(t)()

	ctx := server.NewTestContext()
	ctx.TestingKnobs.SQLExecutor = &sql.ExecutorTestingKnobs{FixTxnPriority: true}
	server, sqlDB, _ := setupWithContext(t, ctx)
	defer cleanup(server, sqlDB)
	if _, err := sqlDB.Exec(`
CREATE DATABASE t; CREATE TABLE t.test (k INT PRIMARY KEY, v TEXT);
`); err != nil {
		t.Fatal(err)
	}

	tx, err := sqlDB.Begin()
	if err != nil {
		t.Fatal(err)
	}
	if _, err := tx.Exec("SAVEPOINT cockroach_restart; SET TRANSACTION PRIORITY LOW;"); err != nil {
		t.Fatal(err)
	}
	if _, err = tx.Exec("INSERT INTO t.test (k, v) VALUES (0, 'sentinel');"); err != nil {
		t.Fatal(err)
	}

	abortTxn(t, sqlDB, 0)

	if err = tx.Commit(); err == nil {
		t.Fatal("expected commit to fail")
	}

	// Check that there's no error reading and we don't see any rows.
	var rows *gosql.Rows
	if rows, err = sqlDB.Query("SELECT * FROM t.test"); err != nil {
		t.Fatal(err)
	}
	if rows.Next() {
		var k int
		var v string
		_ = rows.Scan(&k, &v)
		t.Fatalf("found unexpected row: %d %s", k, v)
	}
	rows.Close()
}
开发者ID:GitGoldie,项目名称:cockroach,代码行数:46,代码来源:txn_restart_test.go

示例14: Example_insecure

func Example_insecure() {
	c := cliTest{}
	c.TestServer = &server.TestServer{}
	c.Ctx = server.NewTestContext()
	c.Ctx.Insecure = true
	if err := c.Start(); err != nil {
		log.Fatalf("Could not start server: %v", err)
	}
	defer c.Stop()

	c.Run("kv --insecure put a 1 b 2")
	c.Run("kv --insecure scan")

	// Output:
	// kv --insecure put a 1 b 2
	// kv --insecure scan
	// "a"	"1"
	// "b"	"2"
	// 2 result(s)
}
开发者ID:surpass,项目名称:cockroach,代码行数:20,代码来源:cli_test.go

示例15: Example_insecure

func Example_insecure() {
	c := cliTest{cleanupFunc: func() {}}
	c.TestServer = &server.TestServer{}
	c.Ctx = server.NewTestContext()
	c.Ctx.Insecure = true
	if err := c.Start(); err != nil {
		log.Fatalf("Could not start server: %v", err)
	}
	defer c.stop()

	c.Run("debug kv put --insecure a 1 b 2")
	c.Run("debug kv scan --insecure")

	// Output:
	// debug kv put --insecure a 1 b 2
	// debug kv scan --insecure
	// "a"	"1"
	// "b"	"2"
	// 2 result(s)
}
开发者ID:bogdanbatog,项目名称:cockroach,代码行数:20,代码来源:cli_test.go


注:本文中的github.com/cockroachdb/cockroach/server.NewTestContext函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。