Search in sources :

Example 1 with MetaMockHelper

use of com.pingcap.tikv.meta.MetaUtils.MetaMockHelper in project tispark by pingcap.

the class CatalogTransactionTest method getMultipleDatabasesTest.

@Test
public void getMultipleDatabasesTest() {
    MetaMockHelper helper = new MetaMockHelper(pdServer, kvServer);
    helper.preparePDForRegionRead();
    helper.addDatabase(130, "global_temp");
    for (int i = 1; i <= 200; i++) {
        helper.addDatabase(263 + i, String.format("TPCH_%03d", i));
    }
    CatalogTransaction trx = new CatalogTransaction(session.createSnapshot());
    List<TiDBInfo> dbs = trx.getDatabases();
    assertEquals(201, dbs.size());
    assertEquals(130, dbs.get(0).getId());
    assertEquals("global_temp", dbs.get(0).getName());
    assertEquals(264, dbs.get(1).getId());
    assertEquals("tpch_001", dbs.get(1).getName());
    assertEquals(463, dbs.get(200).getId());
    assertEquals("tpch_200", dbs.get(200).getName());
    TiDBInfo db0 = trx.getDatabase(130);
    assertEquals(130, db0.getId());
    assertEquals("global_temp", db0.getName());
    TiDBInfo db1 = trx.getDatabase(400);
    assertEquals(400, db1.getId());
    assertEquals("tpch_137", db1.getName());
}
Also used : MetaMockHelper(com.pingcap.tikv.meta.MetaUtils.MetaMockHelper) TiDBInfo(com.pingcap.tikv.meta.TiDBInfo) Test(org.junit.Test)

Example 2 with MetaMockHelper

use of com.pingcap.tikv.meta.MetaUtils.MetaMockHelper in project tispark by pingcap.

the class CatalogTransactionTest method getDatabasesTest.

@Test
public void getDatabasesTest() {
    MetaMockHelper helper = new MetaMockHelper(pdServer, kvServer);
    helper.preparePDForRegionRead();
    helper.addDatabase(130, "global_temp");
    helper.addDatabase(264, "TPCH_001");
    CatalogTransaction trx = new CatalogTransaction(session.createSnapshot());
    List<TiDBInfo> dbs = trx.getDatabases();
    assertEquals(2, dbs.size());
    assertEquals(130, dbs.get(0).getId());
    assertEquals("global_temp", dbs.get(0).getName());
    assertEquals(264, dbs.get(1).getId());
    assertEquals("tpch_001", dbs.get(1).getName());
    TiDBInfo db = trx.getDatabase(130);
    assertEquals(130, db.getId());
    assertEquals("global_temp", db.getName());
}
Also used : MetaMockHelper(com.pingcap.tikv.meta.MetaUtils.MetaMockHelper) TiDBInfo(com.pingcap.tikv.meta.TiDBInfo) Test(org.junit.Test)

Example 3 with MetaMockHelper

use of com.pingcap.tikv.meta.MetaUtils.MetaMockHelper 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 4 with MetaMockHelper

use of com.pingcap.tikv.meta.MetaUtils.MetaMockHelper 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)

Example 5 with MetaMockHelper

use of com.pingcap.tikv.meta.MetaUtils.MetaMockHelper in project tispark by pingcap.

the class CatalogTransactionTest method getLatestSchemaVersionTest.

@Test
public void getLatestSchemaVersionTest() {
    MetaMockHelper helper = new MetaMockHelper(pdServer, kvServer);
    helper.preparePDForRegionRead();
    helper.setSchemaVersion(666);
    CatalogTransaction trx = new CatalogTransaction(session.createSnapshot());
    assertEquals(666, trx.getLatestSchemaVersion());
}
Also used : MetaMockHelper(com.pingcap.tikv.meta.MetaUtils.MetaMockHelper) Test(org.junit.Test)

Aggregations

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