Mercurial > hg > release > thermostat-1.6
changeset 1725:5bcf61ecacab
Backport: "List Dumps" window does not update after an in-progress heap dump is completed
review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-August/015366.html
reviewed-by: jerboaa
PR2585
author | Mario Torre <neugens.limasoftware@gmail.com> |
---|---|
date | Wed, 19 Aug 2015 11:41:51 +0200 |
parents | 4f607fa1813d |
children | df0b23875ffb |
files | vm-heap-analysis/client-core/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/core/internal/HeapDumpController.java vm-heap-analysis/client-core/src/test/java/com/redhat/thermostat/vm/heap/analysis/client/core/internal/HeapDumpControllerTest.java |
diffstat | 2 files changed, 62 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/vm-heap-analysis/client-core/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/core/internal/HeapDumpController.java Mon Aug 17 16:05:36 2015 +0200 +++ b/vm-heap-analysis/client-core/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/core/internal/HeapDumpController.java Wed Aug 19 11:41:51 2015 +0200 @@ -110,6 +110,8 @@ private ProgressNotifier notifier; + private HeapDumpListController heapDumpListController; + public HeapDumpController(final VmMemoryStatDAO vmMemoryStatDao, final VmInfoDAO vmInfoDao, final HeapDAO heapDao, final VmRef ref, @@ -210,19 +212,19 @@ public void actionPerformed(ActionEvent<HeapDumperAction> actionEvent) { HeapDump dump = null; switch (actionEvent.getActionId()) { - case DUMP_REQUESTED: + case DUMP_REQUESTED: { view.disableHeapDumping(DumpDisabledReason.DUMP_IN_PROGRESS); requestDump(heapDumper); - break; + } break; - case REQUEST_DISPLAY_DUMP_LIST: + case REQUEST_DISPLAY_DUMP_LIST: { openDumpList(); - break; + } break; - case ANALYSE: + case ANALYSE: { dump = (HeapDump) actionEvent.getPayload(); analyseDump(dump); - break; + } break; case REQUEST_EXPORT: { dump = (HeapDump) actionEvent.getPayload(); @@ -287,16 +289,19 @@ appService.getApplicationExecutor().execute(new Runnable() { @Override public void run() { - List<HeapDump> dumps = getHeapDumps(); - HeapDumpListController controller = - new HeapDumpListController(heapDumpListViewProvider, - HeapDumpController.this); - controller.setDumps(dumps); - view.openDumpListView(controller.getView()); + if (heapDumpListController == null) { + heapDumpListController = createHeapDumpListController(); + } + updateDumpList(); + view.openDumpListView(heapDumpListController.getView()); } }); } - + + HeapDumpListController createHeapDumpListController() { + return new HeapDumpListController(heapDumpListViewProvider, this); + } + private void requestDump(final HeapDumper heapDumper) { appService.getApplicationExecutor().execute(new Runnable() { @Override @@ -314,6 +319,8 @@ heapDumper.dump(); view.enableHeapDumping(); view.notifyHeapDumpComplete(); + updateDumpList(); + } catch (CommandException e) { view.displayWarning(e.getTranslatedMessage()); } finally { @@ -323,6 +330,14 @@ }); } + private void updateDumpList() { + if (heapDumpListController == null) { + return; + } + List<HeapDump> dumps = getHeapDumps(); + heapDumpListController.setDumps(dumps); + } + void analyseDump(final HeapDump dump) { appService.getApplicationExecutor().execute(new Runnable() { @Override
--- a/vm-heap-analysis/client-core/src/test/java/com/redhat/thermostat/vm/heap/analysis/client/core/internal/HeapDumpControllerTest.java Mon Aug 17 16:05:36 2015 +0200 +++ b/vm-heap-analysis/client-core/src/test/java/com/redhat/thermostat/vm/heap/analysis/client/core/internal/HeapDumpControllerTest.java Wed Aug 19 11:41:51 2015 +0200 @@ -132,7 +132,7 @@ private HeapDumpListViewProvider heapDumpListViewProvider; private ProgressNotifier notifier; - + private HeapDumpListController heapDumpListController; @Before public void setUp() { heapDao = mock(HeapDAO.class); @@ -213,10 +213,16 @@ when(ref.getVmId()).thenReturn("vm-id"); when(ref.getHostRef()).thenReturn(hostRef); + heapDumpListController = mock(HeapDumpListController.class); + controller = new HeapDumpController(vmDao, vmInfoDao, heapDao, ref, appService, viewProvider, detailsViewProvider, histogramProvider, treeMapProvider, objectDetailsProvider, objectRootsProvider, heapDumpListViewProvider, - heapDumper, notifier); + heapDumper, notifier) { + HeapDumpListController createHeapDumpListController() { + return heapDumpListController; + } + }; } @After @@ -567,5 +573,31 @@ assertTrue(actual <= expected + 1000); assertTrue(actual >= expected - 1000); } + + @Test + public void testRequestHeapDumpUpdatesDumpList() throws CommandException, InterruptedException { + final CountDownLatch latch = new CountDownLatch(1); + mockExecutorService(latch); + setUpListeners(); + + heapDumperListener.actionPerformed(new ActionEvent<HeapDumperAction>(view, HeapDumperAction.DUMP_REQUESTED)); + latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS); + + verify(heapDumper).dump(); + verify(view).notifyHeapDumpComplete(); + + // the list has not been opened yet, so no interaction should happen + // here + verify(heapDumpListController, times(0)).setDumps(any(List.class)); + + // now the list should be intialiased + heapDumperListener.actionPerformed(new ActionEvent<HeapDumperAction>(view, HeapDumperAction.REQUEST_DISPLAY_DUMP_LIST)); + verify(heapDumpListController, times(1)).setDumps(any(List.class)); + + // since it was initialised before, we should see another interaction + // here + heapDumperListener.actionPerformed(new ActionEvent<HeapDumperAction>(view, HeapDumperAction.DUMP_REQUESTED)); + verify(heapDumpListController, times(2)).setDumps(any(List.class)); + } }