本文整理汇总了Golang中github.com/ceph/go-ceph/rados.NewConn函数的典型用法代码示例。如果您正苦于以下问题:Golang NewConn函数的具体用法?Golang NewConn怎么用?Golang NewConn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewConn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestNotFound
func TestNotFound(t *testing.T) {
conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()
poolname := GetUUID()
err := conn.MakePool(poolname)
assert.NoError(t, err)
ioctx, err := conn.OpenIOContext(poolname)
assert.NoError(t, err)
name := GetUUID()
img := rbd.GetImage(ioctx, name)
err = img.Open()
assert.Equal(t, err, rbd.RbdErrorNotFound)
img.Remove()
assert.Equal(t, err, rbd.RbdErrorNotFound)
ioctx.Destroy()
conn.DeletePool(poolname)
conn.Shutdown()
}
示例2: TestOpen
func TestOpen(t *testing.T) {
conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()
poolname := GetUUID()
err := conn.MakePool(poolname)
assert.NoError(t, err)
pool, err := conn.OpenIOContext(poolname)
assert.NoError(t, err)
_, err = zlog.Open(pool, "", "localhost", "5678")
assert.Error(t, err, "Invalid")
_, err = zlog.Open(pool, "dne", "localhost", "5678")
assert.Error(t, err, "Doesn't exist")
log, err := zlog.Create(pool, "mylog", 5, "localhost", "5678")
assert.NoError(t, err)
log.Destroy()
log, err = zlog.Open(pool, "mylog", "localhost", "5678")
assert.NoError(t, err)
log.Destroy()
pool.Destroy()
conn.Shutdown()
}
示例3: TestObjectStat
func TestObjectStat(t *testing.T) {
conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()
pool_name := GetUUID()
err := conn.MakePool(pool_name)
assert.NoError(t, err)
pool, err := conn.OpenIOContext(pool_name)
assert.NoError(t, err)
bytes_in := []byte("input data")
err = pool.Write("obj", bytes_in, 0)
assert.NoError(t, err)
stat, err := pool.Stat("obj")
assert.Equal(t, uint64(len(bytes_in)), stat.Size)
assert.NotNil(t, stat.ModTime)
_, err = pool.Stat("notfound")
assert.Equal(t, err, rados.RadosErrorNotFound)
pool.Destroy()
conn.Shutdown()
}
示例4: TestAppend
func TestAppend(t *testing.T) {
conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()
poolname := GetUUID()
err := conn.MakePool(poolname)
assert.NoError(t, err)
pool, err := conn.OpenIOContext(poolname)
assert.NoError(t, err)
log, err := zlog.Create(pool, "mylog", 5, "localhost", "5678")
assert.NoError(t, err)
data := []byte("input data")
tail, err := log.CheckTail(false)
assert.NoError(t, err)
for i := 0; i < 100; i++ {
pos, err := log.Append(data)
assert.NoError(t, err)
assert.Equal(t, pos, tail)
tail, err = log.CheckTail(false)
assert.NoError(t, err)
}
log.Destroy()
pool.Destroy()
conn.Shutdown()
}
示例5: TestListXattrs
func TestListXattrs(t *testing.T) {
conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()
// make pool
pool_name := GetUUID()
err := conn.MakePool(pool_name)
assert.NoError(t, err)
pool, err := conn.OpenIOContext(pool_name)
assert.NoError(t, err)
bytes_in := []byte("input data")
err = pool.Write("obj", bytes_in, 0)
assert.NoError(t, err)
input_xattrs := make(map[string][]byte)
for i := 0; i < 200; i++ {
name := fmt.Sprintf("key_%d", i)
data := []byte(GetUUID())
err = pool.SetXattr("obj", name, data)
assert.NoError(t, err)
input_xattrs[name] = data
}
output_xattrs := make(map[string][]byte)
output_xattrs, err = pool.ListXattrs("obj")
assert.NoError(t, err)
assert.Equal(t, len(input_xattrs), len(output_xattrs))
assert.Equal(t, input_xattrs, output_xattrs)
pool.Destroy()
}
示例6: TestPingMonitor
func TestPingMonitor(t *testing.T) {
conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()
// mon id that should work with vstart.sh
reply, err := conn.PingMonitor("a")
if err == nil {
assert.NotEqual(t, reply, "")
return
}
// mon id that should work with micro-osd.sh
reply, err = conn.PingMonitor("0")
if err == nil {
assert.NotEqual(t, reply, "")
return
}
// try to use a hostname as the monitor id
mon_addr, _ := conn.GetConfigOption("mon_host")
hosts, _ := net.LookupAddr(mon_addr)
for _, host := range hosts {
reply, err := conn.PingMonitor(host)
if err == nil {
assert.NotEqual(t, reply, "")
return
}
}
t.Error("Could not find a valid monitor id")
conn.Shutdown()
}
示例7: TestAppend
func TestAppend(t *testing.T) {
conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()
// make pool
pool_name := GetUUID()
err := conn.MakePool(pool_name)
assert.NoError(t, err)
pool, err := conn.OpenIOContext(pool_name)
assert.NoError(t, err)
bytes_accum := []byte{}
for _, str_in := range []string{"input", " ", "another", " ", "data"} {
bytes_in := []byte(str_in)
err = pool.Append("obj", bytes_in)
assert.NoError(t, err)
bytes_accum = append(bytes_accum, bytes_in...)
bytes_out := make([]byte, len(bytes_accum))
n_out, err := pool.Read("obj", bytes_out, 0)
assert.NoError(t, err)
assert.Equal(t, n_out, len(bytes_accum))
assert.Equal(t, bytes_accum, bytes_out)
}
pool.Destroy()
conn.Shutdown()
}
示例8: TestReadWriteXattr
func TestReadWriteXattr(t *testing.T) {
conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()
// make pool
pool_name := GetUUID()
err := conn.MakePool(pool_name)
assert.NoError(t, err)
pool, err := conn.OpenIOContext(pool_name)
assert.NoError(t, err)
bytes_in := []byte("input data")
err = pool.Write("obj", bytes_in, 0)
assert.NoError(t, err)
my_xattr_in := []byte("my_value")
err = pool.SetXattr("obj", "my_key", my_xattr_in)
assert.NoError(t, err)
my_xattr_out := make([]byte, len(my_xattr_in))
n_out, err := pool.GetXattr("obj", "my_key", my_xattr_out)
assert.Equal(t, n_out, len(my_xattr_in))
assert.Equal(t, my_xattr_in, my_xattr_out)
pool.Destroy()
}
示例9: TestReadConfigFile
func TestReadConfigFile(t *testing.T) {
conn, _ := rados.NewConn()
// check current log_file value
log_file_val, err := conn.GetConfigOption("log_file")
assert.NoError(t, err)
assert.NotEqual(t, log_file_val, "/dev/null")
// create a temporary ceph.conf file that changes the log_file conf
// option.
file, err := ioutil.TempFile("/tmp", "go-rados")
assert.NoError(t, err)
_, err = io.WriteString(file, "[global]\nlog_file = /dev/null\n")
assert.NoError(t, err)
// parse the config file
err = conn.ReadConfigFile(file.Name())
assert.NoError(t, err)
// check current log_file value
log_file_val, err = conn.GetConfigOption("log_file")
assert.NoError(t, err)
assert.Equal(t, log_file_val, "/dev/null")
// cleanup
file.Close()
os.Remove(file.Name())
}
示例10: TestStreamId
func TestStreamId(t *testing.T) {
conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()
poolname := GetUUID()
err := conn.MakePool(poolname)
assert.NoError(t, err)
pool, err := conn.OpenIOContext(poolname)
assert.NoError(t, err)
log, err := zlog.Create(pool, "mylog", 5, "localhost", "5678")
assert.NoError(t, err)
stream0, err := log.OpenStream(0)
assert.NoError(t, err)
assert.Equal(t, 0, int(stream0.Id()))
stream33, err := log.OpenStream(33)
assert.NoError(t, err)
assert.Equal(t, 33, int(stream33.Id()))
log.Destroy()
pool.Destroy()
conn.Shutdown()
}
示例11: GetRadosHandle
// Simple wrapper function to get rados connection handle
func GetRadosHandle(conf string) (conn *rados.Conn, err error) {
conn, err = rados.NewConn()
if err != nil {
return nil, err
}
conn.ReadConfigFile(conf)
err = conn.Connect()
return conn, err
}
示例12: TestWaitForLatestOSDMap
func TestWaitForLatestOSDMap(t *testing.T) {
conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()
err := conn.WaitForLatestOSDMap()
assert.NoError(t, err)
conn.Shutdown()
}
示例13: TestGetInstanceID
func TestGetInstanceID(t *testing.T) {
conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()
id := conn.GetInstanceID()
assert.NotEqual(t, id, 0)
conn.Shutdown()
}
示例14: TestGetFSID
func TestGetFSID(t *testing.T) {
conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()
fsid, err := conn.GetFSID()
assert.NoError(t, err)
assert.NotEqual(t, fsid, "")
conn.Shutdown()
}
示例15: TestStreamAppend
func TestStreamAppend(t *testing.T) {
conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()
poolname := GetUUID()
err := conn.MakePool(poolname)
assert.NoError(t, err)
pool, err := conn.OpenIOContext(poolname)
assert.NoError(t, err)
log, err := zlog.Create(pool, "mylog", 5, "localhost", "5678")
assert.NoError(t, err)
stream, err := log.OpenStream(0)
assert.NoError(t, err)
data := make([]byte, 100)
pos1, err := stream.Append(data)
assert.NoError(t, err)
data_out := make([]byte, 200)
data_out_len, pos2, err := stream.ReadNext(data_out)
assert.Error(t, err)
err = stream.Sync()
assert.NoError(t, err)
data_out_len, pos2, err = stream.ReadNext(data_out)
assert.NoError(t, err)
assert.Equal(t, pos1, pos2)
assert.True(t, data_out_len > 0)
assert.Equal(t, data, data_out[:data_out_len])
data_out_len, pos2, err = stream.ReadNext(data_out)
assert.Error(t, err)
err = stream.Reset()
assert.NoError(t, err)
data_out_len, pos2, err = stream.ReadNext(data_out)
assert.NoError(t, err)
assert.Equal(t, pos1, pos2)
assert.True(t, data_out_len > 0)
assert.Equal(t, data, data_out[:data_out_len])
log.Destroy()
pool.Destroy()
conn.Shutdown()
}