Skip to content
Permalink
Browse files

Use join() when waiting for a thread to terminate

  • Loading branch information...
danielboudreau danielboudreau
danielboudreau authored and danielboudreau committed Oct 28, 2018
1 parent a9afda3 commit e27c524173ef1fa02a1838188938254355207453
Showing with 238 additions and 192 deletions.
  1. +19 −19 help/en/package/jmri/jmrit/operations/Operations.shtml
  2. +4 −1 java/src/jmri/jmrit/operations/rollingstock/JmritOperationsRollingStockBundle.properties
  3. +4 −4 java/src/jmri/jmrit/operations/rollingstock/cars/JmritOperationsCarsBundle.properties
  4. +4 −4 java/src/jmri/jmrit/operations/rollingstock/cars/JmritOperationsCarsBundle_ca.properties
  5. +4 −4 java/src/jmri/jmrit/operations/rollingstock/cars/JmritOperationsCarsBundle_da.properties
  6. +2 −2 java/src/jmri/jmrit/operations/rollingstock/cars/JmritOperationsCarsBundle_en_GB.properties
  7. +2 −2 java/src/jmri/jmrit/operations/rollingstock/cars/JmritOperationsCarsBundle_ja_JP.properties
  8. +4 −0 java/src/jmri/jmrit/operations/rollingstock/cars/tools/CarAttributeEditFrame.java
  9. +4 −0 java/src/jmri/jmrit/operations/rollingstock/cars/tools/CarLoadEditFrame.java
  10. +1 −1 java/src/jmri/jmrit/operations/rollingstock/engines/JmritOperationsEnginesBundle.properties
  11. +1 −1 java/src/jmri/jmrit/operations/rollingstock/engines/JmritOperationsEnginesBundle_ca.properties
  12. +1 −1 java/src/jmri/jmrit/operations/rollingstock/engines/JmritOperationsEnginesBundle_da.properties
  13. +1 −1 java/src/jmri/jmrit/operations/rollingstock/engines/JmritOperationsEnginesBundle_nl.properties
  14. +10 −10 java/test/jmri/jmrit/operations/automation/actions/GotoActionTest.java
  15. +19 −14 java/test/jmri/jmrit/operations/automation/actions/GotoFailureActionTest.java
  16. +11 −7 java/test/jmri/jmrit/operations/automation/actions/GotoSuccessActionTest.java
  17. +124 −100 java/test/jmri/jmrit/operations/rollingstock/cars/CarEditFrameTest.java
  18. +17 −16 java/test/jmri/jmrit/operations/rollingstock/cars/tools/ImportCarsTest.java
  19. +5 −4 java/test/jmri/jmrit/operations/rollingstock/engines/tools/ImportEnginesTest.java
  20. +1 −1 java/test/jmri/jmrit/operations/trains/tools/PrintTrainManifestActionTest.java
@@ -248,11 +248,11 @@

<li><a href="#Kernel">Kernel (Group of Cars)</a></li>

