diff --git a/netmap/context.go b/netmap/context.go index 29b8167..bce1a2c 100644 --- a/netmap/context.go +++ b/netmap/context.go @@ -18,7 +18,7 @@ type Context struct { Selections map[string][]Nodes // numCache stores parsed numeric values. - numCache map[*Filter]uint64 + numCache map[string]uint64 // pivot is a seed for HRW. pivot []byte // pivotHash is a saved HRW hash of pivot @@ -56,7 +56,7 @@ func NewContext(nm *Netmap) *Context { Selectors: make(map[string]*Selector), Selections: make(map[string][]Nodes), - numCache: make(map[*Filter]uint64), + numCache: make(map[string]uint64), aggregator: newMeanIQRAgg, weightFunc: GetDefaultWeightFunc(nm.Nodes), cbf: defaultCBF, diff --git a/netmap/filter.go b/netmap/filter.go index 38fdb4f..3492fac 100644 --- a/netmap/filter.go +++ b/netmap/filter.go @@ -21,8 +21,9 @@ func (c *Context) applyFilter(name string, b *Node) bool { // processFilters processes filters and returns error is any of them is invalid. func (c *Context) processFilters(p *PlacementPolicy) error { - for _, f := range p.Filters() { - if err := c.processFilter(f, true); err != nil { + filters := p.Filters() + for i := range filters { + if err := c.processFilter(&filters[i], true); err != nil { return err } } @@ -50,7 +51,7 @@ func (c *Context) processFilter(f *Filter, top bool) error { switch f.Operation() { case OpAND, OpOR: for _, flt := range f.InnerFilters() { - if err := c.processFilter(flt, false); err != nil { + if err := c.processFilter(&flt, false); err != nil { return err } } @@ -69,7 +70,7 @@ func (c *Context) processFilter(f *Filter, top bool) error { return fmt.Errorf("%w: '%s'", ErrInvalidNumber, f.Value()) } - c.numCache[f] = n + c.numCache[f.Value()] = n default: return fmt.Errorf("%w: %s", ErrInvalidFilterOp, f.Operation()) } @@ -90,10 +91,10 @@ func (c *Context) match(f *Filter, b *Node) bool { case OpAND, OpOR: for _, lf := range f.InnerFilters() { if lf.Name() != "" { - lf = c.Filters[lf.Name()] + lf = *c.Filters[lf.Name()] } - ok := c.match(lf, b) + ok := c.match(&lf, b) if ok == (f.Operation() == OpOR) { return ok } @@ -132,13 +133,13 @@ func (c *Context) matchKeyValue(f *Filter, b *Node) bool { switch f.Operation() { case OpGT: - return attr > c.numCache[f] + return attr > c.numCache[f.Value()] case OpGE: - return attr >= c.numCache[f] + return attr >= c.numCache[f.Value()] case OpLT: - return attr < c.numCache[f] + return attr < c.numCache[f.Value()] case OpLE: - return attr <= c.numCache[f] + return attr <= c.numCache[f.Value()] default: // do nothing and return false } @@ -214,31 +215,31 @@ func (f *Filter) SetOperation(op Operation) { (*netmap.Filter)(f).SetOp(op.ToV2()) } -func filtersFromV2(fs []*netmap.Filter) []*Filter { +func filtersFromV2(fs []netmap.Filter) []Filter { if fs == nil { return nil } - res := make([]*Filter, 0, len(fs)) + res := make([]Filter, len(fs)) for i := range fs { - res = append(res, NewFilterFromV2(fs[i])) + res[i] = *NewFilterFromV2(&fs[i]) } return res } // InnerFilters returns list of inner filters. -func (f *Filter) InnerFilters() []*Filter { +func (f *Filter) InnerFilters() []Filter { return filtersFromV2((*netmap.Filter)(f).GetFilters()) } -func filtersToV2(fs []*Filter) (fsV2 []*netmap.Filter) { +func filtersToV2(fs []Filter) (fsV2 []netmap.Filter) { if fs != nil { - fsV2 = make([]*netmap.Filter, 0, len(fs)) + fsV2 = make([]netmap.Filter, len(fs)) for i := range fs { - fsV2 = append(fsV2, fs[i].ToV2()) + fsV2[i] = *fs[i].ToV2() } } @@ -246,7 +247,7 @@ func filtersToV2(fs []*Filter) (fsV2 []*netmap.Filter) { } // SetInnerFilters sets list of inner filters. -func (f *Filter) SetInnerFilters(fs ...*Filter) { +func (f *Filter) SetInnerFilters(fs ...Filter) { (*netmap.Filter)(f). SetFilters(filtersToV2(fs)) } diff --git a/netmap/filter_test.go b/netmap/filter_test.go index 17c442b..517bc9e 100644 --- a/netmap/filter_test.go +++ b/netmap/filter_test.go @@ -9,7 +9,7 @@ import ( ) func TestContext_ProcessFilters(t *testing.T) { - fs := []*Filter{ + fs := []Filter{ newFilter("StorageSSD", "Storage", "SSD", OpEQ), newFilter("GoodRating", "Rating", "4", OpGE), newFilter("Main", "", "", OpAND, @@ -24,17 +24,17 @@ func TestContext_ProcessFilters(t *testing.T) { require.NoError(t, c.processFilters(p)) require.Equal(t, 3, len(c.Filters)) for _, f := range fs { - require.Equal(t, f, c.Filters[f.Name()]) + require.Equal(t, f, *c.Filters[f.Name()]) } - require.Equal(t, uint64(4), c.numCache[fs[1]]) - require.Equal(t, uint64(123), c.numCache[fs[2].InnerFilters()[1]]) + require.Equal(t, uint64(4), c.numCache[fs[1].Value()]) + require.Equal(t, uint64(123), c.numCache[fs[2].InnerFilters()[1].Value()]) } func TestContext_ProcessFiltersInvalid(t *testing.T) { errTestCases := []struct { name string - filter *Filter + filter Filter err error }{ { @@ -69,16 +69,11 @@ func TestContext_ProcessFiltersInvalid(t *testing.T) { newFilter("*", "Rating", "3", OpGE), ErrInvalidFilterName, }, - { - "MissingFilter", - nil, - ErrMissingField, - }, } for _, tc := range errTestCases { t.Run(tc.name, func(t *testing.T) { c := NewContext(new(Netmap)) - p := newPlacementPolicy(1, nil, nil, []*Filter{tc.filter}) + p := newPlacementPolicy(1, nil, nil, []Filter{tc.filter}) err := c.processFilters(p) require.True(t, errors.Is(err, tc.err), "got: %v", err) }) @@ -93,12 +88,12 @@ func TestFilter_MatchSimple_InvalidOp(t *testing.T) { f := newFilter("Main", "Rating", "5", OpEQ) c := NewContext(new(Netmap)) - p := newPlacementPolicy(1, nil, nil, []*Filter{f}) + p := newPlacementPolicy(1, nil, nil, []Filter{f}) require.NoError(t, c.processFilters(p)) // just for the coverage f.SetOperation(0) - require.False(t, c.match(f, b)) + require.False(t, c.match(&f, b)) } func testFilter() *Filter { @@ -174,11 +169,11 @@ func TestFilter_Operation(t *testing.T) { func TestFilter_InnerFilters(t *testing.T) { f := NewFilter() - f1, f2 := testFilter(), testFilter() + f1, f2 := *testFilter(), *testFilter() f.SetInnerFilters(f1, f2) - require.Equal(t, []*Filter{f1, f2}, f.InnerFilters()) + require.Equal(t, []Filter{f1, f2}, f.InnerFilters()) } func TestFilterEncoding(t *testing.T) { @@ -190,7 +185,7 @@ func TestFilterEncoding(t *testing.T) { data, err := f.Marshal() require.NoError(t, err) - f2 := NewFilter() + f2 := *NewFilter() require.NoError(t, f2.Unmarshal(data)) require.Equal(t, f, f2) @@ -200,7 +195,7 @@ func TestFilterEncoding(t *testing.T) { data, err := f.MarshalJSON() require.NoError(t, err) - f2 := NewFilter() + f2 := *NewFilter() require.NoError(t, f2.UnmarshalJSON(data)) require.Equal(t, f, f2) diff --git a/netmap/helper_test.go b/netmap/helper_test.go index bb5b6d3..f9ca738 100644 --- a/netmap/helper_test.go +++ b/netmap/helper_test.go @@ -6,8 +6,7 @@ import ( "github.com/stretchr/testify/require" ) -func newFilter(name string, k, v string, op Operation, fs ...*Filter) *Filter { - f := NewFilter() +func newFilter(name string, k, v string, op Operation, fs ...Filter) (f Filter) { f.SetName(name) f.SetKey(k) f.SetOperation(op) @@ -16,8 +15,7 @@ func newFilter(name string, k, v string, op Operation, fs ...*Filter) *Filter { return f } -func newSelector(name string, attr string, c Clause, count uint32, filter string) *Selector { - s := NewSelector() +func newSelector(name string, attr string, c Clause, count uint32, filter string) (s Selector) { s.SetName(name) s.SetAttribute(attr) s.SetCount(count) @@ -26,7 +24,7 @@ func newSelector(name string, attr string, c Clause, count uint32, filter string return s } -func newPlacementPolicy(bf uint32, rs []*Replica, ss []*Selector, fs []*Filter) *PlacementPolicy { +func newPlacementPolicy(bf uint32, rs []Replica, ss []Selector, fs []Filter) *PlacementPolicy { p := NewPlacementPolicy() p.SetContainerBackupFactor(bf) p.SetReplicas(rs...) @@ -35,17 +33,15 @@ func newPlacementPolicy(bf uint32, rs []*Replica, ss []*Selector, fs []*Filter) return p } -func newReplica(c uint32, s string) *Replica { - r := NewReplica() +func newReplica(c uint32, s string) (r Replica) { r.SetCount(c) r.SetSelector(s) return r } func nodeInfoFromAttributes(props ...string) NodeInfo { - attrs := make([]*NodeAttribute, len(props)/2) + attrs := make([]NodeAttribute, len(props)/2) for i := range attrs { - attrs[i] = NewNodeAttribute() attrs[i].SetKey(props[i*2]) attrs[i].SetValue(props[i*2+1]) } diff --git a/netmap/netmap.go b/netmap/netmap.go index 369d9ac..5aaefc6 100644 --- a/netmap/netmap.go +++ b/netmap/netmap.go @@ -63,10 +63,6 @@ func (m *Netmap) GetContainerNodes(p *PlacementPolicy, pivot []byte) (ContainerN result := make([]Nodes, len(p.Replicas())) for i, r := range p.Replicas() { - if r == nil { - return nil, fmt.Errorf("%w: REPLICA", ErrMissingField) - } - if r.Selector() == "" { if len(p.Selectors()) == 0 { s := new(Selector) diff --git a/netmap/network_info.go b/netmap/network_info.go index 573f91b..6234beb 100644 --- a/netmap/network_info.go +++ b/netmap/network_info.go @@ -187,16 +187,16 @@ func (x *NetworkConfig) IterateParameters(f func(*NetworkParameter) bool) { } // Value returns value of the network parameter. -func (x *NetworkConfig) SetParameters(ps ...*NetworkParameter) { - var psV2 []*netmap.NetworkParameter +func (x *NetworkConfig) SetParameters(ps ...NetworkParameter) { + var psV2 []netmap.NetworkParameter if ps != nil { ln := len(ps) - psV2 = make([]*netmap.NetworkParameter, 0, ln) + psV2 = make([]netmap.NetworkParameter, ln) for i := 0; i < ln; i++ { - psV2 = append(psV2, ps[i].ToV2()) + psV2[i] = *ps[i].ToV2() } } diff --git a/netmap/network_info_test.go b/netmap/network_info_test.go index 33317b8..56843a4 100644 --- a/netmap/network_info_test.go +++ b/netmap/network_info_test.go @@ -72,19 +72,19 @@ func TestNetworkConfig_SetParameters(t *testing.T) { require.Zero(t, called) - pps := []*NetworkParameter{ - netmaptest.NetworkParameter(), - netmaptest.NetworkParameter(), + pps := []NetworkParameter{ + *netmaptest.NetworkParameter(), + *netmaptest.NetworkParameter(), } x.SetParameters(pps...) require.EqualValues(t, len(pps), x.NumberOfParameters()) - var dst []*NetworkParameter + var dst []NetworkParameter x.IterateParameters(func(p *NetworkParameter) bool { - dst = append(dst, p) + dst = append(dst, *p) called++ return false }) diff --git a/netmap/node_info.go b/netmap/node_info.go index 3a3b57f..040589f 100644 --- a/netmap/node_info.go +++ b/netmap/node_info.go @@ -20,7 +20,7 @@ type ( } // Nodes represents slice of graph leafs. - Nodes []*Node + Nodes []Node ) // NodeState is an enumeration of various states of the NeoFS node. @@ -110,7 +110,7 @@ func (n Nodes) Hash() uint64 { func NodesFromInfo(infos []NodeInfo) Nodes { nodes := make(Nodes, len(infos)) for i := range infos { - nodes[i] = newNodeV2(i, &infos[i]) + nodes[i] = *newNodeV2(i, &infos[i]) } return nodes @@ -142,7 +142,7 @@ func newNodeV2(index int, ni *NodeInfo) *Node { func (n Nodes) Weights(wf weightFunc) []float64 { w := make([]float64, 0, len(n)) for i := range n { - w = append(w, wf(n[i])) + w = append(w, wf(&n[i])) } return w @@ -156,7 +156,7 @@ func (n *Node) Attribute(k string) string { // GetBucketWeight computes weight for a Bucket. func GetBucketWeight(ns Nodes, a aggregator, wf weightFunc) float64 { for i := range ns { - a.Add(wf(ns[i])) + a.Add(wf(&ns[i])) } return a.Compute() @@ -355,7 +355,7 @@ func (i *NodeInfo) SetAddresses(v ...string) { } // Attributes returns list of the node attributes. -func (i *NodeInfo) Attributes() []*NodeAttribute { +func (i *NodeInfo) Attributes() []NodeAttribute { if i == nil { return nil } @@ -366,21 +366,21 @@ func (i *NodeInfo) Attributes() []*NodeAttribute { return nil } - res := make([]*NodeAttribute, 0, len(as)) + res := make([]NodeAttribute, len(as)) - for i := range as { - res = append(res, NewNodeAttributeFromV2(as[i])) + for ind := range as { + res[ind] = *NewNodeAttributeFromV2(&as[ind]) } return res } // SetAttributes sets list of the node attributes. -func (i *NodeInfo) SetAttributes(as ...*NodeAttribute) { - asV2 := make([]*netmap.Attribute, 0, len(as)) +func (i *NodeInfo) SetAttributes(as ...NodeAttribute) { + asV2 := make([]netmap.Attribute, len(as)) - for i := range as { - asV2 = append(asV2, as[i].ToV2()) + for ind := range as { + asV2[ind] = *as[ind].ToV2() } (*netmap.NodeInfo)(i). diff --git a/netmap/node_info_test.go b/netmap/node_info_test.go index ebcd393..7363956 100644 --- a/netmap/node_info_test.go +++ b/netmap/node_info_test.go @@ -152,7 +152,7 @@ func TestNodeInfo_State(t *testing.T) { func TestNodeInfo_Attributes(t *testing.T) { i := new(NodeInfo) - as := []*NodeAttribute{testNodeAttribute(), testNodeAttribute()} + as := []NodeAttribute{*testNodeAttribute(), *testNodeAttribute()} i.SetAttributes(as...) @@ -188,7 +188,7 @@ func TestNodeInfoEncoding(t *testing.T) { i.SetPublicKey([]byte{1, 2, 3}) i.SetAddresses("192.168.0.1", "192.168.0.2") i.SetState(NodeStateOnline) - i.SetAttributes(testNodeAttribute()) + i.SetAttributes(*testNodeAttribute()) t.Run("binary", func(t *testing.T) { data, err := i.Marshal() diff --git a/netmap/policy.go b/netmap/policy.go index f9ee1a6..aa1f336 100644 --- a/netmap/policy.go +++ b/netmap/policy.go @@ -46,7 +46,7 @@ func (p *PlacementPolicy) SetSubnetID(subnet *subnetid.ID) { } // Replicas returns list of object replica descriptors. -func (p *PlacementPolicy) Replicas() []*Replica { +func (p *PlacementPolicy) Replicas() []Replica { rs := (*netmap.PlacementPolicy)(p). GetReplicas() @@ -54,24 +54,24 @@ func (p *PlacementPolicy) Replicas() []*Replica { return nil } - res := make([]*Replica, 0, len(rs)) + res := make([]Replica, len(rs)) for i := range rs { - res = append(res, NewReplicaFromV2(rs[i])) + res[i] = *NewReplicaFromV2(&rs[i]) } return res } // SetReplicas sets list of object replica descriptors. -func (p *PlacementPolicy) SetReplicas(rs ...*Replica) { - var rsV2 []*netmap.Replica +func (p *PlacementPolicy) SetReplicas(rs ...Replica) { + var rsV2 []netmap.Replica if rs != nil { - rsV2 = make([]*netmap.Replica, 0, len(rs)) + rsV2 = make([]netmap.Replica, len(rs)) for i := range rs { - rsV2 = append(rsV2, rs[i].ToV2()) + rsV2[i] = *rs[i].ToV2() } } @@ -91,7 +91,7 @@ func (p *PlacementPolicy) SetContainerBackupFactor(f uint32) { } // Selector returns set of selectors to form the container's nodes subset. -func (p *PlacementPolicy) Selectors() []*Selector { +func (p *PlacementPolicy) Selectors() []Selector { rs := (*netmap.PlacementPolicy)(p). GetSelectors() @@ -99,24 +99,24 @@ func (p *PlacementPolicy) Selectors() []*Selector { return nil } - res := make([]*Selector, 0, len(rs)) + res := make([]Selector, len(rs)) for i := range rs { - res = append(res, NewSelectorFromV2(rs[i])) + res[i] = *NewSelectorFromV2(&rs[i]) } return res } // SetSelectors sets set of selectors to form the container's nodes subset. -func (p *PlacementPolicy) SetSelectors(ss ...*Selector) { - var ssV2 []*netmap.Selector +func (p *PlacementPolicy) SetSelectors(ss ...Selector) { + var ssV2 []netmap.Selector if ss != nil { - ssV2 = make([]*netmap.Selector, 0, len(ss)) + ssV2 = make([]netmap.Selector, len(ss)) for i := range ss { - ssV2 = append(ssV2, ss[i].ToV2()) + ssV2[i] = *ss[i].ToV2() } } @@ -124,7 +124,7 @@ func (p *PlacementPolicy) SetSelectors(ss ...*Selector) { } // Filters returns list of named filters to reference in selectors. -func (p *PlacementPolicy) Filters() []*Filter { +func (p *PlacementPolicy) Filters() []Filter { return filtersFromV2( (*netmap.PlacementPolicy)(p). GetFilters(), @@ -132,7 +132,7 @@ func (p *PlacementPolicy) Filters() []*Filter { } // SetFilters sets list of named filters to reference in selectors. -func (p *PlacementPolicy) SetFilters(fs ...*Filter) { +func (p *PlacementPolicy) SetFilters(fs ...Filter) { (*netmap.PlacementPolicy)(p). SetFilters(filtersToV2(fs)) } diff --git a/netmap/policy_test.go b/netmap/policy_test.go index 546bc3b..737b180 100644 --- a/netmap/policy_test.go +++ b/netmap/policy_test.go @@ -10,21 +10,21 @@ import ( func TestPlacementPolicyFromV2(t *testing.T) { pV2 := new(netmap.PlacementPolicy) - pV2.SetReplicas([]*netmap.Replica{ - testReplica().ToV2(), - testReplica().ToV2(), + pV2.SetReplicas([]netmap.Replica{ + *testReplica().ToV2(), + *testReplica().ToV2(), }) pV2.SetContainerBackupFactor(3) - pV2.SetSelectors([]*netmap.Selector{ - testSelector().ToV2(), - testSelector().ToV2(), + pV2.SetSelectors([]netmap.Selector{ + *testSelector().ToV2(), + *testSelector().ToV2(), }) - pV2.SetFilters([]*netmap.Filter{ - testFilter().ToV2(), - testFilter().ToV2(), + pV2.SetFilters([]netmap.Filter{ + *testFilter().ToV2(), + *testFilter().ToV2(), }) p := NewPlacementPolicyFromV2(pV2) @@ -34,7 +34,7 @@ func TestPlacementPolicyFromV2(t *testing.T) { func TestPlacementPolicy_Replicas(t *testing.T) { p := NewPlacementPolicy() - rs := []*Replica{testReplica(), testReplica()} + rs := []Replica{*testReplica(), *testReplica()} p.SetReplicas(rs...) @@ -52,7 +52,7 @@ func TestPlacementPolicy_ContainerBackupFactor(t *testing.T) { func TestPlacementPolicy_Selectors(t *testing.T) { p := NewPlacementPolicy() - ss := []*Selector{testSelector(), testSelector()} + ss := []Selector{*testSelector(), *testSelector()} p.SetSelectors(ss...) @@ -61,7 +61,7 @@ func TestPlacementPolicy_Selectors(t *testing.T) { func TestPlacementPolicy_Filters(t *testing.T) { p := NewPlacementPolicy() - fs := []*Filter{testFilter(), testFilter()} + fs := []Filter{*testFilter(), *testFilter()} p.SetFilters(fs...) diff --git a/netmap/replica_test.go b/netmap/replica_test.go index c1b0dba..d7d3f44 100644 --- a/netmap/replica_test.go +++ b/netmap/replica_test.go @@ -57,7 +57,7 @@ func TestReplicaEncoding(t *testing.T) { data, err := r.Marshal() require.NoError(t, err) - r2 := NewReplica() + r2 := *NewReplica() require.NoError(t, r2.Unmarshal(data)) require.Equal(t, r, r2) @@ -67,7 +67,7 @@ func TestReplicaEncoding(t *testing.T) { data, err := r.MarshalJSON() require.NoError(t, err) - r2 := NewReplica() + r2 := *NewReplica() require.NoError(t, r2.UnmarshalJSON(data)) require.Equal(t, r, r2) diff --git a/netmap/selector.go b/netmap/selector.go index 87192a0..eb69fe8 100644 --- a/netmap/selector.go +++ b/netmap/selector.go @@ -14,19 +14,18 @@ type Selector netmap.Selector // processSelectors processes selectors and returns error is any of them is invalid. func (c *Context) processSelectors(p *PlacementPolicy) error { - for _, s := range p.Selectors() { - if s == nil { - return fmt.Errorf("%w: SELECT", ErrMissingField) - } else if s.Filter() != MainFilterName { + selectors := p.Selectors() + for i, s := range selectors { + if s.Filter() != MainFilterName { _, ok := c.Filters[s.Filter()] if !ok { return fmt.Errorf("%w: SELECT FROM '%s'", ErrFilterNotFound, s.Filter()) } } - c.Selectors[s.Name()] = s + c.Selectors[s.Name()] = &selectors[i] - result, err := c.getSelection(p, s) + result, err := c.getSelection(p, &s) if err != nil { return err } @@ -141,7 +140,7 @@ func (c *Context) getSelectionBase(subnetID *subnetid.ID, s *Selector) []nodeAtt if !BelongsToSubnet(c.Netmap.Nodes[i].NodeInfo, sid) { continue } - if isMain || c.match(f, c.Netmap.Nodes[i]) { + if isMain || c.match(f, &c.Netmap.Nodes[i]) { if attr == "" { // Default attribute is transparent identifier which is different for every node. result = append(result, nodeAttrPair{attr: "", nodes: Nodes{c.Netmap.Nodes[i]}}) diff --git a/netmap/selector_test.go b/netmap/selector_test.go index 8a55303..264cb0a 100644 --- a/netmap/selector_test.go +++ b/netmap/selector_test.go @@ -94,13 +94,13 @@ func BenchmarkPolicyHRWType(b *testing.B) { const netmapSize = 100 p := newPlacementPolicy(1, - []*Replica{ + []Replica{ newReplica(1, "loc1"), newReplica(1, "loc2")}, - []*Selector{ + []Selector{ newSelector("loc1", "Location", ClauseSame, 1, "loc1"), newSelector("loc2", "Location", ClauseSame, 1, "loc2")}, - []*Filter{ + []Filter{ newFilter("loc1", "Location", "Shanghai", OpEQ), newFilter("loc2", "Location", "Shanghai", OpNE), }) @@ -139,13 +139,13 @@ func TestPlacementPolicy_DeterministicOrder(t *testing.T) { const netmapSize = 100 p := newPlacementPolicy(1, - []*Replica{ + []Replica{ newReplica(1, "loc1"), newReplica(1, "loc2")}, - []*Selector{ + []Selector{ newSelector("loc1", "Location", ClauseSame, 1, "loc1"), newSelector("loc2", "Location", ClauseSame, 1, "loc2")}, - []*Filter{ + []Filter{ newFilter("loc1", "Location", "Shanghai", OpEQ), newFilter("loc2", "Location", "Shanghai", OpNE), }) @@ -188,13 +188,13 @@ func TestPlacementPolicy_DeterministicOrder(t *testing.T) { func TestPlacementPolicy_ProcessSelectors(t *testing.T) { p := newPlacementPolicy(2, nil, - []*Selector{ + []Selector{ newSelector("SameRU", "City", ClauseSame, 2, "FromRU"), newSelector("DistinctRU", "City", ClauseDistinct, 2, "FromRU"), newSelector("Good", "Country", ClauseDistinct, 2, "Good"), newSelector("Main", "Country", ClauseDistinct, 3, "*"), }, - []*Filter{ + []Filter{ newFilter("FromRU", "Country", "Russia", OpEQ), newFilter("Good", "Rating", "4", OpGE), }) @@ -229,7 +229,7 @@ func TestPlacementPolicy_ProcessSelectors(t *testing.T) { for _, res := range sel { require.Equal(t, nodesInBucket, len(res), targ) for j := range res { - require.True(t, c.applyFilter(s.Filter(), res[j]), targ) + require.True(t, c.applyFilter(s.Filter(), &res[j]), targ) } } } @@ -298,7 +298,7 @@ func TestSelectorEncoding(t *testing.T) { data, err := s.Marshal() require.NoError(t, err) - s2 := NewSelector() + s2 := *NewSelector() require.NoError(t, s2.Unmarshal(data)) require.Equal(t, s, s2) @@ -308,7 +308,7 @@ func TestSelectorEncoding(t *testing.T) { data, err := s.MarshalJSON() require.NoError(t, err) - s2 := NewSelector() + s2 := *NewSelector() require.NoError(t, s2.UnmarshalJSON(data)) require.Equal(t, s, s2) diff --git a/netmap/test/generate.go b/netmap/test/generate.go index ae9759e..a6a54a4 100644 --- a/netmap/test/generate.go +++ b/netmap/test/generate.go @@ -11,7 +11,7 @@ func filter(withInner bool) *netmap.Filter { x.SetOperation(netmap.OpAND) if withInner { - x.SetInnerFilters(filter(false), filter(false)) + x.SetInnerFilters(*filter(false), *filter(false)) } return x @@ -50,9 +50,9 @@ func PlacementPolicy() *netmap.PlacementPolicy { x := netmap.NewPlacementPolicy() x.SetContainerBackupFactor(9) - x.SetFilters(Filter(), Filter()) - x.SetReplicas(Replica(), Replica()) - x.SetSelectors(Selector(), Selector()) + x.SetFilters(*Filter(), *Filter()) + x.SetReplicas(*Replica(), *Replica()) + x.SetSelectors(*Selector(), *Selector()) return x } @@ -72,8 +72,8 @@ func NetworkConfig() *netmap.NetworkConfig { x := netmap.NewNetworkConfig() x.SetParameters( - NetworkParameter(), - NetworkParameter(), + *NetworkParameter(), + *NetworkParameter(), ) return x