go.uber.org/yarpc@v1.72.1/peer/hashring32/config_test.go (about)

     1  // Copyright (c) 2022 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package hashring32
    22  
    23  import (
    24  	"testing"
    25  	"time"
    26  
    27  	"github.com/stretchr/testify/assert"
    28  	"go.uber.org/yarpc/api/peer"
    29  	"go.uber.org/yarpc/peer/hostport"
    30  	"go.uber.org/yarpc/yarpcconfig"
    31  	"go.uber.org/yarpc/yarpctest"
    32  )
    33  
    34  func TestPendingHeapConfig(t *testing.T) {
    35  	s := Spec(nil, nil)
    36  	duration := time.Second * 1
    37  
    38  	c := Config{
    39  		OffsetHeader:            "offsetHeader",
    40  		ReplicaDelimiter:        "#",
    41  		NumReplicas:             5,
    42  		NumPeersEstimate:        1000,
    43  		AlternateShardKeyHeader: "test-header",
    44  		DefaultChooseTimeout:    &duration,
    45  	}
    46  	build := s.BuildPeerList.(func(c Config, t peer.Transport, k *yarpcconfig.Kit) (peer.ChooserList, error))
    47  	pl, err := build(c, yarpctest.NewFakeTransport(), nil)
    48  	assert.NoError(t, err, "must construct a peer list")
    49  	pl.Update(peer.ListUpdates{Additions: []peer.Identifier{hostport.PeerIdentifier("127.0.0.1:8080")}})
    50  }
    51  
    52  func TestOffsetGeneratorValueConfig(t *testing.T) {
    53  	s := Spec(nil, nil)
    54  	duration := time.Second * 1
    55  
    56  	c := Config{
    57  		OffsetGeneratorValue:    4,
    58  		ReplicaDelimiter:        "#",
    59  		NumReplicas:             5,
    60  		NumPeersEstimate:        1000,
    61  		AlternateShardKeyHeader: "test-header",
    62  		DefaultChooseTimeout:    &duration,
    63  	}
    64  	build := s.BuildPeerList.(func(c Config, t peer.Transport, k *yarpcconfig.Kit) (peer.ChooserList, error))
    65  	pl, err := build(c, yarpctest.NewFakeTransport(), nil)
    66  	assert.NoError(t, err, "must construct a peer list")
    67  	pl.Update(peer.ListUpdates{Additions: []peer.Identifier{hostport.PeerIdentifier("127.0.0.1:8080")}})
    68  }