Changeset 14052 in josm for trunk/test/unit/org/openstreetmap/josm/TestUtils.java
- Timestamp:
- 2018-07-26T22:01:31+02:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/TestUtils.java
r13742 r14052 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertArrayEquals; 6 import static org.junit.Assert.assertTrue; 5 7 import static org.junit.Assert.fail; 6 8 … … 9 11 import java.awt.Graphics2D; 10 12 import java.io.File; 13 import java.io.FileInputStream; 11 14 import java.io.IOException; 12 15 import java.io.InputStream; … … 23 26 import java.util.Comparator; 24 27 import java.util.Objects; 28 import java.util.concurrent.ExecutionException; 29 import java.util.concurrent.ThreadPoolExecutor; 25 30 import java.util.stream.Stream; 26 31 … … 34 39 import org.openstreetmap.josm.data.osm.RelationMember; 35 40 import org.openstreetmap.josm.data.osm.Way; 41 import org.openstreetmap.josm.gui.MainApplication; 36 42 import org.openstreetmap.josm.gui.progress.AbstractProgressMonitor; 37 43 import org.openstreetmap.josm.gui.progress.CancelHandler; 38 44 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 39 45 import org.openstreetmap.josm.gui.progress.ProgressTaskId; 46 import org.openstreetmap.josm.gui.util.GuiHelper; 40 47 import org.openstreetmap.josm.io.Compression; 41 48 import org.openstreetmap.josm.testutils.FakeGraphics; … … 45 52 import com.github.tomakehurst.wiremock.WireMockServer; 46 53 import com.github.tomakehurst.wiremock.core.WireMockConfiguration; 54 55 import com.google.common.io.ByteStreams; 47 56 48 57 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 429 438 return getHTTPDate(Instant.ofEpochMilli(time)); 430 439 } 440 441 /** 442 * Throws AssertionError if contents of both files are not equal 443 * @param fileA File A 444 * @param fileB File B 445 */ 446 public static void assertFileContentsEqual(final File fileA, final File fileB) { 447 assertTrue(fileA.exists()); 448 assertTrue(fileA.canRead()); 449 assertTrue(fileB.exists()); 450 assertTrue(fileB.canRead()); 451 try { 452 try ( 453 FileInputStream streamA = new FileInputStream(fileA); 454 FileInputStream streamB = new FileInputStream(fileB); 455 ) { 456 assertArrayEquals( 457 ByteStreams.toByteArray(streamA), 458 ByteStreams.toByteArray(streamB) 459 ); 460 } 461 } catch (IOException e) { 462 fail(e.toString()); 463 } 464 } 465 466 /** 467 * Waits until any asynchronous operations launched by the test on the EDT or worker threads have 468 * (almost certainly) completed. 469 */ 470 public static void syncEDTAndWorkerThreads() { 471 boolean workerQueueEmpty = false; 472 while (!workerQueueEmpty) { 473 try { 474 // once our own task(s) have made it to the front of their respective queue(s), 475 // they're both executing at the same time and we know there aren't any outstanding 476 // worker tasks, then presumably the only way there could be incomplete operations 477 // is if the EDT had launched a deferred task to run on itself or perhaps set up a 478 // swing timer - neither are particularly common patterns in JOSM (?) 479 // 480 // there shouldn't be a risk of creating a deadlock in doing this as there shouldn't 481 // (...couldn't?) be EDT operations waiting on the results of a worker task. 482 workerQueueEmpty = MainApplication.worker.submit( 483 () -> GuiHelper.runInEDTAndWaitAndReturn( 484 () -> ((ThreadPoolExecutor) MainApplication.worker).getQueue().isEmpty() 485 ) 486 ).get(); 487 } catch (InterruptedException | ExecutionException e) { 488 // inconclusive - retry... 489 workerQueueEmpty = false; 490 } 491 } 492 } 431 493 }
Note:
See TracChangeset
for help on using the changeset viewer.