grpc: google.golang.org/grpc/xds/internal/testutils Index | Files | Directories

package testutils

import "google.golang.org/grpc/xds/internal/testutils"

Package testutils provides utility types, for use in xds tests.

Index

Package Files

balancer.go protos.go

Variables

var EmptyNodeProtoV2 = &v2corepb.Node{}

EmptyNodeProtoV2 is a v2 Node proto with no fields set.

var EmptyNodeProtoV3 = &v3corepb.Node{}

EmptyNodeProtoV3 is a v3 Node proto with no fields set.

var ErrTestConstPicker = fmt.Errorf("const picker error")

ErrTestConstPicker is error returned by test const picker.

var TestSubConns []*TestSubConn

TestSubConns contains a list of SubConns to be used in tests.

func IsRoundRobin Uses

func IsRoundRobin(want []balancer.SubConn, f func() balancer.SubConn) error

IsRoundRobin checks whether f's return value is roundrobin of elements from want. But it doesn't check for the order. Note that want can contain duplicate items, which makes it weight-round-robin.

Step 1. the return values of f should form a permutation of all elements in want, but not necessary in the same order. E.g. if want is {a,a,b}, the check fails if f returns:

- {a,a,a}: third a is returned before b
- {a,b,b}: second b is returned before the second a

If error is found in this step, the returned error contains only the first iteration until where it goes wrong.

Step 2. the return values of f should be repetitions of the same permutation. E.g. if want is {a,a,b}, the check failes if f returns:

- {a,b,a,b,a,a}: though it satisfies step 1, the second iteration is not
repeating the first iteration.

If error is found in this step, the returned error contains the first iteration + the second iteration until where it goes wrong.

func LocalityIDToProto Uses

func LocalityIDToProto(l internal.LocalityID) *v2corepb.Locality

LocalityIDToProto converts a LocalityID to its proto representation.

func NewTestWRR Uses

func NewTestWRR() wrr.WRR

NewTestWRR return a WRR for testing. It's deterministic instead random.

type AddLocalityOptions Uses

type AddLocalityOptions struct {
    Health []v2corepb.HealthStatus
    Weight []uint32
}

AddLocalityOptions contains options when adding locality to the builder.

type ClusterLoadAssignmentBuilder Uses

type ClusterLoadAssignmentBuilder struct {
    // contains filtered or unexported fields
}

ClusterLoadAssignmentBuilder builds a ClusterLoadAssignment, aka EDS response.

func NewClusterLoadAssignmentBuilder Uses

func NewClusterLoadAssignmentBuilder(clusterName string, dropPercents []uint32) *ClusterLoadAssignmentBuilder

NewClusterLoadAssignmentBuilder creates a ClusterLoadAssignmentBuilder.

func (*ClusterLoadAssignmentBuilder) AddLocality Uses

func (clab *ClusterLoadAssignmentBuilder) AddLocality(subzone string, weight uint32, priority uint32, addrsWithPort []string, opts *AddLocalityOptions)

AddLocality adds a locality to the builder.

func (*ClusterLoadAssignmentBuilder) Build Uses

func (clab *ClusterLoadAssignmentBuilder) Build() *v2xdspb.ClusterLoadAssignment

Build builds ClusterLoadAssignment.

type TestClientConn Uses

type TestClientConn struct {
    NewSubConnAddrsCh chan []resolver.Address // the last 10 []Address to create subconn.
    NewSubConnCh      chan balancer.SubConn   // the last 10 subconn created.
    RemoveSubConnCh   chan balancer.SubConn   // the last 10 subconn removed.

    NewPickerCh chan balancer.Picker    // the last picker updated.
    NewStateCh  chan connectivity.State // the last state.
    // contains filtered or unexported fields
}

TestClientConn is a mock balancer.ClientConn used in tests.

func NewTestClientConn Uses

func NewTestClientConn(t *testing.T) *TestClientConn

NewTestClientConn creates a TestClientConn.

func (*TestClientConn) NewSubConn Uses

