use of doitincloud.rdbcache.models.KvIdType in project rdbcache by rdbcache.
the class RdbcacheApisTest method delkey_get1.
@Test
public void delkey_get1() {
try {
Map<String, Object> data1 = null, data2 = null;
{
RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/rdbcache/v1/select/user_table?limit=1").accept(MediaType.APPLICATION_JSON);
ResultActions actions = mockMvc.perform(requestBuilder);
MvcResult result = actions.andReturn();
MockHttpServletResponse response = result.getResponse();
assertEquals(200, response.getStatus());
String body = response.getContentAsString();
// System.out.println(body);
Map<String, Object> map = Utils.toMap(body);
data1 = (Map<String, Object>) map.get("data");
assertNotNull(data1);
assertEquals(1, data1.size());
}
String key = (String) data1.keySet().toArray()[0];
{
RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/rdbcache/v1/delkey/" + key + "/user_table").accept(MediaType.APPLICATION_JSON);
ResultActions actions = mockMvc.perform(requestBuilder);
MvcResult result = actions.andReturn();
MockHttpServletResponse response = result.getResponse();
assertEquals(200, response.getStatus());
String body = response.getContentAsString();
// System.out.println(body);
Map<String, Object> map = Utils.toMap(body);
data1 = (Map<String, Object>) map.get("data");
assertNull(data1);
}
// allow time to synchronize data
try {
Thread.sleep(250);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
assertFalse(AppCtx.getCacheOps().containsKey(key));
Map<String, Object> redis = MockRedis.getData();
// System.out.println(Utils.toJsonMap(redis));
assertFalse(redis.containsKey(PropCfg.getHdataPrefix() + "::" + key));
Map<String, Object> rdchkeys = (Map<String, Object>) redis.get("rdchkeys::user_table");
assertFalse(rdchkeys.containsKey(key));
KvPair pair = AppCtx.getKvPairRepo().findById(new KvIdType(key, "keyInfo"));
assertNull(pair);
} catch (Exception e) {
e.printStackTrace();
fail("caught an exception");
}
}
use of doitincloud.rdbcache.models.KvIdType in project rdbcache by rdbcache.
the class RdbcacheApisTest method delall_post1.
@Test
public void delall_post1() {
try {
Map<String, Object> data1 = null, data2 = null;
{
RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/rdbcache/v1/select/user_table?limit=3").accept(MediaType.APPLICATION_JSON);
ResultActions actions = mockMvc.perform(requestBuilder);
MvcResult result = actions.andReturn();
MockHttpServletResponse response = result.getResponse();
assertEquals(200, response.getStatus());
String body = response.getContentAsString();
// System.out.println(body);
Map<String, Object> map = Utils.toMap(body);
data1 = (Map<String, Object>) map.get("data");
assertNotNull(data1);
assertEquals(3, data1.size());
}
Set<String> keys = data1.keySet();
{
RequestBuilder requestBuilder = MockMvcRequestBuilders.post("/rdbcache/v1/delall/user_table/sync").contentType(MediaType.APPLICATION_JSON).content(Utils.toJsonMap(keys)).accept(MediaType.APPLICATION_JSON);
ResultActions actions = mockMvc.perform(requestBuilder);
MvcResult result = actions.andReturn();
MockHttpServletResponse response = result.getResponse();
assertEquals(200, response.getStatus());
String body = response.getContentAsString();
// System.out.println(body);
Map<String, Object> map = Utils.toMap(body);
assertNotNull(map.get("data"));
}
Map<String, Object> redis = MockRedis.getData();
// System.out.println(Utils.toJsonMap(redis));
int i = 1;
for (String key : keys) {
assertFalse(AppCtx.getCacheOps().containsKey(key));
assertFalse(redis.containsKey(PropCfg.getHdataPrefix() + "::" + key));
Map<String, Object> rdchkeys = (Map<String, Object>) redis.get("rdchkeys::user_table");
// System.out.println(Utils.toJsonMap(rdchkeys));
assertFalse(rdchkeys.containsKey(key));
KvPair pair = AppCtx.getKvPairRepo().findById(new KvIdType(key, "keyInfo"));
assertNull(pair);
{
RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/rdbcache/v1/get/*/user_table?id=" + i++).accept(MediaType.APPLICATION_JSON);
ResultActions actions = mockMvc.perform(requestBuilder);
MvcResult result = actions.andReturn();
MockHttpServletResponse response = result.getResponse();
assertEquals(404, response.getStatus());
}
}
} catch (Exception e) {
e.printStackTrace();
fail("caught an exception");
}
}
Aggregations