Search in sources :

Example 96 with Collections

use of java.util.Collections in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PreferenceListTest method testConnectedLegacyVpnShownExactlyOnce.

@SmallTest
public void testConnectedLegacyVpnShownExactlyOnce() {
    final VpnProfile vpnProfile = new VpnProfile("test-no-duplicates");
    final LegacyVpnInfo connectedLegacyVpn = new LegacyVpnInfo();
    connectedLegacyVpn.key = new String(vpnProfile.key);
    final VpnSettings.UpdatePreferences updater = new VpnSettings.UpdatePreferences(mSettings);
    updater.legacyVpns(/* vpnProfiles */
    Collections.<VpnProfile>singletonList(vpnProfile), /* connectedLegacyVpns */
    new HashMap<String, LegacyVpnInfo>() {

        {
            put(connectedLegacyVpn.key, connectedLegacyVpn);
        }
    }, /* lockdownVpnKey */
    null);
    updater.run();
    final ArgumentMatcher<VpnProfile> equalsFake = arg -> {
        if (arg == vpnProfile)
            return true;
        if (arg == null)
            return false;
        return TextUtils.equals(arg.key, vpnProfile.key);
    };
    // The VPN profile should have been used to create a preference and set up at laest once
    // with update=true to fill in all the fields.
    verify(mSettings, atLeast(1)).findOrCreatePreference(argThat(equalsFake), eq(true));
    // ...But no other VPN profile key should ever have been passed in.
    verify(mSettings, never()).findOrCreatePreference(not(argThat(equalsFake)), anyBoolean());
    // And so we should still have exactly 1 preference created.
    assertEquals(1, mLegacyMocks.size());
    assertEquals(0, mAppMocks.size());
}
Also used : SmallTest(android.test.suitebuilder.annotation.SmallTest) Mock(org.mockito.Mock) Mockito.times(org.mockito.Mockito.times) TextUtils(android.text.TextUtils) HashMap(java.util.HashMap) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.argThat(org.mockito.Mockito.argThat) Mockito.verify(org.mockito.Mockito.verify) AndroidTestCase(android.test.AndroidTestCase) ArgumentMatcher(org.mockito.ArgumentMatcher) MockitoAnnotations(org.mockito.MockitoAnnotations) Mockito.never(org.mockito.Mockito.never) Mockito.anyBoolean(org.mockito.Mockito.anyBoolean) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) Mockito.atLeast(org.mockito.Mockito.atLeast) LegacyVpnInfo(com.android.internal.net.LegacyVpnInfo) VpnProfile(com.android.internal.net.VpnProfile) Mockito.any(org.mockito.Mockito.any) AdditionalMatchers.not(org.mockito.AdditionalMatchers.not) Mockito.doReturn(org.mockito.Mockito.doReturn) Collections(java.util.Collections) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) VpnProfile(com.android.internal.net.VpnProfile) LegacyVpnInfo(com.android.internal.net.LegacyVpnInfo) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 97 with Collections

use of java.util.Collections in project alluxio by Alluxio.

the class UfsJournalCheckpointThreadTest method checkpointBeforeShutdown.

/**
 * The checkpoint thread replays all the logs and checkpoints periodically if not shutdown.
 */
@Test
public void checkpointBeforeShutdown() throws Exception {
    ServerConfiguration.set(PropertyKey.MASTER_JOURNAL_CHECKPOINT_PERIOD_ENTRIES, "2");
    buildCompletedLog(0, 10);
    buildIncompleteLog(10, 15);
    MockMaster mockMaster = new MockMaster();
    UfsJournalCheckpointThread checkpointThread = new UfsJournalCheckpointThread(mockMaster, mJournal, Collections::emptySet);
    checkpointThread.start();
    CommonUtils.waitFor("checkpoint", () -> {
        try {
            UfsJournalSnapshot snapshot = UfsJournalSnapshot.getSnapshot(mJournal);
            if (!snapshot.getCheckpoints().isEmpty() && snapshot.getCheckpoints().get(snapshot.getCheckpoints().size() - 1).getEnd() == 10) {
                return true;
            }
        } catch (IOException e) {
            return false;
        }
        return false;
    }, WaitForOptions.defaults().setTimeoutMs(20000));
    Assert.assertEquals(UfsJournalCheckpointThread.CatchupState.DONE, checkpointThread.getCatchupState());
    UfsJournalSnapshot snapshot = UfsJournalSnapshot.getSnapshot(mJournal);
    Assert.assertEquals(1, snapshot.getCheckpoints().size());
    Assert.assertEquals(10, snapshot.getCheckpoints().get(0).getEnd());
    checkpointThread.awaitTermination(true);
}
Also used : MockMaster(alluxio.master.MockMaster) IOException(java.io.IOException) Collections(java.util.Collections) Test(org.junit.Test)

Example 98 with Collections

use of java.util.Collections in project alluxio by Alluxio.

the class UfsJournalTest method gainPrimacyAfterSuspend.

