Search in sources :

Example 26 with SchemaConfig

use of com.alibaba.cobar.config.model.SchemaConfig in project cobar by alibaba.

the class ServerRouteTest method testNonPartitionSQL.

public void testNonPartitionSQL() throws Exception {
    SchemaConfig schema = schemaMap.get("cndb");
    String sql = "  select * from `dual`";
    RouteResultset rrs = ServerRouter.route(schema, sql, null, null);
    Assert.assertEquals(1, rrs.getNodes().length);
    Assert.assertEquals((int) RouteResultsetNode.DEFAULT_REPLICA_INDEX, rrs.getNodes()[0].getReplicaIndex());
    Assert.assertEquals("cndb_dn", rrs.getNodes()[0].getName());
    Assert.assertEquals("  select * from `dual`", rrs.getNodes()[0].getStatement());
    schema = schemaMap.get("dubbo");
    sql = "  select * from `dual`";
    rrs = ServerRouter.route(schema, sql, null, null);
    Assert.assertEquals(1, rrs.getNodes().length);
    Assert.assertEquals((int) RouteResultsetNode.DEFAULT_REPLICA_INDEX, rrs.getNodes()[0].getReplicaIndex());
    Assert.assertEquals("dubbo_dn", rrs.getNodes()[0].getName());
    Assert.assertEquals("  select * from `dual`", rrs.getNodes()[0].getStatement());
    schema = schemaMap.get("dubbo");
    sql = "  select * from dubbo.`dual`";
    rrs = ServerRouter.route(schema, sql, null, null);
    Assert.assertEquals(1, rrs.getNodes().length);
    Assert.assertEquals((int) RouteResultsetNode.DEFAULT_REPLICA_INDEX, rrs.getNodes()[0].getReplicaIndex());
    Assert.assertEquals("dubbo_dn", rrs.getNodes()[0].getName());
    Assert.assertEquals("  select * from dubbo.`dual`", rrs.getNodes()[0].getStatement());
    sql = "SHOW TABLES from db_name like 'solo'";
    rrs = ServerRouter.route(schema, sql, null, null);
    Assert.assertEquals(-1L, rrs.getLimitSize());
    Assert.assertEquals((int) RouteResultsetNode.DEFAULT_REPLICA_INDEX, rrs.getNodes()[0].getReplicaIndex());
    Assert.assertEquals(1, rrs.getNodes().length);
    Assert.assertEquals("dubbo_dn", rrs.getNodes()[0].getName());
    Assert.assertEquals("SHOW TABLES from db_name like 'solo'", rrs.getNodes()[0].getStatement());
    sql = "desc cndb.offer";
    rrs = ServerRouter.route(schema, sql, null, null);
    Assert.assertEquals(-1L, rrs.getLimitSize());
    Assert.assertEquals((int) RouteResultsetNode.DEFAULT_REPLICA_INDEX, rrs.getNodes()[0].getReplicaIndex());
    Assert.assertEquals(1, rrs.getNodes().length);
    Assert.assertEquals("dubbo_dn", rrs.getNodes()[0].getName());
    Assert.assertEquals("desc cndb.offer", rrs.getNodes()[0].getStatement());
    schema = schemaMap.get("cndb");
    sql = "SHOW fulL TaBLES from db_name like 'solo'";
    rrs = ServerRouter.route(schema, sql, null, null);
    Map<String, RouteResultsetNode> nodeMap = getNodeMap(rrs, 4);
    NodeNameAsserter nameAsserter = new NodeNameAsserter("detail_dn[0]", "offer_dn[0]", "cndb_dn", "independent_dn[0]");
    nameAsserter.assertRouteNodeNames(nodeMap.keySet());
    SimpleSQLAsserter sqlAsserter = new SimpleSQLAsserter();
    sqlAsserter.addExpectSQL(0, "SHOW FULL TABLES LIKE 'solo'").addExpectSQL(1, "SHOW FULL TABLES LIKE 'solo'").addExpectSQL(2, "SHOW FULL TABLES LIKE 'solo'").addExpectSQL(3, "SHOW FULL TABLES LIKE 'solo'");
    RouteNodeAsserter asserter = new RouteNodeAsserter(nameAsserter, sqlAsserter);
    for (RouteResultsetNode node : nodeMap.values()) {
        asserter.assertNode(node);
    }
}
Also used : SchemaConfig(com.alibaba.cobar.config.model.SchemaConfig)

Example 27 with SchemaConfig

use of com.alibaba.cobar.config.model.SchemaConfig in project cobar by alibaba.

the class ServerRoutePerformance method perf.

public void perf() throws Exception {
    TestProvider provider;
    provider = new InsertLongSQLGen();
    provider = new InsertLongSQLGenShort();
    provider = new SelectShort();
    provider = new InsertLong();
    provider = new SelectLongIn();
    provider = new ShardingMultiTableSpace();
    provider = new ShardingDefaultSpace();
    provider = new ShardingTableSpace();
    SchemaConfig schema = getSchema();
    String sql = provider.getSql();
    System.out.println(ServerRouter.route(schema, sql, null, null));
    long start = System.currentTimeMillis();
    provider.route(schema, 1, sql);
    long end;
    int loop = 200 * 10000;
    start = System.currentTimeMillis();
    provider.route(schema, loop, sql);
    end = System.currentTimeMillis();
    System.out.println((end - start) * 1000.0d / loop + " us");
}
Also used : SchemaConfig(com.alibaba.cobar.config.model.SchemaConfig)

Aggregations

SchemaConfig (com.alibaba.cobar.config.model.SchemaConfig)27 CobarConfig (com.alibaba.cobar.CobarConfig)6 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)5 MySQLDataSource (com.alibaba.cobar.mysql.MySQLDataSource)4 RowDataPacket (com.alibaba.cobar.net.mysql.RowDataPacket)4 CobarCluster (com.alibaba.cobar.CobarCluster)3 EOFPacket (com.alibaba.cobar.net.mysql.EOFPacket)3 FieldPacket (com.alibaba.cobar.net.mysql.FieldPacket)3 ByteBuffer (java.nio.ByteBuffer)3 DataSourceConfig (com.alibaba.cobar.config.model.DataSourceConfig)2 QuarantineConfig (com.alibaba.cobar.config.model.QuarantineConfig)2 UserConfig (com.alibaba.cobar.config.model.UserConfig)2 ConfigException (com.alibaba.cobar.config.util.ConfigException)2 SQLNonTransientException (java.sql.SQLNonTransientException)2 ArrayList (java.util.ArrayList)2 CobarNode (com.alibaba.cobar.CobarNode)1 ConfigInitializer (com.alibaba.cobar.ConfigInitializer)1 TableConfig (com.alibaba.cobar.config.model.TableConfig)1 RowExpression (com.alibaba.cobar.parser.ast.expression.primary.RowExpression)1 SQLStatement (com.alibaba.cobar.parser.ast.stmt.SQLStatement)1