Search in sources :

Example 1 with HostInfo

use of com.mysql.cj.conf.HostInfo in project gocd by gocd.

the class MySQLBackupProcessor method createProcessExecutor.

private ProcessExecutor createProcessExecutor(File targetDir, DbProperties dbProperties) {
    ConnectionUrl connectionUrlInstance = ConnectionUrl.getConnectionUrlInstance(dbProperties.url(), dbProperties.connectionProperties());
    LinkedHashMap<String, String> env = new LinkedHashMap<>();
    if (isNotBlank(dbProperties.password())) {
        env.put("MYSQL_PWD", dbProperties.password());
    }
    // override with any user specified environment
    env.putAll(dbProperties.extraBackupEnv());
    ArrayList<String> argv = new ArrayList<>();
    argv.add("mysqldump");
    String dbName = connectionUrlInstance.getDatabase();
    HostInfo mainHost = connectionUrlInstance.getMainHost();
    if (mainHost != null) {
        argv.add("--host=" + mainHost.getHost());
        argv.add("--port=" + mainHost.getPort());
    }
    if (isNotBlank(dbProperties.user())) {
        argv.add("--user=" + dbProperties.user());
    }
    // append any user specified args for mysqldump
    if (isNotBlank(dbProperties.extraBackupCommandArgs())) {
        Collections.addAll(argv, Commandline.translateCommandline(dbProperties.extraBackupCommandArgs()));
    }
    argv.add("--result-file=" + new File(targetDir, "db." + dbName).toString());
    argv.add(connectionUrlInstance.getDatabase());
    ProcessExecutor processExecutor = new ProcessExecutor();
    processExecutor.redirectOutputAlsoTo(Slf4jStream.of(getClass()).asDebug());
    processExecutor.redirectErrorAlsoTo(Slf4jStream.of(getClass()).asDebug());
    processExecutor.environment(env);
    processExecutor.command(argv);
    return processExecutor;
}
Also used : ArrayList(java.util.ArrayList) ConnectionUrl(com.mysql.cj.conf.ConnectionUrl) ProcessExecutor(org.zeroturnaround.exec.ProcessExecutor) HostInfo(com.mysql.cj.conf.HostInfo) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with HostInfo

use of com.mysql.cj.conf.HostInfo in project Mycat2 by MyCATApache.

the class BinlogUtil method observe.