<li><a href="#EditCarAttributes">Edit Car Attributes (Road, Type, Length, Color,
<li><a href="#EditCarAttributes">Edit Car Attribute Names (Road, Type, Length, Color,
Kernel, Owner)</a>

<ul>
<li><a href="#DeleteUnusedAttributes"> Delete Unused Attributes</a></li>
<li><a href="#DeleteUnusedAttributes"> Delete Unused Attribute Names</a></li>
</ul></li>

<li><a href="#EditCarLoads">Edit Car Loads</a></li>
@@ -1584,7 +1584,7 @@

<h3>Message Format</h3>
If you would like your Manifest and switch lists printed in a tabular (columns) format select the
"Tabular" checkbox. The program determines the maximum character length for each attribute (Road,
"Tabular" checkbox. The program determines the maximum character length for each of the attribute's names (Road,
Number, Type, Length, Color, Load, etc.) when determining the width of each column. Location
names and track names can be up to 25 characters, so you might want to consider reasonable length
names when using the "Tabular" feature. FYI, the program reports the maximum track and location
@@ -1909,7 +1909,7 @@
deselect all types, or "Select All" to select all types, then select or deselect the rolling
stock you wish the location to accept. After configuring the tracks for a location, you can use
the "Auto Select" button to have the location reflect the rolling stock serviced by the various
tracks. See <a href="#EditCarAttributes">Edit Car Attributes</a> to add or delete car types that
tracks. See <a href="#EditCarAttributes">Edit Car Attributes</a> to add or delete car type names that
a location can service. You can also access the "Edit Car Attributes" window from the edit
location "Tools" menu by selecting <a href="#EditCarType">Edit Car Type</a>.

@@ -2003,7 +2003,7 @@
<h4>Edit Car Type</h4>
<p>
This tool opens the car attribute window for car types. This allows you the add, delete, or
replace a car type. See <a href="#EditCarAttributes">Edit Car Attributes</a> for more info.
replace a car type name. See <a href="#EditCarAttributes">Edit Car Attribute Names</a> for more info.
</p>

<a name="ShowCars" id="ShowCars"></a>
@@ -2051,7 +2051,7 @@
If the rolling stock that you wish doesn't appear for a yard, confirm that the location's
rolling stock types are properly selected. If the rolling stock type you want doesn't exist for
a location, you will have to create the type using the <a href="#EditCarAttributes">Edit Car
Attributes</a> window which is also available from the edit location "Tools" menu <a
Attribute Names</a> window which is also available from the edit location "Tools" menu <a
href="#EditCarType">Edit Car Type</a>.
</p>

@@ -2274,7 +2274,7 @@

<p>
If you want custom <a href="#CarLoad">loads</a> for your cars, you can create them using the <a
href="#EditCarLoads">Edit Car Attributes</a> for car "Load". Each new load is associated with
href="#EditCarLoads">Edit Car Loads</a>. Each new load name is associated with
the car type. For example you can have "Freight" for a boxcar, and "Oil" for a tankcar. The
program will deliver cars with a custom load to a spur that has a schedule that also requests
that particular load. However, cars with a custom load can still be placed at yards, staging,
@@ -3229,38 +3229,38 @@
created each time the "Save" button is pressed.</p>

<a name="EditCarAttributes" id="EditCarAttributes"></a>
<h3>Edit Car Attributes</h3>
<h3>Edit Car Attribute Names</h3>
To the right of each of the car attributes (Road, Type, Length, Color, Kernel, Load, Owner) in
the <a href="#CarsEdit">Edit Car</a> or <a href="#CarsEdit">Add Car</a> window is an "Edit"
button. Use this to add, delete, or replace the various attributes for a car.
button. Use this to add, delete, or replace the various attribute names for a car.

<p>
<img src="images/EditCarAttribute.png">
</p>

<h4>Add Button</h4>
To add a new car attribute, enter the desired text in the text box and press the "Add" button.
When you first enter a new car attribute it will show up at the start of the list. Later when
To add a new car attribute name, enter the desired text in the text box and press the "Add" button.
When you first enter a new car attribute name, it will show up at the start of the list. Later when
your restart the program it will be sorted in the correct order.

<h4>Delete Button</h4>
To delete a car attribute, select the attribute you want to delete in the menu box and press the
To delete a car attribute name, select the name you want to delete in the menu box and press the
"Delete" button.

<h4>Replace Button</h4>
If you need to change a specific car attribute (road, type, color, etc) in your entire car
If you need to change a specific car attribute name (road, type, color, etc) in your entire car
roster, you can use the "Replace" button found at the bottom right of the edit car attribute
window. For example, if you wish to change the car road (reporting mark) attribute "UP" to "UPS"
window. For example, if you wish to change the car road (reporting mark) attribute name "UP" to "UPS"
for all of your cars. Press the "Edit" button for any of your cars in the Cars window, and then
press the "Edit" button across from Road in the "Car Edit" window. Enter the new road "UPS" in
the text box, select "UP" in the menu box, and press "Replace". All cars with "UP" as their road
will now have "UPS" as their road.
the text box, select "UP" in the menu box, and press "Replace". All cars with "UP" as their road name
will now have "UPS" as their road name.

<a name="DeleteUnusedAttributes" id="DeleteUnusedAttributes"></a>
<h4>Delete Unused Attributes</h4>
Under "Tools" in the "Edit Attribute Window" you will find two items, "Show the number of cars with this attribute" and "Delete unused attributes".
<h4>Delete Unused Attribute Names</h4>
Under "Tools" in the "Edit Attribute Window" you will find two items, "Show the number of cars with this attribute name" and "Delete unused attribute names".
The first will show a count in front of the menu box. The count is the number of'cars that have this particular
attribute. The delete option will prompt you to delete any attribute that hasn't been assigned to a car.
attribute name. The delete option will prompt you to delete any attribute name that hasn't been assigned to a car.

<a name="EditCarLoads" id="EditCarLoads"></a>
<h3>Edit Car Loads</h3>
@@ -31,7 +31,10 @@ BorderLayoutOptionalProgram = Optional -- Normally Set by Program --
rsTipAutoTrain = When checked, show only available trains for this car
TipIgnore = When checked, ignore this set of fields during change
TipLocationUnknown = When checked, add comment to manifest to search for this car
TipAddDeleteReplace = Add, delete or replace {0}
TipAddDeleteReplace = Add, delete or replace {0} names
TipAddAttributeName = Add {0} Name
TipDeleteAttributeName = Delete Selected {0} Name
TipReplaceAttributeName = Replace Selected {0} Name

# Import Rolling Stock
MenuItemImport = Import from file
@@ -45,7 +45,7 @@ BorderLayoutFontSize = Font Size
(P) = (P)

RoadNumMustBeLess = Car road number must be less than {0} characters
carAttribute = Car attribute must be {0} characters or less
carAttribute = Car attribute names must be {0} characters or less
canNotAdd = Can not add {0}
canNotReplace = Can not replace {0}
canNotDelete = Can not delete {0}
@@ -233,9 +233,9 @@ MenuItemResetMoves = Reset move count all cars
MenuEnableDestination = Enable Destination
MenuDeleteCarsTrack = Delete cars on track {0}

CarQuantity = Show the number of cars with this attribute
DeleteUnusedAttributes = Delete unused attributes
DeleteAttribute? = Delete Attribute?
CarQuantity = Show the number of cars with this attribute name
DeleteUnusedAttributes = Delete unused attribute names
DeleteAttribute? = Delete Attribute Name?
ConfirmDeleteAttribute = Do you really want to delete {0} {1}?

# print options
@@ -52,7 +52,7 @@ road = road
load = load

RoadNumMustBeLess = Car road number must be less than {0} characters
carAttribute = Car attribute must be {0} characters or less
carAttribute = Car attribute name must be {0} characters or less
canNotAdd = Can not add {0}
canNotReplace = Can not replace {0}
canNotDelete = Can not delete {0}
@@ -240,9 +240,9 @@ MenuItemResetMoves = Reset move count all cars
MenuEnableDestination = Enable Destination
MenuDeleteCarsTrack = Delete cars on track {0}

CarQuantity = Show the number of cars with this attribute
DeleteUnusedAttributes = Delete unused attributes
DeleteAttribute? = Delete Attribute?
CarQuantity = Show the number of cars with this attribute name
DeleteUnusedAttributes = Delete unused attribute names
DeleteAttribute? = Delete Attribute Name?
ConfirmDeleteAttribute = Do you really want to delete {0} {1}?

# print options
@@ -47,7 +47,7 @@ BorderLayoutFontSize = Skrift St\u00f8rrelse
(P) = (P)

RoadNumMustBeLess = Vognens road nummer skal v\u00e6re mindre end {0} tegn
carAttribute = Car attribute must be {0} characters or less
carAttribute = Car attribute names must be {0} characters or less
canNotAdd = Can not add {0}
canNotReplace = Can not replace {0}
canNotDelete = Can not delete {0}
@@ -221,9 +221,9 @@ MenuItemResetMoves = Reset move count all cars
MenuEnableDestination = Enable Destination
MenuDeleteCarsTrack = Delete cars on track {0}

CarQuantity = Show the number of cars with this attribute
DeleteUnusedAttributes = Delete unused attributes
DeleteAttribute? = Delete Attribute?
CarQuantity = Show the number of cars with this attribute name
DeleteUnusedAttributes = Delete unused attribute names
DeleteAttribute? = Delete Attribute Name?
ConfirmDeleteAttribute = Do you really want to delete {0} {1}?

# print options
@@ -16,7 +16,7 @@ TitleCarEditAtrribute = Edit Wagon {0}
road = railway

RoadNumMustBeLess = Wagon railway number must be less than {0} characters
carAttribute = Wagon attribute must be {0} characters or less
carAttribute = Wagon attribute names must be {0} characters or less
RoadNumTooLong = Wagon railway number too long!
carRoadExists = Wagon with this railway name and number already exists!
carCanNotAdd = Can not add wagon!
@@ -101,7 +101,7 @@ AddNewCarType = Add new wagon type to service?
MenuItemDelete = Delete all wagons
MenuDeleteCarsTrack = Delete wagons on track {0}

CarQuantity = Show the number of wagons with this attribute
CarQuantity = Show the number of wagons with this attribute name

# print options
PrintCarsWithLocation= Only print wagons with a location
@@ -17,7 +17,7 @@ TitleCarEditLoad = Edit {0} Loads
(H) = (H)

RoadNumMustBeLess = Car road number must be less than {0} characters
carAttribute = Car attribute must be {0} characters or less
carAttribute = Car attribute names must be {0} characters or less
canNotAdd = Can not add {0}
canNotReplace = Can not replace {0}
canNotDelete = Can not delete {0}
@@ -61,7 +61,7 @@ carDefault = Load and Empty defaults must be unique
carNameNoAndChar = Can''t have the characters "{0}" in the name
EmptyCar = E
LoadedCar = L
CarQuantity = Show the number of cars with this attribute
CarQuantity = Show the number of cars with this attribute name

# tool tips
TipBuildDate = Enter the year that the car was built, use 4 digits
@@ -117,6 +117,10 @@ public void initComponents(String comboboxName, String select) {

addComboBoxAction(comboBox);
carManager.addPropertyChangeListener(this);

deleteButton.setToolTipText( MessageFormat.format(Bundle.getMessage("TipDeleteAttributeName"), new Object[]{comboboxName}));
addButton.setToolTipText( MessageFormat.format(Bundle.getMessage("TipAddAttributeName"), new Object[]{comboboxName}));
replaceButton.setToolTipText( MessageFormat.format(Bundle.getMessage("TipReplaceAttributeName"), new Object[]{comboboxName}));

// build menu
JMenuBar menuBar = new JMenuBar();
@@ -98,6 +98,10 @@ public void initComponents(String type, String selectedItem) {

// row 4
addItem(pLoad, replaceButton, 3, 4);

deleteButton.setToolTipText( MessageFormat.format(Bundle.getMessage("TipDeleteAttributeName"), new Object[]{Bundle.getMessage("Load")}));
addButton.setToolTipText( MessageFormat.format(Bundle.getMessage("TipAddAttributeName"), new Object[]{Bundle.getMessage("Load")}));
replaceButton.setToolTipText( MessageFormat.format(Bundle.getMessage("TipReplaceAttributeName"), new Object[]{Bundle.getMessage("Load")}));

// row 6
JPanel pLoadType = new JPanel();
@@ -21,7 +21,7 @@ BUnit = B Unit
(B) = (B)

RoadNumMustBeLess = Locomotive road number must be less than 10 characters
engineAttribute = Locomotive attribute must be {0} characters or less
engineAttribute = Locomotive attribute name must be {0} characters or less
canNotAdd = Can not add {0}
canNotReplace = Can not replace {0}
RoadNumTooLong = Locomotive road number too long!
@@ -23,7 +23,7 @@ BUnit = Unitat B
(B) = (B)

RoadNumMustBeLess = El n\u00famero de s\u00e8rie de la Locomotora ha de ser m\u00e9s curt de 10 car\u00e0cters
engineAttribute = Locomotive attribute must be {0} characters or less
engineAttribute = Locomotive attribute name must be {0} characters or less
canNotAdd = Can not add {0}
canNotReplace = Can not replace {0}
RoadNumTooLong = Locomotive road number too long!
@@ -22,7 +22,7 @@ Hp = Horsepower
HP = HP

RoadNumMustBeLess = Locomotive road number must be less than 10 characters
engineAttribute = Locomotive attribute must be {0} characters or less
engineAttribute = Locomotive attribute name must be {0} characters or less
canNotAdd = Can not add {0}
canNotReplace = Can not replace {0}
RoadNumTooLong = Locomotive road number too long!
@@ -23,7 +23,7 @@ BUnit = B Eenheid
(B) = (B)

RoadNumMustBeLess = Locomotive road number must be less than 10 characters
engineAttribute = Locomotive attribute must be {0} characters or less
engineAttribute = Locomotive attribute name must be {0} characters or less
canNotAdd = Can not add {0}
canNotReplace = Can not replace {0}
RoadNumTooLong = Locomotive road number too long!
@@ -118,23 +118,23 @@ public void testAction() {
automation.run();

Thread run = JUnitUtil.getThreadByName("Run action item: " + automationItem1.getId());

if (run != null) {
jmri.util.JUnitUtil.waitFor(() -> {
return run.getState().equals(Thread.State.TERMINATED);
}, "wait for terminated");
try {
run.join();
} catch (InterruptedException e) {
// do nothing
}

Assert.assertTrue(automationItem1.isActionSuccessful());
Assert.assertTrue(automationItem1.isActionRan());
Assert.assertFalse(automationItem1.isActionRunning());

Thread run2 = JUnitUtil.getThreadByName("Run action item: " + automationItem2.getId());

if (run2 != null) {
jmri.util.JUnitUtil.waitFor(() -> {
return run2.getState().equals(Thread.State.TERMINATED);
}, "wait for terminated");
try {
run2.join();
} catch (InterruptedException e) {
// do nothing
}

// the first halt
@@ -13,16 +13,16 @@

/**
*
* @author Paul Bender Copyright (C) 2017
* @author Paul Bender Copyright (C) 2017
*/
public class GotoFailureActionTest extends OperationsTestCase {

@Test
public void testCTor() {
GotoFailureAction t = new GotoFailureAction();
Assert.assertNotNull("exists",t);
Assert.assertNotNull("exists", t);
}

@Test
public void testActionNoAutomationItem() {
GotoFailureAction action = new GotoFailureAction();
@@ -62,7 +62,7 @@ public void testAction() {

AutomationItem automationItem3 = automation.addItem();
automationItem3.setAction(new HaltAction());

AutomationItem automationItem4 = automation.addItem();
automationItem4.setAction(new HaltAction());

@@ -74,28 +74,32 @@ public void testAction() {
Thread run = JUnitUtil.getThreadByName("Run action item: " + automationItem1.getId());

if (run != null) {
jmri.util.JUnitUtil.waitFor(() -> {
return run.getState().equals(Thread.State.TERMINATED);
}, "wait for terminated");
try {
run.join();
} catch (InterruptedException e) {
// do nothing
}
}

Assert.assertTrue(automationItem1.isActionSuccessful());
Assert.assertTrue(automationItem1.isActionRan());
Assert.assertFalse(automationItem1.isActionRunning());

Thread run2 = JUnitUtil.getThreadByName("Run action item: " + automationItem3.getId());

if (run2 != null) {
jmri.util.JUnitUtil.waitFor(() -> {
return run2.getState().equals(Thread.State.TERMINATED);
}, "wait for terminated");
try {
run2.join();
} catch (InterruptedException e) {
// do nothing
}
}

// the first halt is jumped over
Assert.assertFalse(automationItem2.isActionSuccessful());
Assert.assertFalse(automationItem2.isActionRan());
Assert.assertFalse(automationItem2.isActionRunning());

// the 2nd halt is goto address
Assert.assertTrue(automationItem3.isActionSuccessful());
Assert.assertTrue(automationItem3.isActionRan());
@@ -112,7 +116,8 @@ public void testAction() {
@Override
@Before
public void setUp() {
super.setUp(); }
super.setUp();
}

@Override
@After

0 comments on commit e27c524

Please sign in to comment.
You can’t perform that action at this time.