-
-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added parameter `stmt_cache_size` to DSN string
- Loading branch information
Showing
9 changed files
with
271 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// +build go1.13 | ||
|
||
package oci8 | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
// TestStatementCaching tests to ensure statement caching is working | ||
func TestStatementCaching(t *testing.T) { | ||
if TestDisableDatabase { | ||
t.SkipNow() | ||
} | ||
|
||
t.Parallel() | ||
|
||
var err error | ||
|
||
db := testGetDB("?stmt_cache_size=10") | ||
if db == nil { | ||
t.Fatal("db is null") | ||
} | ||
|
||
defer func() { | ||
err = db.Close() | ||
if err != nil { | ||
t.Fatal("db close error:", err) | ||
} | ||
}() | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), TestContextTimeout) | ||
conn, err := db.Conn(ctx) | ||
cancel() | ||
// we need to get access to the raw connection so we can access the different fields on the oci8.Stmt | ||
var rawConn *Conn | ||
// NOTE that conn.Raw() is only available with Go >= 1.13 | ||
_ = conn.Raw(func(driverConn interface{}) error { | ||
rawConn = driverConn.(*Conn) | ||
return nil | ||
}) | ||
|
||
ctx, cancel = context.WithTimeout(context.Background(), TestContextTimeout) | ||
stmt, err := rawConn.PrepareContext(ctx, "select ?, ?, ? from dual") | ||
cancel() | ||
if err != nil { | ||
t.Fatal("prepare error:", err) | ||
} | ||
|
||
rawStmt := stmt.(*Stmt) | ||
if rawStmt.cacheKey != "select ?, ?, ? from dual" { | ||
err := stmt.Close() | ||
if err != nil { | ||
t.Fatal("stmt close error:", err) | ||
} | ||
t.Fatalf("cacheKey not equal: expected %s, but got %s", "select ?, ?, ? from dual", rawStmt.cacheKey) | ||
} | ||
|
||
// closing the statement should put the statement into the cache | ||
err = stmt.Close() | ||
if err != nil { | ||
t.Fatal("stmt close error:", err) | ||
} | ||
|
||
ctx, cancel = context.WithTimeout(context.Background(), TestContextTimeout) | ||
stmt, err = rawConn.PrepareContext(ctx, "select ?, ?, ? from dual") | ||
cancel() | ||
if err != nil { | ||
t.Fatal("prepare error:", err) | ||
} | ||
|
||
rawStmt = stmt.(*Stmt) | ||
if rawStmt.cacheKey != "select ?, ?, ? from dual" { | ||
err := stmt.Close() | ||
if err != nil { | ||
t.Fatal("stmt close error:", err) | ||
} | ||
t.Fatalf("cacheKey not equal: expected %s, but got %s", "select ?, ?, ? from dual", rawStmt.cacheKey) | ||
} | ||
err = stmt.Close() | ||
if err != nil { | ||
t.Fatal("stmt close error:", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.