@@ -27,84 +27,6 @@ import (
2727
2828const TestTime = 1620000000
2929
30- func TestUpdateCount (t * testing.T ) {
31- t .Run ("givenTimeExistsPodExistsPartitionExistsCountAvailable_whenUpdate_thenUpdatePodPartitionCount" , func (t * testing.T ) {
32- q := sharedqueue.New [* TimestampedCounts ](1800 )
33- tc := NewTimestampedCounts (TestTime )
34- tc .Update (& PodReadCount {"pod1" , map [string ]float64 {"partition1" : 10.0 }})
35- q .Append (tc )
36-
37- UpdateCount (q , TestTime , & PodReadCount {"pod1" , map [string ]float64 {"partition1" : 20.0 }})
38-
39- assert .Equal (t , 1 , q .Length ())
40- assert .Equal (t , 20.0 , q .Items ()[0 ].podPartitionCount ["pod1" ]["partition1" ])
41- })
42-
43- t .Run ("givenTimeExistsPodExistsPartitionNotExistsCountAvailable_whenUpdate_thenAddPodPartitionCount" , func (t * testing.T ) {
44- q := sharedqueue.New [* TimestampedCounts ](1800 )
45- tc := NewTimestampedCounts (TestTime )
46- tc .Update (& PodReadCount {"pod1" , map [string ]float64 {"partition1" : 10.0 }})
47- q .Append (tc )
48-
49- UpdateCount (q , TestTime , & PodReadCount {"pod1" , map [string ]float64 {"partition1" : 20.0 , "partition2" : 30.0 }})
50-
51- assert .Equal (t , 1 , q .Length ())
52- assert .Equal (t , 20.0 , q .Items ()[0 ].podPartitionCount ["pod1" ]["partition1" ])
53- assert .Equal (t , 30.0 , q .Items ()[0 ].podPartitionCount ["pod1" ]["partition2" ])
54- })
55-
56- t .Run ("givenTimeExistsPodNotExistsCountAvailable_whenUpdate_thenAddPodCount" , func (t * testing.T ) {
57- q := sharedqueue.New [* TimestampedCounts ](1800 )
58- tc := NewTimestampedCounts (TestTime )
59- tc .Update (& PodReadCount {"pod1" , map [string ]float64 {"partition1" : 20.0 }})
60- q .Append (tc )
61-
62- UpdateCount (q , TestTime , & PodReadCount {"pod2" , map [string ]float64 {"partition1" : 10.0 }})
63-
64- assert .Equal (t , 1 , q .Length ())
65- assert .Equal (t , 20.0 , q .Items ()[0 ].podPartitionCount ["pod1" ]["partition1" ])
66- assert .Equal (t , 10.0 , q .Items ()[0 ].podPartitionCount ["pod2" ]["partition1" ])
67- })
68-
69- t .Run ("givenTimeExistsPodExistsCountNotAvailable_whenUpdate_thenNotUpdatePod" , func (t * testing.T ) {
70- q := sharedqueue.New [* TimestampedCounts ](1800 )
71- tc := NewTimestampedCounts (TestTime )
72- tc .Update (& PodReadCount {"pod1" , map [string ]float64 {"partition1" : 10.0 }})
73- q .Append (tc )
74-
75- UpdateCount (q , TestTime , nil )
76-
77- assert .Equal (t , 1 , q .Length ())
78- assert .Equal (t , 1 , len (q .Items ()[0 ].podPartitionCount ))
79- assert .Equal (t , 10.0 , q .Items ()[0 ].podPartitionCount ["pod1" ]["partition1" ])
80- })
81-
82- t .Run ("givenTimeExistsPodNotExistsCountNotAvailable_whenUpdate_thenNoUpdate" , func (t * testing.T ) {
83- q := sharedqueue.New [* TimestampedCounts ](1800 )
84- tc := NewTimestampedCounts (TestTime )
85- tc .Update (& PodReadCount {"pod1" , map [string ]float64 {"partition1" : 10.0 }})
86- q .Append (tc )
87-
88- UpdateCount (q , TestTime , nil )
89-
90- assert .Equal (t , 1 , q .Length ())
91- assert .Equal (t , 10.0 , q .Items ()[0 ].podPartitionCount ["pod1" ]["partition1" ])
92- })
93-
94- t .Run ("givenTimeNotExistsCountAvailable_whenUpdate_thenAddNewItem" , func (t * testing.T ) {
95- q := sharedqueue.New [* TimestampedCounts ](1800 )
96- tc := NewTimestampedCounts (TestTime )
97- tc .Update (& PodReadCount {"pod1" , map [string ]float64 {"partition1" : 10.0 }})
98- q .Append (tc )
99-
100- UpdateCount (q , TestTime + 1 , & PodReadCount {"pod1" , map [string ]float64 {"partition1" : 20.0 }})
101-
102- assert .Equal (t , 2 , q .Length ())
103- assert .Equal (t , 10.0 , q .Items ()[0 ].podPartitionCount ["pod1" ]["partition1" ])
104- assert .Equal (t , 20.0 , q .Items ()[1 ].podPartitionCount ["pod1" ]["partition1" ])
105- })
106- }
107-
10830func TestCalculateRate (t * testing.T ) {
10931 t .Run ("givenCollectedTimeLessThanTwo_whenCalculateRate_thenReturnRateNotAvailable" , func (t * testing.T ) {
11032 q := sharedqueue.New [* TimestampedCounts ](1800 )
0 commit comments