Esempio n. 1
0
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)
}
Esempio n. 2
0
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)
}