diff options
author | Nate(Qiang) Jiang <qiangjiang@google.com> | 2020-02-21 09:53:42 -0800 |
---|---|---|
committer | Nate(Qiang) Jiang <qiangjiang@google.com> | 2020-02-27 15:20:25 -0800 |
commit | 2ca9524eb2e869cf0c9749d4c57593eb7066ec18 (patch) | |
tree | b3eaf5be876c18309fc69429002a2a6be3290d60 /tests | |
parent | 9370bc7456b04557e76a205919ca52a551cf49f3 (diff) |
Utility class for user disconnect lock list
Every entry in the lock list has a CounteTimer, when missed count reach
the threshhold, timer will start. When timer expired, that entry will be
remove from the lock list.
Bug: 136005248
Test: atest com.android.server.wifi
Change-Id: I11669f18246320477ddc16cd83487a8bd56dec1f
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/util/MissingCounterTimerLockListTest.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/util/MissingCounterTimerLockListTest.java b/tests/wifitests/src/com/android/server/wifi/util/MissingCounterTimerLockListTest.java new file mode 100644 index 000000000..c145f7fb7 --- /dev/null +++ b/tests/wifitests/src/com/android/server/wifi/util/MissingCounterTimerLockListTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * 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 com.android.server.wifi.util; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.when; + +import androidx.test.filters.SmallTest; + +import com.android.server.wifi.Clock; +import com.android.server.wifi.WifiBaseTest; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.util.HashSet; +import java.util.Set; + +@SmallTest +public class MissingCounterTimerLockListTest extends WifiBaseTest { + private static final int TEST_MISSING_COUNT = 2; + private static final long BLOCKING_DURATION = 1000; + private static final String TEST_SSID = "testSSID"; + private static final String TEST_FQDN = "testFQDN"; + + private MissingCounterTimerLockList<String> mMissingCounterTimerLockList; + + @Mock Clock mClock; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mMissingCounterTimerLockList = + new MissingCounterTimerLockList<>(TEST_MISSING_COUNT, mClock); + } + + @Test + public void testAddRemove() { + mMissingCounterTimerLockList.add(TEST_SSID, BLOCKING_DURATION); + mMissingCounterTimerLockList.add(TEST_FQDN, BLOCKING_DURATION); + mMissingCounterTimerLockList.add(null, BLOCKING_DURATION); + assertEquals(2, mMissingCounterTimerLockList.size()); + assertTrue(mMissingCounterTimerLockList.isLocked(TEST_SSID)); + assertTrue(mMissingCounterTimerLockList.isLocked(TEST_FQDN)); + assertTrue(mMissingCounterTimerLockList.remove(TEST_SSID)); + assertEquals(1, mMissingCounterTimerLockList.size()); + assertFalse(mMissingCounterTimerLockList.isLocked(TEST_SSID)); + assertTrue(mMissingCounterTimerLockList.isLocked(TEST_FQDN)); + mMissingCounterTimerLockList.clear(); + assertEquals(0, mMissingCounterTimerLockList.size()); + } + + @Test + public void testUpdateAndTimer() { + mMissingCounterTimerLockList.add(TEST_SSID, BLOCKING_DURATION); + mMissingCounterTimerLockList.add(TEST_FQDN, BLOCKING_DURATION); + assertEquals(2, mMissingCounterTimerLockList.size()); + when(mClock.getWallClockMillis()).thenReturn((long) 0); + Set<String> updateSet = new HashSet<>(); + updateSet.add(TEST_FQDN); + mMissingCounterTimerLockList.update(updateSet); + assertEquals(2, mMissingCounterTimerLockList.size()); + mMissingCounterTimerLockList.update(updateSet); + assertEquals(2, mMissingCounterTimerLockList.size()); + when(mClock.getWallClockMillis()).thenReturn(BLOCKING_DURATION + 50); + assertEquals(2, mMissingCounterTimerLockList.size()); + assertFalse(mMissingCounterTimerLockList.isLocked(TEST_SSID)); + assertTrue(mMissingCounterTimerLockList.isLocked(TEST_FQDN)); + } +} |