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


Golang security.SetReadFileFn函数代码示例

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


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

示例1: TestMain

func TestMain(m *testing.M) {
	security.SetReadFileFn(securitytest.Asset)
	randutil.SeedForTests()
	serverutils.InitTestServerFactory(server.TestServerFactory)
	serverutils.InitTestClusterFactory(testcluster.TestClusterFactory)
	os.Exit(m.Run())
}
开发者ID:yangxuanjia,项目名称:cockroach,代码行数:7,代码来源:main_test.go

示例2: TestQuit

func TestQuit(t *testing.T) {
	defer leaktest.AfterTest(t)()
	c := newCLITest()
	c.Run("quit")
	// Wait until this async command stops the server.
	<-c.Stopper().IsStopped()
	// Manually run the cleanup functions.
	c.cleanupFunc()
	security.SetReadFileFn(securitytest.Asset)
}
开发者ID:bogdanbatog,项目名称:cockroach,代码行数:10,代码来源:cli_test.go

示例3: maybeStartLocalServer

// maybeStartLocalServer will start a temporary local server if no database URL has been
// provided.
func maybeStartLocalServer() *server.TestServer {
	if *dbURL != "" {
		return nil
	}
	// Start a local test server.
	security.SetReadFileFn(securitytest.Asset)
	serv := server.StartTestServer(nil)
	*dbURL = "https://[email protected]" + serv.ServingAddr() + "?certs=test_certs"
	return serv
}
开发者ID:tschottdorf,项目名称:examples-go,代码行数:12,代码来源:main.go

示例4: main

func main() {
	stopper := stop.NewStopper()
	defer stopper.Stop()

	fmt.Printf("A simple program that keeps moving money between bank accounts.\n\n")
	flag.Parse()
	if *numAccounts < 2 {
		fmt.Fprintf(os.Stderr, "At least two accounts are required to transfer money.\n")
		os.Exit(1)
	}
	if *numParallelTransfers < 1 {
		fmt.Fprintf(os.Stderr, "At least one transfer routine must be active.\n")
		os.Exit(1)
	}
	if !*useTransaction {
		fmt.Printf("Use of transactions has been disabled.\n")
	}
	// Initialize the bank.
	var bank Bank
	bank.firstAccount = *firstAccount
	bank.numAccounts = *numAccounts
	if *dbName == "" {
		// Run a test cockroach instance to represent the bank.
		security.SetReadFileFn(securitytest.Asset)
		serv := server.StartTestServer(nil)
		defer serv.Stop()
		*dbName = fmt.Sprintf("rpcs://%[email protected]%s?certs=test_certs",
			security.NodeUser, serv.ServingAddr())
	}
	// Create a database handle.
	db, err := client.Open(stopper, *dbName)
	if err != nil {
		log.Fatal(err)
	}
	bank.db = db
	// Initialize all the bank accounts.
	const initCash = 1000
	totalCash := bank.initBankAccounts(initCash)

	// Start all the money transfer routines.
	for i := 0; i < *numParallelTransfers; i++ {
		// Keep transferring upto 10% of initCash between accounts.
		go bank.continuouslyTransferMoney(initCash / 10)
	}

	go bank.periodicallyReportStats()
	bank.periodicallyCheckBalances(totalCash)
}
开发者ID:GokulSrinivas,项目名称:cockroach,代码行数:48,代码来源:main.go

示例5: main

func main() {
	var dbDriver string
	flag.StringVar(&dbDriver, "db-driver", "cockroach", "database driver to use")
	var dbAddr string
	flag.StringVar(&dbAddr, "db-addr", "", "database address. defaults to ephemeral cockroach instance")

	numChannels := flag.Int("num-channels", 100, "number of channels")
	numWriters := flag.Int("num-writers", 2, "number of writers")
	flag.Parse()

	if dbAddr == "" {
		security.SetReadFileFn(securitytest.Asset)
		srv := server.StartTestServer(nil)
		defer srv.Stop()

		dbDriver = "cockroach"
		dbAddr = fmt.Sprintf("https://[email protected]%s?certs=test_certs", srv.ServingAddr())
	}
	db, err := sql.Open(dbDriver, dbAddr)
	if err != nil {
		log.Fatal(err)
	}

	if err := createTables(db); err != nil {
		log.Fatal(err)
	}

	var stats statistics
	var wg sync.WaitGroup
	for i := 0; i < *numWriters; i++ {
		wg.Add(1)
		w := writer{db, *numChannels, &wg, &stats}
		go w.run()
	}
	go stats.report()
	wg.Wait()
}
开发者ID:BramGruneir,项目名称:examples-go,代码行数:37,代码来源:main.go

示例6: init

func init() {
	security.SetReadFileFn(securitytest.Asset)
}
开发者ID:kaustubhkurve,项目名称:cockroach,代码行数:3,代码来源:main_test.go

示例7: stop

func (c cliTest) stop() {
	c.cleanupFunc()
	security.SetReadFileFn(securitytest.Asset)
	c.Stop()
}
开发者ID:bogdanbatog,项目名称:cockroach,代码行数:5,代码来源:cli_test.go

示例8: main

