changeset 2599:1652930da47b

Fix HeapDumpListViewTest sporadic test failures PR3317 Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-February/022236.html
author Alex Macdonald <almacdon@redhat.com>
date Fri, 24 Feb 2017 10:22:42 -0500
parents 3d42591a926c
children fb44fdd2a164
files vm-heap-analysis/client-swing/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/SwingHeapDumpListView.java vm-heap-analysis/client-swing/src/test/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/HeapDumpListViewTest.java
diffstat 2 files changed, 33 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/vm-heap-analysis/client-swing/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/SwingHeapDumpListView.java	Thu Feb 23 09:22:15 2017 -0500
+++ b/vm-heap-analysis/client-swing/src/main/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/SwingHeapDumpListView.java	Fri Feb 24 10:22:42 2017 -0500
@@ -110,6 +110,12 @@
     public void setDumps(List<HeapDump> dumps) {
         setDumps(dumps, null);
     }
+
+    // package-private for testing
+    // otherwise, container dimension is 10 x 12 for test
+    void setContainerSize(int width, int height) {
+        container.setPreferredSize(new Dimension(width, height));
+    }
     
     // package-private for testing
     void setDumps(final List<HeapDump> dumps, final Runnable callback) {
@@ -230,7 +236,6 @@
             button.setToolTipText("Export heap dump.");
             button.setName(heapDump.toString() + "_button");
             button.setBackground(null);
-
             button.addActionListener(new ActionListener() {
                 @Override
                 public void actionPerformed(ActionEvent e) {
@@ -244,16 +249,21 @@
             setLayout(gbl);
 
             GridBagConstraints gbc = new GridBagConstraints();
-
+            gbc.gridx = 0;
             gbc.gridy = 0;
-            gbc.gridx = GridBagConstraints.RELATIVE;
-            gbc.fill = GridBagConstraints.HORIZONTAL;
+            gbc.weightx = 0.01; // has to be non-zero for anchor
             gbc.weighty = 1;
-
-            gbc.weightx = 1;
+            gbc.anchor = GridBagConstraints.FIRST_LINE_START;
+            gbc.fill = GridBagConstraints.NONE;
             add(label, gbc);
 
-            gbc.weightx = 0;
+            gbc = new GridBagConstraints();
+            gbc.gridx = 1;
+            gbc.gridy = 0;
+            gbc.weightx = 0.01;
+            gbc.weighty = 1;
+            gbc.anchor = GridBagConstraints.EAST;
+            gbc.fill = GridBagConstraints.NONE;
             add(button, gbc);
 
             setOpaque(false);
@@ -265,7 +275,6 @@
                     if (evt.getClickCount() == 2) {
                         listNotifier.fireAction(ListAction.OPEN_DUMP_DETAILS, HeapDumpItem.this.heapDump);
                     }
-
                 }
 
                 public void mouseEntered(MouseEvent evt) {
--- a/vm-heap-analysis/client-swing/src/test/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/HeapDumpListViewTest.java	Thu Feb 23 09:22:15 2017 -0500
+++ b/vm-heap-analysis/client-swing/src/test/java/com/redhat/thermostat/vm/heap/analysis/client/swing/internal/HeapDumpListViewTest.java	Fri Feb 24 10:22:42 2017 -0500
@@ -74,7 +74,7 @@
 import com.redhat.thermostat.annotations.internal.CacioTest;
 import com.redhat.thermostat.common.ActionEvent;
 import com.redhat.thermostat.common.ActionListener;
-import com.redhat.thermostat.vm.heap.analysis.client.core.HeapDumpListView;
+import com.redhat.thermostat.vm.heap.analysis.client.core.HeapDumpListView.ListAction;
 import com.redhat.thermostat.vm.heap.analysis.common.HeapDump;
 
 @Category(CacioTest.class)
@@ -96,9 +96,9 @@
             @Override
             protected void executeInEDT() throws Throwable {
                 view = new SwingHeapDumpListView();
+                view.setContainerSize(32, 12);
                 frame = new JFrame();
                 frame.add(view.getUiComponent());
-
             }
         });
         frameFixture = new FrameFixture(frame);
@@ -110,20 +110,22 @@
         frameFixture.cleanUp();
         frameFixture = null;
     }
-    
+
     @GUITest
     @Test
     public void testDumpDetailsFired() {
         final boolean [] result = new boolean[1];
         final HeapDump [] selectedHeap = new HeapDump[1];
+        final ListAction[] actionEventId = new ListAction[1];
 
-        view.addListListener(new ActionListener<HeapDumpListView.ListAction>() {
+        view.addListListener(new ActionListener<ListAction>() {
             @Override
-            public void actionPerformed(ActionEvent<HeapDumpListView.ListAction> actionEvent) {
+            public void actionPerformed(ActionEvent<ListAction> actionEvent) {
                 switch (actionEvent.getActionId()) {
                     case OPEN_DUMP_DETAILS:
                         result[0] = true;
                         selectedHeap[0] = (HeapDump) actionEvent.getPayload();
+                        actionEventId[0] = actionEvent.getActionId();
                         break;
                 }
             }
@@ -139,7 +141,7 @@
 
         JLabelFixture label = frameFixture.label("dump1_label");
         label.doubleClick();
-
+        assertEquals(ListAction.OPEN_DUMP_DETAILS, actionEventId[0]);
         assertTrue(result[0]);
         assertEquals(dump1, selectedHeap[0]);
     }
@@ -240,14 +242,16 @@
     public void testExportFired() {
         final boolean [] result = new boolean[1];
         final HeapDump [] selectedHeap = new HeapDump[1];
+        final ListAction[] actionEventId = new ListAction[1];
 
-        view.addListListener(new ActionListener<HeapDumpListView.ListAction>() {
+        view.addListListener(new ActionListener<ListAction>() {
             @Override
-            public void actionPerformed(ActionEvent<HeapDumpListView.ListAction> actionEvent) {
+            public void actionPerformed(ActionEvent<ListAction> actionEvent) {
                 switch (actionEvent.getActionId()) {
                     case EXPORT_DUMP:
                         result[0] = true;
                         selectedHeap[0] = (HeapDump) actionEvent.getPayload();
+                        actionEventId[0] = actionEvent.getActionId();
                         break;
                 }
             }
@@ -260,13 +264,12 @@
         dumps.add(dump1);
 
         view.setDumps(dumps);
-
-        JLabelFixture label = frameFixture.label("dump1_label");
-        label.click();
+        
+        frameFixture.label("dump1_label").click();
 
-        JButtonFixture button = frameFixture.button("dump1_button");
-        button.click();
+        frameFixture.button("dump1_button").click();
 
+        assertEquals(ListAction.EXPORT_DUMP, actionEventId[0]);
         assertTrue(result[0]);
         assertEquals(dump1, selectedHeap[0]);
     }