lookup_vid_cache_test.go 466 B

1234567891011121314151617181920212223242526
  1. package operation
  2. import (
  3. "fmt"
  4. "testing"
  5. "time"
  6. )
  7. func TestCaching(t *testing.T) {
  8. var (
  9. vc VidCache
  10. )
  11. var locations []Location
  12. locations = append(locations, Location{Url: "a.com:8080"})
  13. vc.Set("123", locations, time.Second)
  14. ret, _ := vc.Get("123")
  15. if ret == nil {
  16. t.Fatal("Not found vid 123")
  17. }
  18. fmt.Printf("vid 123 locations = %v\n", ret)
  19. time.Sleep(2 * time.Second)
  20. ret, _ = vc.Get("123")
  21. if ret != nil {
  22. t.Fatal("Not found vid 123")
  23. }
  24. }