@@ -83,3 +83,46 @@ func TestAllocationPerNode(t *testing.T) {
83
83
assert .Equal (t , actualItem , itemsForCollector [0 ])
84
84
}
85
85
}
86
+
87
+ func TestTargetsWithNoCollectorsPerNode (t * testing.T ) {
88
+ // prepare allocator with initial targets and collectors
89
+ c , _ := New ("per-node" , loggerPerNode )
90
+
91
+ // Adding 10 new targets
92
+ numItems := 10
93
+ c .SetTargets (MakeNNewTargetsWithEmptyCollectors (numItems , 0 ))
94
+ actualTargetItems := c .TargetItems ()
95
+ assert .Len (t , actualTargetItems , numItems )
96
+
97
+ // Adding 5 new targets, and removing the old 10 targets
98
+ numItemsUpdate := 5
99
+ c .SetTargets (MakeNNewTargetsWithEmptyCollectors (numItemsUpdate , 10 ))
100
+ actualTargetItemsUpdated := c .TargetItems ()
101
+ assert .Len (t , actualTargetItemsUpdated , numItemsUpdate )
102
+
103
+ // Adding 5 new targets, and one existing target
104
+ numItemsUpdate = 6
105
+ c .SetTargets (MakeNNewTargetsWithEmptyCollectors (numItemsUpdate , 14 ))
106
+ actualTargetItemsUpdated = c .TargetItems ()
107
+ assert .Len (t , actualTargetItemsUpdated , numItemsUpdate )
108
+
109
+ // Adding collectors to test allocation
110
+ numCols := 2
111
+ cols := MakeNCollectors (2 , 0 )
112
+ c .SetCollectors (cols )
113
+
114
+ // Checking to see that there is no change to number of targets
115
+ actualTargetItems = c .TargetItems ()
116
+ assert .Len (t , actualTargetItems , numItemsUpdate )
117
+ // Checking to see collectors are added correctly
118
+ actualCollectors := c .Collectors ()
119
+ assert .Len (t , actualCollectors , numCols )
120
+ // Based on lable all targets should be assigned to node-0
121
+ for name , ac := range actualCollectors {
122
+ if name == "node-0" {
123
+ assert .Equal (t , 6 , ac .NumTargets )
124
+ } else {
125
+ assert .Equal (t , 0 , ac .NumTargets )
126
+ }
127
+ }
128
+ }
0 commit comments