func (tcc *TestClientConn) NewSubConn(a []resolver.Address, o balancer.NewSubConnOptions) (balancer.SubConn, error)

NewSubConn creates a new SubConn.

func (*TestClientConn) RemoveSubConn Uses

func (tcc *TestClientConn) RemoveSubConn(sc balancer.SubConn)

RemoveSubConn removes the SubConn.

func (*TestClientConn) ResolveNow Uses

func (tcc *TestClientConn) ResolveNow(resolver.ResolveNowOptions)

ResolveNow panics.

func (*TestClientConn) Target Uses

func (tcc *TestClientConn) Target() string

Target panics.

func (*TestClientConn) UpdateBalancerState Uses

func (tcc *TestClientConn) UpdateBalancerState(s connectivity.State, p balancer.Picker)

UpdateBalancerState implements balancer.Balancer API. It will be removed when switching to the new balancer interface.

func (*TestClientConn) UpdateState Uses

func (tcc *TestClientConn) UpdateState(bs balancer.State)

UpdateState updates connectivity state and picker.

type TestConstBalancerBuilder Uses

type TestConstBalancerBuilder struct{}

TestConstBalancerBuilder is a balancer builder for tests.

func (*TestConstBalancerBuilder) Build Uses

func (*TestConstBalancerBuilder) Build(cc balancer.ClientConn, opts balancer.BuildOptions) balancer.Balancer

Build builds a test const balancer.

func (*TestConstBalancerBuilder) Name Uses

func (*TestConstBalancerBuilder) Name() string

Name returns test-const-balancer name.

type TestConstPicker Uses

type TestConstPicker struct {
    Err error
    SC  balancer.SubConn
}

TestConstPicker is a const picker for tests.

func (*TestConstPicker) Pick Uses

func (tcp *TestConstPicker) Pick(info balancer.PickInfo) (balancer.PickResult, error)

Pick returns the const SubConn or the error.

type TestLoadStore Uses

type TestLoadStore struct {
    CallsStarted []internal.LocalityID
    CallsEnded   []internal.LocalityID
    CallsCost    []TestServerLoad
}

TestLoadStore is a load store to be used in tests.

func NewTestLoadStore Uses

func NewTestLoadStore() *TestLoadStore

NewTestLoadStore creates a new TestLoadStore.

func (*TestLoadStore) CallDropped Uses

func (*TestLoadStore) CallDropped(category string)

CallDropped records a call dropped.

func (*TestLoadStore) CallFinished Uses

func (tls *TestLoadStore) CallFinished(l internal.LocalityID, err error)

CallFinished records a call finished.

func (*TestLoadStore) CallServerLoad Uses

func (tls *TestLoadStore) CallServerLoad(l internal.LocalityID, name string, d float64)

CallServerLoad records a call server load.

func (*TestLoadStore) CallStarted Uses

func (tls *TestLoadStore) CallStarted(l internal.LocalityID)

CallStarted records a call started.

func (*TestLoadStore) ReportTo Uses

func (*TestLoadStore) ReportTo(ctx context.Context, cc *grpc.ClientConn, clusterName string, node *corepb.Node)

ReportTo panics.

type TestServerLoad Uses

type TestServerLoad struct {
    Name string
    D    float64
}

TestServerLoad is testing Load for testing LRS.

type TestSubConn Uses

type TestSubConn struct {
    // contains filtered or unexported fields
}

TestSubConn implements the SubConn interface, to be used in tests.

func (*TestSubConn) Connect Uses

func (tsc *TestSubConn) Connect()

Connect is a no-op.

func (*TestSubConn) String Uses

func (tsc *TestSubConn) String() string

String implements stringer to print human friendly error message.

func (*TestSubConn) UpdateAddresses Uses

func (tsc *TestSubConn) UpdateAddresses([]resolver.Address)

UpdateAddresses panics.

Directories

PathSynopsis
fakeclientPackage fakeclient provides a fake implementation of an xDS client.
fakeserverPackage fakeserver provides a fake implementation of an xDS server.

Package testutils imports 18 packages (graph). Updated 2020-09-08. Refresh now. Tools for package owners.