@Test
public void gainPrimacyAfterSuspend() throws Exception {
    mJournal.start();
    mJournal.gainPrimacy();
    // Create a counting master implementation that counts how many journal entries it processed.
    CountingNoopMaster countingMaster = new CountingNoopMaster();
    // Find journal base path for standby journal to consume the same journal files.
    String parentPath = new File(mJournal.getLocation().getPath()).getParent();
    UfsJournal standbyJournal = new UfsJournal(new URI(parentPath), countingMaster, 0, Collections::emptySet);
    standbyJournal.start();
    // Suspend standby journal
    standbyJournal.suspend();
    // Write entries
    int entryCount = 10;
    for (int i = 0; i < entryCount; i++) {
        mJournal.write(Journal.JournalEntry.getDefaultInstance());
    }
    mJournal.flush();
    // Validate standby didn't apply any entries yet.
    Assert.assertEquals(0, countingMaster.getApplyCount());
    // Gain primacy.
    standbyJournal.gainPrimacy();
    CommonUtils.waitFor("catching up to current state", () -> countingMaster.getApplyCount() == entryCount);
    // Resume should fail after becoming primary.
    mThrown.expect(IllegalStateException.class);
    standbyJournal.resume();
}
Also used : Collections(java.util.Collections) File(java.io.File) URI(java.net.URI) Test(org.junit.Test)

Example 99 with Collections

use of java.util.Collections in project alluxio by Alluxio.

the class UfsJournalTest method gainPrimacyDuringCatchup.

@Test
public void gainPrimacyDuringCatchup() throws Exception {
    mJournal.start();
    mJournal.gainPrimacy();
    // Create a counting master implementation that counts how many journal entries it processed.
    CountingNoopMaster countingMaster = new SleepingCountingMaster(50);
    // Find journal base path for standby journal to consume the same journal files.
    String parentPath = new File(mJournal.getLocation().getPath()).getParent();
    UfsJournal standbyJournal = new UfsJournal(new URI(parentPath), countingMaster, 0, Collections::emptySet);
    standbyJournal.start();
    // Suspend standby journal.
    standbyJournal.suspend();
    // Write many entries to guarantee that advancing will be in progress
    // when gainPrimacy() is called.
    int entryCount = 10;
    for (int i = 0; i < entryCount; i++) {
        mJournal.write(Journal.JournalEntry.getDefaultInstance());
    }
    mJournal.flush();
    // Validate standby didn't apply any entries yet.
    Assert.assertEquals(0, countingMaster.getApplyCount());
    // Initiate catching up.
    standbyJournal.catchup(entryCount - 2);
    // Gain primacy.
    standbyJournal.gainPrimacy();
    CommonUtils.waitFor("catching up to current state", () -> countingMaster.getApplyCount() == entryCount);
}
Also used : Collections(java.util.Collections) File(java.io.File) URI(java.net.URI) Test(org.junit.Test)

Example 100 with Collections

use of java.util.Collections in project alluxio by Alluxio.

the class UfsJournalTest method gainPrimacyAfterCatchup.

@Test
public void gainPrimacyAfterCatchup() throws Exception {
    mJournal.start();
    mJournal.gainPrimacy();
    // Create a counting master implementation that counts how many journal entries it processed.
    CountingNoopMaster countingMaster = new CountingNoopMaster();
    // Find journal base path for standby journal to consume the same journal files.
    String parentPath = new File(mJournal.getLocation().getPath()).getParent();
    UfsJournal standbyJournal = new UfsJournal(new URI(parentPath), countingMaster, 0, Collections::emptySet);
    standbyJournal.start();
    // Suspend standby journal.
    standbyJournal.suspend();
    // Write many entries to guarantee that advancing will be in progress
    // when gainPrimacy() is called.
    int entryCount = 10;
    for (int i = 0; i < entryCount; i++) {
        mJournal.write(Journal.JournalEntry.getDefaultInstance());
    }
    mJournal.flush();
    // Validate standby didn't apply any entries yet.
    Assert.assertEquals(0, countingMaster.getApplyCount());
    // Initiate and wait for catching up.
    standbyJournal.catchup(entryCount - 2).waitTermination();
    Assert.assertEquals(entryCount - 1, countingMaster.getApplyCount());
    // Gain primacy.
    standbyJournal.gainPrimacy();
    CommonUtils.waitFor("catching up to current state", () -> countingMaster.getApplyCount() == entryCount);
}
Also used : Collections(java.util.Collections) File(java.io.File) URI(java.net.URI) Test(org.junit.Test)

Aggregations

Collections (java.util.Collections)113 List (java.util.List)59 ArrayList (java.util.ArrayList)41 Test (org.junit.Test)39 Map (java.util.Map)37 Collectors (java.util.stream.Collectors)34 Arrays (java.util.Arrays)28 HashMap (java.util.HashMap)26 Set (java.util.Set)25 HashSet (java.util.HashSet)23 IOException (java.io.IOException)19 Collection (java.util.Collection)19 Optional (java.util.Optional)19 TimeUnit (java.util.concurrent.TimeUnit)16 URI (java.net.URI)13 Assert (org.junit.Assert)13 Function (java.util.function.Function)12 Stream (java.util.stream.Stream)12 Before (org.junit.Before)12 Logger (org.slf4j.Logger)12