|
|
@ -16,23 +16,25 @@ import ( |
|
|
|
cmn "github.com/tendermint/tendermint/libs/common" |
|
|
|
) |
|
|
|
|
|
|
|
// NOTE: Returned group has ticker stopped
|
|
|
|
func createTestGroup(t *testing.T, headSizeLimit int64) *Group { |
|
|
|
func createTestGroupWithHeadSizeLimit(t *testing.T, headSizeLimit int64) *Group { |
|
|
|
testID := cmn.RandStr(12) |
|
|
|
testDir := "_test_" + testID |
|
|
|
err := cmn.EnsureDir(testDir, 0700) |
|
|
|
require.NoError(t, err, "Error creating dir") |
|
|
|
|
|
|
|
headPath := testDir + "/myfile" |
|
|
|
g, err := OpenGroup(headPath) |
|
|
|
require.NoError(t, err, "Error opening Group") |
|
|
|
g.SetHeadSizeLimit(headSizeLimit) |
|
|
|
g.stopTicker() |
|
|
|
require.NotEqual(t, nil, g, "Failed to create Group") |
|
|
|
|
|
|
|
g.SetHeadSizeLimit(headSizeLimit) |
|
|
|
|
|
|
|
return g |
|
|
|
} |
|
|
|
|
|
|
|
func destroyTestGroup(t *testing.T, g *Group) { |
|
|
|
g.Close() |
|
|
|
|
|
|
|
err := os.RemoveAll(g.Dir) |
|
|
|
require.NoError(t, err, "Error removing test Group directory") |
|
|
|
} |
|
|
@ -45,7 +47,7 @@ func assertGroupInfo(t *testing.T, gInfo GroupInfo, minIndex, maxIndex int, tota |
|
|
|
} |
|
|
|
|
|
|
|
func TestCheckHeadSizeLimit(t *testing.T) { |
|
|
|
g := createTestGroup(t, 1000*1000) |
|
|
|
g := createTestGroupWithHeadSizeLimit(t, 1000*1000) |
|
|
|
|
|
|
|
// At first, there are no files.
|
|
|
|
assertGroupInfo(t, g.ReadGroupInfo(), 0, 0, 0, 0) |
|
|
@ -107,7 +109,7 @@ func TestCheckHeadSizeLimit(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestSearch(t *testing.T) { |
|
|
|
g := createTestGroup(t, 10*1000) |
|
|
|
g := createTestGroupWithHeadSizeLimit(t, 10*1000) |
|
|
|
|
|
|
|
// Create some files in the group that have several INFO lines in them.
|
|
|
|
// Try to put the INFO lines in various spots.
|
|
|
@ -208,7 +210,7 @@ func TestSearch(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestRotateFile(t *testing.T) { |
|
|
|
g := createTestGroup(t, 0) |
|
|
|
g := createTestGroupWithHeadSizeLimit(t, 0) |
|
|
|
g.WriteLine("Line 1") |
|
|
|
g.WriteLine("Line 2") |
|
|
|
g.WriteLine("Line 3") |
|
|
@ -238,7 +240,7 @@ func TestRotateFile(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestFindLast1(t *testing.T) { |
|
|
|
g := createTestGroup(t, 0) |
|
|
|
g := createTestGroupWithHeadSizeLimit(t, 0) |
|
|
|
|
|
|
|
g.WriteLine("Line 1") |
|
|
|
g.WriteLine("Line 2") |
|
|
@ -262,7 +264,7 @@ func TestFindLast1(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestFindLast2(t *testing.T) { |
|
|
|
g := createTestGroup(t, 0) |
|
|
|
g := createTestGroupWithHeadSizeLimit(t, 0) |
|
|
|
|
|
|
|
g.WriteLine("Line 1") |
|
|
|
g.WriteLine("Line 2") |
|
|
@ -286,7 +288,7 @@ func TestFindLast2(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestFindLast3(t *testing.T) { |
|
|
|
g := createTestGroup(t, 0) |
|
|
|
g := createTestGroupWithHeadSizeLimit(t, 0) |
|
|
|
|
|
|
|
g.WriteLine("Line 1") |
|
|
|
g.WriteLine("# a") |
|
|
@ -310,7 +312,7 @@ func TestFindLast3(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestFindLast4(t *testing.T) { |
|
|
|
g := createTestGroup(t, 0) |
|
|
|
g := createTestGroupWithHeadSizeLimit(t, 0) |
|
|
|
|
|
|
|
g.WriteLine("Line 1") |
|
|
|
g.WriteLine("Line 2") |
|
|
@ -332,7 +334,7 @@ func TestFindLast4(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestWrite(t *testing.T) { |
|
|
|
g := createTestGroup(t, 0) |
|
|
|
g := createTestGroupWithHeadSizeLimit(t, 0) |
|
|
|
|
|
|
|
written := []byte("Medusa") |
|
|
|
g.Write(written) |
|
|
@ -353,7 +355,7 @@ func TestWrite(t *testing.T) { |
|
|
|
// test that Read reads the required amount of bytes from all the files in the
|
|
|
|
// group and returns no error if n == size of the given slice.
|
|
|
|
func TestGroupReaderRead(t *testing.T) { |
|
|
|
g := createTestGroup(t, 0) |
|
|
|
g := createTestGroupWithHeadSizeLimit(t, 0) |
|
|
|
|
|
|
|
professor := []byte("Professor Monster") |
|
|
|
g.Write(professor) |
|
|
@ -382,7 +384,7 @@ func TestGroupReaderRead(t *testing.T) { |
|
|
|
// test that Read returns an error if number of bytes read < size of
|
|
|
|
// the given slice. Subsequent call should return 0, io.EOF.
|
|
|
|
func TestGroupReaderRead2(t *testing.T) { |
|
|
|
g := createTestGroup(t, 0) |
|
|
|
g := createTestGroupWithHeadSizeLimit(t, 0) |
|
|
|
|
|
|
|
professor := []byte("Professor Monster") |
|
|
|
g.Write(professor) |
|
|
@ -413,7 +415,7 @@ func TestGroupReaderRead2(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestMinIndex(t *testing.T) { |
|
|
|
g := createTestGroup(t, 0) |
|
|
|
g := createTestGroupWithHeadSizeLimit(t, 0) |
|
|
|
|
|
|
|
assert.Zero(t, g.MinIndex(), "MinIndex should be zero at the beginning") |
|
|
|
|
|
|
@ -422,7 +424,7 @@ func TestMinIndex(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestMaxIndex(t *testing.T) { |
|
|
|
g := createTestGroup(t, 0) |
|
|
|
g := createTestGroupWithHeadSizeLimit(t, 0) |
|
|
|
|
|
|
|
assert.Zero(t, g.MaxIndex(), "MaxIndex should be zero at the beginning") |
|
|
|
|
|
|
|