public static Flowable<ParamSQL> observe(String targetName, List<Partition> partitions) {
    JdbcConnectionManager jdbcConnectionManager = MetaClusterCurrent.wrapper(JdbcConnectionManager.class);
    DatasourceConfig datasourceConfig = jdbcConnectionManager.getConfigAsMap().get(targetName);
    ConnectionUrlParser connectionUrlParser = ConnectionUrlParser.parseConnectionString(datasourceConfig.getUrl());
    HostInfo hostInfo = connectionUrlParser.getHosts().get(0);
    int port = hostInfo.getPort();
    String host = hostInfo.getHost();
    String username = datasourceConfig.getUser();
    String password = datasourceConfig.getPassword();
    BinaryLogClient client = new BinaryLogClient(datasourceConfig.getUrl(), port, username, password);
    NameMap<NameMap<Boolean>> filterMap = new NameMap<>();
    for (Partition partition : partitions) {
        String schema = partition.getSchema();
        String table = partition.getTable();
        NameMap<Boolean> map = filterMap.computeIfAbsent(SQLUtils.normalize(schema), s -> new NameMap<>());
        map.put(table, Boolean.TRUE);
    }
    return Flowable.create(new FlowableOnSubscribe<ParamSQL>() {

        @Override
        public void subscribe(@NonNull FlowableEmitter<ParamSQL> emitter) throws Throwable {
            client.registerEventListener(new BinaryLogClient.EventListener() {

                private final Map<Long, TableMapEventData> tablesById = new HashMap<Long, TableMapEventData>();

                private final Map<String, Map<Integer, Map<String, Object>>> tablesColumnMap = new HashMap<>();

                private String binlogFilename;

                private Charset charset = StandardCharsets.UTF_8;

                private Map<Integer, Map<String, Object>> loadColumn(String database, String table) {
                    Map<Integer, Map<String, Object>> res = new HashMap<>();
                    try (DefaultConnection defaultConnection = jdbcConnectionManager.getConnection(targetName)) {
                        List<Map<String, Object>> list = JdbcUtils.executeQuery(defaultConnection.getRawConnection(), "select  COLUMN_NAME, ORDINAL_POSITION, DATA_TYPE, CHARACTER_SET_NAME from INFORMATION_SCHEMA.COLUMNS where table_name='" + table + "' and TABLE_SCHEMA='" + database + "'", Collections.emptyList());
                        for (Map<String, Object> stringObjectMap : list) {
                            Number pos = (Number) stringObjectMap.get("ORDINAL_POSITION");
                            res.put(pos.intValue(), stringObjectMap);
                        }
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    return res;
                }

                @Override
                public void onEvent(Event event) {
                    try {
                        EventHeader header = event.getHeader();
                        switch(header.getEventType()) {
                            case UNKNOWN:
                                break;
                            case START_V3:
                                break;
                            case QUERY:
                                QueryEventData queryEventData = event.getData();
                                String query = queryEventData.getSql();
                                if (!query.startsWith("S")) {
                                    handleDDL(queryEventData);
                                }
                                break;
                            case STOP:
                                emitter.onComplete();
                                break;
                            case ROTATE:
                                {
                                    RotateEventData data = event.getData();
                                    this.binlogFilename = data.getBinlogFilename();
                                    break;
                                }
                            case INTVAR:
                                break;
                            case LOAD:
                                break;
                            case SLAVE:
                                break;
                            case CREATE_FILE:
                                break;
                            case APPEND_BLOCK:
                                break;
                            case EXEC_LOAD:
                                break;
                            case DELETE_FILE:
                                break;
                            case NEW_LOAD:
                                break;
                            case RAND:
                                break;
                            case USER_VAR:
                                break;
                            case FORMAT_DESCRIPTION:
                                break;
                            case XID:
                                break;
                            case BEGIN_LOAD_QUERY:
                                break;
                            case EXECUTE_LOAD_QUERY:
                                break;
                            case TABLE_MAP:
                                {
                                    handleTableMap(event);
                                    break;
                                }
                            case PRE_GA_WRITE_ROWS:
                            case WRITE_ROWS:
                            case EXT_WRITE_ROWS:
                                handleWriteRowsEvent(event);
                                break;
                            case EXT_UPDATE_ROWS:
                            case PRE_GA_UPDATE_ROWS:
                            case UPDATE_ROWS:
                                handleUpdateRowsEvent(event);
                                break;
                            case PRE_GA_DELETE_ROWS:
                            case EXT_DELETE_ROWS:
                            case DELETE_ROWS:
                                handleDeleteRowsEvent(event);
                                break;
                            case INCIDENT:
                                break;
                            case HEARTBEAT:
                                break;
                            case IGNORABLE:
                                break;
                            case ROWS_QUERY:
                                break;
                            case GTID:
                                break;
                            case ANONYMOUS_GTID:
                                break;
                            case PREVIOUS_GTIDS:
                                break;
                            case TRANSACTION_CONTEXT:
                                break;
                            case VIEW_CHANGE:
                                break;
                            case XA_PREPARE:
                                break;
                        }
                    } catch (Exception e) {
                        emitter.tryOnError(e);
                    }
                }

                private void handleDDL(QueryEventData event) {
                    String sql = event.getSql();
                    String database = event.getDatabase();
                    SQLStatement sqlStatement = SQLUtils.parseSingleMysqlStatement(sql);
                    if (sqlStatement instanceof SQLDDLStatement) {
                        SQLDDLStatement sqlDdlStatement = (SQLDDLStatement) sqlStatement;
                        MySqlSchemaStatVisitor mySqlSchemaStatVisitor = new MySqlSchemaStatVisitor();
                        sqlDdlStatement.accept(mySqlSchemaStatVisitor);
                        Map<TableStat.Name, TableStat> tables = mySqlSchemaStatVisitor.getTables();
                        boolean meet = tables.keySet().stream().allMatch(i -> filter(database, i.getName()));
                    }
                }

                private void handleUpdateRowsEvent(Event event) {
                    UpdateRowsEventData eventData = event.getData();
                    BitSet includedColumnsBeforeUpdate = eventData.getIncludedColumnsBeforeUpdate();
                    BitSet includedColumns = eventData.getIncludedColumns();
                    List<Map.Entry<Serializable[], Serializable[]>> rows = eventData.getRows();
                    TableMapEventData tableMapEvent = tablesById.get(eventData.getTableId());
                    if (!filter(tableMapEvent.getDatabase(), tableMapEvent.getTable()))
                        return;
                    MySqlUpdateStatement mySqlUpdateStatement = new MySqlUpdateStatement();
                    SQLExprTableSource sqlTableSource = new SQLExprTableSource();
                    sqlTableSource.setExpr("`" + tableMapEvent.getTable() + "`");
                    sqlTableSource.setSchema("`" + tableMapEvent.getDatabase() + "`");
                    mySqlUpdateStatement.setTableSource(sqlTableSource);
                    Map<Integer, Map<String, Object>> xxx = tablesColumnMap.get(tableMapEvent.getDatabase() + "." + tableMapEvent.getTable());
                    SQLBinaryOpExprGroup sqlBinaryOpExprGroup = getCondition(includedColumnsBeforeUpdate, xxx);
                    for (int i = 0; i < includedColumns.length(); i++) {
                        int column = includedColumns.nextSetBit(i);
                        Map<String, Object> coumnMap = xxx.get(column + 1);
                        Object column_name = coumnMap.get("COLUMN_NAME");
                        SQLUpdateSetItem sqlUpdateSetItem = new SQLUpdateSetItem();
                        sqlUpdateSetItem.setColumn(new SQLIdentifierExpr("`" + column_name + "`"));
                        sqlUpdateSetItem.setValue(new SQLVariantRefExpr("?"));
                        mySqlUpdateStatement.getItems().add(sqlUpdateSetItem);
                    }
                    mySqlUpdateStatement.setWhere(sqlBinaryOpExprGroup);
                    mySqlUpdateStatement.setLimit(new SQLLimit(1));
                    sqlUpdate(mySqlUpdateStatement.toString(), rows);
                }

                private SQLBinaryOpExprGroup getCondition(BitSet includedColumnsBeforeUpdate, Map<Integer, Map<String, Object>> xxx) {
                    SQLBinaryOpExprGroup sqlBinaryOpExprGroup = new SQLBinaryOpExprGroup(SQLBinaryOperator.BooleanAnd);
                    for (int i = 0; i < includedColumnsBeforeUpdate.length(); i++) {
                        int column = includedColumnsBeforeUpdate.nextSetBit(i);
                        Map<String, Object> coumnMap = xxx.get(column + 1);
                        Object column_name = coumnMap.get("COLUMN_NAME");
                        SQLExpr sqlExpr = SQLUtils.toSQLExpr("`" + column_name + "` <=> ?");
                        sqlBinaryOpExprGroup.add(sqlExpr);
                    }
                    return sqlBinaryOpExprGroup;
                }

                private void sqlUpdate(String toString, List<Map.Entry<Serializable[], Serializable[]>> rows) {
                    for (Map.Entry<Serializable[], Serializable[]> row : rows) {
                        Serializable[] key = row.getKey();
                        Serializable[] value = row.getValue();
                        Object[] objects = new Object[key.length + value.length];
                        System.arraycopy(key, 0, objects, 0, key.length);
                        System.arraycopy(value, 0, objects, key.length, key.length + value.length);
                        emitter.onNext(ParamSQL.of(toString, objects));
                    }
                }

                private boolean filter(String database, String table) {
                    if (Strings.isNullOrEmpty(database)) {
                        return false;
                    }
                    if (Strings.isNullOrEmpty(table)) {
                        return false;
                    }
                    NameMap<Boolean> tableMap = filterMap.get(SQLUtils.normalize(database), false);
                    if (tableMap != null && !tableMap.map().isEmpty()) {
                        return Boolean.TRUE.equals(tableMap.get(SQLUtils.normalize(table)));
                    }
                    return false;
                }

                private void handleTableMap(Event event) {
                    TableMapEventData tableMapEventData = event.getData();
                    tablesById.put(tableMapEventData.getTableId(), tableMapEventData);
                    String tableName = tableMapEventData.getDatabase() + "." + tableMapEventData.getTable();
                    if (!tablesColumnMap.containsKey(tableName)) {
                        tablesColumnMap.put(tableName, loadColumn(tableMapEventData.getDatabase(), tableMapEventData.getTable()));
                    }
                }

                private void handleWriteRowsEvent(Event event) {
                    WriteRowsEventData eventData = event.getData();
                    TableMapEventData tableMapEvent = tablesById.get(eventData.getTableId());
                    if (!filter(tableMapEvent.getDatabase(), tableMapEvent.getTable()))
                        return;
                    Map<Integer, Map<String, Object>> xxx = tablesColumnMap.get(tableMapEvent.getDatabase() + "." + tableMapEvent.getTable());
                    BitSet inculudeColumn = eventData.getIncludedColumns();
                    MySqlInsertStatement mySqlInsertStatement = new MySqlInsertStatement();
                    mySqlInsertStatement.setTableName(new SQLIdentifierExpr("`" + tableMapEvent.getTable() + "`"));
                    mySqlInsertStatement.getTableSource().setSchema("`" + tableMapEvent.getDatabase() + "`");
                    SQLInsertStatement.ValuesClause values = new SQLInsertStatement.ValuesClause();
                    mySqlInsertStatement.setValues(values);
                    int size = inculudeColumn.length();
                    List<Serializable[]> rows = eventData.getRows();
                    for (int i = 0; i < size; i++) {
                        int column = inculudeColumn.nextSetBit(i);
                        Map<String, Object> coumnMap = xxx.get(column + 1);
                        Object column_name = coumnMap.get("COLUMN_NAME");
                        mySqlInsertStatement.addColumn(new SQLIdentifierExpr("`" + column_name + "`"));
                        values.addValue(new SQLVariantRefExpr("?"));
                    }
                    sqlInsert(mySqlInsertStatement.toString(), rows);
                }

                private void sqlInsert(String sql, List<Serializable[]> rows) {
                    for (Serializable[] row : rows) {
                        Object[] objects = new Object[row.length];
                        System.arraycopy(row, 0, objects, 0, row.length);
                        emitter.onNext(ParamSQL.of(sql, objects));
                    }
                }

                private void handleDeleteRowsEvent(Event event) {
                    DeleteRowsEventData eventData = event.getData();
                    EventHeader header = event.getHeader();
                    TableMapEventData tableMapEvent = tablesById.get(eventData.getTableId());
                    if (!filter(tableMapEvent.getDatabase(), tableMapEvent.getTable()))
                        return;
                    Map<Integer, Map<String, Object>> xxx = tablesColumnMap.get(tableMapEvent.getDatabase() + "." + tableMapEvent.getTable());
                    BitSet inculudeColumn = eventData.getIncludedColumns();
                    SQLBinaryOpExprGroup condition = getCondition(inculudeColumn, xxx);
                    int size = inculudeColumn.length();
                    List<Serializable[]> rows = eventData.getRows();
                    MySqlDeleteStatement mySqlDeleteStatement = new MySqlDeleteStatement();
                    mySqlDeleteStatement.setLimit(new SQLLimit(1));
                    SQLExprTableSource sqlExprTableSource = new SQLExprTableSource();
                    sqlExprTableSource.setExpr("`" + tableMapEvent.getTable() + "`");
                    sqlExprTableSource.setSchema("`" + tableMapEvent.getDatabase() + "`");
                    mySqlDeleteStatement.setTableSource(sqlExprTableSource);
                    mySqlDeleteStatement.addWhere(condition);
                    sqlDelete(mySqlDeleteStatement.toString(), rows);
                }

                private void sqlDelete(String mySqlDeleteStatement, List<Serializable[]> rows) {
                    for (Serializable[] row : rows) {
                        Object[] objects = new Object[row.length];
                        System.arraycopy(row, 0, objects, 0, row.length);
                        emitter.onNext(ParamSQL.of(mySqlDeleteStatement, objects));
                    }
                }
            });
            client.connect();
        }
    }, BackpressureStrategy.BUFFER);
}
Also used : Serializable(java.io.Serializable) ToString(groovy.transform.ToString) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) DatasourceConfig(io.mycat.config.DatasourceConfig) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) SQLDDLStatement(com.alibaba.druid.sql.ast.statement.SQLDDLStatement) SQLUpdateSetItem(com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem) MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) MySqlDeleteStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDeleteStatement) SQLVariantRefExpr(com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr) NameMap(io.mycat.util.NameMap) SQLException(java.sql.SQLException) SQLLimit(com.alibaba.druid.sql.ast.SQLLimit) TableStat(com.alibaba.druid.stat.TableStat) BinaryLogClient(com.github.shyiko.mysql.binlog.BinaryLogClient) MySqlUpdateStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement) SQLInsertStatement(com.alibaba.druid.sql.ast.statement.SQLInsertStatement) SQLBinaryOpExprGroup(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExprGroup) Partition(io.mycat.Partition) Charset(java.nio.charset.Charset) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) NameMap(io.mycat.util.NameMap) MySqlInsertStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement) ConnectionUrlParser(com.mysql.cj.conf.ConnectionUrlParser) SQLException(java.sql.SQLException) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) DefaultConnection(io.mycat.datasource.jdbc.datasource.DefaultConnection) SQLExprTableSource(com.alibaba.druid.sql.ast.statement.SQLExprTableSource) JdbcConnectionManager(io.mycat.datasource.jdbc.datasource.JdbcConnectionManager) HostInfo(com.mysql.cj.conf.HostInfo)

