use of doitincloud.rdbcache.services.DbaseOps 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.DbaseOps in project rdbcache by rdbcache.
the class ParserTest method prepareStandardClauseParams.
@Test
public void prepareStandardClauseParams() {
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("test-table.json");
assertNotNull(inputStream);
String text = null;
try (final Reader reader = new InputStreamReader(inputStream)) {
text = CharStreams.toString(reader);
} catch (Exception e) {
e.printStackTrace();
fail(e.getCause().getMessage());
}
assertNotNull(text);
Map<String, Object> testTable = Utils.toMap(text);
assertNotNull(testTable);
DbaseOps dbaseOps = new DbaseOps();
AppCtx.setDbaseOps(dbaseOps);
Context context = new Context();
String json = "{\n" + " \"id\" : 12467,\n" + " \"email\" : \"kevin@example.com\",\n" + " \"name\" : \"Kevin B.\",\n" + " \"dob\" : \"1980-07-21\"\n" + " }";
KvPair pair = new KvPair("*", "data", Utils.toMap(json));
try {
KeyInfo keyInfo = new KeyInfo();
keyInfo.setExpire("100");
keyInfo.setTable("user_table");
keyInfo.setCreatedAt(1522367710621L);
String json2 = "{\"table\":\"user_table\",\"conditions\":{\"id\":{\"=\":[\"1\",\"2\",\"3\"]}},\"limit\":2}";
QueryInfo queryInfo = Utils.toPojo(Utils.toMap(json2), QueryInfo.class);
keyInfo.setQuery(queryInfo);
keyInfo.setColumns((Map<String, Object>) testTable.get("table_columns::user_table"));
keyInfo.setPrimaryIndexes(Arrays.asList("id"));
Parser.prepareStandardClauseParams(context, pair, keyInfo);
// System.out.println(Utils.toJsonMap(keyInfo));
assertEquals("{\"expire\":\"100\",\"table\":\"user_table\",\"clause\":\"id = ?\"," + "\"params\":[12467],\"query\":{\"table\":\"user_table\",\"conditions\":{\"id\":{\"=\":" + "[\"1\",\"2\",\"3\"]}},\"limit\":2},\"query_key\":\"87677684c30a46c6e5afec88d0131410\"," + "\"is_new\":false,\"expire_old\":\"180\",\"created_at\":1522367710621}", Utils.toJsonMap(keyInfo));
keyInfo.cleanup();
// System.out.println(Utils.toJsonMap(keyInfo));
assertEquals("{\"expire\":\"100\",\"table\":\"user_table\",\"clause\":\"id = ?\",\"params\":[12467]" + ",\"query_key\":\"87677684c30a46c6e5afec88d0131410\",\"is_new\":false,\"created_at\":1522367710621}", Utils.toJsonMap(keyInfo));
} catch (Exception e) {
e.printStackTrace();
fail(e.getCause().getMessage());
}
}
use of doitincloud.rdbcache.services.DbaseOps in project rdbcache by rdbcache.
the class Context method closeMonitor.
public synchronized void closeMonitor() {
if (monitor == null) {
return;
}
duration = monitor.getMainDuration();
monitor.stopNow();
DbaseOps dbaseOps = AppCtx.getDbaseOps();
if (dbaseOps != null) {
try {
dbaseOps.saveMonitor(this);
} catch (Exception e) {
e.printStackTrace();
}
}
monitor = null;
}
Aggregations