-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix integer overflow for czCount (#7272)
* Fix integer overflow for czCount * code review * fix changelog, test message
- Loading branch information
1 parent
a5e85bb
commit f489865
Showing
3 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
.../src/test/java/org/apache/traffic_control/traffic_router/core/router/StatTrackerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.traffic_control.traffic_router.core.router; | ||
|
||
import org.junit.Test; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import static org.powermock.api.mockito.PowerMockito.spy; | ||
import static org.powermock.api.mockito.PowerMockito.when; | ||
import static org.springframework.test.util.AssertionErrors.assertEquals; | ||
|
||
public class StatTrackerTest { | ||
@Test | ||
public void testIncTally() { | ||
StatTracker tracker = spy(new StatTracker()); | ||
StatTracker.Tallies tallies = new StatTracker.Tallies(); | ||
StatTracker.Track track = StatTracker.getTrack(); | ||
|
||
tallies.setCzCount(Long.MAX_VALUE); | ||
|
||
Map<String, StatTracker.Tallies> map = new HashMap<>(); | ||
map.put("blah", tallies); | ||
when(tracker.getDnsMap()).thenReturn(map); | ||
|
||
track.setRouteType(StatTracker.Track.RouteType.DNS, "blah"); | ||
track.setResult(StatTracker.Track.ResultType.CZ); | ||
tracker.saveTrack(track); | ||
assertEquals("expected czCount to be max long value but got " + tallies.getCzCount(), Long.MAX_VALUE, tallies.getCzCount()); | ||
} | ||
} |