source: josm/trunk/test/performance/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRendererPerformanceTest.java@ 9458

Last change on this file since 9458 was 9458, checked in by Don-vip, 8 years ago

timeouts for unit/performance tests

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/plain
File size: 3.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm.visitor.paint;
3
4import java.awt.Graphics2D;
5import java.awt.image.BufferedImage;
6import java.io.File;
7import java.io.FileInputStream;
8import java.io.InputStream;
9
10import org.junit.BeforeClass;
11import org.junit.Rule;
12import org.junit.Test;
13import org.junit.rules.Timeout;
14import org.openstreetmap.josm.JOSMFixture;
15import org.openstreetmap.josm.data.Bounds;
16import org.openstreetmap.josm.data.osm.DataSet;
17import org.openstreetmap.josm.gui.NavigatableComponent;
18import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
19import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
20import org.openstreetmap.josm.io.Compression;
21import org.openstreetmap.josm.io.OsmReader;
22
23public class StyledMapRendererPerformanceTest {
24
25 private static final int IMG_WIDTH = 1400;
26 private static final int IMG_HEIGHT = 1050;
27
28 private static Graphics2D g;
29 private static BufferedImage img;
30 private static NavigatableComponent nc;
31 private static DataSet dsRestriction;
32 private static DataSet dsMultipolygon;
33 private static DataSet dsCity;
34
35 /**
36 * Global timeout applied to all test methods.
37 */
38 @Rule
39 public Timeout globalTimeout = Timeout.seconds(15*60);
40
41 @BeforeClass
42 public static void load() throws Exception {
43 JOSMFixture.createPerformanceTestFixture().init();
44 img = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_3BYTE_BGR);
45 g = (Graphics2D) img.getGraphics();
46 nc = new NavigatableComponent();
47 nc.setBounds(0, 0, IMG_WIDTH, IMG_HEIGHT);
48
49 // TODO Test should have it's own copy of styles because change in style can influence performance
50 MapPaintStyles.readFromPreferences();
51
52 try (
53 InputStream fisR = new FileInputStream("data_nodist/restriction.osm");
54 InputStream fisM = new FileInputStream("data_nodist/multipolygon.osm");
55 InputStream fisC = Compression.getUncompressedFileInputStream(new File("data_nodist/neubrandenburg.osm.bz2"));
56 ) {
57 dsRestriction = OsmReader.parseDataSet(fisR, NullProgressMonitor.INSTANCE);
58 dsMultipolygon = OsmReader.parseDataSet(fisM, NullProgressMonitor.INSTANCE);
59 dsCity = OsmReader.parseDataSet(fisC, NullProgressMonitor.INSTANCE);
60 }
61 }
62
63 private static void test(int iterations, DataSet ds, Bounds bounds) throws Exception {
64 Rendering visitor = new StyledMapRenderer(g, nc, false);
65 nc.zoomTo(bounds);
66 for (int i = 0; i < iterations; i++) {
67 visitor.render(ds, true, bounds);
68 }
69 }
70
71 @Test
72 public void testRestriction() throws Exception {
73 test(700, dsRestriction, new Bounds(51.12, 14.147472381591795, 51.128, 14.162492752075195));
74 }
75
76 @Test
77 public void testRestrictionSmall() throws Exception {
78 test(1500, dsRestriction, new Bounds(51.125, 14.147, 51.128, 14.152));
79 }
80
81 @Test
82 public void testMultipolygon() throws Exception {
83 test(400, dsMultipolygon, new Bounds(60, -180, 85, -122));
84 }
85
86 @Test
87 public void testMultipolygonSmall() throws Exception {
88 test(850, dsMultipolygon, new Bounds(-90, -180, 90, 180));
89 }
90
91 @Test
92 public void testCity() throws Exception {
93 test(50, dsCity, new Bounds(53.51, 13.20, 53.59, 13.34));
94 }
95
96 @Test
97 public void testCitySmall() throws Exception {
98 test(70, dsCity, new Bounds(52, 11, 55, 14));
99 }
100
101 @Test
102 public void testCityPart1() throws Exception {
103 test(250, dsCity, new Bounds(53.56, 13.25, 53.57, 13.26));
104 }
105
106 @Test
107 public void testCityPart2() throws Exception {
108 test(200, dsCity, new Bounds(53.55, 13.29, 53.57, 13.30));
109 }
110
111 @Test
112 public void testCitySmallPart2() throws Exception {
113 test(200, dsCity, new Bounds(53.56, 13.295, 53.57, 13.30));
114 }
115}
Note: See TracBrowser for help on using the repository browser.