func main() {
	flag.Parse()
	var db *sql.DB
	var err error
	var url string
	if *usePostgres {
		if db, err = sql.Open("postgres", "dbname=postgres sslmode=disable"); err != nil {
			log.Fatal(err)
		}
	} else {
		security.SetReadFileFn(securitytest.Asset)
		serv := server.StartTestServer(nil)
		defer serv.Stop()
		url = "https://[email protected]" + serv.ServingAddr() + "?certs=test_certs"
		if db, err = sql.Open("cockroach", url); err != nil {
			log.Fatal(err)
		}
	}
	if _, err := db.Exec("CREATE DATABASE bank"); err != nil {
		if pqErr, ok := err.(*pq.Error); *usePostgres && (!ok || pqErr.Code.Name() != "duplicate_database") {
			log.Fatal(err)
		}
	}
	db.Close()

	// Open db client with database settings.
	if *usePostgres {
		if db, err = sql.Open("postgres", "dbname=bank sslmode=disable"); err != nil {
			log.Fatal(err)
		}
	} else {
		if db, err = sql.Open("cockroach", url+"&database=bank"); err != nil {
			log.Fatal(err)
		}
	}

	// concurrency + 1, for this thread and the "concurrency" number of
	// goroutines that move money
	db.SetMaxOpenConns(*concurrency + 1)

	if _, err = db.Exec("CREATE TABLE IF NOT EXISTS accounts (id BIGINT PRIMARY KEY, balance BIGINT NOT NULL)"); err != nil {
		log.Fatal(err)
	}

	if _, err = db.Exec("TRUNCATE TABLE accounts"); err != nil {
		log.Fatal(err)
	}

	for i := 0; i < *numAccounts; i++ {
		if _, err = db.Exec("INSERT INTO accounts (id, balance) VALUES ($1, $2)", i, 1000); err != nil {
			log.Fatal(err)
		}
	}

	verifyBank(db)

	lastNow := time.Now()
	readings := make(chan measurement, 10000)

	for i := 0; i < *concurrency; i++ {
		go moveMoney(db, readings)
	}

	for range time.NewTicker(*balanceCheckInterval).C {
		now := time.Now()
		elapsed := time.Since(lastNow)
		lastNow = now
		transfers := len(readings)
		log.Infof("%d transfers were executed at %.1f/second.", transfers, float64(transfers)/elapsed.Seconds())
		if transfers > 0 {
			var aggr measurement
			for i := 0; i < transfers; i++ {
				reading := <-readings
				aggr.read += reading.read
				aggr.write += reading.write
				aggr.total += reading.total
			}
			d := time.Duration(transfers)
			log.Infof("read time: %v, write time: %v, txn time: %v", aggr.read/d, aggr.write/d, aggr.total/d)
		}
		verifyBank(db)
	}
}
开发者ID:BramGruneir,项目名称:examples-go,代码行数:83,代码来源:main.go

示例9: init

func init() {
	security.SetReadFileFn(securitytest.Asset)
	tracing.SetTestTracing()
}
开发者ID:danieldeb,项目名称:cockroach,代码行数:4,代码来源:main_test.go

示例10: main

func main() {
	flag.Parse()
	var db *sql.DB
	var err error
	var url string
	if *usePostgres {
		if db, err = sql.Open("postgres", "dbname=postgres sslmode=disable"); err != nil {
			log.Fatal(err)
		}
	} else {
		security.SetReadFileFn(securitytest.Asset)
		serv := server.StartTestServer(nil)
		defer serv.Stop()
		url = "https://[email protected]" + serv.ServingAddr() + "?certs=test_certs"
		if db, err = sql.Open("cockroach", url); err != nil {
			log.Fatal(err)
		}
	}
	if _, err := db.Exec("CREATE DATABASE bank"); err != nil {
		if pqErr, ok := err.(*pq.Error); *usePostgres && (!ok || pqErr.Code.Name() != "duplicate_database") {
			log.Fatal(err)
		}
	}
	db.Close()

	// Open db client with database settings.
	if *usePostgres {
		if db, err = sql.Open("postgres", "dbname=bank sslmode=disable"); err != nil {
			log.Fatal(err)
		}
	} else {
		if db, err = sql.Open("cockroach", url+"&database=bank"); err != nil {
			log.Fatal(err)
		}
	}

	// concurrency + 1, for this thread and the "concurrency" number of
	// goroutines that move money
	db.SetMaxOpenConns(*concurrency + 1)

	if _, err = db.Exec("CREATE TABLE IF NOT EXISTS accounts (id BIGINT PRIMARY KEY, balance BIGINT NOT NULL)"); err != nil {
		log.Fatal(err)
	}

	if _, err = db.Exec("TRUNCATE TABLE accounts"); err != nil {
		log.Fatal(err)
	}

	for i := 0; i < *numAccounts; i++ {
		if _, err = db.Exec("INSERT INTO accounts (id, balance) VALUES ($1, $2)", i, 0); err != nil {
			log.Fatal(err)
		}
	}

	verifyBank(db)

	var lastNumTransfers uint64
	lastNow := time.Now()

	for i := 0; i < *concurrency; i++ {
		go moveMoney(db)
	}

	for range time.NewTicker(*balanceCheckInterval).C {
		now := time.Now()
		elapsed := time.Since(lastNow)
		numTransfers := atomic.LoadUint64(&numTransfers)
		log.Infof("%d transfers were executed at %.1f/second.", (numTransfers - lastNumTransfers), float64(numTransfers-lastNumTransfers)/elapsed.Seconds())
		verifyBank(db)
		lastNumTransfers = numTransfers
		lastNow = now
	}
}
开发者ID:Eric-Gaudiello,项目名称:cockroach,代码行数:73,代码来源:main.go

示例11: TestMain

func TestMain(m *testing.M) {
	security.SetReadFileFn(securitytest.Asset)
	serverutils.InitTestServerFactory(server.TestServerFactory)
	os.Exit(m.Run())
}
开发者ID:yangxuanjia,项目名称:cockroach,代码行数:5,代码来源:main_test.go

示例12: ResetTest

// ResetTest sets up the test environment. In particular, it embeds the
// EmbeddedCertsDir folder and makes the tls package load from there.
func ResetTest() {
	security.SetReadFileFn(securitytest.Asset)
}
开发者ID:kaustubhkurve,项目名称:cockroach,代码行数:5,代码来源:main_test.go


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