mirror of
https://github.com/ceph/go-ceph
synced 2024-12-23 06:33:24 +00:00
4c8fb2d210
This commit implements binding for rados_read_op_assert_version RADOS Read operation as well as rados_write_op_assert_version RADOS Write operation. Includes unit tests for both. Signed-off-by: Robert Vasek <robert.vasek@cern.ch>
49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
//go:build ceph_preview
|
|
// +build ceph_preview
|
|
|
|
package rados
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func (suite *RadosTestSuite) TestWriteOpAssertVersion() {
|
|
suite.SetupConnection()
|
|
ta := assert.New(suite.T())
|
|
|
|
var (
|
|
oid = "TestWriteOpAssertVersion"
|
|
err error
|
|
)
|
|
|
|
// Create an object.
|
|
op1 := CreateWriteOp()
|
|
defer op1.Release()
|
|
op1.Create(CreateIdempotent)
|
|
err = op1.Operate(suite.ioctx, oid, OperationNoFlag)
|
|
ta.NoError(err)
|
|
|
|
// Retrieve last object version after writing.
|
|
ver1, err := suite.ioctx.GetLastVersion()
|
|
ta.NoError(err)
|
|
|
|
// Write with version assert. It should succeed.
|
|
op2 := CreateWriteOp()
|
|
defer op2.Release()
|
|
op2.AssertVersion(ver1)
|
|
err = op2.Operate(suite.ioctx, oid, OperationNoFlag)
|
|
ta.NoError(err)
|
|
|
|
// Refresh the version.
|
|
ver2, err := suite.ioctx.GetLastVersion()
|
|
ta.NoError(err)
|
|
|
|
// Write with version assert, but modify the version first.
|
|
// It should fail.
|
|
op3 := CreateWriteOp()
|
|
defer op3.Release()
|
|
op3.AssertVersion(ver2 + 1)
|
|
err = op3.Operate(suite.ioctx, oid, OperationNoFlag)
|
|
ta.Error(err)
|
|
}
|