@Test public void testIndexSearchAndRemove() throws Exception { String id = Utils.generateUniqueString(); String title = "test"; TodoView todoView = new TodoView(id, title, false, 0); todoViewService.index(todoView); Thread.sleep(2000); //Elasticsearch by default refreshes each shard every 1s List<TodoView> todoViews = todoViewService.search(title); Assert.assertTrue(todoViews.stream().anyMatch(view -> id.equals(view.getId()))); todoViewService.remove(id); Thread.sleep(2000); todoViews = todoViewService.search(title); Assert.assertFalse(todoViews.stream().anyMatch(view -> id.equals(view.getId()))); } }
@Test public void testIndexSearchAndRemove() throws Exception { String id = Utils.generateUniqueString(); String title = "test"; TodoView todoView = new TodoView(id, title, false, 0); todoViewService.index(todoView); Thread.sleep(2000); //Elasticsearch by default refreshes each shard every 1s List<TodoView> todoViews = todoViewService.search(title); Assert.assertTrue(todoViews.stream().anyMatch(view -> id.equals(view.getId()))); todoViewService.remove(id); Thread.sleep(2000); todoViews = todoViewService.search(title); Assert.assertFalse(todoViews.stream().anyMatch(view -> id.equals(view.getId()))); } }
public DomainEventHandlers domainEventHandlers() { return DomainEventHandlersBuilder .forAggregateType(Todo.class.getName()) .onEvent(TodoCreated.class, dee -> { TodoCreated todoCreated = dee.getEvent(); todoViewService.index(new TodoView(dee.getAggregateId(), todoCreated.getTitle(), todoCreated.isCompleted(), todoCreated.getExecutionOrder())); }) .onEvent(TodoUpdated.class, dee -> { TodoUpdated todoUpdated = dee.getEvent(); todoViewService.index(new TodoView(dee.getAggregateId(), todoUpdated.getTitle(), todoUpdated.isCompleted(), todoUpdated.getExecutionOrder())); }) .onEvent(TodoDeleted.class, dee -> todoViewService.remove(dee.getAggregateId())) .build(); } }
public DomainEventHandlers domainEventHandlers() { return DomainEventHandlersBuilder .forAggregateType("io.eventuate.tram.examples.todolist.command.Todo") .onEvent(TodoCreated.class, dee -> { TodoCreated todoCreated = dee.getEvent(); todoViewService.index(new TodoView(dee.getAggregateId(), todoCreated.getTitle(), todoCreated.isCompleted(), todoCreated.getExecutionOrder())); }) .onEvent(TodoUpdated.class, dee -> { TodoUpdated todoUpdated = dee.getEvent(); todoViewService.index(new TodoView(dee.getAggregateId(), todoUpdated.getTitle(), todoUpdated.isCompleted(), todoUpdated.getExecutionOrder())); }) .onEvent(TodoDeleted.class, dee -> todoViewService.remove(dee.getAggregateId())) .build(); } }