@Test void reIndexMailboxShouldWaitsForExecution() throws Exception { Task task = mock(Task.class); doReturn(Task.Result.COMPLETED).when(task).run(); String namespace = "namespace"; String user = "user"; String name = "name"; when(reIndexer.reIndex(any(MailboxPath.class), any(RunningOptions.class))).thenReturn(task); assertThat(taskManager.list()).isEmpty(); testee.reIndex(namespace, user, name); verify(reIndexer).reIndex(new MailboxPath(namespace, Username.of(user), name), RunningOptions.DEFAULT); assertThat(taskManager.list()).hasSize(1); }
@Override public void reIndex(String namespace, String user, String name) throws MailboxException { try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.PROTOCOL, "CLI") .addContext(MDCBuilder.ACTION, "reIndex") .build()) { TaskId taskId = taskManager.submit(reIndexer.reIndex(new MailboxPath(namespace, Username.of(user), name), RunningOptions.DEFAULT)); taskManager.await(taskId, Duration.ofMillis(Long.MAX_VALUE)); } catch (IOException | TaskManager.ReachedTimeoutException e) { throw new RuntimeException(e); } }
ReIndexerManagement implements ReIndexerManagementMBean { @Override public void reIndex(String namespace, String user, String name) throws MailboxException { try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.PROTOCOL, "CLI") .addContext(MDCBuilder.ACTION, "reIndex") .build()) { TaskId taskId = taskManager.submit(reIndexer.reIndex(new MailboxPath(namespace, Username.of(user), name), RunningOptions.DEFAULT)); taskManager.await(taskId, Duration.ofMillis(Long.MAX_VALUE)); } catch (IOException | TaskManager.ReachedTimeoutException e) { throw new RuntimeException(e); } } }
ReIndexerManagement implements ReIndexerManagementMBean { @Override public void reIndex(String namespace, String user, String name) throws MailboxException { try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.PROTOCOL, "CLI") .addContext(MDCBuilder.ACTION, "reIndex") .build()) { TaskId taskId = taskManager.submit(reIndexer.reIndex(new MailboxPath(namespace, Username.of(user), name), RunningOptions.DEFAULT)); taskManager.await(taskId, Duration.ofMillis(Long.MAX_VALUE)); } catch (IOException | TaskManager.ReachedTimeoutException e) { throw new RuntimeException(e); } } @Inject  ReIndexerManagement(TaskManager taskManager, @Named("reindexer") ReIndexer reIndexer); }
ReIndexerManagement implements ReIndexerManagementMBean { @Override public void reIndex(String namespace, String user, String name) throws MailboxException { try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.PROTOCOL, "CLI") .addContext(MDCBuilder.ACTION, "reIndex") .build()) { TaskId taskId = taskManager.submit(reIndexer.reIndex(new MailboxPath(namespace, Username.of(user), name), RunningOptions.DEFAULT)); taskManager.await(taskId, Duration.ofMillis(Long.MAX_VALUE)); } catch (IOException | TaskManager.ReachedTimeoutException e) { throw new RuntimeException(e); } } @Inject  ReIndexerManagement(TaskManager taskManager, @Named("reindexer") ReIndexer reIndexer); @Override void reIndex(String namespace, String user, String name); @Override void reIndex(); }
ReIndexerManagement implements ReIndexerManagementMBean { @Override public void reIndex(String namespace, String user, String name) throws MailboxException { try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.PROTOCOL, "CLI") .addContext(MDCBuilder.ACTION, "reIndex") .build()) { TaskId taskId = taskManager.submit(reIndexer.reIndex(new MailboxPath(namespace, Username.of(user), name), RunningOptions.DEFAULT)); taskManager.await(taskId, Duration.ofMillis(Long.MAX_VALUE)); } catch (IOException | TaskManager.ReachedTimeoutException e) { throw new RuntimeException(e); } } @Inject  ReIndexerManagement(TaskManager taskManager, @Named("reindexer") ReIndexer reIndexer); @Override void reIndex(String namespace, String user, String name); @Override void reIndex();  }