Skip to content

Instantly share code, notes, and snippets.

@shohi
Created July 17, 2019 02:02
Show Gist options
  • Save shohi/1216888fc071679b9e41e0dfb39419f6 to your computer and use it in GitHub Desktop.
Save shohi/1216888fc071679b9e41e0dfb39419f6 to your computer and use it in GitHub Desktop.
`select for update` feature test for ignite v2.7.5 using golang client (NOT work yet)
package examples
import (
"database/sql"
"fmt"
"log"
"net"
"testing"
"time"
ignite "github.com/amsokol/ignite-go-client/binary/v1"
_ "github.com/amsokol/ignite-go-client/sql"
)
// NOTE: not work. invalid request/response
func Test_Hello(t *testing.T) {
fmt.Println("hello world")
connInfo := ignite.ConnInfo{
Dialer: net.Dialer{
Timeout: 2 * time.Second,
},
Host: "localhost",
Major: 1,
Minor: 1,
Network: "tcp",
Port: 10800,
/*
TLSConfig: &tls.Config{
InsecureSkipVerify: true,
},
*/
// Go zero values for Username, Password and Patch
}
c, err := ignite.Connect(connInfo)
if err != nil {
panic(err)
} else {
defer c.Close()
}
// create cache
var cacheMode int32 = 2
var atomicMode int32 = 2
name := "SQL_PUBLIC_CITY"
sqlSchema := "PUBLIC"
conf := &ignite.CacheConfigurationRefs{
Name: &name,
CacheMode: &cacheMode,
AtomicityMode: &atomicMode,
SQLSchema: &sqlSchema,
}
conf.QueryEntities = []ignite.QueryEntity{
ignite.QueryEntity{
TableName: "CITY",
KeyFieldName: "ID",
KeyTypeName: "java.lang.Integer",
ValueTypeName: "SQL_PUBLIC_CITY_TYPE",
QueryFields: []ignite.QueryField{
ignite.QueryField{
Name: "ID",
TypeName: "java.lang.Integer",
},
ignite.QueryField{
Name: "Name",
TypeName: "java.lang.String",
},
ignite.QueryField{
Name: "CountryCode",
TypeName: "java.lang.String",
},
ignite.QueryField{
Name: "District",
TypeName: "java.lang.String",
},
ignite.QueryField{
Name: "Population",
TypeName: "java.lang.Integer",
},
},
},
}
err = c.CacheCreateWithConfiguration(conf)
log.Printf("create cache error: %v", err)
fmt.Printf("Connected: %v", c.Connected())
}
func Test_Driver(t *testing.T) {
// open connection
db, err := sql.Open("ignite", "tcp://localhost:10800/ExampleDB?version=1.1.0&page-size=10000&timeout=5000")
if err != nil {
t.Fatalf("failed to open connection: %v", err)
}
defer db.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment