Task.Result reIndex(ReprocessingContext reprocessingContext) throws MailboxException { MailboxSession mailboxSession = mailboxManager.createSystemSession("re-indexing"); LOGGER.info("Starting a full reindex"); List<MailboxPath> mailboxPaths = mailboxManager.list(mailboxSession); try { return reIndex(mailboxPaths, mailboxSession, reprocessingContext); } finally { LOGGER.info("Full reindex finished"); } }
.thenReturn(MessageUid.of(1)); when(mailboxManager.list(systemMailboxSession)) .thenReturn(ImmutableList.of(user1MailboxPath));
@Test public void getMailboxesShouldNotFailWhenMailboxManagerErrors() throws Exception { MailboxManager mockedMailboxManager = mock(MailboxManager.class); when(mockedMailboxManager.list(any())) .thenReturn(ImmutableList.of(new MailboxPath("namespace", "user", "name"))); when(mockedMailboxManager.getMailbox(any(MailboxPath.class), any())) .thenThrow(new MailboxException()); GetMailboxesMethod testee = new GetMailboxesMethod(mockedMailboxManager, mailboxFactory, new DefaultMetricFactory()); GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() .build(); MailboxSession session = new MockMailboxSession(USERNAME); List<JmapResponse> getMailboxesResponse = testee.process(getMailboxesRequest, clientId, session).collect(Collectors.toList()); assertThat(getMailboxesResponse) .hasSize(1) .extracting(JmapResponse::getResponse) .hasOnlyElementsOfType(GetMailboxesResponse.class) .extracting(GetMailboxesResponse.class::cast) .flatExtracting(GetMailboxesResponse::getList) .isEmpty(); }
/** * Utility method to assert the number of mailboxes and messages per mailbox * are the ones expected. * * @throws MailboxException * @throws BadCredentialsException */ private void assertMailboxManagerSize(MailboxManager mailboxManager, int multiplicationFactor) throws BadCredentialsException, MailboxException { MailboxSession mailboxSession = mailboxManager.createSystemSession("manager"); mailboxManager.startProcessingRequest(mailboxSession); List<MailboxPath> mailboxPathList = mailboxManager.list(mailboxSession); assertThat(mailboxPathList).hasSize(DataProvisioner.EXPECTED_MAILBOXES_COUNT); for (MailboxPath mailboxPath: mailboxPathList) { MailboxSession userSession = mailboxManager.createSystemSession(mailboxPath.getUser()); mailboxManager.startProcessingRequest(mailboxSession); MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, userSession); assertThat(messageManager.getMetaData(false, userSession, FetchGroup.NO_UNSEEN).getMessageCount()).isEqualTo(DataProvisioner.MESSAGE_PER_MAILBOX_COUNT * multiplicationFactor); } mailboxManager.endProcessingRequest(mailboxSession); mailboxManager.logout(mailboxSession, true); }
/** * Utility method to assert the number of mailboxes and messages per mailbox * are the ones expected. * * @throws MailboxException * @throws BadCredentialsException */ private void assertMailboxManagerSize(MailboxManager mailboxManager, int multiplicationFactor) throws BadCredentialsException, MailboxException { MailboxSession mailboxSession = mailboxManager.createSystemSession("manager"); mailboxManager.startProcessingRequest(mailboxSession); List<MailboxPath> mailboxPathList = mailboxManager.list(mailboxSession); assertThat(mailboxPathList).hasSize(DataProvisioner.EXPECTED_MAILBOXES_COUNT); for (MailboxPath mailboxPath: mailboxPathList) { MailboxSession userSession = mailboxManager.createSystemSession(mailboxPath.getUser()); mailboxManager.startProcessingRequest(mailboxSession); MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, userSession); assertThat(messageManager.getMetaData(false, userSession, FetchGroup.NO_UNSEEN).getMessageCount()).isEqualTo(DataProvisioner.MESSAGE_PER_MAILBOX_COUNT * multiplicationFactor); } mailboxManager.endProcessingRequest(mailboxSession); mailboxManager.logout(mailboxSession, true); }