2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-03 12:17:14 +00:00
|
|
|
// See LICENSE for copying information
|
|
|
|
|
|
|
|
package testplanet_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
2019-02-04 15:40:37 +00:00
|
|
|
"time"
|
2018-11-03 12:17:14 +00:00
|
|
|
|
2019-02-04 15:40:37 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"storj.io/storj/internal/testcontext"
|
2018-11-03 12:17:14 +00:00
|
|
|
"storj.io/storj/internal/testplanet"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBasic(t *testing.T) {
|
2019-02-04 15:40:37 +00:00
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
2018-11-03 12:17:14 +00:00
|
|
|
|
2019-02-04 15:40:37 +00:00
|
|
|
planet, err := testplanet.New(t, 2, 4, 1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer ctx.Check(planet.Shutdown)
|
2018-11-03 12:17:14 +00:00
|
|
|
|
2019-02-04 15:40:37 +00:00
|
|
|
planet.Start(ctx)
|
2018-11-03 12:17:14 +00:00
|
|
|
|
|
|
|
for _, satellite := range planet.Satellites {
|
|
|
|
t.Log("SATELLITE", satellite.ID(), satellite.Addr())
|
|
|
|
}
|
|
|
|
for _, storageNode := range planet.StorageNodes {
|
|
|
|
t.Log("STORAGE", storageNode.ID(), storageNode.Addr())
|
|
|
|
}
|
|
|
|
for _, uplink := range planet.Uplinks {
|
|
|
|
t.Log("UPLINK", uplink.ID(), uplink.Addr())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Example of using pointer db
|
|
|
|
client, err := planet.Uplinks[0].DialPointerDB(planet.Satellites[0], "apikey")
|
2019-02-04 15:40:37 +00:00
|
|
|
require.NoError(t, err)
|
2018-11-03 12:17:14 +00:00
|
|
|
|
2018-11-05 15:12:19 +00:00
|
|
|
message := client.SignedMessage()
|
2018-11-03 12:17:14 +00:00
|
|
|
t.Log(message)
|
2019-01-10 13:13:27 +00:00
|
|
|
|
|
|
|
// ping a satellite
|
2019-02-06 12:37:17 +00:00
|
|
|
_, err = planet.StorageNodes[0].Kademlia.Service.Ping(ctx, planet.Satellites[0].Local())
|
2019-02-04 15:40:37 +00:00
|
|
|
require.NoError(t, err)
|
2019-01-10 13:13:27 +00:00
|
|
|
|
|
|
|
// ping a storage node
|
2019-02-06 12:37:17 +00:00
|
|
|
_, err = planet.StorageNodes[0].Kademlia.Service.Ping(ctx, planet.StorageNodes[1].Local())
|
2019-02-04 15:40:37 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-02-06 12:37:17 +00:00
|
|
|
err = planet.StopPeer(planet.StorageNodes[1])
|
2019-02-04 15:40:37 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-02-06 12:37:17 +00:00
|
|
|
// ping a stopped storage node
|
|
|
|
_, err = planet.StorageNodes[0].Kademlia.Service.Ping(ctx, planet.StorageNodes[1].Local())
|
|
|
|
require.Error(t, err)
|
|
|
|
|
2019-02-04 15:40:37 +00:00
|
|
|
// wait a bit to see whether some failures occur
|
|
|
|
time.Sleep(time.Second)
|
2018-11-03 12:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkCreate(b *testing.B) {
|
|
|
|
storageNodes := []int{4, 10, 100}
|
|
|
|
for _, count := range storageNodes {
|
|
|
|
b.Run(strconv.Itoa(count), func(b *testing.B) {
|
|
|
|
ctx := context.Background()
|
|
|
|
for i := 0; i < b.N; i++ {
|
2018-11-15 08:57:47 +00:00
|
|
|
planet, err := testplanet.New(nil, 1, count, 1)
|
2019-02-04 15:40:37 +00:00
|
|
|
require.NoError(b, err)
|
2018-11-03 12:17:14 +00:00
|
|
|
|
|
|
|
planet.Start(ctx)
|
|
|
|
|
|
|
|
err = planet.Shutdown()
|
2019-02-04 15:40:37 +00:00
|
|
|
require.NoError(b, err)
|
2018-11-03 12:17:14 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|