Exemplo n.º 1
0
func TestQueueDub(t *testing.T) {
	rq := newRenderQueue(10)

	coordA := gopnik.TileCoord{
		X:    10,
		Y:    7,
		Zoom: 11,
	}
	coordB := gopnik.TileCoord{
		X:    10,
		Y:    7,
		Zoom: 11,
	}
	resCh := make(chan *RenderPoolResponse, 1)

	go func() {
		err := rq.Push(coordA, resCh)
		if err != nil {
			t.Errorf("Push error: %v", err)
		}
		err = rq.Push(coordB, resCh)
		if err != nil {
			t.Errorf("Push error: %v", err)
		}
	}()

	coord2 := <-rq.TasksChan()
	if !coordA.Equals(&coord2) {
		t.Error("Coordinates not equal")
	}
}
Exemplo n.º 2
0
func TestRoute(t *testing.T) {
	renders := []string{"localhost:9001", "localhost:9002", "localhost:9003"}

	for _, r := range renders {
		go runFakeRender(r)
	}
	time.Sleep(100 * time.Millisecond)

	rs, err := NewRenderSelector(renders, time.Second, 30*time.Second)
	require.Nil(t, err)
	defer rs.Stop()

	coord := gopnik.TileCoord{
		X:    0,
		Y:    0,
		Zoom: 1,
		Size: 1,
	}
	back1, err1 := rs.SelectRender(coord)
	require.Nil(t, err1)
	coord.X = 3
	back2, err2 := rs.SelectRender(coord)
	require.Nil(t, err2)
	coord.Y = 4
	back3, err3 := rs.SelectRender(coord)
	require.Nil(t, err3)
	coord.Zoom = 5
	back4, err4 := rs.SelectRender(coord)
	require.Nil(t, err4)

	require.True(t,
		back1.Addr != back2.Addr || back1.Addr != back3.Addr || back1.Addr != back4.Addr,
	)
}
Exemplo n.º 3
0
func (self *plan) setStatus(coord gopnik.TileCoord, status uint8) error {
	self.mu.Lock()
	defer self.mu.Unlock()

	for i, c := range self.bboxes {
		if coord.Equals(&c) {
			self.status[i] = status
			self.cond.Broadcast()
			return nil
		}
	}
	return fmt.Errorf("Can't find task %v", coord)
}
Exemplo n.º 4
0
func TestQueueWaitMulti(t *testing.T) {
	rq := newRenderQueue(10)

	coordA := gopnik.TileCoord{
		X:    10,
		Y:    7,
		Zoom: 11,
	}
	coordB := gopnik.TileCoord{
		X:    3,
		Y:    5,
		Zoom: 12,
	}
	coordC := gopnik.TileCoord{
		X:    3,
		Y:    5,
		Zoom: 12,
		Size: 4,
	}
	resCh := make(chan *RenderPoolResponse, 10)

	go func() {
		time.Sleep(1 * time.Millisecond)
		err := rq.Push(coordA, resCh)
		if err != nil {
			t.Errorf("Push error: %v", err)
		}
		time.Sleep(1 * time.Millisecond)
		err = rq.Push(coordB, resCh)
		if err != nil {
			t.Errorf("Push error: %v", err)
		}
		time.Sleep(1 * time.Millisecond)
		err = rq.Push(coordC, resCh)
		if err != nil {
			t.Errorf("Push error: %v", err)
		}
	}()

	coordA2 := <-rq.TasksChan()
	if !coordA.Equals(&coordA2) {
		t.Errorf("Coordinates not equal: %v != %v", coordA2, coordA)
	}

	coordB2 := <-rq.TasksChan()
	if !coordB.Equals(&coordB2) {
		t.Errorf("Coordinates not equal: %v != %v", coordB2, coordB)
	}

	coordC2 := <-rq.TasksChan()
	if !coordC.Equals(&coordC2) {
		t.Errorf("Coordinates not equal: %v != %v", coordC2, coordC)
	}
}
Exemplo n.º 5
0
func (self *BBoxTagFilterPlugin) applyFilterItem(coord *gopnik.TileCoord, fi *filterItem, inBb bool) {
	if inBb {
		for _, tag := range fi.Drop {
			coord.Tags = strArrDrop(coord.Tags, tag)
		}
		for _, tag := range fi.Add {
			coord.Tags = strArrAdd(coord.Tags, tag)
		}
	} else {
		for _, tag := range fi.DropOtherwise {
			coord.Tags = strArrDrop(coord.Tags, tag)
		}
		for _, tag := range fi.AddOtherwise {
			coord.Tags = strArrAdd(coord.Tags, tag)
		}
	}
}
Exemplo n.º 6
0
func runWebUI(addr string, perfData []perflog.PerfLogEntry) {
	m := staticbin.Classic(gopnikwebstatic.Asset)

	m.Map(log.New(os.Stderr, "", log.LstdFlags))

	m.Use(rendergold.Renderer(rendergold.Options{Asset: Asset}))

	m.Get("/", func(r rendergold.Render) {

		totalStats := getStats(perfData, nil)
		var zoomsStats []zoomStats
		zrng := getZooms(perfData)
		for z := zrng.MinZoom; z <= zrng.MaxZoom; z++ {
			zoomsStats = append(zoomsStats, zoomStats{
				Zoom:  z,
				Stats: getStats(perfData, &z),
			})
		}

		r.HTML(
			http.StatusOK,
			"index",
			map[string]interface{}{
				"Page":       "Results",
				"TotalStats": totalStats,
				"ZoomsStats": zoomsStats,
			},
		)
	})

	m.Get("/heatmap", func(r rendergold.Render) {
		r.HTML(
			http.StatusOK,
			"heatmap",
			map[string]interface{}{
				"Page": "Heat",
			},
		)
	})

	m.Get("/heattiles_zooms", func(res http.ResponseWriter) {
		var zooms struct {
			Min uint64
			Max uint64
		}

		if len(perfData) > 0 {
			zooms.Min = perfData[0].Coord.Zoom
			zooms.Max = perfData[0].Coord.Zoom

			for i := 1; i < len(perfData); i++ {
				zoom := perfData[i].Coord.Zoom
				if zoom < zooms.Min {
					zooms.Min = zoom
				}
				if zoom > zooms.Max {
					zooms.Max = zoom
				}
			}
		}

		enc := json.NewEncoder(res)
		if err := enc.Encode(zooms); err != nil {
			http.Error(res, err.Error(), 500)
			return
		}
	})

	m.Get("/heattiles/:zoom_orig/:zoom/:x/:y.png", func(params martini.Params, res http.ResponseWriter) {
		var coord gopnik.TileCoord

		coord.Size = 1
		_, err := fmt.Sscan(params["zoom"], &coord.Zoom)
		if err != nil {
			http.Error(res, err.Error(), 400)
			return
		}
		_, err = fmt.Sscan(params["x"], &coord.X)
		if err != nil {
			http.Error(res, err.Error(), 400)
			return
		}
		_, err = fmt.Sscan(params["y"], &coord.Y)
		if err != nil {
			http.Error(res, err.Error(), 400)
			return
		}
		var zoomOrig uint64
		_, err = fmt.Sscan(params["zoom_orig"], &zoomOrig)
		if err != nil {
			http.Error(res, err.Error(), 400)
			return
		}

		tile, err := genPerfTile(perfData, coord, zoomOrig)
		if err != nil {
			http.Error(res, err.Error(), 500)
			return
		}

		res.Header().Set("Content-Type", "image/png")
		res.Write(tile)
	})

	log.Printf("Starting WebUI on %v", addr)
	log.Fatal(http.ListenAndServe(addr, m))
}