use of com.zimbra.cs.redolog.RedoPlayer in project zm-mailbox by Zimbra.
the class TestRedoLog method testTestRestoreMessageToNewAccount.
/**
* Verifies that redolog replay successfully copies a message from one mailbox
* to another and leaves the original blob intact. See bug 22873.
*/
@Test
public void testTestRestoreMessageToNewAccount() throws Exception {
TestUtil.createAccount(USER_NAME);
// make sure mailbox is pre-created as well as account
Mailbox sourceMbox = TestUtil.getMailbox(USER_NAME);
// Add message to source account.
long startTime = System.currentTimeMillis();
Message sourceMsg = TestUtil.addMessage(sourceMbox, NAME_PREFIX + " testRestoreMessageToNewAccount");
String sourceContent = new String(sourceMsg.getContent());
assertTrue("Message.getContent() length should not be 0", sourceContent.length() != 0);
// Replay log to destination account.
Account destAccount = TestUtil.createAccount(RESTORED_NAME);
RedoPlayer player = new RedoPlayer(false, true, false, false, false);
Map<Integer, Integer> idMap = new HashMap<Integer, Integer>();
Mailbox destMbox = MailboxManager.getInstance().getMailboxByAccount(destAccount);
idMap.put(sourceMbox.getId(), destMbox.getId());
ZimbraLog.test.info("Source Mailbox ID=%s Dest ID=%s", sourceMbox.getId(), destMbox.getId());
player.scanLog(getRedoLogFile(), true, idMap, startTime, Long.MAX_VALUE);
// Get destination message and compare content.
List<Integer> destIds = TestUtil.search(destMbox, "in:inbox " + NAME_PREFIX, MailItem.Type.MESSAGE);
assertEquals("Search should should only find 1 message", 1, destIds.size());
Message destMsg = destMbox.getMessageById(null, destIds.get(0));
String destContent = new String(destMsg.getContent());
assertEquals("Expected=sourceContent Actual=destContent", sourceContent, destContent);
// Make sure source content is still on disk.
MailboxBlob blob = sourceMsg.getBlob();
assertNotNull("Blob for sourceMsg should not be null", blob);
sourceContent = new String(ByteUtil.getContent(StoreManager.getInstance().getContent(blob), sourceContent.length()));
assertEquals("From disk Expected=destContent Actual=sourceContent", destContent, sourceContent);
}
Aggregations