2680bae88c
Remove direct dependency on uplink.RSConfig, this simplifies moving the config file without introducing weird dependencies. Change-Id: I7fd2a145401e0205d7047631df9d2810241efeec
111 lines
3.3 KiB
Go
111 lines
3.3 KiB
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package metrics_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"storj.io/common/memory"
|
|
"storj.io/common/testcontext"
|
|
"storj.io/common/testrand"
|
|
"storj.io/storj/pkg/storj"
|
|
"storj.io/storj/private/testplanet"
|
|
)
|
|
|
|
func TestCounterInlineAndRemote(t *testing.T) {
|
|
testplanet.Run(t, testplanet.Config{
|
|
SatelliteCount: 1, StorageNodeCount: 5, 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/" + string(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/" + string(i)
|
|
err := ul.UploadWithConfig(ctx, satellite, &storj.RedundancyScheme{
|
|
Algorithm: storj.ReedSolomon,
|
|
RequiredShares: 3,
|
|
RepairShares: 4,
|
|
OptimalShares: 5,
|
|
TotalShares: 5,
|
|
}, "testbucket", path, testData)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
metricsChore.Loop.TriggerWait()
|
|
require.EqualValues(t, 2, metricsChore.Counter.Inline)
|
|
require.EqualValues(t, 2, metricsChore.Counter.RemoteDependent)
|
|
require.EqualValues(t, 4, metricsChore.Counter.Total)
|
|
})
|
|
}
|
|
|
|
func TestCounterInlineOnly(t *testing.T) {
|
|
testplanet.Run(t, testplanet.Config{
|
|
SatelliteCount: 1, StorageNodeCount: 5, 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/" + string(i)
|
|
err := ul.Upload(ctx, satellite, "bucket", path, testData)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
metricsChore.Loop.TriggerWait()
|
|
require.EqualValues(t, 2, metricsChore.Counter.Inline)
|
|
require.EqualValues(t, 0, metricsChore.Counter.RemoteDependent)
|
|
require.EqualValues(t, 2, metricsChore.Counter.Total)
|
|
})
|
|
}
|
|
|
|
func TestCounterRemoteOnly(t *testing.T) {
|
|
testplanet.Run(t, testplanet.Config{
|
|
SatelliteCount: 1, StorageNodeCount: 5, 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 remote files with 1 segment
|
|
for i := 0; i < 2; i++ {
|
|
testData := testrand.Bytes(8 * memory.KiB)
|
|
path := "/some/remote/path/" + string(i)
|
|
err := ul.UploadWithConfig(ctx, satellite, &storj.RedundancyScheme{
|
|
Algorithm: storj.ReedSolomon,
|
|
RequiredShares: 3,
|
|
RepairShares: 4,
|
|
OptimalShares: 5,
|
|
TotalShares: 5,
|
|
}, "testbucket", path, testData)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
metricsChore.Loop.TriggerWait()
|
|
require.EqualValues(t, 0, metricsChore.Counter.Inline)
|
|
require.EqualValues(t, 2, metricsChore.Counter.RemoteDependent)
|
|
require.EqualValues(t, 2, metricsChore.Counter.Total)
|
|
})
|
|
}
|