2021-11-11 13:58:07 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2021-10-27 14:50:58 +00:00
|
|
|
"os"
|
2022-03-01 08:59:05 +00:00
|
|
|
"path/filepath"
|
2021-11-11 13:58:07 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
2022-06-28 14:05:08 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard/mode"
|
2021-11-15 09:37:56 +00:00
|
|
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
2021-11-11 13:58:07 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestExecBlocks(t *testing.T) {
|
|
|
|
e := testNewEngineWithShardNum(t, 2) // number doesn't matter in this test, 2 is several but not many
|
2021-10-27 14:50:58 +00:00
|
|
|
t.Cleanup(func() {
|
|
|
|
e.Close()
|
|
|
|
os.RemoveAll(t.Name())
|
|
|
|
})
|
2021-11-11 13:58:07 +00:00
|
|
|
|
|
|
|
// put some object
|
2022-03-03 14:19:05 +00:00
|
|
|
obj := generateObjectWithCID(t, cidtest.ID())
|
2021-11-11 13:58:07 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
addr := object.AddressOf(obj)
|
2021-11-11 13:58:07 +00:00
|
|
|
|
|
|
|
require.NoError(t, Put(e, obj))
|
|
|
|
|
|
|
|
// block executions
|
|
|
|
errBlock := errors.New("block exec err")
|
|
|
|
|
|
|
|
require.NoError(t, e.BlockExecution(errBlock))
|
|
|
|
|
|
|
|
// try to exec some op
|
|
|
|
_, err := Head(e, addr)
|
|
|
|
require.ErrorIs(t, err, errBlock)
|
|
|
|
|
|
|
|
// resume executions
|
|
|
|
require.NoError(t, e.ResumeExecution())
|
|
|
|
|
|
|
|
_, err = Head(e, addr) // can be any data-related op
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// close
|
|
|
|
require.NoError(t, e.Close())
|
|
|
|
|
|
|
|
// try exec after close
|
|
|
|
_, err = Head(e, addr)
|
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
// try to resume
|
|
|
|
require.Error(t, e.ResumeExecution())
|
|
|
|
}
|
2022-03-01 08:59:05 +00:00
|
|
|
|
|
|
|
func TestPersistentShardID(t *testing.T) {
|
|
|
|
dir, err := os.MkdirTemp("", "*")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
e, _, id := newEngineWithErrorThreshold(t, dir, 1)
|
|
|
|
|
2022-06-28 14:05:08 +00:00
|
|
|
checkShardState(t, e, id[0], 0, mode.ReadWrite)
|
2022-03-01 08:59:05 +00:00
|
|
|
require.NoError(t, e.Close())
|
|
|
|
|
|
|
|
e, _, newID := newEngineWithErrorThreshold(t, dir, 1)
|
|
|
|
require.Equal(t, id, newID)
|
|
|
|
require.NoError(t, e.Close())
|
|
|
|
|
|
|
|
p1 := e.shards[id[0].String()].Shard.DumpInfo().MetaBaseInfo.Path
|
|
|
|
p2 := e.shards[id[1].String()].Shard.DumpInfo().MetaBaseInfo.Path
|
|
|
|
tmp := filepath.Join(dir, "tmp")
|
|
|
|
require.NoError(t, os.Rename(p1, tmp))
|
|
|
|
require.NoError(t, os.Rename(p2, p1))
|
|
|
|
require.NoError(t, os.Rename(tmp, p2))
|
|
|
|
|
|
|
|
e, _, newID = newEngineWithErrorThreshold(t, dir, 1)
|
|
|
|
require.Equal(t, id[1], newID[0])
|
|
|
|
require.Equal(t, id[0], newID[1])
|
|
|
|
require.NoError(t, e.Close())
|
|
|
|
|
|
|
|
}
|