Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

✅ 补充ehcache测试用例内容 #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
yeternallove wants to merge 1 commit into xkcoding:dev
base: dev
Choose a base branch
Loading
from yeternallove:dev
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import com.xkcoding.cache.ehcache.SpringBootDemoCacheEhcacheApplicationTests;
import com.xkcoding.cache.ehcache.entity.User;
import lombok.extern.slf4j.Slf4j;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

Expand Down Expand Up @@ -48,13 +52,28 @@ public void getAfterSave() {
}

/**
* 测试删除,查看redis是否存在缓存数据
* 测试删除,查看ehcache是否存在缓存数据
*/
@Test
public void deleteUser() {
// 查询一次,使ehcache中存在缓存数据
userService.get(1L);
// 获取cache,用以验证缓存存在情况
CacheManager cacheManager = CacheManager.create();
Cache cache = cacheManager.getCache("user");

long id = 1L;
// ehcache中不存在缓存数据
Assert.assertNull(cache.get(id));

// 查询一次,使
User user = userService.get(id);
// ehcache中存在缓存数据
Element element = cache.get(id);
Assert.assertNotNull(element);
Assert.assertEquals(user, element.getObjectValue());

// 删除,查看ehcache是否存在缓存数据
userService.delete(1L);
userService.delete(id);
// ehcache中不存在缓存数据
Assert.assertNull(cache.get(id));
}
}

AltStyle によって変換されたページ (->オリジナル) /