Example #1
0
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()
}
Example #2
0
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()
}
Example #3
0
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()
}
Example #4
0
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()
}
Example #5
0
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()
}
Example #6
0
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()
}
Example #7
0
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()
}
Example #8
0
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()
}
Example #9
0
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())
}
Example #10
0
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()
}
Example #11
0
// 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
}
Example #12
0
func TestWaitForLatestOSDMap(t *testing.T) {
	conn, _ := rados.NewConn()
	conn.ReadDefaultConfigFile()
	conn.Connect()

	err := conn.WaitForLatestOSDMap()
	assert.NoError(t, err)

	conn.Shutdown()
}
Example #13
0
func TestGetInstanceID(t *testing.T) {
	conn, _ := rados.NewConn()
	conn.ReadDefaultConfigFile()
	conn.Connect()

	id := conn.GetInstanceID()
	assert.NotEqual(t, id, 0)

	conn.Shutdown()
}
Example #14
0
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()
}
Example #15
0
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()
}
Example #16
0
func TestRead(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)

	buf := make([]byte, 4096)

	size, err := log.Read(0, buf)
	assert.Error(t, err, "Not written")

	err = log.Fill(0)
	assert.NoError(t, err)

	size, err = log.Read(0, buf)
	assert.Error(t, err, "Filled")

	size, err = log.Read(232, buf)
	assert.Error(t, err, "Not written")

	err = log.Fill(232)
	assert.NoError(t, err)

	size, err = log.Read(232, buf)
	assert.Error(t, err, "Filled")

	bytes_in := []byte("this is a string")
	pos, err := log.Append(bytes_in)
	assert.NoError(t, err)

	bytes_out := make([]byte, len(bytes_in))
	assert.Equal(t, len(bytes_in), len(bytes_out))
	assert.NotEqual(t, bytes_in, bytes_out)

	size, err = log.Read(pos, bytes_out)
	assert.Equal(t, size, len(bytes_in))
	assert.Equal(t, bytes_in, bytes_out)

	log.Destroy()

	pool.Destroy()
	conn.Shutdown()
}
Example #17
0
func TestCheckTailBatch(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)

	pos, err := log.CheckTail(false)
	assert.NoError(t, err)
	assert.Equal(t, pos, uint64(0))

	pos2 := make([]uint64, 50)

	err = log.CheckTailBatch(pos2[:1])
	assert.NoError(t, err)
	assert.Equal(t, pos2[0], uint64(0))

	err = log.CheckTailBatch(pos2[:5])
	assert.NoError(t, err)
	assert.Equal(t, pos2[0], uint64(1))
	assert.Equal(t, pos2[1], uint64(2))
	assert.Equal(t, pos2[2], uint64(3))
	assert.Equal(t, pos2[3], uint64(4))
	assert.Equal(t, pos2[4], uint64(5))

	pos, err = log.CheckTail(false)
	assert.NoError(t, err)
	assert.Equal(t, pos, uint64(6))

	pos, err = log.CheckTail(true)
	assert.NoError(t, err)
	assert.Equal(t, pos, uint64(6))

	err = log.CheckTailBatch(pos2[:2])
	assert.NoError(t, err)
	assert.Equal(t, pos2[0], uint64(7))
	assert.Equal(t, pos2[1], uint64(8))

	log.Destroy()

	pool.Destroy()
	conn.Shutdown()
}
Example #18
0
func TestParseCmdLineArgs(t *testing.T) {
	conn, _ := rados.NewConn()
	conn.ReadDefaultConfigFile()

	mon_host_val, _ := conn.GetConfigOption("mon_host")
	assert.NotEqual(t, mon_host_val, "1.1.1.1")

	args := []string{"--mon-host", "1.1.1.1"}
	err := conn.ParseCmdLineArgs(args)
	assert.NoError(t, err)

	mon_host_val, _ = conn.GetConfigOption("mon_host")
	assert.Equal(t, mon_host_val, "1.1.1.1")
}
Example #19
0
func TestRmXattr(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)

	key := "key1"
	val := []byte("val1")
	err = pool.SetXattr("obj", key, val)
	assert.NoError(t, err)

	key = "key2"
	val = []byte("val2")
	err = pool.SetXattr("obj", key, val)
	assert.NoError(t, err)

	xattr_list := make(map[string][]byte)
	xattr_list, err = pool.ListXattrs("obj")
	assert.NoError(t, err)
	assert.Equal(t, len(xattr_list), 2)

	pool.RmXattr("obj", "key2")
	xattr_list, err = pool.ListXattrs("obj")
	assert.NoError(t, err)
	assert.Equal(t, len(xattr_list), 1)

	found := false
	for key, _ = range xattr_list {
		if key == "key2" {
			found = true
		}

	}

	if found {
		t.Error("Deleted pool still exists")
	}

	pool.Destroy()
}
Example #20
0
func TestParseDefaultConfigEnv(t *testing.T) {
	conn, _ := rados.NewConn()

	log_file_val, _ := conn.GetConfigOption("log_file")
	assert.NotEqual(t, log_file_val, "/dev/null")

	err := os.Setenv("CEPH_ARGS", "--log-file /dev/null")
	assert.NoError(t, err)

	err = conn.ParseDefaultConfigEnv()
	assert.NoError(t, err)

	log_file_val, _ = conn.GetConfigOption("log_file")
	assert.Equal(t, log_file_val, "/dev/null")
}
Example #21
0
func TestGetSetConfigOption(t *testing.T) {
	conn, _ := rados.NewConn()

	// rejects invalid options
	err := conn.SetConfigOption("wefoijweojfiw", "welfkwjelkfj")
	assert.Error(t, err, "Invalid option")

	// verify SetConfigOption changes a values
	log_file_val, err := conn.GetConfigOption("log_file")
	assert.NotEqual(t, log_file_val, "/dev/null")

	err = conn.SetConfigOption("log_file", "/dev/null")
	assert.NoError(t, err, "Invalid option")

	log_file_val, err = conn.GetConfigOption("log_file")
	assert.Equal(t, log_file_val, "/dev/null")
}
Example #22
0
func TestMonCommand(t *testing.T) {
	conn, _ := rados.NewConn()
	conn.ReadDefaultConfigFile()
	conn.Connect()
	defer conn.Shutdown()

	command, err := json.Marshal(map[string]string{"prefix": "df", "format": "json"})
	assert.NoError(t, err)

	buf, info, err := conn.MonCommand(command)
	assert.NoError(t, err)
	assert.Equal(t, info, "")

	var message map[string]interface{}
	err = json.Unmarshal(buf, &message)
	assert.NoError(t, err)
}
Example #23
0
func TestObjectIterator(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)

	objectList := []string{}
	iter, err := ioctx.Iter()
	assert.NoError(t, err)
	for iter.Next() {
		objectList = append(objectList, iter.Value())
	}
	iter.Close()
	assert.NoError(t, iter.Err())
	assert.True(t, len(objectList) == 0)

	createdList := []string{}
	for i := 0; i < 200; i++ {
		oid := GetUUID()
		bytes_in := []byte("input data")
		err = ioctx.Write(oid, bytes_in, 0)
		assert.NoError(t, err)
		createdList = append(createdList, oid)
	}
	assert.True(t, len(createdList) == 200)

	iter, err = ioctx.Iter()
	assert.NoError(t, err)
	for iter.Next() {
		objectList = append(objectList, iter.Value())
	}
	iter.Close()
	assert.NoError(t, iter.Err())
	assert.Equal(t, len(objectList), len(createdList))

	sort.Strings(objectList)
	sort.Strings(createdList)

	assert.Equal(t, objectList, createdList)
}
Example #24
0
func TestGetClusterStats(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)

	// grab current stats
	prev_stat, err := conn.GetClusterStats()
	fmt.Printf("prev_stat: %+v\n", prev_stat)
	assert.NoError(t, err)

	// make some changes to the cluster
	buf := make([]byte, 1<<20)
	for i := 0; i < 10; i++ {
		objname := GetUUID()
		pool.Write(objname, buf, 0)
	}

	// wait a while for the stats to change
	for i := 0; i < 30; i++ {
		stat, err := conn.GetClusterStats()
		assert.NoError(t, err)

		// wait for something to change
		if stat == prev_stat {
			fmt.Printf("curr_stat: %+v (trying again...)\n", stat)
			time.Sleep(time.Second)
		} else {
			// success
			fmt.Printf("curr_stat: %+v (change detected)\n", stat)
			conn.Shutdown()
			return
		}
	}

	pool.Destroy()
	conn.Shutdown()
	t.Error("Cluster stats aren't changing")
}
Example #25
0
func TestReadFilterOmap(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)

	orig := map[string][]byte{
		"key1":          []byte("value1"),
		"prefixed-key3": []byte("value3"),
		"key2":          []byte("value2"),
	}

	err = pool.SetOmap("obj", orig)
	assert.NoError(t, err)

	// filter by prefix
	fetched, err := pool.GetOmapValues("obj", "", "prefixed", 4)
	assert.NoError(t, err)
	assert.Equal(t, map[string][]byte{
		"prefixed-key3": []byte("value3"),
	}, fetched)

	// "start_after" a key
	fetched, err = pool.GetOmapValues("obj", "key1", "", 4)
	assert.NoError(t, err)
	assert.Equal(t, map[string][]byte{
		"prefixed-key3": []byte("value3"),
		"key2":          []byte("value2"),
	}, fetched)

	// maxReturn
	fetched, err = pool.GetOmapValues("obj", "", "key", 1)
	assert.NoError(t, err)
	assert.Equal(t, map[string][]byte{
		"key1": []byte("value1"),
	}, fetched)

	pool.Destroy()
}
Example #26
0
func newConn() (*rados.Conn, error) {
	conn, err := rados.NewConn()
	if err != nil {
		return nil, err
	}

	err = conn.ReadDefaultConfigFile()
	if err != nil {
		return nil, err
	}

	err = conn.Connect()
	if err != nil {
		return nil, err
	}

	return conn, nil
}
Example #27
0
func TestTrim(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)

	// can trim empty spot
	err = log.Trim(55)
	assert.NoError(t, err)

	// can trim filled spot
	err = log.Fill(60)
	assert.NoError(t, err)
	err = log.Trim(60)
	assert.NoError(t, err)

	// can trim written spot
	data := []byte("input data")
	pos, err := log.Append(data)
	assert.NoError(t, err)
	err = log.Trim(pos)
	assert.NoError(t, err)

	// can trim trimmed spot
	err = log.Trim(70)
	assert.NoError(t, err)
	err = log.Trim(70)
	assert.NoError(t, err)

	log.Destroy()

	pool.Destroy()
	conn.Shutdown()
}
Example #28
0
func TestGetPoolName(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)

	poolname_ret, err := ioctx.GetPoolName()
	assert.NoError(t, err)

	assert.Equal(t, poolname, poolname_ret)

	ioctx.Destroy()
	conn.Shutdown()
}
Example #29
0
func TestCheckTail(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)

	pos, err := log.CheckTail(false)
	assert.NoError(t, err)
	assert.Equal(t, pos, uint64(0))

	pos, err = log.CheckTail(false)
	assert.NoError(t, err)
	assert.Equal(t, pos, uint64(0))

	pos, err = log.CheckTail(true)
	assert.NoError(t, err)
	assert.Equal(t, pos, uint64(0))

	pos, err = log.CheckTail(true)
	assert.NoError(t, err)
	assert.Equal(t, pos, uint64(1))

	pos, err = log.CheckTail(false)
	assert.NoError(t, err)
	assert.Equal(t, pos, uint64(2))

	log.Destroy()

	pool.Destroy()
	conn.Shutdown()
}
Example #30
0
func (d *radosdesc) New() (factory.DrvInterface, error) {
	chunksize := uint64(defaultChunkSize)
	if setting.Chunksize != "" {
		if tmp, err := strconv.Atoi(setting.Chunksize); err != nil {
			return nil, fmt.Errorf("The chunksize parameter should be a number")
		} else {
			chunksize = uint64(tmp)
		}
	}

	var err error
	var conn *rados.Conn
	if setting.Username != "" {
		conn, err = rados.NewConnWithUser(setting.Username)
	} else {
		conn, err = rados.NewConn()
	}
	if err != nil {
		return nil, err
	}

	if err := conn.ReadDefaultConfigFile(); err != nil {
		return nil, err
	}

	if err := conn.Connect(); err != nil {
		return nil, err
	}

	ioctx, err := conn.OpenIOContext(setting.Poolname)
	if err != nil {
		return nil, err
	}

	return &radosdesc{
		Ioctx:     ioctx,
		Conn:      conn,
		Chunksize: chunksize,
	}, nil
}