
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.
124 lines
3.4 KiB
Go
124 lines
3.4 KiB
Go
// Copyright 2015-2018 The NATS Authors
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package test
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"runtime"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/nats-io/gnatsd/server"
|
|
"github.com/nats-io/go-nats"
|
|
|
|
gnatsd "github.com/nats-io/gnatsd/test"
|
|
)
|
|
|
|
// So that we can pass tests and benchmarks...
|
|
type tLogger interface {
|
|
Fatalf(format string, args ...interface{})
|
|
Errorf(format string, args ...interface{})
|
|
}
|
|
|
|
// TestLogger
|
|
type TestLogger tLogger
|
|
|
|
// Dumb wait program to sync on callbacks, etc... Will timeout
|
|
func Wait(ch chan bool) error {
|
|
return WaitTime(ch, 5*time.Second)
|
|
}
|
|
|
|
// Wait for a chan with a timeout.
|
|
func WaitTime(ch chan bool, timeout time.Duration) error {
|
|
select {
|
|
case <-ch:
|
|
return nil
|
|
case <-time.After(timeout):
|
|
}
|
|
return errors.New("timeout")
|
|
}
|
|
|
|
func stackFatalf(t tLogger, f string, args ...interface{}) {
|
|
lines := make([]string, 0, 32)
|
|
msg := fmt.Sprintf(f, args...)
|
|
lines = append(lines, msg)
|
|
|
|
// Generate the Stack of callers: Skip us and verify* frames.
|
|
for i := 1; true; i++ {
|
|
_, file, line, ok := runtime.Caller(i)
|
|
if !ok {
|
|
break
|
|
}
|
|
msg := fmt.Sprintf("%d - %s:%d", i, file, line)
|
|
lines = append(lines, msg)
|
|
}
|
|
t.Fatalf("%s", strings.Join(lines, "\n"))
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Creating client connections
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// NewDefaultConnection
|
|
func NewDefaultConnection(t tLogger) *nats.Conn {
|
|
return NewConnection(t, nats.DefaultPort)
|
|
}
|
|
|
|
// NewConnection forms connection on a given port.
|
|
func NewConnection(t tLogger, port int) *nats.Conn {
|
|
url := fmt.Sprintf("nats://localhost:%d", port)
|
|
nc, err := nats.Connect(url)
|
|
if err != nil {
|
|
t.Fatalf("Failed to create default connection: %v\n", err)
|
|
return nil
|
|
}
|
|
return nc
|
|
}
|
|
|
|
// NewEConn
|
|
func NewEConn(t tLogger) *nats.EncodedConn {
|
|
ec, err := nats.NewEncodedConn(NewDefaultConnection(t), nats.DEFAULT_ENCODER)
|
|
if err != nil {
|
|
t.Fatalf("Failed to create an encoded connection: %v\n", err)
|
|
}
|
|
return ec
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// Running gnatsd server in separate Go routines
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// RunDefaultServer will run a server on the default port.
|
|
func RunDefaultServer() *server.Server {
|
|
return RunServerOnPort(nats.DefaultPort)
|
|
}
|
|
|
|
// RunServerOnPort will run a server on the given port.
|
|
func RunServerOnPort(port int) *server.Server {
|
|
opts := gnatsd.DefaultTestOptions
|
|
opts.Port = port
|
|
return RunServerWithOptions(opts)
|
|
}
|
|
|
|
// RunServerWithOptions will run a server with the given options.
|
|
func RunServerWithOptions(opts server.Options) *server.Server {
|
|
return gnatsd.RunServer(&opts)
|
|
}
|
|
|
|
// RunServerWithConfig will run a server with the given configuration file.
|
|
func RunServerWithConfig(configFile string) (*server.Server, *server.Options) {
|
|
return gnatsd.RunServerWithConfig(configFile)
|
|
}
|