func TestExtraEurekacheSetExpire(t *testing.T) {
	assert := assert.New(t)
	val := "value"

	e := New()
	m := memorycache.NewCacheTTL(1)
	e.SetCacheSources([]Cache{m})
	e.SetExpire("key", val, 100)

	var result string
	var ok bool

	ok = m.Get("nokey", &result)
	assert.False(ok)
	assert.Empty(result)

	result = ""
	ok = e.Get("key", &result)
	assert.True(ok)
	assert.Equal(val, result)

	result = ""
	time.Sleep(100 * time.Millisecond)
	ok = e.Get("key", &result)
	assert.False(ok)
	assert.Empty(result)
}
func TestExtraEurekacheGetGobBytes(t *testing.T) {
	assert := assert.New(t)
	val := "value"

	// encode value
	var buf bytes.Buffer
	enc := gob.NewEncoder(&buf)
	err := enc.Encode(val)
	assert.Nil(err)

	e := New()
	m := memorycache.NewCacheTTL(1)
	e.SetCacheSources([]Cache{m})
	m.Set("key", val)

	var b []byte
	var ok bool

	// check gob encoded result
	b, ok = e.GetGobBytes("key")
	assert.True(ok)
	assert.Equal(buf.Bytes(), b)

	// check gob encoded result
	b, ok = e.GetGobBytes("nokey")
	assert.False(ok)
	assert.Empty(b)
}
func TestIntegrationGetTimeout(t *testing.T) {
	assert := assert.New(t)
	key := "testintegrationgettimeout"
	val := "TestIntegrationGetTimeout"

	dc := newDummySleepCache(100 * time.Millisecond)
	mc := memorycache.NewCacheTTL(3)

	e := eurekache.New()
	e.SetCacheSources([]eurekache.Cache{dc, mc})
	e.Set(key, val)

	var ok bool
	var result string

	// default timeout(hour)
	ok = e.Get(key, &result)
	assert.True(ok)
	assert.Equal(val, result)

	// timeout within 20ms
	result = ""
	e.SetTimeout(20 * time.Millisecond)
	ok = e.Get(key, &result)
	assert.False(ok)
	assert.Equal("", result)
}
func TestExtraEurekacheGet(t *testing.T) {
	assert := assert.New(t)

	e := New()
	m := memorycache.NewCacheTTL(1)
	e.SetCacheSources([]Cache{m})

	m.Set("key", "value")

	var ok bool
	var valInt int
	var valStr string

	// int value
	ok = e.Get("key", &valInt)
	assert.False(ok)
	assert.Empty(valInt)

	// string value
	ok = e.Get("key", &valStr)
	assert.True(ok)
	assert.Equal("value", valStr)

	// struct value
	var valItem1, valItem2 Item
	var valNonItem *Eurekache
	valItem1 = Item{
		Value: "val",
	}
	m.Set("item", valItem1)

	ok = e.Get("item", valNonItem)
	assert.False(ok)
	assert.Nil(valNonItem)

	ok = e.Get("item", &valItem2)
	assert.True(ok)
	assert.Equal(valItem1, valItem2)

	// pointer value
	var valPtr1, valPtr2 *Item
	m.Set("item_ptr", &valPtr1)

	ok = e.Get("item_ptr", &valPtr2)
	assert.True(ok)
	assert.Equal(valPtr1, valPtr2)

}
func TestIntegrationGet(t *testing.T) {
	assert := assert.New(t)
	key := "testintegrationget"
	val := "TestIntegrationGet"

	mc := memorycache.NewCacheTTL(3)
	mc.SetTTL(200)
	rc := rediscache.NewRedisCache(helper.TestGetPool())
	rc.SetTTL(1000)
	rc.SetPrefix(testRedisPrefix)

	e := eurekache.New()
	e.SetCacheSources([]eurekache.Cache{mc, rc})
	e.Set(key, val)

	var ok bool
	var result string

	// miss cache
	ok = e.Get("key", &result)
	assert.False(ok)
	assert.Empty(result)

	// hit memory
	ok = e.Get(key, &result)
	assert.True(ok)
	assert.Equal(val, result)

	// hit redis
	result = ""
	time.Sleep(300 * time.Millisecond)
	ok = e.Get(key, &result)
	assert.True(ok)
	assert.Equal(val, result)

	// cache expired
	result = ""
	time.Sleep(1000 * time.Millisecond)
	ok = e.Get(key, &result)
	assert.False(ok)
	assert.Equal("", result)
}
func TestExtraEurekacheGetInterface(t *testing.T) {
	assert := assert.New(t)
	val := "value"

	e := New()
	m := memorycache.NewCacheTTL(1)
	e.SetCacheSources([]Cache{m})
	m.Set("key", val)

	var result interface{}
	var ok bool

	result, ok = e.GetInterface("key")
	assert.True(ok)
	assert.Equal(val, result)

	result, ok = e.GetInterface("nokey")
	assert.False(ok)
	assert.Nil(result)
}
func TestExtraEurekacheSet(t *testing.T) {
	assert := assert.New(t)
	val := "value"

	e := New()
	m := memorycache.NewCacheTTL(1)
	e.SetCacheSources([]Cache{m})
	e.Set("key", val)

	var item *Item
	var ok bool

	var result string
	ok = m.Get("nokey", &result)
	assert.False(ok)
	assert.Nil(item)

	ok = m.Get("key", &result)
	assert.True(ok)
	assert.Equal(val, result)

}