Search in sources :

Example 1 with DbaseOps

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);
}
Also used : Context(doitincloud.rdbcache.supports.Context) MockServletContext(org.springframework.mock.web.MockServletContext) DbaseOps(doitincloud.rdbcache.services.DbaseOps) SimpleKeyInfoRepo(doitincloud.rdbcache.repositories.SimpleKeyInfoRepo) CacheOps(doitincloud.rdbcache.services.CacheOps) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) LinkedHashMap(java.util.LinkedHashMap) Before(org.junit.Before)

Example 2 with DbaseOps

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());
    }
}
Also used : Context(doitincloud.rdbcache.supports.Context) DbaseOps(doitincloud.rdbcache.services.DbaseOps) InputStreamReader(java.io.InputStreamReader) KvPair(doitincloud.rdbcache.models.KvPair) KeyInfo(doitincloud.rdbcache.models.KeyInfo) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Test(org.junit.Test)

Example 3 with DbaseOps

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;
}
Also used : DbaseOps(doitincloud.rdbcache.services.DbaseOps)

Aggregations

DbaseOps (doitincloud.rdbcache.services.DbaseOps)3 Context (doitincloud.rdbcache.supports.Context)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 KeyInfo (doitincloud.rdbcache.models.KeyInfo)1 KvPair (doitincloud.rdbcache.models.KvPair)1 SimpleKeyInfoRepo (doitincloud.rdbcache.repositories.SimpleKeyInfoRepo)1 CacheOps (doitincloud.rdbcache.services.CacheOps)1 LinkedHashMap (java.util.LinkedHashMap)1 Before (org.junit.Before)1 Test (org.junit.Test)1 MockServletContext (org.springframework.mock.web.MockServletContext)1