storj/satellite/metrics/counter_test.go
Michał Niewrzał 6e79923996 satellite/metainfo: bring back validation while committing segment
During metainfo refactor we disabled some validation as it was designed to validate pointer. Now part of this validation is restored. This is first part.

Change-Id: I6132f922fe23d60118bbccfdb77fd93c3c81afed
2021-04-12 15:12:42 -06:00

103 lines
3.2 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package metrics_test
import (
"strconv"
"testing"
"github.com/stretchr/testify/require"
"storj.io/common/memory"
"storj.io/common/testcontext"
"storj.io/common/testrand"
"storj.io/storj/private/testplanet"
)
func TestCounterInlineAndRemote(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
satellite := planet.Satellites[0]
ul := planet.Uplinks[0]
metricsChore := satellite.Metrics.Chore
metricsChore.Loop.Pause()
segmentSize := 8 * memory.KiB
// upload 2 inline files
for i := 0; i < 2; i++ {
testData := testrand.Bytes(segmentSize / 8)
path := "/some/inline/path/" + strconv.Itoa(i)
err := ul.Upload(ctx, satellite, "bucket", path, testData)
require.NoError(t, err)
}
// upload 2 remote files with 1 segment
for i := 0; i < 2; i++ {
testData := testrand.Bytes(segmentSize)
path := "/some/remote/path/" + strconv.Itoa(i)
err := ul.Upload(ctx, satellite, "testbucket", path, testData)
require.NoError(t, err)
}
metricsChore.Loop.TriggerWait()
require.EqualValues(t, 2, metricsChore.Counter.InlineObjectCount())
require.EqualValues(t, 2, metricsChore.Counter.RemoteDependent)
require.EqualValues(t, 4, metricsChore.Counter.ObjectCount)
})
}
func TestCounterInlineOnly(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
satellite := planet.Satellites[0]
ul := planet.Uplinks[0]
metricsChore := satellite.Metrics.Chore
metricsChore.Loop.Pause()
// upload 2 inline files
for i := 0; i < 2; i++ {
testData := testrand.Bytes(memory.KiB)
path := "/some/inline/path/" + strconv.Itoa(i)
err := ul.Upload(ctx, satellite, "bucket", path, testData)
require.NoError(t, err)
}
metricsChore.Loop.TriggerWait()
require.EqualValues(t, 2, metricsChore.Counter.InlineObjectCount())
require.EqualValues(t, 0, metricsChore.Counter.RemoteDependent)
require.EqualValues(t, 2, metricsChore.Counter.ObjectCount)
})
}
func TestCounterRemoteOnly(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 4, UplinkCount: 1,
Reconfigure: testplanet.Reconfigure{
Satellite: testplanet.MaxSegmentSize(150 * memory.KiB),
},
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
satellite := planet.Satellites[0]
ul := planet.Uplinks[0]
metricsChore := satellite.Metrics.Chore
metricsChore.Loop.Pause()
// upload 2 remote files with multiple segments
for i := 0; i < 2; i++ {
testData := testrand.Bytes(300 * memory.KiB)
path := "/some/remote/path/" + strconv.Itoa(i)
err := ul.Upload(ctx, satellite, "testbucket", path, testData)
require.NoError(t, err)
}
metricsChore.Loop.TriggerWait()
t.Log(metricsChore.Counter.ObjectCount, metricsChore.Counter.RemoteDependent)
require.EqualValues(t, 0, metricsChore.Counter.InlineObjectCount())
require.EqualValues(t, 2, metricsChore.Counter.RemoteDependent)
require.EqualValues(t, 2, metricsChore.Counter.ObjectCount)
})
}