Search in sources :

Example 1 with DbaseOps

use of com.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);
    Mockito.when(dbaseOps.getTableList(any(Context.class))).thenReturn(Arrays.asList("user_table", "tb1"));
    BDDMockito.when(AppCtx.getDbaseOps()).thenReturn(dbaseOps);
    LocalCache localCache = new LocalCache();
    localCache.init();
    localCache.handleEvent(null);
    BDDMockito.when(AppCtx.getLocalCache()).thenReturn(localCache);
}
Also used : MockServletContext(org.springframework.mock.web.MockServletContext) DbaseOps(com.rdbcache.services.DbaseOps) SimpleKeyInfoRepo(com.rdbcache.repositories.SimpleKeyInfoRepo) InputStreamReader(java.io.InputStreamReader) LocalCache(com.rdbcache.services.LocalCache) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Before(org.junit.Before)

Example 2 with DbaseOps

use of com.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(com.rdbcache.helpers.Context) DbaseOps(com.rdbcache.services.DbaseOps) InputStreamReader(java.io.InputStreamReader) KvPair(com.rdbcache.models.KvPair) KeyInfo(com.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 com.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(com.rdbcache.services.DbaseOps)

Aggregations

DbaseOps (com.rdbcache.services.DbaseOps)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 Context (com.rdbcache.helpers.Context)1 KeyInfo (com.rdbcache.models.KeyInfo)1 KvPair (com.rdbcache.models.KvPair)1 SimpleKeyInfoRepo (com.rdbcache.repositories.SimpleKeyInfoRepo)1 LocalCache (com.rdbcache.services.LocalCache)1 Before (org.junit.Before)1 Test (org.junit.Test)1 MockServletContext (org.springframework.mock.web.MockServletContext)1