forked from omniscale/imposm3
-
Notifications
You must be signed in to change notification settings - Fork 1
/
expire_tiles_test.go
219 lines (195 loc) · 6.53 KB
/
expire_tiles_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package test
import (
"bufio"
"database/sql"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"testing"
"github.com/omniscale/imposm3/geom/geos"
)
func TestExpireTiles(t *testing.T) {
if testing.Short() {
t.Skip("system test skipped with -test.short")
}
t.Parallel()
ts := importTestSuite{
name: "expire_tiles",
}
t.Run("Prepare", func(t *testing.T) {
var err error
ts.dir, err = ioutil.TempDir("", "imposm_test")
if err != nil {
t.Fatal(err)
}
ts.config = importConfig{
connection: "postgis:https://",
cacheDir: ts.dir,
osmFileName: "build/expire_tiles.pbf",
mappingFileName: "expire_tiles_mapping.yml",
expireTileDir: filepath.Join(ts.dir, "expiretiles"),
}
ts.g = geos.NewGeos()
ts.db, err = sql.Open("postgres", "sslmode=disable")
if err != nil {
t.Fatal(err)
}
ts.dropSchemas()
})
t.Run("Import", func(t *testing.T) {
if ts.tableExists(t, ts.dbschemaImport(), "osm_roads") != false {
t.Fatalf("table osm_roads exists in schema %s", ts.dbschemaImport())
}
ts.importOsm(t)
ts.deployOsm(t)
if ts.tableExists(t, ts.dbschemaProduction(), "osm_roads") != true {
t.Fatalf("table osm_roads does not exists in schema %s", ts.dbschemaProduction())
}
})
t.Run("Elements", func(t *testing.T) {
ts.assertRecords(t, []checkElem{
{"osm_roads", 20151, "motorway", nil},
{"osm_roads", 20251, "motorway", nil},
{"osm_roads", 20351, "motorway", nil},
{"osm_roads", 20651, "motorway", nil},
{"osm_buildings", -30191, "yes", nil},
{"osm_buildings", -30291, "yes", nil},
{"osm_buildings", -30391, "yes", nil},
{"osm_buildings", -30491, "yes", nil},
})
})
t.Run("Update", func(t *testing.T) {
ts.updateOsm(t, "build/expire_tiles.osc.gz")
})
t.Run("CheckExpireFile", func(t *testing.T) {
files, err := filepath.Glob(filepath.Join(ts.config.expireTileDir, "*", "*.tiles"))
if err != nil {
t.Fatal(err)
}
if len(files) != 1 {
t.Fatalf("expected one expire tile file, got: %v", files)
}
tiles, err := parseTileList(files[0])
if err != nil {
t.Error(err)
}
for _, test := range []struct {
reason string
tiles []tile
expire bool
}{
{"create node", []tile{{8328, 8146, 14}}, true},
{"modify node (old)", []tile{{8237, 8146, 14}}, true},
{"modify node (new)", []tile{{8237, 8237, 14}}, true},
{"modify node to unmapped (old)", []tile{{8373, 8146, 14}, {8374, 8146, 14}}, true},
{"modify node to unmapped (new)", []tile{{8373, 8146, 14}, {8374, 8146, 14}}, false},
{"delete node", []tile{{8282, 8146, 14}, {8283, 8146, 14}}, true},
{"delete way", []tile{{8283, 8100, 14}}, true},
{"modify way", []tile{{8237, 8100, 14}}, true},
{"modify way from node (old)", []tile{{8328, 8100, 14}}, true},
{"modify way from node (new)", []tile{{8328, 8283, 14}}, true},
{"create way", []tile{{8374, 8100, 14}}, true},
{"create long way", []tile{{8419, 8100, 14}, {8420, 8100, 14}, {8421, 8100, 14}}, true},
{"delete way including its nodes", []tile{{8465, 8100, 14}}, true},
{"modify relation", []tile{{8237, 8055, 14}}, true},
{"delete relation", []tile{{8283, 8055, 14}}, true},
{"modify relation from way", []tile{{8328, 8055, 14}}, true},
{"modify relation from nodes (old)", []tile{{8374, 8055, 14}}, true},
{"modify relation from nodes (new)", []tile{{8374, 8328, 14}}, true},
{"create polygon (box)", []tile{
{8237, 8007, 14},
{8237, 8008, 14},
{8237, 8009, 14},
{8238, 8007, 14},
{8238, 8008, 14},
{8238, 8009, 14},
{8239, 8007, 14},
{8239, 8008, 14},
{8239, 8009, 14},
}, true},
{"create polygon (outline)", []tile{
{8310, 8005, 14}, {8302, 7991, 14}, {8283, 7993, 14},
{8300, 8009, 14}, {8283, 8003, 14}, {8308, 8009, 14},
{8310, 7995, 14}, {8285, 8009, 14}, {8288, 8009, 14},
{8301, 8009, 14}, {8310, 8002, 14}, {8302, 8009, 14},
{8310, 8003, 14}, {8286, 8009, 14}, {8300, 7991, 14},
{8283, 7994, 14}, {8296, 8009, 14}, {8298, 8009, 14},
{8310, 8009, 14}, {8283, 7999, 14}, {8283, 7992, 14},
{8290, 7991, 14}, {8305, 8009, 14}, {8309, 7991, 14},
{8306, 7991, 14}, {8291, 7991, 14}, {8283, 7996, 14},
{8310, 7996, 14}, {8293, 7991, 14}, {8310, 8007, 14},
{8310, 8001, 14}, {8307, 8009, 14}, {8299, 8009, 14},
{8310, 7998, 14}, {8310, 7999, 14}, {8301, 7991, 14},
{8283, 7998, 14}, {8283, 8006, 14}, {8289, 8009, 14},
{8310, 8008, 14}, {8285, 7991, 14}, {8283, 8002, 14},
{8289, 7991, 14}, {8286, 7991, 14}, {8288, 7991, 14},
{8283, 8008, 14}, {8283, 8005, 14}, {8310, 7992, 14},
{8310, 8004, 14}, {8310, 7991, 14}, {8296, 7991, 14},
{8292, 7991, 14}, {8283, 8009, 14}, {8291, 8009, 14},
{8293, 8009, 14}, {8284, 8009, 14}, {8287, 7991, 14},
{8297, 8009, 14}, {8283, 8007, 14}, {8299, 7991, 14},
{8310, 7997, 14}, {8303, 8009, 14}, {8290, 8009, 14},
{8306, 8009, 14}, {8283, 7995, 14}, {8283, 8000, 14},
{8295, 8009, 14}, {8310, 8006, 14}, {8304, 8009, 14},
{8295, 7991, 14}, {8292, 8009, 14}, {8309, 8009, 14},
{8283, 8004, 14}, {8307, 7991, 14}, {8305, 7991, 14},
{8283, 8001, 14}, {8284, 7991, 14}, {8297, 7991, 14},
{8310, 7993, 14}, {8303, 7991, 14}, {8294, 8009, 14},
{8287, 8009, 14}, {8283, 7991, 14}, {8283, 7997, 14},
{8308, 7991, 14}, {8304, 7991, 14}, {8298, 7991, 14},
{8310, 8000, 14}, {8310, 7994, 14}, {8294, 7991, 14},
}, true},
} {
for _, coord := range test.tiles {
if test.expire {
if _, ok := tiles[coord]; !ok {
t.Errorf("missing expire tile for %s %v", test.reason, coord)
} else {
delete(tiles, coord)
}
} else {
if _, ok := tiles[coord]; ok {
t.Errorf("found expire tile for %s %v", test.reason, coord)
}
}
}
}
if len(tiles) > 0 {
t.Errorf("found %d unexpected tiles", len(tiles))
}
for tile := range tiles {
t.Errorf("unexpected tile expired: %v", tile)
}
})
t.Run("Cleanup", func(t *testing.T) {
ts.dropSchemas()
if err := os.RemoveAll(ts.dir); err != nil {
t.Error(err)
}
})
}
type tile struct {
x, y, z int
}
func parseTileList(filename string) (map[tile]struct{}, error) {
file, err := os.Open(filename)
if err != nil {
return nil, err
}
defer file.Close()
scanner := bufio.NewScanner(file)
tiles := make(map[tile]struct{})
for scanner.Scan() {
parts := strings.Split(scanner.Text(), "/")
z, _ := strconv.ParseInt(parts[0], 10, 32)
x, _ := strconv.ParseInt(parts[1], 10, 32)
y, _ := strconv.ParseInt(parts[2], 10, 32)
tiles[tile{x: int(x), y: int(y), z: int(z)}] = struct{}{}
}
if err := scanner.Err(); err != nil {
return nil, err
}
return tiles, nil
}