Example 3 with HostInfo

use of com.mysql.cj.conf.HostInfo in project Mycat2 by MyCATApache.

the class AbstractSQLHandler method executeOnDataNodes.

public void executeOnDataNodes(SQLStatement sqlStatement, JdbcConnectionManager connectionManager, Collection<Partition> partitions, SQLExprTableSource tableSource) {
    HashSet<String> set = new HashSet<>();
    for (Partition partition : partitions) {
        MycatSQLExprTableSourceUtil.setSqlExprTableSource(partition.getSchema(), partition.getTable(), tableSource);
        String sql = sqlStatement.toString();
        try (DefaultConnection connection = connectionManager.getConnection(partition.getTargetName())) {
            DatasourceConfig config = connection.getDataSource().getConfig();
            ConnectionUrlParser connectionUrlParser = ConnectionUrlParser.parseConnectionString(config.getUrl());
            HostInfo hostInfo = connectionUrlParser.getHosts().get(0);
            String ip = hostInfo.getHost();
            String port = hostInfo.getPort() + "";
            if (set.add(ip + ":" + port + ":" + sql)) {
                connection.executeUpdate(sql, false);
            }
        }
    }
}
Also used : DatasourceConfig(io.mycat.config.DatasourceConfig) DefaultConnection(io.mycat.datasource.jdbc.datasource.DefaultConnection) ConnectionUrlParser(com.mysql.cj.conf.ConnectionUrlParser) HostInfo(com.mysql.cj.conf.HostInfo)

