|
@ -1,6 +1,7 @@ |
|
|
package autofile |
|
|
package autofile |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"context" |
|
|
"io" |
|
|
"io" |
|
|
"os" |
|
|
"os" |
|
|
"path/filepath" |
|
|
"path/filepath" |
|
@ -14,14 +15,14 @@ import ( |
|
|
tmrand "github.com/tendermint/tendermint/libs/rand" |
|
|
tmrand "github.com/tendermint/tendermint/libs/rand" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func createTestGroupWithHeadSizeLimit(t *testing.T, logger log.Logger, headSizeLimit int64) *Group { |
|
|
|
|
|
|
|
|
func createTestGroupWithHeadSizeLimit(ctx context.Context, t *testing.T, logger log.Logger, headSizeLimit int64) *Group { |
|
|
testID := tmrand.Str(12) |
|
|
testID := tmrand.Str(12) |
|
|
testDir := "_test_" + testID |
|
|
testDir := "_test_" + testID |
|
|
err := tmos.EnsureDir(testDir, 0700) |
|
|
err := tmos.EnsureDir(testDir, 0700) |
|
|
require.NoError(t, err, "Error creating dir") |
|
|
require.NoError(t, err, "Error creating dir") |
|
|
|
|
|
|
|
|
headPath := testDir + "/myfile" |
|
|
headPath := testDir + "/myfile" |
|
|
g, err := OpenGroup(logger, headPath, GroupHeadSizeLimit(headSizeLimit)) |
|
|
|
|
|
|
|
|
g, err := OpenGroup(ctx, logger, headPath, GroupHeadSizeLimit(headSizeLimit)) |
|
|
require.NoError(t, err, "Error opening Group") |
|
|
require.NoError(t, err, "Error opening Group") |
|
|
require.NotEqual(t, nil, g, "Failed to create Group") |
|
|
require.NotEqual(t, nil, g, "Failed to create Group") |
|
|
|
|
|
|
|
@ -43,9 +44,12 @@ func assertGroupInfo(t *testing.T, gInfo GroupInfo, minIndex, maxIndex int, tota |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func TestCheckHeadSizeLimit(t *testing.T) { |
|
|
func TestCheckHeadSizeLimit(t *testing.T) { |
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
|
|
defer cancel() |
|
|
|
|
|
|
|
|
logger := log.TestingLogger() |
|
|
logger := log.TestingLogger() |
|
|
|
|
|
|
|
|
g := createTestGroupWithHeadSizeLimit(t, logger, 1000*1000) |
|
|
|
|
|
|
|
|
g := createTestGroupWithHeadSizeLimit(ctx, t, logger, 1000*1000) |
|
|
|
|
|
|
|
|
// At first, there are no files.
|
|
|
// At first, there are no files.
|
|
|
assertGroupInfo(t, g.ReadGroupInfo(), 0, 0, 0, 0) |
|
|
assertGroupInfo(t, g.ReadGroupInfo(), 0, 0, 0, 0) |
|
@ -114,7 +118,9 @@ func TestCheckHeadSizeLimit(t *testing.T) { |
|
|
func TestRotateFile(t *testing.T) { |
|
|
func TestRotateFile(t *testing.T) { |
|
|
logger := log.TestingLogger() |
|
|
logger := log.TestingLogger() |
|
|
|
|
|
|
|
|
g := createTestGroupWithHeadSizeLimit(t, logger, 0) |
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
|
|
defer cancel() |
|
|
|
|
|
g := createTestGroupWithHeadSizeLimit(ctx, t, logger, 0) |
|
|
|
|
|
|
|
|
// Create a different temporary directory and move into it, to make sure
|
|
|
// Create a different temporary directory and move into it, to make sure
|
|
|
// relative paths are resolved at Group creation
|
|
|
// relative paths are resolved at Group creation
|
|
@ -180,7 +186,10 @@ func TestRotateFile(t *testing.T) { |
|
|
func TestWrite(t *testing.T) { |
|
|
func TestWrite(t *testing.T) { |
|
|
logger := log.TestingLogger() |
|
|
logger := log.TestingLogger() |
|
|
|
|
|
|
|
|
g := createTestGroupWithHeadSizeLimit(t, logger, 0) |
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
|
|
defer cancel() |
|
|
|
|
|
|
|
|
|
|
|
g := createTestGroupWithHeadSizeLimit(ctx, t, logger, 0) |
|
|
|
|
|
|
|
|
written := []byte("Medusa") |
|
|
written := []byte("Medusa") |
|
|
_, err := g.Write(written) |
|
|
_, err := g.Write(written) |
|
@ -205,7 +214,10 @@ func TestWrite(t *testing.T) { |
|
|
func TestGroupReaderRead(t *testing.T) { |
|
|
func TestGroupReaderRead(t *testing.T) { |
|
|
logger := log.TestingLogger() |
|
|
logger := log.TestingLogger() |
|
|
|
|
|
|
|
|
g := createTestGroupWithHeadSizeLimit(t, logger, 0) |
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
|
|
defer cancel() |
|
|
|
|
|
|
|
|
|
|
|
g := createTestGroupWithHeadSizeLimit(ctx, t, logger, 0) |
|
|
|
|
|
|
|
|
professor := []byte("Professor Monster") |
|
|
professor := []byte("Professor Monster") |
|
|
_, err := g.Write(professor) |
|
|
_, err := g.Write(professor) |
|
@ -240,7 +252,10 @@ func TestGroupReaderRead(t *testing.T) { |
|
|
func TestGroupReaderRead2(t *testing.T) { |
|
|
func TestGroupReaderRead2(t *testing.T) { |
|
|
logger := log.TestingLogger() |
|
|
logger := log.TestingLogger() |
|
|
|
|
|
|
|
|
g := createTestGroupWithHeadSizeLimit(t, logger, 0) |
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
|
|
defer cancel() |
|
|
|
|
|
|
|
|
|
|
|
g := createTestGroupWithHeadSizeLimit(ctx, t, logger, 0) |
|
|
|
|
|
|
|
|
professor := []byte("Professor Monster") |
|
|
professor := []byte("Professor Monster") |
|
|
_, err := g.Write(professor) |
|
|
_, err := g.Write(professor) |
|
@ -276,7 +291,10 @@ func TestGroupReaderRead2(t *testing.T) { |
|
|
|
|
|
|
|
|
func TestMinIndex(t *testing.T) { |
|
|
func TestMinIndex(t *testing.T) { |
|
|
logger := log.TestingLogger() |
|
|
logger := log.TestingLogger() |
|
|
g := createTestGroupWithHeadSizeLimit(t, logger, 0) |
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
|
|
defer cancel() |
|
|
|
|
|
|
|
|
|
|
|
g := createTestGroupWithHeadSizeLimit(ctx, t, logger, 0) |
|
|
|
|
|
|
|
|
assert.Zero(t, g.MinIndex(), "MinIndex should be zero at the beginning") |
|
|
assert.Zero(t, g.MinIndex(), "MinIndex should be zero at the beginning") |
|
|
|
|
|
|
|
@ -286,7 +304,10 @@ func TestMinIndex(t *testing.T) { |
|
|
|
|
|
|
|
|
func TestMaxIndex(t *testing.T) { |
|
|
func TestMaxIndex(t *testing.T) { |
|
|
logger := log.TestingLogger() |
|
|
logger := log.TestingLogger() |
|
|
g := createTestGroupWithHeadSizeLimit(t, logger, 0) |
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
|
|
defer cancel() |
|
|
|
|
|
|
|
|
|
|
|
g := createTestGroupWithHeadSizeLimit(ctx, t, logger, 0) |
|
|
|
|
|
|
|
|
assert.Zero(t, g.MaxIndex(), "MaxIndex should be zero at the beginning") |
|
|
assert.Zero(t, g.MaxIndex(), "MaxIndex should be zero at the beginning") |
|
|
|
|
|
|
|
|