コード例 #1
0
ファイル: conn.go プロジェクト: harveymonster/ogonori
func (c *ogonoriConn) Close() error {
	ogl.Debugln("** ogoConn.Close")
	// Close() must be idempotent
	if c.dbc != nil {
		err := obinary.CloseDatabase(c.dbc)
		c.dbc = nil
		return err
	}
	return nil
}
コード例 #2
0
func testConcurrentClients() {
	var (
		dbc1, dbc2, dbc3, dbc4 *obinary.DBClient
		err                    error
	)

	const nclients = 4

	runtime.GOMAXPROCS(nclients)

	dbc1, err = obinary.NewDBClient(obinary.ClientOptions{})
	Ok(err)
	defer dbc1.Close()

	dbc2, err = obinary.NewDBClient(obinary.ClientOptions{})
	Ok(err)
	defer dbc2.Close()

	dbc3, err = obinary.NewDBClient(obinary.ClientOptions{})
	Ok(err)
	defer dbc3.Close()

	dbc4, err = obinary.NewDBClient(obinary.ClientOptions{})
	Ok(err)
	defer dbc4.Close()

	err = obinary.OpenDatabase(dbc1, dbDocumentName, constants.DocumentDB, "admin", "admin")
	Ok(err)
	defer obinary.CloseDatabase(dbc1)

	err = obinary.OpenDatabase(dbc2, dbDocumentName, constants.DocumentDB, "admin", "admin")
	Ok(err)
	defer obinary.CloseDatabase(dbc2)

	err = obinary.OpenDatabase(dbc3, dbDocumentName, constants.DocumentDB, "admin", "admin")
	Ok(err)
	defer obinary.CloseDatabase(dbc3)

	err = obinary.OpenDatabase(dbc4, dbDocumentName, constants.DocumentDB, "admin", "admin")
	Ok(err)
	defer obinary.CloseDatabase(dbc4)

	/* ---[ queries and insertions concurrently ]--- */

	var wg sync.WaitGroup
	wg.Add(nclients)

	sql := `select count(*) from Cat where caretaker like 'Eva%'`
	docs, err := obinary.SQLQuery(dbc1, sql, "")
	Ok(err)
	beforeCount := toInt(docs[0].GetField("count").Value)

	go doQueriesAndInsertions(&wg, dbc1, 1)
	go doQueriesAndInsertions(&wg, dbc2, 2)
	go doQueriesAndInsertions(&wg, dbc3, 3)
	go doQueriesAndInsertions(&wg, dbc4, 4)

	wg.Wait()

	sql = `select count(*) from Cat where caretaker like 'Eva%'`
	docs, err = obinary.SQLQuery(dbc1, sql, "")
	Ok(err)
	afterCount := toInt(docs[0].GetField("count").Value)
	Equals(beforeCount, afterCount)

	fmt.Println(afterCount)
}