mirror of https://github.com/ceph/go-ceph
test: convert more tests to use suite
Signed-off-by: Noah Watkins <nwatkins@redhat.com>
This commit is contained in:
parent
fad63ff1f9
commit
a1c3394414
|
@ -871,207 +871,175 @@ func (suite *RadosTestSuite) TestReadFilterOmap() {
|
||||||
}, fetched)
|
}, fetched)
|
||||||
}
|
}
|
||||||
|
|
||||||
//func TestSetNamespace(t *testing.T) {
|
func (suite *RadosTestSuite) TestSetNamespace() {
|
||||||
// conn, _ := rados.NewConn()
|
suite.SetupConnection()
|
||||||
// conn.ReadDefaultConfigFile()
|
|
||||||
// conn.Connect()
|
// create oid
|
||||||
//
|
oid := suite.GenObjectName()
|
||||||
// pool_name := GetUUID()
|
bytes_in := []byte("input data")
|
||||||
// err := conn.MakePool(pool_name)
|
err := suite.ioctx.Write(oid, bytes_in, 0)
|
||||||
// assert.NoError(t, err)
|
assert.NoError(suite.T(), err)
|
||||||
//
|
|
||||||
// pool, err := conn.OpenIOContext(pool_name)
|
stat, err := suite.ioctx.Stat(oid)
|
||||||
// assert.NoError(t, err)
|
assert.Equal(suite.T(), uint64(len(bytes_in)), stat.Size)
|
||||||
//
|
assert.NotNil(suite.T(), stat.ModTime)
|
||||||
// bytes_in := []byte("input data")
|
|
||||||
// err = pool.Write("obj", bytes_in, 0)
|
// oid isn't seen in space1 ns
|
||||||
// assert.NoError(t, err)
|
suite.ioctx.SetNamespace("space1")
|
||||||
//
|
stat, err = suite.ioctx.Stat(oid)
|
||||||
// stat, err := pool.Stat("obj")
|
assert.Equal(suite.T(), err, rados.RadosErrorNotFound)
|
||||||
// assert.Equal(t, uint64(len(bytes_in)), stat.Size)
|
|
||||||
// assert.NotNil(t, stat.ModTime)
|
// create oid2 in space1 ns
|
||||||
//
|
oid2 := suite.GenObjectName()
|
||||||
// pool.SetNamespace("space1")
|
bytes_in = []byte("input data")
|
||||||
// stat, err = pool.Stat("obj")
|
err = suite.ioctx.Write(oid2, bytes_in, 0)
|
||||||
// assert.Equal(t, err, rados.RadosErrorNotFound)
|
assert.NoError(suite.T(), err)
|
||||||
//
|
|
||||||
// bytes_in = []byte("input data")
|
suite.ioctx.SetNamespace("")
|
||||||
// err = pool.Write("obj2", bytes_in, 0)
|
stat, err = suite.ioctx.Stat(oid2)
|
||||||
// assert.NoError(t, err)
|
assert.Equal(suite.T(), err, rados.RadosErrorNotFound)
|
||||||
//
|
|
||||||
// pool.SetNamespace("")
|
stat, err = suite.ioctx.Stat(oid)
|
||||||
//
|
assert.Equal(suite.T(), uint64(len(bytes_in)), stat.Size)
|
||||||
// stat, err = pool.Stat("obj2")
|
assert.NotNil(suite.T(), stat.ModTime)
|
||||||
// assert.Equal(t, err, rados.RadosErrorNotFound)
|
}
|
||||||
//
|
|
||||||
// stat, err = pool.Stat("obj")
|
func (suite *RadosTestSuite) TestListAcrossNamespaces() {
|
||||||
// assert.Equal(t, uint64(len(bytes_in)), stat.Size)
|
suite.SetupConnection()
|
||||||
// assert.NotNil(t, stat.ModTime)
|
|
||||||
//
|
// count objects in pool
|
||||||
// pool.Destroy()
|
origObjects := 0
|
||||||
// conn.Shutdown()
|
err := suite.ioctx.ListObjects(func(oid string) {
|
||||||
//}
|
origObjects++
|
||||||
//
|
})
|
||||||
//func TestListAcrossNamespaces(t *testing.T) {
|
|
||||||
// conn, _ := rados.NewConn()
|
// create oid
|
||||||
// conn.ReadDefaultConfigFile()
|
oid := suite.GenObjectName()
|
||||||
// conn.Connect()
|
bytes_in := []byte("input data")
|
||||||
//
|
err = suite.ioctx.Write(oid, bytes_in, 0)
|
||||||
// pool_name := GetUUID()
|
assert.NoError(suite.T(), err)
|
||||||
// err := conn.MakePool(pool_name)
|
|
||||||
// assert.NoError(t, err)
|
// create oid2 in space1 ns
|
||||||
//
|
suite.ioctx.SetNamespace("space1")
|
||||||
// pool, err := conn.OpenIOContext(pool_name)
|
oid2 := suite.GenObjectName()
|
||||||
// assert.NoError(t, err)
|
bytes_in = []byte("input data")
|
||||||
//
|
err = suite.ioctx.Write(oid2, bytes_in, 0)
|
||||||
// bytes_in := []byte("input data")
|
assert.NoError(suite.T(), err)
|
||||||
// err = pool.Write("obj", bytes_in, 0)
|
|
||||||
// assert.NoError(t, err)
|
// count objects in space1 ns
|
||||||
//
|
nsFoundObjects := 0
|
||||||
// pool.SetNamespace("space1")
|
err = suite.ioctx.ListObjects(func(oid string) {
|
||||||
//
|
nsFoundObjects++
|
||||||
// bytes_in = []byte("input data")
|
})
|
||||||
// err = pool.Write("obj2", bytes_in, 0)
|
assert.NoError(suite.T(), err)
|
||||||
// assert.NoError(t, err)
|
assert.EqualValues(suite.T(), 1, nsFoundObjects)
|
||||||
//
|
|
||||||
// foundObjects := 0
|
// count objects in pool
|
||||||
// err = pool.ListObjects(func(oid string) {
|
suite.ioctx.SetNamespace(rados.RadosAllNamespaces)
|
||||||
// foundObjects++
|
allFoundObjects := 0
|
||||||
// })
|
err = suite.ioctx.ListObjects(func(oid string) {
|
||||||
// assert.NoError(t, err)
|
allFoundObjects++
|
||||||
// assert.EqualValues(t, 1, foundObjects)
|
})
|
||||||
//
|
assert.NoError(suite.T(), err)
|
||||||
// pool.SetNamespace(rados.RadosAllNamespaces)
|
assert.EqualValues(suite.T(), (origObjects + 2), allFoundObjects)
|
||||||
//
|
}
|
||||||
// foundObjects = 0
|
|
||||||
// err = pool.ListObjects(func(oid string) {
|
func (suite *RadosTestSuite) TestLocking() {
|
||||||
// foundObjects++
|
suite.SetupConnection()
|
||||||
// })
|
|
||||||
// assert.NoError(t, err)
|
oid := suite.GenObjectName()
|
||||||
// assert.EqualValues(t, 2, foundObjects)
|
|
||||||
//
|
// lock ex
|
||||||
// pool.Destroy()
|
res, err := suite.ioctx.LockExclusive(oid, "myLock", "myCookie", "this is a test lock", 0, nil)
|
||||||
// conn.Shutdown()
|
assert.NoError(suite.T(), err)
|
||||||
//}
|
assert.Equal(suite.T(), 0, res)
|
||||||
//
|
|
||||||
//func TestLocking(t *testing.T) {
|
// verify lock ex
|
||||||
// conn, _ := rados.NewConn()
|
info, err := suite.ioctx.ListLockers(oid, "myLock")
|
||||||
// conn.ReadDefaultConfigFile()
|
assert.NoError(suite.T(), err)
|
||||||
// conn.Connect()
|
assert.Equal(suite.T(), 1, len(info.Clients))
|
||||||
//
|
assert.Equal(suite.T(), true, info.Exclusive)
|
||||||
// pool_name := GetUUID()
|
|
||||||
// err := conn.MakePool(pool_name)
|
// fail to lock ex again
|
||||||
// assert.NoError(t, err)
|
res, err = suite.ioctx.LockExclusive(oid, "myLock", "myCookie", "this is a description", 0, nil)
|
||||||
//
|
assert.NoError(suite.T(), err)
|
||||||
// pool, err := conn.OpenIOContext(pool_name)
|
assert.Equal(suite.T(), -17, res)
|
||||||
// assert.NoError(t, err)
|
|
||||||
//
|
// fail to lock sh
|
||||||
// // lock ex
|
res, err = suite.ioctx.LockShared(oid, "myLock", "myCookie", "", "a description", 0, nil)
|
||||||
// res, err := pool.LockExclusive("obj", "myLock", "myCookie", "this is a test lock", 0, nil)
|
assert.NoError(suite.T(), err)
|
||||||
// assert.NoError(t, err)
|
assert.Equal(suite.T(), -17, res)
|
||||||
// assert.Equal(t, 0, res)
|
|
||||||
//
|
// unlock
|
||||||
// // verify lock ex
|
res, err = suite.ioctx.Unlock(oid, "myLock", "myCookie")
|
||||||
// info, err := pool.ListLockers("obj", "myLock")
|
assert.NoError(suite.T(), err)
|
||||||
// assert.NoError(t, err)
|
assert.Equal(suite.T(), 0, res)
|
||||||
// assert.Equal(t, 1, len(info.Clients))
|
|
||||||
// assert.Equal(t, true, info.Exclusive)
|
// verify unlock
|
||||||
//
|
info, err = suite.ioctx.ListLockers(oid, "myLock")
|
||||||
// // fail to lock ex again
|
assert.NoError(suite.T(), err)
|
||||||
// res, err = pool.LockExclusive("obj", "myLock", "myCookie", "this is a description", 0, nil)
|
assert.Equal(suite.T(), 0, len(info.Clients))
|
||||||
// assert.NoError(t, err)
|
|
||||||
// assert.Equal(t, -17, res)
|
// lock sh
|
||||||
//
|
res, err = suite.ioctx.LockShared(oid, "myLock", "myCookie", "", "a description", 0, nil)
|
||||||
// // fail to lock sh
|
assert.NoError(suite.T(), err)
|
||||||
// res, err = pool.LockShared("obj", "myLock", "myCookie", "", "a description", 0, nil)
|
assert.Equal(suite.T(), 0, res)
|
||||||
// assert.NoError(t, err)
|
|
||||||
// assert.Equal(t, -17, res)
|
// verify lock sh
|
||||||
//
|
info, err = suite.ioctx.ListLockers(oid, "myLock")
|
||||||
// // unlock
|
assert.NoError(suite.T(), err)
|
||||||
// res, err = pool.Unlock("obj", "myLock", "myCookie")
|
assert.Equal(suite.T(), 1, len(info.Clients))
|
||||||
// assert.NoError(t, err)
|
assert.Equal(suite.T(), false, info.Exclusive)
|
||||||
// assert.Equal(t, 0, res)
|
|
||||||
//
|
// fail to lock sh again
|
||||||
// // verify unlock
|
res, err = suite.ioctx.LockExclusive(oid, "myLock", "myCookie", "a description", 0, nil)
|
||||||
// info, err = pool.ListLockers("obj", "myLock")
|
assert.NoError(suite.T(), err)
|
||||||
// assert.NoError(t, err)
|
assert.Equal(suite.T(), -17, res)
|
||||||
// assert.Equal(t, 0, len(info.Clients))
|
|
||||||
//
|
// fail to lock ex
|
||||||
// // lock sh
|
res, err = suite.ioctx.LockExclusive(oid, "myLock", "myCookie", "this is a test lock", 0, nil)
|
||||||
// res, err = pool.LockShared("obj", "myLock", "myCookie", "", "a description", 0, nil)
|
assert.NoError(suite.T(), err)
|
||||||
// assert.NoError(t, err)
|
assert.Equal(suite.T(), res, -17)
|
||||||
// assert.Equal(t, 0, res)
|
|
||||||
//
|
// break the lock
|
||||||
// // verify lock sh
|
res, err = suite.ioctx.BreakLock(oid, "myLock", info.Clients[0], "myCookie")
|
||||||
// info, err = pool.ListLockers("obj", "myLock")
|
assert.NoError(suite.T(), err)
|
||||||
// assert.NoError(t, err)
|
assert.Equal(suite.T(), 0, res)
|
||||||
// assert.Equal(t, 1, len(info.Clients))
|
|
||||||
// assert.Equal(t, false, info.Exclusive)
|
// verify lock broken
|
||||||
//
|
info, err = suite.ioctx.ListLockers(oid, "myLock")
|
||||||
// // fail to lock sh again
|
assert.NoError(suite.T(), err)
|
||||||
// res, err = pool.LockExclusive("obj", "myLock", "myCookie", "a description", 0, nil)
|
assert.Equal(suite.T(), 0, len(info.Clients))
|
||||||
// assert.NoError(t, err)
|
|
||||||
// assert.Equal(t, -17, res)
|
// lock sh with duration
|
||||||
//
|
res, err = suite.ioctx.LockShared(oid, "myLock", "myCookie", "", "a description", time.Millisecond, nil)
|
||||||
// // fail to lock ex
|
assert.NoError(suite.T(), err)
|
||||||
// res, err = pool.LockExclusive("obj", "myLock", "myCookie", "this is a test lock", 0, nil)
|
assert.Equal(suite.T(), 0, res)
|
||||||
// assert.NoError(t, err)
|
|
||||||
// assert.Equal(t, res, -17)
|
// verify lock sh expired
|
||||||
//
|
time.Sleep(time.Second)
|
||||||
// // break the lock
|
info, err = suite.ioctx.ListLockers(oid, "myLock")
|
||||||
// res, err = pool.BreakLock("obj", "myLock", info.Clients[0], "myCookie")
|
assert.NoError(suite.T(), err)
|
||||||
// assert.NoError(t, err)
|
assert.Equal(suite.T(), 0, len(info.Clients))
|
||||||
// assert.Equal(t, 0, res)
|
|
||||||
//
|
// lock sh with duration
|
||||||
// // verify lock broken
|
res, err = suite.ioctx.LockExclusive(oid, "myLock", "myCookie", "a description", time.Millisecond, nil)
|
||||||
// info, err = pool.ListLockers("obj", "myLock")
|
assert.NoError(suite.T(), err)
|
||||||
// assert.NoError(t, err)
|
assert.Equal(suite.T(), 0, res)
|
||||||
// assert.Equal(t, 0, len(info.Clients))
|
|
||||||
//
|
// verify lock sh expired
|
||||||
// // lock sh with duration
|
time.Sleep(time.Second)
|
||||||
// res, err = pool.LockShared("obj", "myLock", "myCookie", "", "a description", time.Millisecond, nil)
|
info, err = suite.ioctx.ListLockers(oid, "myLock")
|
||||||
// assert.NoError(t, err)
|
assert.NoError(suite.T(), err)
|
||||||
// assert.Equal(t, 0, res)
|
assert.Equal(suite.T(), 0, len(info.Clients))
|
||||||
//
|
}
|
||||||
// // verify lock sh expired
|
|
||||||
// time.Sleep(time.Second)
|
func (suite *RadosTestSuite) TestOmapOnNonexistentObjectError() {
|
||||||
// info, err = pool.ListLockers("obj", "myLock")
|
suite.SetupConnection()
|
||||||
// assert.NoError(t, err)
|
oid := suite.GenObjectName()
|
||||||
// assert.Equal(t, 0, len(info.Clients))
|
_, err := suite.ioctx.GetAllOmapValues(oid, "", "", 100)
|
||||||
//
|
assert.Equal(suite.T(), err, rados.RadosErrorNotFound)
|
||||||
// // lock sh with duration
|
}
|
||||||
// res, err = pool.LockExclusive("obj", "myLock", "myCookie", "a description", time.Millisecond, nil)
|
|
||||||
// assert.NoError(t, err)
|
|
||||||
// assert.Equal(t, 0, res)
|
|
||||||
//
|
|
||||||
// // verify lock sh expired
|
|
||||||
// time.Sleep(time.Second)
|
|
||||||
// info, err = pool.ListLockers("obj", "myLock")
|
|
||||||
// assert.NoError(t, err)
|
|
||||||
// assert.Equal(t, 0, len(info.Clients))
|
|
||||||
//
|
|
||||||
// pool.Destroy()
|
|
||||||
// conn.Shutdown()
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func TestOmapOnNonexistentObjectError(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)
|
|
||||||
//
|
|
||||||
// //This object does not exist
|
|
||||||
// objname := GetUUID()
|
|
||||||
//
|
|
||||||
// _, err = pool.GetAllOmapValues(objname, "", "", 100)
|
|
||||||
// assert.Equal(t, err, rados.RadosErrorNotFound)
|
|
||||||
//}
|
|
||||||
|
|
||||||
func TestRadosTestSuite(t *testing.T) {
|
func TestRadosTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(RadosTestSuite))
|
suite.Run(t, new(RadosTestSuite))
|
||||||
|
|
Loading…
Reference in New Issue