diff --git a/core/trino-main/src/test/java/io/trino/execution/buffer/TestArbitraryOutputBuffer.java b/core/trino-main/src/test/java/io/trino/execution/buffer/TestArbitraryOutputBuffer.java index 1b375a573a51..95d179d413b9 100644 --- a/core/trino-main/src/test/java/io/trino/execution/buffer/TestArbitraryOutputBuffer.java +++ b/core/trino-main/src/test/java/io/trino/execution/buffer/TestArbitraryOutputBuffer.java @@ -464,7 +464,7 @@ public void testResumeFromPreviousPosition() } } - @Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "No more buffers already set") + @Test public void testUseUndeclaredBufferAfterFinalBuffersSet() { ArbitraryOutputBuffer buffer = createArbitraryBuffer( @@ -475,7 +475,9 @@ public void testUseUndeclaredBufferAfterFinalBuffersSet() assertFalse(buffer.isFinished()); // get a page from a buffer that was not declared, which will fail - buffer.get(SECOND, 0L, sizeOfPages(1)); + assertThatThrownBy(() -> buffer.get(SECOND, 0L, sizeOfPages(1))) + .isInstanceOf(IllegalStateException.class) + .hasMessage("No more buffers already set"); } @Test diff --git a/core/trino-main/src/test/java/io/trino/execution/buffer/TestBroadcastOutputBuffer.java b/core/trino-main/src/test/java/io/trino/execution/buffer/TestBroadcastOutputBuffer.java index 1c79bb2b9898..90f013ce1737 100644 --- a/core/trino-main/src/test/java/io/trino/execution/buffer/TestBroadcastOutputBuffer.java +++ b/core/trino-main/src/test/java/io/trino/execution/buffer/TestBroadcastOutputBuffer.java @@ -495,7 +495,7 @@ public void testGetBeforeCreate() assertBufferResultEquals(TYPES, getFuture(future, NO_WAIT), bufferResult(0, createPage(33))); } - @Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = ".*does not contain.*\\[0]") + @Test public void testSetFinalBuffersWihtoutDeclaringUsedBuffer() { BroadcastOutputBuffer buffer = createBroadcastBuffer(createInitialEmptyOutputBuffers(BROADCAST), sizeOfPages(10)); @@ -518,10 +518,12 @@ public void testSetFinalBuffersWihtoutDeclaringUsedBuffer() buffer.abort(FIRST); // set final buffers to a set that does not contain the buffer, which will fail - buffer.setOutputBuffers(createInitialEmptyOutputBuffers(BROADCAST).withNoMoreBufferIds()); + assertThatThrownBy(() -> buffer.setOutputBuffers(createInitialEmptyOutputBuffers(BROADCAST).withNoMoreBufferIds())) + .isInstanceOf(IllegalStateException.class) + .hasMessageMatching(".*does not contain.*\\[0]"); } - @Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "No more buffers already set") + @Test public void testUseUndeclaredBufferAfterFinalBuffersSet() { BroadcastOutputBuffer buffer = createBroadcastBuffer( @@ -532,7 +534,9 @@ public void testUseUndeclaredBufferAfterFinalBuffersSet() assertFalse(buffer.isFinished()); // get a page from a buffer that was not declared, which will fail - buffer.get(SECOND, 0L, sizeOfPages(1)); + assertThatThrownBy(() -> buffer.get(SECOND, 0L, sizeOfPages(1))) + .isInstanceOf(IllegalStateException.class) + .hasMessage("No more buffers already set"); } @Test diff --git a/core/trino-main/src/test/java/io/trino/security/TestAccessControlManager.java b/core/trino-main/src/test/java/io/trino/security/TestAccessControlManager.java index 13b64be01b82..58450ed22067 100644 --- a/core/trino-main/src/test/java/io/trino/security/TestAccessControlManager.java +++ b/core/trino-main/src/test/java/io/trino/security/TestAccessControlManager.java @@ -86,11 +86,13 @@ public class TestAccessControlManager private static final String USER_NAME = "user_name"; private static final QueryId queryId = new QueryId("query_id"); - @Test(expectedExceptions = TrinoException.class, expectedExceptionsMessageRegExp = "Trino server is still initializing") + @Test public void testInitializing() { AccessControlManager accessControlManager = createAccessControlManager(createTestTransactionManager()); - accessControlManager.checkCanSetUser(Optional.empty(), "foo"); + assertThatThrownBy(() -> accessControlManager.checkCanSetUser(Optional.empty(), "foo")) + .isInstanceOf(TrinoException.class) + .hasMessage("Trino server is still initializing"); } @Test @@ -169,7 +171,7 @@ public void testNoCatalogAccessControl() }); } - @Test(expectedExceptions = TrinoException.class, expectedExceptionsMessageRegExp = "Access Denied: Cannot select from columns \\[column\\] in table or view schema.table") + @Test public void testDenyCatalogAccessControl() { CatalogManager catalogManager = new CatalogManager(); @@ -183,10 +185,12 @@ public void testDenyCatalogAccessControl() CatalogName catalogName = registerBogusConnector(catalogManager, transactionManager, accessControlManager, "catalog"); accessControlManager.addCatalogAccessControl(catalogName, new DenyConnectorAccessControl()); - transaction(transactionManager, accessControlManager) + assertThatThrownBy(() -> transaction(transactionManager, accessControlManager) .execute(transactionId -> { accessControlManager.checkCanSelectFromColumns(context(transactionId), new QualifiedObjectName("catalog", "schema", "table"), ImmutableSet.of("column")); - }); + })) + .isInstanceOf(TrinoException.class) + .hasMessageMatching("Access Denied: Cannot select from columns \\[column\\] in table or view schema.table"); } @Test @@ -253,7 +257,7 @@ private static SecurityContext context(TransactionId transactionId) return new SecurityContext(transactionId, identity, queryId); } - @Test(expectedExceptions = TrinoException.class, expectedExceptionsMessageRegExp = "Access Denied: Cannot select from table secured_catalog.schema.table") + @Test public void testDenySystemAccessControl() { CatalogManager catalogManager = new CatalogManager(); @@ -267,10 +271,12 @@ public void testDenySystemAccessControl() registerBogusConnector(catalogManager, transactionManager, accessControlManager, "connector"); accessControlManager.addCatalogAccessControl(new CatalogName("connector"), new DenyConnectorAccessControl()); - transaction(transactionManager, accessControlManager) + assertThatThrownBy(() -> transaction(transactionManager, accessControlManager) .execute(transactionId -> { accessControlManager.checkCanSelectFromColumns(context(transactionId), new QualifiedObjectName("secured_catalog", "schema", "table"), ImmutableSet.of("column")); - }); + })) + .isInstanceOf(TrinoException.class) + .hasMessageMatching("Access Denied: Cannot select from table secured_catalog.schema.table"); } @Test diff --git a/core/trino-main/src/test/java/io/trino/server/TestQuerySessionSupplier.java b/core/trino-main/src/test/java/io/trino/server/TestQuerySessionSupplier.java index 2c70205e3350..4863c60cfb40 100644 --- a/core/trino-main/src/test/java/io/trino/server/TestQuerySessionSupplier.java +++ b/core/trino-main/src/test/java/io/trino/server/TestQuerySessionSupplier.java @@ -132,7 +132,7 @@ public void testClientCapabilities() assertEquals(context2.getClientCapabilities(), ImmutableSet.of()); } - @Test(expectedExceptions = TrinoException.class) + @Test public void testInvalidTimeZone() { MultivaluedMap headers = new GuavaMultivaluedMap<>(ImmutableListMultimap.builder() @@ -141,7 +141,9 @@ public void testInvalidTimeZone() .build()); SessionContext context = SESSION_CONTEXT_FACTORY.createSessionContext(headers, Optional.empty(), Optional.of("remoteAddress"), Optional.empty()); QuerySessionSupplier sessionSupplier = createSessionSupplier(new SqlEnvironmentConfig()); - sessionSupplier.createSession(new QueryId("test_query_id"), context); + assertThatThrownBy(() -> sessionSupplier.createSession(new QueryId("test_query_id"), context)) + .isInstanceOf(TrinoException.class) + .hasMessage("Time zone not supported: unknown_timezone"); } @Test diff --git a/core/trino-main/src/test/java/io/trino/spiller/TestSpillSpaceTracker.java b/core/trino-main/src/test/java/io/trino/spiller/TestSpillSpaceTracker.java index a862e3dadb21..2c31c0f6459d 100644 --- a/core/trino-main/src/test/java/io/trino/spiller/TestSpillSpaceTracker.java +++ b/core/trino-main/src/test/java/io/trino/spiller/TestSpillSpaceTracker.java @@ -19,6 +19,7 @@ import org.testng.annotations.Test; import static io.airlift.units.DataSize.Unit.MEGABYTE; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.testng.Assert.assertEquals; @Test(singleThreaded = true) @@ -57,18 +58,22 @@ public void testSpillSpaceTracker() assertEquals(spillSpaceTracker.getCurrentBytes(), 0); } - @Test(expectedExceptions = ExceededSpillLimitException.class) + @Test public void testSpillOutOfSpace() { assertEquals(spillSpaceTracker.getCurrentBytes(), 0); - spillSpaceTracker.reserve(MAX_DATA_SIZE.toBytes() + 1); + assertThatThrownBy(() -> spillSpaceTracker.reserve(MAX_DATA_SIZE.toBytes() + 1)) + .isInstanceOf(ExceededSpillLimitException.class) + .hasMessageMatching("Query exceeded local spill limit of.*"); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void testFreeToMuch() { assertEquals(spillSpaceTracker.getCurrentBytes(), 0); spillSpaceTracker.reserve(1000); - spillSpaceTracker.free(1001); + assertThatThrownBy(() -> spillSpaceTracker.free(1001)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("tried to free more disk space than is reserved"); } }