From 576841e0e091a895691637763dfe6c573ed14462 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 30 Nov 2020 13:32:52 +0300 Subject: [PATCH] [#215] netmap: add test with multiple replicas Signed-off-by: Evgenii Stratonikov --- pkg/netmap/selector_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pkg/netmap/selector_test.go b/pkg/netmap/selector_test.go index 8ba4465..15ab572 100644 --- a/pkg/netmap/selector_test.go +++ b/pkg/netmap/selector_test.go @@ -31,6 +31,42 @@ func TestPlacementPolicy_UnspecifiedClause(t *testing.T) { require.Equal(t, 4, len(v.Flatten())) } +// Issue #215. +func TestPlacementPolicy_MultipleREP(t *testing.T) { + p := newPlacementPolicy(1, + []*Replica{ + newReplica(1, "LOC_SPB_PLACE"), + newReplica(1, "LOC_MSK_PLACE"), + }, + []*Selector{ + newSelector("LOC_SPB_PLACE", "", ClauseUnspecified, 1, "LOC_SPB"), + newSelector("LOC_MSK_PLACE", "", ClauseUnspecified, 1, "LOC_MSK"), + }, + []*Filter{ + newFilter("LOC_SPB", "City", "Saint-Petersburg", OpEQ), + newFilter("LOC_MSK", "City", "Moscow", OpEQ), + }, + ) + nodes := []NodeInfo{ + nodeInfoFromAttributes("City", "Saint-Petersburg"), + nodeInfoFromAttributes("City", "Moscow"), + nodeInfoFromAttributes("City", "Berlin"), + nodeInfoFromAttributes("City", "Paris"), + } + nm, err := NewNetmap(NodesFromInfo(nodes)) + require.NoError(t, err) + + v, err := nm.GetContainerNodes(p, nil) + require.NoError(t, err) + + rs := v.Replicas() + require.Equal(t, 2, len(rs)) + require.Equal(t, 1, len(rs[0])) + require.Equal(t, "Saint-Petersburg", rs[0][0].Attribute("City")) + require.Equal(t, 1, len(rs[1])) + require.Equal(t, "Moscow", rs[1][0].Attribute("City")) +} + func TestPlacementPolicy_DefaultCBF(t *testing.T) { p := newPlacementPolicy(0, []*Replica{