private static void assertCreateConnectorFails(String metastoreUri, String exceptionString) { try { assertCreateConnector(metastoreUri); fail("expected connector creation to fail:" + metastoreUri); } catch (RuntimeException e) { assertContains(e.getMessage(), exceptionString); } } }
private static void assertFutureFailsWithMockFailure(ListenableFuture<?> future) { assertTrue(future.isDone()); try { future.get(); fail(); } catch (Exception e) { assertContains(e.getMessage(), "Mock failure"); } }
@Test public void testPassEscapeInMetaDataQuery() throws Exception { DatabaseMetaData metaData = connection.getMetaData(); Set<String> queries = captureQueries(() -> { String schemaPattern = "defau" + metaData.getSearchStringEscape() + "_t"; try (ResultSet resultSet = metaData.getColumns("blackhole", schemaPattern, null, null)) { assertFalse(resultSet.next(), "There should be no results"); } return null; }); assertEquals(queries.size(), 1, "Expected exactly one query, got " + queries.size()); String query = getOnlyElement(queries); assertContains(query, "_t' ESCAPE '", "Metadata query does not contain ESCAPE"); }
private static void assertCreateClientFails(HiveCluster cluster, String message) { try { cluster.createMetastoreClient(); fail("expected exception"); } catch (TException e) { assertContains(e.getMessage(), message); } }
assertContains(queryFailure.get().getMessage(), "Query exceeded maximum time limit of 1.00s");
@Test public void testBuildSqlWithVarchar() throws SQLException { TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( columns.get(3), Domain.create(SortedRangeSet.copyOf(VARCHAR, ImmutableList.of( Range.range(VARCHAR, utf8Slice("test_str_700"), true, utf8Slice("test_str_702"), false), Range.equal(VARCHAR, utf8Slice("test_str_180")), Range.equal(VARCHAR, utf8Slice("test_str_196")))), false))); Connection connection = database.getConnection(); try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain, Optional.empty()); ResultSet resultSet = preparedStatement.executeQuery()) { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); while (resultSet.next()) { builder.add((String) resultSet.getObject("col_3")); } assertEquals(builder.build(), ImmutableSet.of("test_str_700", "test_str_701", "test_str_180", "test_str_196")); assertContains(preparedStatement.toString(), "\"col_3\" >= ?"); assertContains(preparedStatement.toString(), "\"col_3\" < ?"); assertContains(preparedStatement.toString(), "\"col_3\" IN (?,?)"); } }
@Test public void testBuildSqlWithChar() throws SQLException { CharType charType = CharType.createCharType(0); TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( columns.get(11), Domain.create(SortedRangeSet.copyOf(charType, ImmutableList.of( Range.range(charType, utf8Slice("test_str_700"), true, utf8Slice("test_str_702"), false), Range.equal(charType, utf8Slice("test_str_180")), Range.equal(charType, utf8Slice("test_str_196")))), false))); Connection connection = database.getConnection(); try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain, Optional.empty()); ResultSet resultSet = preparedStatement.executeQuery()) { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); while (resultSet.next()) { builder.add((String) resultSet.getObject("col_11")); } assertEquals(builder.build(), ImmutableSet.of("test_str_700", "test_str_701", "test_str_180", "test_str_196")); assertContains(preparedStatement.toString(), "\"col_11\" >= ?"); assertContains(preparedStatement.toString(), "\"col_11\" < ?"); assertContains(preparedStatement.toString(), "\"col_11\" IN (?,?)"); } }
assertContains(e.getMessage(), "Driver-group exchange cannot be created."); assertContains(e.getMessage(), "Task-wide exchange cannot be created.");
private void assertInvalidTypeTranslation(String typeName, ErrorCode errorCode, String message) { Type type = TYPE_MANAGER.getType(parseTypeSignature(typeName)); try { HiveType.toHiveType(typeTranslator, type); fail("expected exception"); } catch (PrestoException e) { try { assertEquals(e.getErrorCode(), errorCode); assertContains(e.getMessage(), message); } catch (Throwable failure) { failure.addSuppressed(e); throw failure; } } } }
@Test public void testBuildSqlWithTimestamp() throws SQLException { TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( columns.get(6), Domain.create(SortedRangeSet.copyOf(TIMESTAMP, ImmutableList.of( Range.equal(TIMESTAMP, toTimestamp(2016, 6, 3, 0, 23, 37).getTime()), Range.equal(TIMESTAMP, toTimestamp(2016, 10, 19, 16, 23, 37).getTime()), Range.range(TIMESTAMP, toTimestamp(2016, 6, 7, 8, 23, 37).getTime(), false, toTimestamp(2016, 6, 9, 12, 23, 37).getTime(), true))), false))); Connection connection = database.getConnection(); try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain, Optional.empty()); ResultSet resultSet = preparedStatement.executeQuery()) { ImmutableSet.Builder<Timestamp> builder = ImmutableSet.builder(); while (resultSet.next()) { builder.add((Timestamp) resultSet.getObject("col_6")); } assertEquals(builder.build(), ImmutableSet.of( toTimestamp(2016, 6, 3, 0, 23, 37), toTimestamp(2016, 6, 8, 10, 23, 37), toTimestamp(2016, 6, 9, 12, 23, 37), toTimestamp(2016, 10, 19, 16, 23, 37))); assertContains(preparedStatement.toString(), "\"col_6\" > ?"); assertContains(preparedStatement.toString(), "\"col_6\" <= ?"); assertContains(preparedStatement.toString(), "\"col_6\" IN (?,?)"); } }
assertEquals(timeBuilder.build(), ImmutableSet.of(toTime(2016, 6, 7, 8, 23, 37), toTime(2016, 10, 21, 20, 23, 37))); assertContains(preparedStatement.toString(), "\"col_4\" >= ?"); assertContains(preparedStatement.toString(), "\"col_4\" < ?"); assertContains(preparedStatement.toString(), "\"col_4\" IN (?,?)"); assertContains(preparedStatement.toString(), "\"col_5\" > ?"); assertContains(preparedStatement.toString(), "\"col_5\" <= ?"); assertContains(preparedStatement.toString(), "\"col_5\" IN (?,?)");
assertContains(e.getMessage(), "test fail"); assertContains(e.getMessage(), "test fail");
assertEquals(callback.getFailedBuffers(), 1); assertInstanceOf(callback.getFailure(), PageTransportTimeoutException.class); assertContains(callback.getFailure().getMessage(), WORKER_NODE_ERROR + " (http://localhost:8080/0 - 3 failures, failure duration 31.00s, total failed request time 31.00s)"); assertStatus(client, location, "queued", 0, 3, 3, 3, "not scheduled");
assertEquals(callback.getFailedBuffers(), 1); assertInstanceOf(callback.getFailure(), PageTransportErrorException.class); assertContains(callback.getFailure().getMessage(), "Expected response code to be 200, but was 404 Not Found"); assertStatus(client, location, "queued", 0, 1, 1, 1, "not scheduled"); assertEquals(callback.getFailedBuffers(), 1); assertInstanceOf(callback.getFailure(), PageTransportErrorException.class); assertContains(callback.getFailure().getMessage(), "Expected application/x-presto-pages response from server but got INVALID_TYPE"); assertStatus(client, location, "queued", 0, 2, 2, 2, "not scheduled"); assertEquals(callback.getFailedBuffers(), 1); assertInstanceOf(callback.getFailure(), PageTransportErrorException.class); assertContains(callback.getFailure().getMessage(), "Expected application/x-presto-pages response from server but got text/plain"); assertStatus(client, location, "queued", 0, 3, 3, 3, "not scheduled");
assertContains(e.getMessage(), "Split buffering for database.table exceeded memory limit");
@Test public void testNonQueryAccessControl() { skipTestUnless(supportsViews()); assertAccessDenied("SET SESSION " + QUERY_MAX_MEMORY + " = '10MB'", "Cannot set system session property " + QUERY_MAX_MEMORY, privilege(QUERY_MAX_MEMORY, SET_SESSION)); assertAccessDenied("CREATE TABLE foo (pk bigint)", "Cannot create table .*.foo.*", privilege("foo", CREATE_TABLE)); assertAccessDenied("DROP TABLE orders", "Cannot drop table .*.orders.*", privilege("orders", DROP_TABLE)); assertAccessDenied("ALTER TABLE orders RENAME TO foo", "Cannot rename table .*.orders.* to .*.foo.*", privilege("orders", RENAME_TABLE)); assertAccessDenied("ALTER TABLE orders ADD COLUMN foo bigint", "Cannot add a column to table .*.orders.*", privilege("orders", ADD_COLUMN)); assertAccessDenied("ALTER TABLE orders DROP COLUMN foo", "Cannot drop a column from table .*.orders.*", privilege("orders", DROP_COLUMN)); assertAccessDenied("ALTER TABLE orders RENAME COLUMN orderkey TO foo", "Cannot rename a column in table .*.orders.*", privilege("orders", RENAME_COLUMN)); assertAccessDenied("CREATE VIEW foo as SELECT * FROM orders", "Cannot create view .*.foo.*", privilege("foo", CREATE_VIEW)); // todo add DROP VIEW test... not all connectors have view support try { assertAccessDenied("SELECT 1", "Principal .* cannot become user " + getSession().getUser() + ".*", privilege(getSession().getUser(), SET_USER)); } catch (AssertionError e) { // There is no clean exception message for authorization failure. We simply get a 403 Assertions.assertContains(e.getMessage(), "statusCode=403"); } }
public static void assertContainsAllOf(String actual, String... expectedParts) { // todo improve naive implementation for (String expected : expectedParts) { assertContains(actual, expected, null); } }
public static void assertContainsAllOf(String actual, String... expectedParts) { // todo improve naive implementation for (String expected : expectedParts) { assertContains(actual, expected, null); } }
private void passContains(String actual, String expected) { assertContains(actual, expected); assertContains(actual, expected, MESSAGE); }
@Test public void testGetHtmlPage() throws Exception { StringResponse response = client.execute( prepareGet().setUri(uriFor("/v1/jmx")).build(), createStringResponseHandler()); assertEquals(response.getStatusCode(), 200); assertContentType(response, HTML_UTF_8); assertContains(response.getBody(), "<html>"); }