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());
}
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);
}
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();
}
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);
}
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);
}
Aggregations