Search in sources :

Example 26 with SQLSyntaxErrorException

use of java.sql.SQLSyntaxErrorException in project zipkin by openzipkin.

the class SchemaTest method hasDependencies_missing.

@Test
public void hasDependencies_missing() throws SQLException {
    SQLSyntaxErrorException sqlException = new SQLSyntaxErrorException("SQL [select count(*) from `zipkin_dependencies`]; Table 'zipkin.zipkin_dependencies' doesn't exist\n" + "  Query is : select count(*) from `zipkin_dependencies`", "42S02", 1146);
    DataSource dataSource = mock(DataSource.class);
    // cheats to lower mock count: this exception is really thrown during execution of the query
    when(dataSource.getConnection()).thenThrow(new DataAccessException(sqlException.getMessage(), sqlException));
    assertThat(schema.hasPreAggregatedDependencies).isFalse();
}
Also used : SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) DataAccessException(org.jooq.exception.DataAccessException) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 27 with SQLSyntaxErrorException

use of java.sql.SQLSyntaxErrorException in project zipkin by openzipkin.

the class SchemaTest method hasRemoteServiceName_falseWhenKnownSQLState.

@Test
public void hasRemoteServiceName_falseWhenKnownSQLState() throws SQLException {
    SQLSyntaxErrorException sqlException = new SQLSyntaxErrorException("Unknown column 'zipkin_spans.remote_serviceName' in 'field list'", "42S22", 1054);
    // cheats to lower mock count: this exception is really thrown during execution of the query
    when(dataSource.getConnection()).thenThrow(new DataAccessException(sqlException.getMessage(), sqlException));
    assertThat(schema.hasRemoteServiceName).isFalse();
}
Also used : SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) DataAccessException(org.jooq.exception.DataAccessException) Test(org.junit.Test)

Example 28 with SQLSyntaxErrorException

use of java.sql.SQLSyntaxErrorException in project zipkin by openzipkin.

the class SchemaTest method hasIpv6_falseWhenUnknownSQLState.

/**
 * This returns false instead of failing when the SQLState code doesn't imply the column is
 * missing. This is to prevent zipkin from crashing due to scenarios we haven't thought up, yet.
 * The root error goes into the log in this case.
 */
@Test
public void hasIpv6_falseWhenUnknownSQLState() throws SQLException {
    SQLSyntaxErrorException sqlException = new SQLSyntaxErrorException("java.sql.SQLSyntaxErrorException: Table 'zipkin.zipkin_annotations' doesn't exist", "42S02", 1146);
    DataSource dataSource = mock(DataSource.class);
    // cheats to lower mock count: this exception is really thrown during execution of the query
    when(dataSource.getConnection()).thenThrow(new DataAccessException(sqlException.getMessage(), sqlException));
    assertThat(schema.hasIpv6).isFalse();
}
Also used : SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) DataAccessException(org.jooq.exception.DataAccessException) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 29 with SQLSyntaxErrorException

use of java.sql.SQLSyntaxErrorException in project zipkin by openzipkin.

the class SchemaTest method hasErrorCount_falseWhenUnknownSQLState.

/**
 * This returns false instead of failing when the SQLState code doesn't imply the column is
 * missing. This is to prevent zipkin from crashing due to scenarios we haven't thought up, yet.
 * The root error goes into the log in this case.
 */
@Test
public void hasErrorCount_falseWhenUnknownSQLState() throws SQLException {
    SQLSyntaxErrorException sqlException = new SQLSyntaxErrorException("java.sql.SQLSyntaxErrorException: Table 'zipkin.zipkin_dependencies' doesn't exist", "42S02", 1146);
    DataSource dataSource = mock(DataSource.class);
    // cheats to lower mock count: this exception is really thrown during execution of the query
    when(dataSource.getConnection()).thenThrow(new DataAccessException(sqlException.getMessage(), sqlException));
    assertThat(schema.hasErrorCount).isFalse();
}
Also used : SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) DataAccessException(org.jooq.exception.DataAccessException) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 30 with SQLSyntaxErrorException

use of java.sql.SQLSyntaxErrorException in project zipkin by openzipkin.

the class SchemaTest method hasIpv6_falseWhenUnknownSQLState.

/**
   * This returns false instead of failing when the SQLState code doesn't imply the column is
   * missing. This is to prevent zipkin from crashing due to scenarios we haven't thought up, yet.
   * The root error goes into the log in this case.
   */
@Test
public void hasIpv6_falseWhenUnknownSQLState() throws SQLException {
    SQLSyntaxErrorException sqlException = new SQLSyntaxErrorException("java.sql.SQLSyntaxErrorException: Table 'zipkin.zipkin_annotations' doesn't exist", "42S02", 1146);
    DataSource dataSource = mock(DataSource.class);
    // cheats to lower mock count: this exception is really thrown during execution of the query
    when(dataSource.getConnection()).thenThrow(new DataAccessException(sqlException.getMessage(), sqlException));
    assertThat(schema.hasIpv6).isFalse();
}
Also used : SQLSyntaxErrorException(java.sql.SQLSyntaxErrorException) DataAccessException(org.jooq.exception.DataAccessException) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Aggregations

SQLSyntaxErrorException (java.sql.SQLSyntaxErrorException)55 Test (org.junit.Test)14 Test (org.testng.annotations.Test)14 BaseTest (util.BaseTest)14 DataAccessException (org.jooq.exception.DataAccessException)9 HashMap (java.util.HashMap)7 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)6 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)6 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)6 TableConfig (io.mycat.config.model.TableConfig)6 SQLNonTransientException (java.sql.SQLNonTransientException)6 Expression (com.alibaba.cobar.parser.ast.expression.Expression)5 Identifier (com.alibaba.cobar.parser.ast.expression.primary.Identifier)4 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)4 SchemaConfig (io.mycat.config.model.SchemaConfig)4 DruidShardingParseInfo (io.mycat.route.parser.druid.DruidShardingParseInfo)4 MycatSchemaStatVisitor (io.mycat.route.parser.druid.MycatSchemaStatVisitor)4 MycatStatementParser (io.mycat.route.parser.druid.MycatStatementParser)4 SQLException (java.sql.SQLException)4 DataSource (javax.sql.DataSource)4