2018-08-17 20:11:46 +01:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information
|
|
|
|
|
|
|
|
package kademlia
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2018-09-18 05:39:06 +01:00
|
|
|
|
|
|
|
"storj.io/storj/pkg/pb"
|
2018-08-17 20:11:46 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAddToReplacementCache(t *testing.T) {
|
2018-09-11 14:57:12 +01:00
|
|
|
rt, cleanup := createRoutingTable(t, []byte{244, 255})
|
|
|
|
defer cleanup()
|
2018-08-17 20:11:46 +01:00
|
|
|
kadBucketID := []byte{255, 255}
|
|
|
|
node1 := mockNode(string([]byte{233, 255}))
|
|
|
|
rt.addToReplacementCache(kadBucketID, node1)
|
2018-09-18 05:39:06 +01:00
|
|
|
assert.Equal(t, []*pb.Node{node1}, rt.replacementCache[string(kadBucketID)])
|
2018-08-17 20:11:46 +01:00
|
|
|
kadBucketID2 := []byte{127, 255}
|
|
|
|
node2 := mockNode(string([]byte{100, 255}))
|
|
|
|
node3 := mockNode(string([]byte{90, 255}))
|
|
|
|
node4 := mockNode(string([]byte{80, 255}))
|
|
|
|
rt.addToReplacementCache(kadBucketID2, node2)
|
|
|
|
rt.addToReplacementCache(kadBucketID2, node3)
|
|
|
|
|
2018-09-18 05:39:06 +01:00
|
|
|
assert.Equal(t, []*pb.Node{node1}, rt.replacementCache[string(kadBucketID)])
|
|
|
|
assert.Equal(t, []*pb.Node{node2, node3}, rt.replacementCache[string(kadBucketID2)])
|
2018-08-17 20:11:46 +01:00
|
|
|
rt.addToReplacementCache(kadBucketID2, node4)
|
2018-09-18 05:39:06 +01:00
|
|
|
assert.Equal(t, []*pb.Node{node3, node4}, rt.replacementCache[string(kadBucketID2)])
|
2018-08-17 20:11:46 +01:00
|
|
|
}
|