| 687 | } |
| 688 | |
| 689 | func TestInt64Key(t *testing.T) { |
| 690 | cache := NewCache(1024) |
| 691 | err := cache.SetInt(1, []byte("abc"), 3) |
| 692 | if err != nil { |
| 693 | t.Error("err should be nil") |
| 694 | } |
| 695 | err = cache.SetInt(2, []byte("cde"), 3) |
| 696 | if err != nil { |
| 697 | t.Error("err should be nil") |
| 698 | } |
| 699 | val, err := cache.GetInt(1) |
| 700 | if err != nil { |
| 701 | t.Error("err should be nil") |
| 702 | } |
| 703 | if !bytes.Equal(val, []byte("abc")) { |
| 704 | t.Error("value not equal") |
| 705 | } |
| 706 | time.Sleep(2 * time.Second) |
| 707 | val, expiry, err := cache.GetIntWithExpiration(1) |
| 708 | if err != nil { |
| 709 | t.Error("err should be nil") |
| 710 | } |
| 711 | if !bytes.Equal(val, []byte("abc")) { |
| 712 | t.Error("value not equal") |
| 713 | } |
| 714 | now := time.Now() |
| 715 | if expiry != uint32(now.Unix()+1) { |
| 716 | t.Errorf("Expiry should one second in the future but was %v", now) |
| 717 | } |
| 718 | |
| 719 | affected := cache.DelInt(1) |
| 720 | if !affected { |
| 721 | t.Error("del should return affected true") |
| 722 | } |
| 723 | _, err = cache.GetInt(1) |
| 724 | if err != ErrNotFound { |
| 725 | t.Error("error should be ErrNotFound after being deleted") |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | func TestIterator(t *testing.T) { |
| 730 | cache := NewCache(1024) |