本文整理了Java中io.airlift.testing.Assertions.assertContains()
方法的一些代码示例,展示了Assertions.assertContains()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assertions.assertContains()
方法的具体详情如下:
包路径:io.airlift.testing.Assertions
类名称:Assertions
方法名:assertContains
暂无
代码示例来源:origin: prestodb/presto
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);
}
}
}
代码示例来源:origin: prestodb/presto
private static void assertFutureFailsWithMockFailure(ListenableFuture<?> future)
{
assertTrue(future.isDone());
try {
future.get();
fail();
}
catch (Exception e) {
assertContains(e.getMessage(), "Mock failure");
}
}
代码示例来源:origin: prestodb/presto
@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");
}
代码示例来源:origin: prestodb/presto
private static void assertCreateClientFails(HiveCluster cluster, String message)
{
try {
cluster.createMetastoreClient();
fail("expected exception");
}
catch (TException e) {
assertContains(e.getMessage(), message);
}
}
代码示例来源:origin: prestodb/presto
assertContains(queryFailure.get().getMessage(), "Query exceeded maximum time limit of 1.00s");
代码示例来源:origin: prestodb/presto
@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 (?,?)");
}
}
代码示例来源:origin: prestodb/presto
@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 (?,?)");
}
}
代码示例来源:origin: prestodb/presto
assertContains(e.getMessage(), "Driver-group exchange cannot be created.");
assertContains(e.getMessage(), "Task-wide exchange cannot be created.");
代码示例来源:origin: prestodb/presto
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;
}
}
}
}
代码示例来源:origin: prestodb/presto
@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 (?,?)");
}
}
代码示例来源:origin: prestodb/presto
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 (?,?)");
代码示例来源:origin: prestodb/presto
assertContains(e.getMessage(), "test fail");
assertContains(e.getMessage(), "test fail");
代码示例来源:origin: prestodb/presto
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");
代码示例来源:origin: prestodb/presto
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");
代码示例来源:origin: prestodb/presto
assertContains(e.getMessage(), "Split buffering for database.table exceeded memory limit");
代码示例来源:origin: prestodb/presto
@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");
}
}
代码示例来源:origin: io.airlift/testing
public static void assertContainsAllOf(String actual, String... expectedParts)
{
// todo improve naive implementation
for (String expected : expectedParts) {
assertContains(actual, expected, null);
}
}
代码示例来源:origin: airlift/airlift
public static void assertContainsAllOf(String actual, String... expectedParts)
{
// todo improve naive implementation
for (String expected : expectedParts) {
assertContains(actual, expected, null);
}
}
代码示例来源:origin: airlift/airlift
private void passContains(String actual, String expected)
{
assertContains(actual, expected);
assertContains(actual, expected, MESSAGE);
}
代码示例来源:origin: airlift/airlift
@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>");
}
内容来源于网络,如有侵权,请联系作者删除!