Search in sources :

Example 1 with MySQLDatabaseMeta

use of org.pentaho.di.core.database.MySQLDatabaseMeta in project pentaho-kettle by pentaho.

the class DatabaseLogExceptionFactoryTest method testExceptionStrategyWithMysqlDataTruncationException.

/**
 * PDI-5153
 * Test that in case of MysqlDataTruncation exception there will be no stack trace in log
 */
@Test
public void testExceptionStrategyWithMysqlDataTruncationException() {
    DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
    DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
    MysqlDataTruncation e = new MysqlDataTruncation();
    when(logTable.getDatabaseMeta()).thenReturn(databaseMeta);
    when(databaseMeta.getDatabaseInterface()).thenReturn(databaseInterface);
    LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy(logTable, new KettleDatabaseException(e));
    String strategyName = exceptionStrategy.getClass().getName();
    assertEquals(SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName);
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) MysqlDataTruncation(com.mysql.jdbc.MysqlDataTruncation) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) MariaDBDatabaseMeta(org.pentaho.di.core.database.MariaDBDatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) Test(org.junit.Test)

Example 2 with MySQLDatabaseMeta

use of org.pentaho.di.core.database.MySQLDatabaseMeta in project pentaho-kettle by pentaho.

the class DatabaseLookupUTest method createDatabaseMeta.

private DatabaseLookupMeta createDatabaseMeta() throws KettleException {
    MySQLDatabaseMeta mysql = new MySQLDatabaseMeta();
    mysql.setName("MySQL");
    DatabaseMeta dbMeta = new DatabaseMeta();
    dbMeta.setDatabaseInterface(mysql);
    DatabaseLookupMeta meta = new DatabaseLookupMeta();
    meta.setDatabaseMeta(dbMeta);
    meta.setTablename("VirtualTable");
    meta.setTableKeyField(new String[] { ID_FIELD });
    meta.setKeyCondition(new String[] { "=" });
    meta.setReturnValueNewName(new String[] { "returned value" });
    meta.setReturnValueField(new String[] { BINARY_FIELD });
    meta.setReturnValueDefaultType(new int[] { ValueMetaInterface.TYPE_BINARY });
    meta.setStreamKeyField1(new String[0]);
    meta.setStreamKeyField2(new String[0]);
    meta.setReturnValueDefault(new String[] { "" });
    meta = spy(meta);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            RowMetaInterface row = (RowMetaInterface) invocation.getArguments()[0];
            ValueMetaInterface v = new ValueMetaBinary(BINARY_FIELD);
            row.addValueMeta(v);
            return null;
        }
    }).when(meta).getFields(any(RowMetaInterface.class), anyString(), any(RowMetaInterface[].class), any(StepMeta.class), any(VariableSpace.class), any(Repository.class), any(IMetaStore.class));
    return meta;
}
Also used : VariableSpace(org.pentaho.di.core.variables.VariableSpace) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) ValueMetaBinary(org.pentaho.di.core.row.value.ValueMetaBinary) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) Repository(org.pentaho.di.repository.Repository) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 3 with MySQLDatabaseMeta

use of org.pentaho.di.core.database.MySQLDatabaseMeta in project pentaho-kettle by pentaho.

the class ValueMetaBaseTest method testGetValueFromSQLTypeBinaryMysql.

// PDI-14721 ESR-5021
@Test
public void testGetValueFromSQLTypeBinaryMysql() throws Exception {
    final int binaryColumnIndex = 1;
    ValueMetaBase valueMetaBase = new ValueMetaBase();
    DatabaseMeta dbMeta = Mockito.spy(new DatabaseMeta());
    DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
    dbMeta.setDatabaseInterface(databaseInterface);
    ResultSet resultSet = Mockito.mock(ResultSet.class);
    ResultSetMetaData metaData = Mockito.mock(ResultSetMetaData.class);
    Mockito.when(resultSet.getMetaData()).thenReturn(metaData);
    Mockito.when(metaData.getColumnType(binaryColumnIndex)).thenReturn(Types.LONGVARBINARY);
    ValueMetaInterface binaryValueMeta = valueMetaBase.getValueFromSQLType(dbMeta, TEST_NAME, metaData, binaryColumnIndex, false, false);
    Assert.assertEquals(ValueMetaInterface.TYPE_BINARY, binaryValueMeta.getType());
    Assert.assertTrue(binaryValueMeta.isBinary());
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) ResultSet(java.sql.ResultSet) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) NetezzaDatabaseMeta(org.pentaho.di.core.database.NetezzaDatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) Vertica5DatabaseMeta(org.pentaho.di.core.database.Vertica5DatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 4 with MySQLDatabaseMeta

use of org.pentaho.di.core.database.MySQLDatabaseMeta in project pentaho-kettle by pentaho.

the class DatabaseLogExceptionFactoryTest method testExceptionStrategyWithPacketTooBigExceptionPropSetY.

/**
 * Property value has priority
 */
@Test
public void testExceptionStrategyWithPacketTooBigExceptionPropSetY() {
    System.setProperty(DatabaseLogExceptionFactory.KETTLE_GLOBAL_PROP_NAME, PROPERTY_VALUE_TRUE);
    DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
    DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
    PacketTooBigException e = new PacketTooBigException();
    when(logTable.getDatabaseMeta()).thenReturn(databaseMeta);
    when(databaseMeta.getDatabaseInterface()).thenReturn(databaseInterface);
    LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy(logTable, new KettleDatabaseException(e));
    String strategyName = exceptionStrategy.getClass().getName();
    assertEquals(THROWABLE, strategyName);
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) PacketTooBigException(com.mysql.jdbc.PacketTooBigException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) MariaDBDatabaseMeta(org.pentaho.di.core.database.MariaDBDatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) Test(org.junit.Test)

Example 5 with MySQLDatabaseMeta

use of org.pentaho.di.core.database.MySQLDatabaseMeta in project pentaho-kettle by pentaho.

the class DatabaseLogExceptionFactoryTest method testExceptionStrategyWithPacketTooBigException.

/**
 * PDI-5153
 * Test that in case of PacketTooBigException exception there will be no stack trace in log
 */
@Test
public void testExceptionStrategyWithPacketTooBigException() {
    DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
    DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
    PacketTooBigException e = new PacketTooBigException();
    when(logTable.getDatabaseMeta()).thenReturn(databaseMeta);
    when(databaseMeta.getDatabaseInterface()).thenReturn(databaseInterface);
    LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy(logTable, new KettleDatabaseException(e));
    String strategyName = exceptionStrategy.getClass().getName();
    assertEquals(SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName);
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) PacketTooBigException(com.mysql.jdbc.PacketTooBigException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) MariaDBDatabaseMeta(org.pentaho.di.core.database.MariaDBDatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) Test(org.junit.Test)

Aggregations

DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)7 MySQLDatabaseMeta (org.pentaho.di.core.database.MySQLDatabaseMeta)7 Test (org.junit.Test)5 DatabaseInterface (org.pentaho.di.core.database.DatabaseInterface)4 MariaDBDatabaseMeta (org.pentaho.di.core.database.MariaDBDatabaseMeta)3 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)3 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)3 StepMeta (org.pentaho.di.trans.step.StepMeta)3 PacketTooBigException (com.mysql.jdbc.PacketTooBigException)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)2 VariableSpace (org.pentaho.di.core.variables.VariableSpace)2 Repository (org.pentaho.di.repository.Repository)2 IMetaStore (org.pentaho.metastore.api.IMetaStore)2 MysqlDataTruncation (com.mysql.jdbc.MysqlDataTruncation)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1