Example #1
0
func (s *StorePluginSuite) GetSetTest(c *C, cfgStr string) {
	var cfg app.PluginConfig
	err := json.Unmarshal([]byte(cfgStr), &cfg)
	c.Assert(err, IsNil)

	var tiles []gopnik.Tile
	for _, fname := range []string{"1_0_0.png", "1_1_0.png", "1_0_1.png", "1_1_1.png"} {
		data, err := sampledata.Asset(fname)
		c.Assert(err, IsNil)
		tile, err := gopnik.NewTile(data)
		c.Assert(err, IsNil)
		c.Assert(tile, Not(IsNil))
		tiles = append(tiles, *tile)
	}

	plgn, err := plugins.DefaultPluginStore.Create(cfg.Plugin, cfg.PluginConfig)
	c.Assert(err, IsNil)
	store, ok := plgn.(gopnik.CachePluginInterface)
	c.Assert(ok, Equals, true)

	err = store.Set(gopnik.TileCoord{
		X:    0,
		Y:    0,
		Zoom: 1,
		Size: 2,
	}, tiles)
	// Set error should be nil
	c.Assert(err, IsNil)

	t01, err := store.Get(gopnik.TileCoord{
		X:    0,
		Y:    1,
		Zoom: 1,
		Size: 1,
	})
	// Get error should be nil
	c.Assert(err, IsNil)

	t01Orig, err := sampledata.Asset("1_0_1.png")
	c.Assert(err, IsNil)
	sampledata.CheckImage(c, t01, t01Orig)
}
Example #2
0
func copyMetaTile(metaCoord gopnik.TileCoord, cfg *Config, from, to gopnik.CachePluginInterface) {
	var metaTile []gopnik.Tile

	for y := uint(0); y < cfg.MetaSize; y++ {
		for x := uint(0); x < cfg.MetaSize; x++ {
			coord := gopnik.TileCoord{
				X:    metaCoord.X + uint64(x),
				Y:    metaCoord.Y + uint64(y),
				Zoom: metaCoord.Zoom,
				Size: 1,
				Tags: metaCoord.Tags,
			}

			attempt := 0
		TRYLOOP:
			for {
				if cfg.Copy.Retries > 0 {
					attempt++
				}

				var err error
				var rawTile []byte

				rawTile, err = from.Get(coord)
				if err != nil {
					if attempt <= cfg.Copy.Retries {
						log.Error("Get error: %v", err)
						continue
					} else {
						if cfg.Copy.SkipErrors {
							log.Error("Get error: %v", err)
							return
						}
						log.Fatalf("Get error: %v", err)
					}
				}

				tile, err := gopnik.NewTile(rawTile)
				if err != nil {
					if attempt <= cfg.Copy.Retries {
						log.Error("NewTile error: %v", err)
						continue
					} else {
						if cfg.Copy.SkipErrors {
							log.Error("NewTile error: %v", err)
							return
						}
						log.Fatalf("NewTile error: %v", err)
					}
				}

				metaTile = append(metaTile, *tile)
				break TRYLOOP
			}
		}
	}

	attempt := 0
TRYLOOP2:
	for {
		if cfg.Copy.Retries > 0 {
			attempt++
		}

		err := to.Set(metaCoord, metaTile)
		if err != nil {
			if attempt <= cfg.Copy.Retries {
				log.Error("Set error: %v", err)
				continue
			} else {
				if cfg.Copy.SkipErrors {
					log.Error("Set error: %v", err)
					return
				}
				log.Fatalf("Set error: %v", err)
			}
		}
		break TRYLOOP2
	}
}