lotus/blockstore/autobatch_test.go

35 lines
766 B
Go
Raw Normal View History

2022-01-11 16:31:59 +00:00
package blockstore
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestAutobatchBlockstore(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ab := NewAutobatch(ctx, NewMemory(), len(b0.RawData())+len(b1.RawData())-1)
2022-02-03 19:40:37 +00:00
require.NoError(t, ab.Put(b0))
require.NoError(t, ab.Put(b1))
require.NoError(t, ab.Put(b2))
2022-01-11 16:31:59 +00:00
2022-02-03 19:40:37 +00:00
v0, err := ab.Get(b0.Cid())
2022-01-11 16:31:59 +00:00
require.NoError(t, err)
require.Equal(t, b0.RawData(), v0.RawData())
2022-02-03 19:40:37 +00:00
v1, err := ab.Get(b1.Cid())
2022-01-11 16:31:59 +00:00
require.NoError(t, err)
require.Equal(t, b1.RawData(), v1.RawData())
2022-02-03 19:40:37 +00:00
v2, err := ab.Get(b2.Cid())
2022-01-11 16:31:59 +00:00
require.NoError(t, err)
require.Equal(t, b2.RawData(), v2.RawData())
2022-01-12 20:03:34 +00:00
require.NoError(t, ab.Flush(ctx))
require.NoError(t, ab.Shutdown(ctx))
2022-01-11 16:31:59 +00:00
}