tile38/internal/client/pool_test.go
tidwall 6257ddba78 Faster point in polygon / GeoJSON updates
The big change is that the GeoJSON package has been completely
rewritten to fix a few of geometry calculation bugs, increase
performance, and to better follow the GeoJSON spec RFC 7946.

GeoJSON updates

- A LineString now requires at least two points.
- All json members, even foreign, now persist with the object.
- The bbox member persists too but is no longer used for geometry
  calculations. This is change in behavior. Previously Tile38 would
  treat the bbox as the object's physical rectangle.
- Corrections to geometry intersects and within calculations.

Faster spatial queries

- The performance of Point-in-polygon and object intersect operations
  are greatly improved for complex polygons and line strings. It went
  from O(n) to roughly O(log n).
- The same for all collection types with many children, including
  FeatureCollection, GeometryCollection, MultiPoint, MultiLineString,
  and MultiPolygon.

Codebase changes

- The pkg directory has been renamed to internal
- The GeoJSON internal package has been moved to a seperate repo at
  https://github.com/tidwall/geojson. It's now vendored.

Please look out for higher memory usage for datasets using complex
shapes. A complex shape is one that has 64 or more points. For these
shapes it's expected that there will be increase of least 54 bytes per
point.
2018-10-13 04:30:48 -07:00

68 lines
1.4 KiB
Go

package client
import (
"encoding/json"
"fmt"
"math/rand"
"strings"
"sync"
"testing"
"time"
)
func TestPool(t *testing.T) {
rand.Seed(time.Now().UnixNano())
pool, err := DialPool("localhost:9876")
if err != nil {
t.Fatal(err)
}
defer pool.Close()
var wg sync.WaitGroup
wg.Add(25)
for i := 0; i < 25; i++ {
go func(i int) {
defer func() {
wg.Done()
}()
conn, err := pool.Get()
if err != nil {
t.Fatal(err)
}
defer conn.Close()
msg, err := conn.Do("PING")
if err != nil {
t.Fatal(err)
}
var m map[string]interface{}
if err := json.Unmarshal([]byte(msg), &m); err != nil {
t.Fatal(err)
}
if ok1, ok2 := m["ok"].(bool); !ok1 || !ok2 {
t.Fatal("not ok")
}
if pong, ok := m["ping"].(string); !ok || pong != "pong" {
t.Fatal("not pong")
}
defer conn.Do(fmt.Sprintf("drop test:%d", i))
msg, err = conn.Do(fmt.Sprintf("drop test:%d", i))
if err != nil {
t.Fatal(err)
}
if !strings.HasPrefix(string(msg), `{"ok":true`) {
t.Fatal("expecting OK:TRUE response")
}
for j := 0; j < 100; j++ {
lat, lon := rand.Float64()*180-90, rand.Float64()*360-180
msg, err = conn.Do(fmt.Sprintf("set test:%d %d point %f %f", i, j, lat, lon))
if err != nil {
t.Fatal(err)
}
if !strings.HasPrefix(string(msg), `{"ok":true`) {
t.Fatal("expecting OK:TRUE response")
}
}
}(i)
}
wg.Wait()
}