@@ -1591,13 +1591,70 @@ public void testSetPriority() {
1591
1591
}
1592
1592
}
1593
1593
1594
- /**
1595
- * Tests the API methods Job.setProgressGroup
1596
- */
1597
1594
@ Test
1598
- public void testSetProgressGroup () {
1595
+ public void testSetProgressGroup_withNullGroup () {
1596
+ assertThrows (RuntimeException .class ,
1597
+ () -> new TestJob ("testSetProgressGroup_withNullGroup" ).setProgressGroup (null , 5 ));
1598
+ }
1599
+
1600
+ @ Test
1601
+ public void testSetProgressGroup_withProperGroup () throws InterruptedException {
1602
+ Job job = new TestJob ("testSetProgressGroup_withProperGroup" ) {
1603
+ @ Override
1604
+ public IStatus run (IProgressMonitor monitor ) {
1605
+ monitor .setCanceled (true );
1606
+ return super .run (monitor );
1607
+ }
1608
+ };
1609
+ IProgressMonitor group = Job .getJobManager ().createProgressGroup ();
1610
+ group .beginTask ("Group task name" , 10 );
1611
+ job .setProgressGroup (group , 0 );
1612
+ job .schedule ();
1613
+ job .join ();
1614
+ assertThat ("job progress has not been reported to group monitor" , group .isCanceled ());
1615
+ group .done ();
1616
+ }
1617
+
1618
+ @ Test
1619
+ public void testSetProgressGroup_ignoreWhileWaiting () throws InterruptedException {
1620
+ Job job = new TestJob ("testSetProgressGroup_ignoreWhileWaiting" ) {
1621
+ @ Override
1622
+ public IStatus run (IProgressMonitor monitor ) {
1623
+ monitor .setCanceled (true );
1624
+ return super .run (monitor );
1625
+ }
1626
+ };
1627
+ IProgressMonitor group = Job .getJobManager ().createProgressGroup ();
1628
+ job .schedule (10000 ); // put job to waiting state
1629
+ job .setProgressGroup (group , 0 );
1630
+ job .wakeUp ();
1631
+ job .join ();
1632
+ assertThat ("job progress has unexpectedly been reported to group monitor" , !group .isCanceled ());
1633
+ }
1634
+
1635
+ @ Test
1636
+ public void testSetProgressGroup_ignoreWhileRunning () throws InterruptedException {
1637
+ TestBarrier2 barrier = new TestBarrier2 ();
1638
+ Job job = new TestJob ("testSetProgressGroup_ignoreWhileRunning" ) {
1639
+ @ Override
1640
+ public IStatus run (IProgressMonitor monitor ) {
1641
+ barrier .upgradeTo (TestBarrier2 .STATUS_RUNNING );
1642
+ monitor .setCanceled (true );
1643
+ return super .run (monitor );
1644
+ }
1645
+ };
1646
+ IProgressMonitor group = Job .getJobManager ().createProgressGroup ();
1647
+ job .schedule ();
1648
+ barrier .waitForStatus (TestBarrier2 .STATUS_RUNNING );
1649
+ job .setProgressGroup (group , 0 );
1650
+ job .join ();
1651
+ assertThat ("job progress has unexpectedly been reported to group monitor" , !group .isCanceled ());
1652
+ }
1653
+
1654
+ @ Test
1655
+ public void testSetProgressGroup_cancellationPropagatedToMonitor () {
1599
1656
final TestBarrier2 barrier = new TestBarrier2 ();
1600
- Job job = new Job ("testSetProgressGroup " ) {
1657
+ Job job = new Job ("testSetProgressGroup_cancellationStillWorks " ) {
1601
1658
@ Override
1602
1659
protected IStatus run (IProgressMonitor monitor ) {
1603
1660
barrier .setStatus (TestBarrier2 .STATUS_RUNNING );
@@ -1608,25 +1665,15 @@ protected IStatus run(IProgressMonitor monitor) {
1608
1665
return Status .OK_STATUS ;
1609
1666
}
1610
1667
};
1611
- //null group
1612
- assertThrows (RuntimeException .class , () -> job .setProgressGroup (null , 5 ));
1613
1668
IProgressMonitor group = Job .getJobManager ().createProgressGroup ();
1614
- group .beginTask ("Group task name" , 10 );
1615
- job .setProgressGroup (group , 5 );
1616
-
1617
- //ignore changes to group while waiting or running
1618
- job .schedule (100 );
1619
1669
job .setProgressGroup (group , 0 );
1620
- //wait until job starts and try to set the progress group
1670
+ job . schedule ();
1621
1671
barrier .waitForStatus (TestBarrier2 .STATUS_RUNNING );
1622
- job .setProgressGroup (group , 0 );
1623
-
1624
- //ensure cancelation still works
1625
1672
job .cancel ();
1626
1673
barrier .setStatus (TestBarrier2 .STATUS_WAIT_FOR_DONE );
1627
1674
waitForState (job , Job .NONE );
1628
- assertEquals ( "1.0 " , IStatus . CANCEL , job . getResult (). getSeverity ());
1629
- group . done ( );
1675
+ assertThat ( "job progress has not been reported to group monitor " , group . isCanceled ());
1676
+ assertEquals ( "job was unexpectedly not canceled" , IStatus . CANCEL , job . getResult (). getSeverity () );
1630
1677
}
1631
1678
1632
1679
@ Test
0 commit comments