Example #1
0
func (s *TileRenderSuite) TestTileRender(c *C) {
	render, err := NewTileRender(sampledata.SlaveCmd)

	c.Assert(err, IsNil)

	coord := gopnik.TileCoord{
		X:    0,
		Y:    0,
		Zoom: 1,
		Size: 1,
	}
	tiles, err := render.RenderTiles(coord)

	c.Assert(err, IsNil)
	c.Assert(len(tiles), Equals, 1)

	sampledata.CheckTile(c, tiles[0].Image, "1_0_0.png")
}
Example #2
0
func TestOneRender(t *testing.T) {
	rpool, err := NewRenderPool(sampledata.SlaveCmd, 1, 1, 1, 0)
	require.Nil(t, err)

	coord := gopnik.TileCoord{
		X:    0,
		Y:    0,
		Zoom: 1,
		Size: 1,
	}
	ansCh := make(chan *RenderPoolResponse)
	err = rpool.EnqueueRequest(coord, ansCh, gopnikrpc.Priority_HIGH)
	require.Nil(t, err)
	ans := <-ansCh
	require.Nil(t, ans.Error)
	require.Equal(t, len(ans.Tiles), 1)
	sampledata.CheckTile(t, ans.Tiles[0].Image, "1_0_0.png")
}
Example #3
0
func TestOneRender4Tiles(t *testing.T) {
	rpool, err := NewRenderPool(sampledata.SlaveCmd, 1, 1, 0, 0)
	require.Nil(t, err)

	coord := gopnik.TileCoord{
		X:    0,
		Y:    0,
		Zoom: 1,
		Size: 2,
	}
	ansCh := make(chan *RenderPoolResponse)
	err = rpool.EnqueueRequest(coord, ansCh, gopnikrpc.Priority_HIGH)
	require.Nil(t, err)
	ans := <-ansCh
	require.Nil(t, ans.Error)
	require.Equal(t, len(ans.Tiles), 4)
	for i := 0; i < 2; i++ {
		for j := 0; j < 2; j++ {
			sampledata.CheckTile(t, ans.Tiles[i*2+j].Image,
				fmt.Sprintf("1_%d_%d.png", j, i))
		}
	}
}
Example #4
0
func Test5RendersLP(t *testing.T) {
	const nTiles = 15

	rpool, err := NewRenderPool(sampledata.SlaveCmd, 5, 0, nTiles, 0)
	require.Nil(t, err)

	coord := gopnik.TileCoord{
		X:    0,
		Y:    0,
		Zoom: 1,
		Size: 1,
	}
	ansCh := make(chan *RenderPoolResponse)
	for i := 0; i < nTiles; i++ {
		err = rpool.EnqueueRequest(coord, ansCh, gopnikrpc.Priority_LOW)
		require.Nil(t, err)
	}
	for i := 0; i < nTiles; i++ {
		ans := <-ansCh
		require.Nil(t, ans.Error)
		require.Equal(t, len(ans.Tiles), 1)
		sampledata.CheckTile(t, ans.Tiles[0].Image, "1_0_0.png")
	}
}
Example #5
0
func TestSimple(t *testing.T) {
	addr := "127.0.0.1:5342"

	cfg := []byte(`{
		"UseMultilevel": true,
		"Backend": {
			"Plugin":       "MemoryKV",
			"PluginConfig": {}
		}
	}`)
	renderPoolsConfig := app.RenderPoolsConfig{
		[]app.RenderPoolConfig{
			app.RenderPoolConfig{
				Cmd:         sampledata.SlaveCmd, // Render slave binary
				MinZoom:     0,
				MaxZoom:     19,
				PoolSize:    1,
				HPQueueSize: 10,
				LPQueueSize: 10,
				RenderTTL:   0,
			},
		},
	}

	cpI, err := plugins.DefaultPluginStore.Create("KVStorePlugin", json.RawMessage(cfg))
	if err != nil {
		t.Fatal(err)
	}
	cp, ok := cpI.(gopnik.CachePluginInterface)
	if !ok {
		t.Fatal("Invalid cache plugin type")
	}

	ts, err := NewTileServer(renderPoolsConfig, cp, time.Duration(0))
	if err != nil {
		t.Fatalf("Failed to create tile server: %v", err)
	}
	go func() {
		err := RunServer(addr, ts)
		if err != nil {
			panic(err)
		}
	}()
	time.Sleep(time.Millisecond)

	transportFactory := thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
	socket, err := thrift.NewTSocket(addr)
	require.Nil(t, err)
	transport := transportFactory.GetTransport(socket)
	defer transport.Close()
	err = transport.Open()
	if err != nil {
		t.Errorf("transport open: %v", err.Error())
	}

	renderClient := gopnikrpc.NewRenderClientFactory(transport, protocolFactory)
	resp, err := renderClient.Render(&types.Coord{
		Zoom: 1,
		X:    0,
		Y:    0,
		Size: 1,
	},
		gopnikrpc.Priority_HIGH, false)

	require.Nil(t, err)
	require.Equal(t, 1, len(resp.Tiles))
	require.NotNil(t, resp.Tiles[0].Image)

	sampledata.CheckTile(t, resp.Tiles[0].Image, "1_0_0.png")
}