Example 4 with HostInfo

use of com.mysql.cj.conf.HostInfo in project Mycat2 by MyCATApache.

the class MycatMySQLManagerImpl method createNativeDatasourcePool.

@NotNull
public static MycatDatasourcePool createNativeDatasourcePool(DatasourceConfig datasource, String targetName) {
    ConnectionUrlParser connectionUrlParser = ConnectionUrlParser.parseConnectionString(datasource.getUrl());
    HostInfo hostInfo = connectionUrlParser.getHosts().get(0);
    int port = hostInfo.getPort();
    String host = hostInfo.getHost();
    String username = datasource.getUser();
    String password = datasource.getPassword();
    VertxPoolConnectionImpl.Config config = new VertxPoolConnectionImpl.Config();
    config.setHost(host);
    config.setPassword(password);
    config.setUsername(username);
    config.setPort(port);
    config.setDatabase(connectionUrlParser.getPath());
    config.setRetry(datasource.getMaxRetryCount());
    config.setTimer(datasource.getIdleTimeout());
    config.setClientDeprecateEof(NewMycatConnectionConfig.CLIENT_DEPRECATE_EOF);
    Vertx vertx = MetaClusterCurrent.wrapper(Vertx.class);
    VertxPoolConnectionImpl vertxConnectionPool = new VertxPoolConnectionImpl(config, vertx);
    return new MycatNativeDatasourcePool(vertxConnectionPool, targetName);
}
Also used : VertxPoolConnectionImpl(io.mycat.mysqlclient.VertxPoolConnectionImpl) MycatNativeDatasourcePool(io.mycat.mysqlclient.MycatNativeDatasourcePool) NewMycatConnectionConfig(io.mycat.newquery.NewMycatConnectionConfig) DatasourceConfig(io.mycat.config.DatasourceConfig) Vertx(io.vertx.core.Vertx) ConnectionUrlParser(com.mysql.cj.conf.ConnectionUrlParser) HostInfo(com.mysql.cj.conf.HostInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with HostInfo

use of com.mysql.cj.conf.HostInfo in project aws-mysql-jdbc by awslabs.

the class ConnectionUrlTest method testBug28150662.

/**
 * Tests fix for BUG#28150662, CONNECTOR/J 8 MALFORMED DATABASE URL EXCEPTION WHIT CORRECT URL STRING.
 */
@Test
public void testBug28150662() {
    List<String> connStr = new ArrayList<>();
    connStr.add("jdbc:mysql://localhost:3306/db1?connectionCollation=utf8mb4_unicode_ci&user=user1&sessionVariables=sql_mode='IGNORE_SPACE,ANSI',FOREIGN_KEY_CHECKS=0");
    connStr.add("jdbc:mysql://localhost:3306/db1?connectionCollation=utf8mb4_unicode_ci&sessionVariables=sql_mode='IGNORE_SPACE,ANSI',FOREIGN_KEY_CHECKS=0&user=user1");
    connStr.add("jdbc:mysql://address=(host=localhost)(port=3306)(connectionCollation=utf8mb4_unicode_ci)(sessionVariables=sql_mode='IGNORE_SPACE,ANSI',FOREIGN_KEY_CHECKS=0)(user=user1)/db1");
    connStr.add("jdbc:mysql://(host=localhost,port=3306,connectionCollation=utf8mb4_unicode_ci,sessionVariables=sql_mode='IGNORE_SPACE%2CANSI'%2CFOREIGN_KEY_CHECKS=0,user=user1)/db1");
    connStr.add("jdbc:mysql://verylonghostname01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789:3306/db1?connectionCollation=utf8mb4_unicode_ci&user=user1&sessionVariables=sql_mode='IGNORE_SPACE,ANSI',FOREIGN_KEY_CHECKS=0");
    connStr.add("jdbc:mysql://verylonghostname01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789:3306/db1?connectionCollation=utf8mb4_unicode_ci&sessionVariables=sql_mode='IGNORE_SPACE,ANSI',FOREIGN_KEY_CHECKS=0&user=user1");
    connStr.add("jdbc:mysql://address=(host=verylonghostname01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789)(port=3306)(connectionCollation=utf8mb4_unicode_ci)(sessionVariables=sql_mode='IGNORE_SPACE,ANSI',FOREIGN_KEY_CHECKS=0)(user=user1)/db1");
    connStr.add("jdbc:mysql://(host=verylonghostname01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789,port=3306,connectionCollation=utf8mb4_unicode_ci,sessionVariables=sql_mode='IGNORE_SPACE%2CANSI'%2CFOREIGN_KEY_CHECKS=0,user=user1)/db1");
    for (String cs : connStr) {
        ConnectionUrl url = ConnectionUrl.getConnectionUrlInstance(cs, null);
        HostInfo hi = url.getMainHost();
        assertEquals("utf8mb4_unicode_ci", hi.getHostProperties().get("connectionCollation"));
        assertEquals("user1", hi.getUser());
        assertEquals("sql_mode='IGNORE_SPACE,ANSI',FOREIGN_KEY_CHECKS=0", hi.getHostProperties().get("sessionVariables"));
    }
}
Also used : ArrayList(java.util.ArrayList) ReplicationConnectionUrl(com.mysql.cj.conf.url.ReplicationConnectionUrl) XDevApiConnectionUrl(com.mysql.cj.conf.url.XDevApiConnectionUrl) SingleConnectionUrl(com.mysql.cj.conf.url.SingleConnectionUrl) LoadBalanceConnectionUrl(com.mysql.cj.conf.url.LoadBalanceConnectionUrl) XDevApiDnsSrvConnectionUrl(com.mysql.cj.conf.url.XDevApiDnsSrvConnectionUrl) LoadBalanceDnsSrvConnectionUrl(com.mysql.cj.conf.url.LoadBalanceDnsSrvConnectionUrl) FailoverDnsSrvConnectionUrl(com.mysql.cj.conf.url.FailoverDnsSrvConnectionUrl) ConnectionUrl(com.mysql.cj.conf.ConnectionUrl) ReplicationDnsSrvConnectionUrl(com.mysql.cj.conf.url.ReplicationDnsSrvConnectionUrl) FailoverConnectionUrl(com.mysql.cj.conf.url.FailoverConnectionUrl) HostInfo(com.mysql.cj.conf.HostInfo) Test(org.junit.jupiter.api.Test)

Aggregations

HostInfo (com.mysql.cj.conf.HostInfo)82 Test (org.junit.jupiter.api.Test)40 JdbcConnection (com.mysql.cj.jdbc.JdbcConnection)27 ArrayList (java.util.ArrayList)27 ConnectionUrl (com.mysql.cj.conf.ConnectionUrl)22 Properties (java.util.Properties)21 HashMap (java.util.HashMap)17 SQLException (java.sql.SQLException)16 ConnectionImpl (com.mysql.cj.jdbc.ConnectionImpl)15 IConnectionProvider (com.mysql.cj.jdbc.ha.plugins.IConnectionProvider)13 Statement (java.sql.Statement)13 ResultSet (java.sql.ResultSet)12 List (java.util.List)10 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)9 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)9 Assertions.assertSame (org.junit.jupiter.api.Assertions.assertSame)9 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)9 Log (com.mysql.cj.log.Log)8 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)8 ArgumentMatchers.refEq (org.mockito.ArgumentMatchers.refEq)8