Search in sources :

Example 1 with TestingWarningCollector

use of io.trino.testing.TestingWarningCollector in project trino by trinodb.

the class TestJdbcWarnings method testExecuteQueryWarnings.

@Test
public void testExecuteQueryWarnings() throws SQLException {
    try (ResultSet rs = statement.executeQuery("SELECT a FROM (VALUES 1, 2, 3) t(a)")) {
        assertNull(statement.getConnection().getWarnings());
        Set<WarningEntry> currentWarnings = new HashSet<>();
        assertWarnings(rs.getWarnings(), currentWarnings);
        while (rs.next()) {
            assertWarnings(statement.getWarnings(), currentWarnings);
        }
        TestingWarningCollectorConfig warningCollectorConfig = new TestingWarningCollectorConfig().setPreloadedWarnings(PRELOADED_WARNINGS).setAddWarnings(true);
        TestingWarningCollector warningCollector = new TestingWarningCollector(new WarningCollectorConfig(), warningCollectorConfig);
        List<TrinoWarning> expectedWarnings = warningCollector.getWarnings();
        for (TrinoWarning trinoWarning : expectedWarnings) {
            assertTrue(currentWarnings.contains(new WarningEntry(toTrinoSqlWarning(trinoWarning))));
        }
    }
}
Also used : WarningCollectorConfig(io.trino.execution.warnings.WarningCollectorConfig) TestingWarningCollectorConfig(io.trino.testing.TestingWarningCollectorConfig) TestingWarningCollectorConfig(io.trino.testing.TestingWarningCollectorConfig) ResultSet(java.sql.ResultSet) TestingWarningCollector(io.trino.testing.TestingWarningCollector) TrinoWarning(io.trino.spi.TrinoWarning) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with TestingWarningCollector

use of io.trino.testing.TestingWarningCollector in project trino by trinodb.

the class TestJdbcWarnings method testStatementWarnings.

@Test
public void testStatementWarnings() throws SQLException {
    assertFalse(statement.execute("CREATE SCHEMA blackhole.test_schema"));
    SQLWarning warning = statement.getWarnings();
    assertNotNull(warning);
    TestingWarningCollectorConfig warningCollectorConfig = new TestingWarningCollectorConfig().setPreloadedWarnings(PRELOADED_WARNINGS);
    TestingWarningCollector warningCollector = new TestingWarningCollector(new WarningCollectorConfig(), warningCollectorConfig);
    List<TrinoWarning> expectedWarnings = warningCollector.getWarnings();
    assertStartsWithExpectedWarnings(warning, fromTrinoWarnings(expectedWarnings));
    statement.clearWarnings();
    assertNull(statement.getWarnings());
}
Also used : SQLWarning(java.sql.SQLWarning) WarningCollectorConfig(io.trino.execution.warnings.WarningCollectorConfig) TestingWarningCollectorConfig(io.trino.testing.TestingWarningCollectorConfig) TestingWarningCollectorConfig(io.trino.testing.TestingWarningCollectorConfig) TestingWarningCollector(io.trino.testing.TestingWarningCollector) TrinoWarning(io.trino.spi.TrinoWarning) Test(org.testng.annotations.Test)

Example 3 with TestingWarningCollector

use of io.trino.testing.TestingWarningCollector in project trino by trinodb.

the class TestTestingWarningCollector method testAddWarnings.

@Test
public void testAddWarnings() {
    TestingWarningCollector collector = new TestingWarningCollector(new WarningCollectorConfig(), new TestingWarningCollectorConfig().setAddWarnings(true));
    ImmutableList.Builder<TrinoWarning> expectedWarningsBuilder = ImmutableList.builder();
    expectedWarningsBuilder.add(createTestWarning(1));
    assertEquals(collector.getWarnings(), expectedWarningsBuilder.build());
}
Also used : TestingWarningCollectorConfig(io.trino.testing.TestingWarningCollectorConfig) TestingWarningCollectorConfig(io.trino.testing.TestingWarningCollectorConfig) ImmutableList(com.google.common.collect.ImmutableList) TestingWarningCollector(io.trino.testing.TestingWarningCollector) TrinoWarning(io.trino.spi.TrinoWarning) Test(org.testng.annotations.Test)

Example 4 with TestingWarningCollector

use of io.trino.testing.TestingWarningCollector in project trino by trinodb.

the class TestCompletedEventWarnings method testCompletedEventWarnings.

@Test
public void testCompletedEventWarnings() throws InterruptedException {
    TestingWarningCollectorConfig warningCollectorConfig = new TestingWarningCollectorConfig().setPreloadedWarnings(TEST_WARNINGS);
    TestingWarningCollector testingWarningCollector = new TestingWarningCollector(new WarningCollectorConfig(), warningCollectorConfig);
    assertWarnings("select 1", ImmutableMap.of(), testingWarningCollector.getWarnings().stream().map(TrinoWarning::getWarningCode).collect(toImmutableList()));
}
Also used : WarningCollectorConfig(io.trino.execution.warnings.WarningCollectorConfig) TestingWarningCollectorConfig(io.trino.testing.TestingWarningCollectorConfig) TestingWarningCollectorConfig(io.trino.testing.TestingWarningCollectorConfig) TestingWarningCollector(io.trino.testing.TestingWarningCollector) TrinoWarning(io.trino.spi.TrinoWarning) Test(org.testng.annotations.Test)

Aggregations

TrinoWarning (io.trino.spi.TrinoWarning)4 TestingWarningCollector (io.trino.testing.TestingWarningCollector)4 TestingWarningCollectorConfig (io.trino.testing.TestingWarningCollectorConfig)4 Test (org.testng.annotations.Test)4 WarningCollectorConfig (io.trino.execution.warnings.WarningCollectorConfig)3 ImmutableList (com.google.common.collect.ImmutableList)1 ResultSet (java.sql.ResultSet)1 SQLWarning (java.sql.SQLWarning)1 HashSet (java.util.HashSet)1