forked from apache/cassandra-gocql-driver
-
Notifications
You must be signed in to change notification settings - Fork 59
/
control_integration_test.go
71 lines (57 loc) · 1.43 KB
/
control_integration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//go:build integration && scylla
// +build integration,scylla
package gocql
import (
"context"
"fmt"
"net"
"testing"
)
// unixSocketDialer is a special dialer which connects only to the maintenance_socket.
type unixSocketDialer struct {
dialer net.Dialer
socketPath string
}
func (d unixSocketDialer) DialContext(_ context.Context, _, _ string) (net.Conn, error) {
return d.dialer.Dial("unix", d.socketPath)
}
func TestUnixSockets(t *testing.T) {
socketPath := "/tmp/scylla/cql.m"
c := createCluster()
c.NumConns = 1
c.DisableInitialHostLookup = true
c.ProtoVersion = 3
c.ReconnectInterval = 0
c.WriteCoalesceWaitTime = 0
c.Events.DisableNodeStatusEvents = true
c.Events.DisableTopologyEvents = true
c.Events.DisableSchemaEvents = true
d := net.Dialer{
Timeout: c.Timeout,
}
if c.SocketKeepalive > 0 {
d.KeepAlive = c.SocketKeepalive
}
c.Dialer = unixSocketDialer{
dialer: d,
socketPath: socketPath,
}
sess, err := c.CreateSession()
if err != nil {
panic(fmt.Sprintf("unable to create session: %v", err))
}
defer sess.Close()
keyspace := "test1"
err = createTable(sess, `DROP KEYSPACE IF EXISTS `+keyspace)
if err != nil {
t.Fatal("unable to drop keyspace if exists:", err)
}
err = createTable(sess, fmt.Sprintf(`CREATE KEYSPACE %s
WITH replication = {
'class' : 'NetworkTopologyStrategy',
'replication_factor' : 1
}`, keyspace))
if err != nil {
t.Fatal("unable to create keyspace:", err)
}
}