Search in sources :

Example 1 with ReflectionWrapper

use of com.pingcap.tikv.util.ReflectionWrapper in project tispark by pingcap.

the class CatalogTest method listTablesTest.

@Test
public void listTablesTest() {
    MetaMockHelper helper = new MetaMockHelper(pdServer, kvServer);
    helper.preparePDForRegionRead();
    helper.setSchemaVersion(666);
    helper.addDatabase(130, "global_temp");
    helper.addDatabase(264, "tpch_001");
    helper.addTable(130, 42, "test");
    helper.addTable(130, 43, "test1");
    Catalog cat = session.getCatalog();
    TiDBInfo db = cat.getDatabase("gLObal_temp");
    List<TiTableInfo> tables = cat.listTables(db);
    List<String> names = tables.stream().map(TiTableInfo::getName).sorted().collect(Collectors.toList());
    assertEquals(2, tables.size());
    assertEquals("test", names.get(0));
    assertEquals("test1", names.get(1));
    assertEquals("test", cat.getTable(db, 42).getName());
    assertEquals("test1", cat.getTable(db, 43).getName());
    assertNull(cat.getTable(db, 44));
    helper.addTable(130, 44, "other");
    helper.setSchemaVersion(667);
    ReflectionWrapper wrapper = new ReflectionWrapper(cat, boolean.class);
    wrapper.call("reloadCache", true);
    tables = cat.listTables(db);
    names = tables.stream().map(TiTableInfo::getName).sorted().collect(Collectors.toList());
    assertEquals(3, tables.size());
    assertEquals("other", names.get(0));
    assertEquals("test", names.get(1));
    assertEquals("test1", names.get(2));
    assertEquals(42, cat.getTable("global_temp", "test").getId());
    assertNull(cat.getTable("global_temp", "test111"));
    helper.dropTable(db.getId(), tables.get(0).getId());
    helper.setSchemaVersion(668);
    wrapper.call("reloadCache", true);
    tables = cat.listTables(db);
    assertEquals(2, tables.size());
    db = cat.getDatabase("TpCH_001");
    tables = cat.listTables(db);
    assertTrue(tables.isEmpty());
}
Also used : MetaMockHelper(com.pingcap.tikv.meta.MetaUtils.MetaMockHelper) TiTableInfo(com.pingcap.tikv.meta.TiTableInfo) TiDBInfo(com.pingcap.tikv.meta.TiDBInfo) ReflectionWrapper(com.pingcap.tikv.util.ReflectionWrapper) PDMockServerTest(com.pingcap.tikv.PDMockServerTest) Test(org.junit.Test)

Example 2 with ReflectionWrapper

use of com.pingcap.tikv.util.ReflectionWrapper in project tispark by pingcap.

the class CatalogTest method listDatabasesTest.

@Test
public void listDatabasesTest() {
    MetaMockHelper helper = new MetaMockHelper(pdServer, kvServer);
    helper.preparePDForRegionRead();
    helper.setSchemaVersion(666);
    helper.addDatabase(130, "global_temp");
    helper.addDatabase(264, "TPCH_001");
    Catalog cat = session.getCatalog();
    List<TiDBInfo> dbs = cat.listDatabases();
    List<String> names = dbs.stream().map(TiDBInfo::getName).sorted().collect(Collectors.toList());
    assertEquals(2, dbs.size());
    assertEquals("global_temp", names.get(0));
    assertEquals("tpch_001", names.get(1));
    helper.addDatabase(265, "other");
    helper.setSchemaVersion(667);
    ReflectionWrapper wrapper = new ReflectionWrapper(cat);
    wrapper.call("reloadCache");
    dbs = cat.listDatabases();
    assertEquals(3, dbs.size());
    names = dbs.stream().map(TiDBInfo::getName).sorted().collect(Collectors.toList());
    assertEquals("global_temp", names.get(0));
    assertEquals("other", names.get(1));
    assertEquals("tpch_001", names.get(2));
    assertEquals(130, cat.getDatabase("global_temp").getId());
    assertNull(cat.getDatabase("global_temp111"));
}
Also used : MetaMockHelper(com.pingcap.tikv.meta.MetaUtils.MetaMockHelper) TiDBInfo(com.pingcap.tikv.meta.TiDBInfo) ReflectionWrapper(com.pingcap.tikv.util.ReflectionWrapper) PDMockServerTest(com.pingcap.tikv.PDMockServerTest) Test(org.junit.Test)

Aggregations

PDMockServerTest (com.pingcap.tikv.PDMockServerTest)2 MetaMockHelper (com.pingcap.tikv.meta.MetaUtils.MetaMockHelper)2 TiDBInfo (com.pingcap.tikv.meta.TiDBInfo)2 ReflectionWrapper (com.pingcap.tikv.util.ReflectionWrapper)2 Test (org.junit.Test)2 TiTableInfo (com.pingcap.tikv.meta.TiTableInfo)1