Merge changes from topics "ms56-historybuilder", "ms65.3" am: 4794105511
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1951102 Change-Id: Ic25be733c673e36d5086d82563abfb0349556b51
This commit is contained in:
commit
5877663151
1 changed files with 35 additions and 0 deletions
|
|
@ -56,6 +56,7 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@RunWith(DevSdkIgnoreRunner.class)
|
||||
|
|
@ -532,6 +533,40 @@ public class NetworkStatsHistoryTest {
|
|||
assertEquals(512L + 4096L, stats.getTotalBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuilder() {
|
||||
final NetworkStatsHistory.Entry entry1 = new NetworkStatsHistory.Entry(10, 30, 40,
|
||||
4, 50, 5, 60);
|
||||
final NetworkStatsHistory.Entry entry2 = new NetworkStatsHistory.Entry(30, 15, 3,
|
||||
41, 7, 1, 0);
|
||||
final NetworkStatsHistory.Entry entry3 = new NetworkStatsHistory.Entry(7, 301, 11,
|
||||
14, 31, 2, 80);
|
||||
|
||||
final NetworkStatsHistory statsEmpty = new NetworkStatsHistory
|
||||
.Builder(HOUR_IN_MILLIS, 10).build();
|
||||
assertEquals(0, statsEmpty.getEntries().size());
|
||||
assertEquals(HOUR_IN_MILLIS, statsEmpty.getBucketDuration());
|
||||
|
||||
NetworkStatsHistory statsSingle = new NetworkStatsHistory
|
||||
.Builder(HOUR_IN_MILLIS, 8)
|
||||
.addEntry(entry1)
|
||||
.build();
|
||||
assertEquals(1, statsSingle.getEntries().size());
|
||||
assertEquals(HOUR_IN_MILLIS, statsSingle.getBucketDuration());
|
||||
assertEquals(entry1, statsSingle.getEntries().get(0));
|
||||
|
||||
NetworkStatsHistory statsMultiple = new NetworkStatsHistory
|
||||
.Builder(SECOND_IN_MILLIS, 0)
|
||||
.addEntry(entry1).addEntry(entry2).addEntry(entry3)
|
||||
.build();
|
||||
final List<NetworkStatsHistory.Entry> entries = statsMultiple.getEntries();
|
||||
assertEquals(3, entries.size());
|
||||
assertEquals(SECOND_IN_MILLIS, statsMultiple.getBucketDuration());
|
||||
assertEquals(entry1, entries.get(0));
|
||||
assertEquals(entry2, entries.get(1));
|
||||
assertEquals(entry3, entries.get(2));
|
||||
}
|
||||
|
||||
private static void assertIndexBeforeAfter(
|
||||
NetworkStatsHistory stats, int before, int after, long time) {
|
||||
assertEquals("unexpected before", before, stats.getIndexBefore(time));
|
||||
|
|
|
|||
Loading…
Reference in a new issue