コード例 #1
0
ファイル: connection.go プロジェクト: mikhailborodin/gopnik
func (self *connection) Connect() error {
	log.Debug("Connecting to %v...", self.addr)

	// Creating connection
	var err error
	self.transportFactory = thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory())
	self.protocolFactory = thrift.NewTBinaryProtocolFactoryDefault()
	self.socket, err = thrift.NewTSocketTimeout(self.addr, self.timeout)
	if err != nil {
		return fmt.Errorf("socket error: %v", err.Error())
	}
	self.transport = self.transportFactory.GetTransport(self.socket)
	err = self.transport.Open()
	if err != nil {
		return fmt.Errorf("transport open error: %v", err.Error())
	}
	self.renderClient = gopnikrpc.NewRenderClientFactory(self.transport, self.protocolFactory)
	return nil
}
コード例 #2
0
func (self *RenderSelector) connect(addr string) (*thriftConn, error) {
	var err error
	conn := &thriftConn{
		Addr: addr,
	}

	conn.Socket, err = thrift.NewTSocketTimeout(addr, self.timeout)
	if err != nil {
		return nil, err
	}

	conn.Transport = self.transportFactory.GetTransport(conn.Socket)
	err = conn.Transport.Open()
	if err != nil {
		return nil, err
	}

	conn.Client = gopnikrpc.NewRenderClientFactory(conn.Transport, self.protocolFactory)

	return conn, nil
}
コード例 #3
0
func TestErrorRaising(t *testing.T) {
	addr := "127.0.0.1:5347"

	cfg := []byte(`{
		"SetError": "MyTestError"
	}`)
	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("FakeCachePlugin", 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)
	_, err = renderClient.Render(&types.Coord{
		Zoom: 1,
		X:    0,
		Y:    0,
		Size: 1,
	},
		gopnikrpc.Priority_HIGH, true)

	require.NotNil(t, err)
	err2, ok := err.(*gopnikrpc.RenderError)
	require.True(t, ok)
	require.Equal(t, "RenderError({Message:MyTestError})", err2.Error())
}
コード例 #4
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")
}