2018-11-19 20:39:25 +00:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package overlay_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2018-11-20 16:54:52 +00:00
|
|
|
"time"
|
2018-11-19 20:39:25 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-01-15 16:08:45 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-11-19 20:39:25 +00:00
|
|
|
|
|
|
|
"storj.io/storj/internal/testcontext"
|
|
|
|
"storj.io/storj/internal/testplanet"
|
|
|
|
"storj.io/storj/pkg/pb"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestServer(t *testing.T) {
|
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
|
|
|
planet, err := testplanet.New(t, 1, 4, 1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer ctx.Check(planet.Shutdown)
|
|
|
|
|
|
|
|
planet.Start(ctx)
|
2018-11-20 16:54:52 +00:00
|
|
|
// we wait a second for all the nodes to complete bootstrapping off the satellite
|
|
|
|
time.Sleep(2 * time.Second)
|
2018-11-19 20:39:25 +00:00
|
|
|
|
|
|
|
satellite := planet.Satellites[0]
|
2019-01-18 13:54:08 +00:00
|
|
|
server := satellite.Overlay.Endpoint
|
2018-11-19 20:39:25 +00:00
|
|
|
// TODO: handle cleanup
|
|
|
|
|
|
|
|
{ // FindStorageNodes
|
2019-01-15 16:08:45 +00:00
|
|
|
result, err := server.FindStorageNodes(ctx, &pb.FindStorageNodesRequest{
|
|
|
|
Opts: &pb.OverlayOptions{Amount: 2},
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, result)
|
|
|
|
assert.Len(t, result.Nodes, 2)
|
2018-11-19 20:39:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // Lookup
|
2019-01-15 16:08:45 +00:00
|
|
|
result, err := server.Lookup(ctx, &pb.LookupRequest{
|
|
|
|
NodeId: planet.StorageNodes[0].ID(),
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, result)
|
|
|
|
assert.Equal(t, result.Node.Address.Address, planet.StorageNodes[0].Addr())
|
2018-11-19 20:39:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ // BulkLookup
|
|
|
|
result, err := server.BulkLookup(ctx, &pb.LookupRequests{
|
2018-11-24 02:46:53 +00:00
|
|
|
LookupRequest: []*pb.LookupRequest{
|
2018-11-29 18:39:27 +00:00
|
|
|
{NodeId: planet.StorageNodes[0].ID()},
|
|
|
|
{NodeId: planet.StorageNodes[1].ID()},
|
|
|
|
{NodeId: planet.StorageNodes[2].ID()},
|
2018-11-19 20:39:25 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2019-01-15 16:08:45 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, result)
|
|
|
|
require.Len(t, result.LookupResponse, 3)
|
|
|
|
|
|
|
|
for i, resp := range result.LookupResponse {
|
|
|
|
if assert.NotNil(t, resp.Node) {
|
|
|
|
assert.Equal(t, resp.Node.Address.Address, planet.StorageNodes[i].Addr())
|
2018-11-19 20:39:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|