use of doitincloud.rdbcache.services.CacheOps in project rdbcache by rdbcache.
the class RequestTest method setUp.
@Before
public void setUp() throws Exception {
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("test-keyinfos.json");
assertNotNull(inputStream);
String text = null;
try (final Reader reader = new InputStreamReader(inputStream)) {
text = CharStreams.toString(reader);
}
assertNotNull(text);
Map<String, Object> map = Utils.toMap(text);
assertNotNull(map);
PowerMockito.mockStatic(AppCtx.class);
keyInfoRepo = new SimpleKeyInfoRepo(map);
BDDMockito.when(AppCtx.getKeyInfoRepo()).thenReturn(keyInfoRepo);
DbaseOps dbaseOps = mock(DbaseOps.class, Mockito.RETURNS_DEEP_STUBS);
assertNotNull(dbaseOps);
Map<String, Object> tablesMap = new LinkedHashMap<>();
tablesMap.put("user_table", "data");
tablesMap.put("tb1", "data");
Mockito.when(dbaseOps.getTablesMap(any(Context.class))).thenReturn(tablesMap);
BDDMockito.when(AppCtx.getDbaseOps()).thenReturn(dbaseOps);
CacheOps cacheOps = new CacheOps();
cacheOps.init();
cacheOps.handleEvent(null);
BDDMockito.when(AppCtx.getCacheOps()).thenReturn(cacheOps);
}
use of doitincloud.rdbcache.services.CacheOps in project rdbcache by rdbcache.
the class AnyKeyTest method getAny.
@Test
public void getAny() {
AnyKey anyKey;
KeyInfo keyInfo;
anyKey = new AnyKey();
keyInfo = anyKey.getKeyInfo();
assertNull(keyInfo);
keyInfo = new KeyInfo();
keyInfo.setExpire("100");
keyInfo.setTable("table");
anyKey = new AnyKey(keyInfo);
KeyInfo keyInfo2 = anyKey.getKeyInfo();
assertNotNull(keyInfo2);
assertTrue(keyInfo == keyInfo2);
keyInfo2 = anyKey.get(0);
assertNotNull(keyInfo2);
assertTrue(keyInfo == keyInfo2);
CacheOps cacheOps = new CacheOps();
cacheOps.init();
cacheOps.handleEvent(null);
AppCtx.setCacheOps(cacheOps);
try {
for (int i = 0; i < 10; i++) {
keyInfo = anyKey.getAny(i);
assertNotNull(keyInfo);
if (i == 0)
assertFalse(keyInfo.getIsNew());
else
assertTrue(keyInfo.getIsNew());
assertEquals(i + 1, anyKey.size());
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getCause().getMessage());
}
}
use of doitincloud.rdbcache.services.CacheOps in project rdbcache by rdbcache.
the class RTQueryApisTest method retrieveLocalCacheKey.
@Test
public void retrieveLocalCacheKey() throws Exception {
try {
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("test-keys.json");
assertNotNull(inputStream);
String text = null;
try (final Reader reader = new InputStreamReader(inputStream)) {
text = CharStreams.toString(reader);
}
assertNotNull(text);
Map<String, Object> testKeys = Utils.toMap(text);
assertNotNull(testKeys);
// Mockito.when(cacheOps.listAllKeyInfos()).thenReturn(testKeys);
// PowerMockito.mockStatic(AppCtx.class);
// BDDMockito.when(AppCtx.getCacheOps()).thenReturn(cacheOps);
// try different way
//
CacheOps cache = new CacheOps();
cache.init();
cache.handleEvent(null);
// cache.handleApplicationReadyEvent(null);
for (Map.Entry<String, Object> entry : testKeys.entrySet()) {
cache.put(entry.getKey(), (Map<String, Object>) entry.getValue());
}
AppCtx.setCacheOps(cache);
RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/rtquery/v1/cache/key").accept(MediaType.APPLICATION_JSON);
ResultActions actions = mockMvc.perform(requestBuilder);
MvcResult result = actions.andReturn();
MockHttpServletResponse response = result.getResponse();
assertEquals(response.getStatus(), 200);
String body = response.getContentAsString();
// System.out.println(body);
Map<String, Object> map = Utils.toMap(body);
assertTrue(map.containsKey("timestamp"));
assertTrue(map.containsKey("duration"));
assertTrue(map.containsKey("data"));
assertTrue(map.containsKey("trace_id"));
Map<String, Object> data = (Map<String, Object>) map.get("data");
assertTrue(data.size() > 0);
} catch (Exception e) {
e.printStackTrace();
fail(e.getCause().getMessage());
}
}
Aggregations