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) }
func TestAgainstOrientDBServer(t *testing.T) { // do not run functional tests if -short flag is used if testing.Short() { return } var ( dbc *obinary.DBClient err error ) go func() { log.Println(http.ListenAndServe("localhost:6060", nil)) }() /* ---[ set ogl log level ]--- */ ogl.SetLevel(ogl.WARN) testType := "dataOnly" if len(os.Args) > 1 { if os.Args[1] == "full" || os.Args[1] == "create" { testType = os.Args[1] } } dbc, err = obinary.NewDBClient(obinary.ClientOptions{}) if err != nil { t.Fatalf("Unexpected error %s", err) } defer dbc.Close() /* ---[ run clean up in case of panics ]--- */ defer func() { if r := recover(); r != nil { lvl := ogl.GetLevel() ogl.SetLevel(ogl.NORMAL) switch r { case "Equals fail", "Assert fail", "Ok fail": // do not print stack trace default: ogl.Printf("panic recovery: %v\nTrace:\n%s\n", r, debug.Stack()) } ogl.SetLevel(lvl) cleanUp(dbc, testType == "full") os.Exit(1) } }() /* ---[ Use "native" API ]--- */ createOgonoriTestDB(dbc, dbUser, dbPass, testType != "dataOnly") defer cleanUp(dbc, testType == "full") // document database tests ogl.SetLevel(ogl.WARN) dbCommandsNativeAPI(dbc, testType != "dataOnly") if testType == "full" { ogl.SetLevel(ogl.WARN) dbClusterCommandsNativeAPI(dbc) } // create new records from low-level create API (not SQL) createAndUpdateRecordsViaNativeAPI(dbc) /* ---[ Use Go database/sql API on Document DB ]--- */ ogl.SetLevel(ogl.WARN) conxStr := "admin@admin:localhost/" + dbDocumentName databaseSQLAPI(conxStr) databaseSQLPreparedStmtAPI(conxStr) /* ---[ Graph DB ]--- */ // graph database tests ogl.SetLevel(ogl.WARN) graphCommandsNativeAPI(dbc, testType != "dataOnly") graphConxStr := "admin@admin:localhost/" + dbGraphName ogl.SetLevel(ogl.NORMAL) graphCommandsSQLAPI(graphConxStr) // ------ // // experimenting with JSON functionality // // ogl.Println("-------- JSON ---------") // fld := oschema.OField{int32(44), "foo", oschema.LONG, int64(33341234)} // bsjson, err := fld.ToJSON() // Ok(err) // ogl.Printf("%v\n", string(bsjson)) // doc := oschema.NewDocument("Coolio") // doc.AddField("foo", &fld) // bsjson, err = doc.ToJSON() // Ok(err) // ogl.Printf("%v\n", string(bsjson)) ogl.Println("DONE") }