我有使用 FoundationDB 的 Go 代码,我想对其进行测试。
我已经从 Apple 的 Github 复制了 Go 测试。当我取消注释在事务中实际运行的行时,Set
测试挂起然后超时。(该行仍然被注释掉,它按预期工作。)
func TestExampleTransactor(t *testing.T) {
fdb.MustAPIVersion(400) // Note: test behaves the same with MustAPIVersion(600)
db := fdb.MustOpenDefault()
setOne := func(t fdb.Transactor, key fdb.Key, value []byte) error {
fmt.Printf("setOne called with: %T\n", t)
_, e := t.Transact(func(tr fdb.Transaction) (interface{}, error) {
// We don't actually call tr.Set here to avoid mutating a real database.
tr.Set(key, value) // **NOTE** this is the line I uncommented
return nil, nil
})
return e
}
setMany := func(t fdb.Transactor, value []byte, keys ...fdb.Key) error {
fmt.Printf("setMany called with: %T\n", t)
_, e := t.Transact(func(tr fdb.Transaction) (interface{}, error) {
for _, key := range keys {
setOne(tr, key, value)
}
return nil, nil
})
return e
}
var e error
fmt.Println("Calling setOne with a database:")
e = setOne(db, []byte("foo"), []byte("bar"))
if e != nil {
fmt.Println(e)
return
}
fmt.Println("\nCalling setMany with a database:")
e = setMany(db, []byte("bar"), fdb.Key("foo1"), fdb.Key("foo2"), fdb.Key("foo3"))
if e != nil {
fmt.Println(e)
return
}
}
我正在运行 MacOS 10.13.6。我安装了 FoundationDB,我可以使用 连接到它fdbcli
,也可以读取和写入它。
以下是foundation
流程:
ps aux | grep foundation
root 12942 1.0 0.3 4488980 46608 ?? S 12:35PM 2:00.06 /usr/local/libexec/fdbserver --cluster_file /usr/local/etc/foundationdb/fdb.cluster --datadir /usr/local/foundationdb/data/4689 --listen_address
root 12517 0.3 0.1 4382548 12204 ?? S 12:32PM 0:29.63 /usr/local/foundationdb/backup_agent/backup_agent --cluster_file /usr/local/etc/foundationdb/fdb.cluster
bancron 25399 0.0 0.0 4258468 200 s005 R+ 2:55PM 0:00.00 grep foundation
root 12515 0.0 0.0 4297540 584 ?? Ss 12:32PM 0:00.01 /usr/local/libexec/fdbmonitor --conffile /usr/local/etc/foundationdb/foundationdb.conf --lockfile /var/run/FoundationDB.pid
如果相关,这是在以下位置找到的默认集群文件的内容/usr/local/etc/foundationdb/fdb.cluster
:
JCKqKWc6:ku0VRske@127.0.0.1:4689
这是以下内容/usr/local/etc/foundationdb/foundationdb.conf
:
[general]
restart_delay = 60
cluster_file = /usr/local/etc/foundationdb/fdb.cluster
## Default parameters for individual fdbserver processes
[fdbserver]
command = /usr/local/libexec/fdbserver
public_address = auto:$ID
listen_address = public
datadir = /usr/local/foundationdb/data/$ID
logdir = /usr/local/foundationdb/logs
## An individual fdbserver process with id 4689
## Parameters set here override defaults from the [fdbserver] section
[fdbserver.4689]
[backup_agent]
command = /usr/local/foundationdb/backup_agent/backup_agent
logdir = /usr/local/foundationdb/logs
[backup_agent.1]