func TestKeyInt32CacheFullOnPurge(t *testing.T) {
	cache := NewLRUCacheKeyInt32(1)
	value := &PurgeCacheValueKeyInt32{}
	k1 := key.KeyInt32(1)
	k2 := key.KeyInt32(2)

	cache.Set(k1, value)                               // after this cache is full
	purgeReasonFlag4TestKeyInt32 = PURGE_REASON_DELETE // init
	cache.Set(k2, value)                               // after this k1 is delete and reason set to  PURGE_REASON_CACHEFULL
	if purgeReasonFlag4TestKeyInt32 != PURGE_REASON_CACHEFULL {
		t.Errorf("after cache.Delete ,purgeReason should be %d ,but get %d", PURGE_REASON_CACHEFULL, purgeReasonFlag4TestKeyInt32)
	}

}
func TestKeyInt32SetUpdatesSize(t *testing.T) {
	cache := NewLRUCacheKeyInt32(100)
	emptyValue := &CacheValue{0}
	k := key.KeyInt32(1)
	cache.Set(k, emptyValue)
	if _, sz, _ := cache.Stats(); sz != 0 {
		t.Errorf("cache.Size() = %v, expected 0", sz)
	}
	someValue := &CacheValue{20}
	k = key.KeyInt32(2)
	cache.Set(k, someValue)
	if _, sz, _ := cache.Stats(); sz != 20 {
		t.Errorf("cache.Size() = %v, expected 20", sz)
	}
}
func TestKeyInt32ClearOnPurge(t *testing.T) {
	cache := NewLRUCacheKeyInt32(1)
	value := &PurgeCacheValueKeyInt32{}
	k1 := key.KeyInt32(1)
	purgeReasonFlag4TestKeyInt32 = PURGE_REASON_DELETE // init
	cache.Set(k1, value)                               // after this cache is full
	cache.Clear()
	if purgeReasonFlag4TestKeyInt32 != PURGE_REASON_CLEAR_ALL {
		t.Errorf("after cache.Delete ,purgeReason should be %d ,but get %d", PURGE_REASON_CLEAR_ALL, purgeReasonFlag4TestKeyInt32)
	}

}
func TestKeyInt32OnMiss(t *testing.T) {
	fun := func(k key.KeyInt32) (Cacheable, bool) {
		return 1, true
	}
	cache := NewLRUCacheKeyInt32(1)
	cache.OnMiss(fun)
	k1 := key.KeyInt32(1)
	v, ok := cache.Get(k1) //
	if ok != true && v != 1 {
		t.Errorf("lru.onMiss is errror")
	}

}
func TestKeyInt32SetWithOldKeyUpdatesValue(t *testing.T) {
	cache := NewLRUCacheKeyInt32(100)
	emptyValue := &CacheValue{0}
	k := key.KeyInt32(1)
	cache.Set(k, emptyValue)
	someValue := &CacheValue{20}
	cache.Set(k, someValue)

	v, ok := cache.Get(k)
	if !ok || v.(*CacheValue) != someValue {
		t.Errorf("Cache has incorrect value: %v != %v", someValue, v)
	}
}
func TestKeyInt32SetWithOldKeyUpdatesSize(t *testing.T) {
	cache := NewLRUCacheKeyInt32(100)
	emptyValue := &CacheValue{0}
	k := key.KeyInt32(1)
	cache.Set(k, emptyValue)

	if _, sz, _ := cache.Stats(); sz != 0 {
		t.Errorf("cache.Size() = %v, expected %v", sz, 0)
	}

	someValue := &CacheValue{20}
	cache.Set(k, someValue)
	expected := int64(someValue.size)
	if _, sz, _ := cache.Stats(); sz != expected {
		t.Errorf("cache.Size() = %v, expected %v", sz, expected)
	}
}