@Test
public void testMqManager() throws Exception {
HgRepository repo = Configuration.get().find("test-mq");
HgExtensionsManager extManager = repo.getExtensions();
assertTrue(extManager.isEnabled(HgExt.MQ));
MqManager mqManager = extManager.getMQ();
mqManager.refresh();
OutputParser.Stub output = new OutputParser.Stub();
ExecHelper eh = new ExecHelper(output, repo.getWorkingDir());
// `hg qseries`
eh.run("hg", "qseries");
LinkedList<PatchRecord> allKnownPatches = new LinkedList<PatchRecord>(mqManager.getAllKnownPatches());
assertTrue("[sanity]", allKnownPatches.size() > 0);
for (CharSequence l : output.lines()) {
for (Iterator<PatchRecord> it = allKnownPatches.listIterator(); it.hasNext(); ) {
if (it.next().getName().equals(l)) {
it.remove();
}
}
}
assertTrue("Known patches shall match those from `hg qseries`", allKnownPatches.isEmpty());
//
// `hg qapplied`, patches from the queue already applied to the repo
eh.run("hg", "qapplied");
LinkedList<PatchRecord> appliedPatches = new LinkedList<PatchRecord>(mqManager.getAppliedPatches());
assertTrue("[sanity]", appliedPatches.size() > 0);
for (CharSequence l : output.lines()) {
for (Iterator<PatchRecord> it = appliedPatches.listIterator(); it.hasNext(); ) {
if (it.next().getName().equals(l)) {
it.remove();
}
}
}
assertTrue("Each patch reported as applied shall match thos from `hg qapplied`", appliedPatches.isEmpty());
assertTrue("[sanity] ",mqManager.getQueueSize() > 0);
boolean allAppliedAreKnown = mqManager.getAllKnownPatches().containsAll(mqManager.getAppliedPatches());
assertTrue(allAppliedAreKnown); // ensure instances are the same, ==
// `hg qqueue`
assertTrue("[sanity]",mqManager.getQueueNames().size() > 1);
assertTrue(mqManager.getActiveQueueName().length() > 0);
eh.run("hg", "qqueue");
boolean activeQueueFound = false;
LinkedList<String> queueNames = new LinkedList<String>(mqManager.getQueueNames());
for (String l : output.lines()) {
if (l.endsWith("(active)")) {
l = l.substring(0, l.length() - 8).trim();
assertEquals(l, mqManager.getActiveQueueName());
assertFalse("only single active queue", activeQueueFound);
activeQueueFound = true;
}
assertTrue(queueNames.remove(l));
}