JAL-1889 corrected wait for consensus to be calculated
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 21 Apr 2020 11:34:13 +0000 (12:34 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 21 Apr 2020 11:34:13 +0000 (12:34 +0100)
test/jalview/gui/AlignFrameTest.java
test/jalview/gui/AlignViewportTest.java
test/jalview/gui/AlignmentPanelTest.java
test/jalview/schemes/PIDColourSchemeTest.java

index d2284f1..d362d35 100644 (file)
@@ -27,6 +27,14 @@ import static org.testng.Assert.assertNotSame;
 import static org.testng.Assert.assertSame;
 import static org.testng.Assert.assertTrue;
 
+import java.awt.Color;
+import java.util.Iterator;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
 import jalview.api.FeatureColourI;
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
@@ -49,14 +57,6 @@ import jalview.schemes.StrandColourScheme;
 import jalview.schemes.TurnColourScheme;
 import jalview.util.MessageManager;
 
-import java.awt.Color;
-import java.util.Iterator;
-
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
 public class AlignFrameTest
 {
   AlignFrame af;
@@ -94,18 +94,15 @@ public class AlignFrameTest
     /*
      * wait for Consensus thread to complete
      */
-    synchronized (this)
+    do
     {
-      while (af.getViewport().getConsensusSeq() == null)
+      try
+      {
+        Thread.sleep(50);
+      } catch (InterruptedException x)
       {
-        try
-        {
-          wait(50);
-        } catch (InterruptedException e)
-        {
-        }
       }
-    }
+    } while (af.getViewport().getCalcManager().isWorking());
   }
 
   public static void setUpJvOptionPane()
@@ -358,7 +355,7 @@ public class AlignFrameTest
 
     /*
      * inspect the colour of 
-     * FER_CAPAN.9(I), column 14 (14 base 0)
+     * FER_CAPAN.9(I), column 15 (14 base 0)
      * FER_CAPAN.10(SER), column 16 (15 base 0)
      */
     SequenceI ferCapan = al.findName("FER_CAPAN");
@@ -377,10 +374,14 @@ public class AlignFrameTest
     SliderPanel sp = SliderPanel.getSliderPanel();
     assertTrue(sp.isForConservation());
     assertEquals(sp.getValue(), 30); // initial slider setting
+    c = rs.findColour('I', 14, ferCapan);
+    Color i_faded = new Color(255, 255, 255);
+    assertEquals(c, i_faded);
     sp.valueChanged(10);
     assertSame(rs, av.getResidueShading());
+    assertEquals(rs.getConservationInc(), 10);
     c = rs.findColour('I', 14, ferCapan);
-    Color i_faded = new Color(196, 186, 196);
+    i_faded = new Color(196, 186, 196);
     assertEquals(c, i_faded);
     c = rs.findColour('S', 15, ferCapan);
     Color s_faded = new Color(144, 225, 144);
index 4e15dba..00267b3 100644 (file)
@@ -297,6 +297,26 @@ public class AlignViewportTest
      * wait for Conservation thread to complete
      */
     AlignViewport viewport = af.getViewport();
+    waitForCalculations(viewport);
+    AlignmentAnnotation[] anns = viewport.getAlignment()
+            .getAlignmentAnnotation();
+    assertNotNull("No annotations found", anns);
+    assertEquals("More than one annotation found", 1, anns.length);
+    assertTrue("Annotation is not Quality",
+            anns[0].description.startsWith("Alignment Quality"));
+    Annotation[] annotations = anns[0].annotations;
+    assertNotNull("Quality annotations are null", annotations);
+    assertNotNull("Quality in column 1 is null", annotations[0]);
+    assertTrue("No quality value in column 1", annotations[0].value > 10f);
+  }
+
+  /**
+   * Wait for consensus etc calculation threads to complete
+   * 
+   * @param viewport
+   */
+  protected void waitForCalculations(AlignViewport viewport)
+  {
     synchronized (this)
     {
       while (viewport.getCalcManager().isWorking())
@@ -309,16 +329,6 @@ public class AlignViewportTest
         }
       }
     }
-    AlignmentAnnotation[] anns = viewport.getAlignment()
-            .getAlignmentAnnotation();
-    assertNotNull("No annotations found", anns);
-    assertEquals("More than one annotation found", 1, anns.length);
-    assertTrue("Annotation is not Quality",
-            anns[0].description.startsWith("Alignment Quality"));
-    Annotation[] annotations = anns[0].annotations;
-    assertNotNull("Quality annotations are null", annotations);
-    assertNotNull("Quality in column 1 is null", annotations[0]);
-    assertTrue("No quality value in column 1", annotations[0].value > 10f);
   }
 
   @Test(groups = { "Functional" })
@@ -466,6 +476,7 @@ public class AlignViewportTest
     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(fasta,
             DataSourceType.PASTE);
     AlignViewport testme = af.getViewport();
+    waitForCalculations(testme);
     SequenceI cons = testme.getConsensusSeq();
     assertEquals("A-C", cons.getSequenceAsString());
   }
index 3ec8b4d..8871249 100644 (file)
@@ -69,18 +69,15 @@ public class AlignmentPanelTest
     /*
      * wait for Consensus thread to complete
      */
-    synchronized (this)
+    do
     {
-      while (af.getViewport().getConsensusSeq() == null)
+      try
+      {
+        Thread.sleep(50);
+      } catch (InterruptedException x)
       {
-        try
-        {
-          wait(50);
-        } catch (InterruptedException e)
-        {
-        }
       }
-    }
+    } while (af.getViewport().getCalcManager().isWorking());
   }
 
   /**
index fa4b5d9..8a584f6 100644 (file)
@@ -2,16 +2,16 @@ package jalview.schemes;
 
 import static org.testng.Assert.assertEquals;
 
+import java.awt.Color;
+
+import org.testng.annotations.Test;
+
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.gui.AlignViewport;
 import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
 
-import java.awt.Color;
-
-import org.testng.annotations.Test;
-
 public class PIDColourSchemeTest
 {
   static final Color white = Color.white;
@@ -85,18 +85,15 @@ public class PIDColourSchemeTest
             DataSourceType.PASTE);
     AlignViewport viewport = af.getViewport();
     viewport.setIgnoreGapsConsensus(false, af.alignPanel);
-    while (viewport.getConsensusSeq() == null)
+    do
     {
-      synchronized (this)
+      try
+      {
+        Thread.sleep(50);
+      } catch (InterruptedException x)
       {
-        try
-        {
-          wait(50);
-        } catch (InterruptedException e)
-        {
-        }
       }
-    }
+    } while (af.getViewport().getCalcManager().isWorking());
     af.changeColour_actionPerformed(JalviewColourScheme.PID.toString());
 
     SequenceI seq = viewport.getAlignment().getSequenceAt(0);