/** * Asserts that {@code runnable} throws an exception when invoked. If it does not, an * {@link AssertionError} is thrown. * * @param runnable A function that is expected to throw an exception when invoked * @since 6.9.5 */ public static void assertThrows(ThrowingRunnable runnable) { assertThrows(Throwable.class, runnable); }
private static void assertDenied(ThrowingRunnable runnable) { assertThrows(AccessDeniedException.class, runnable); } }
@Test public void testNaN() { assertThrows(() -> new DoubleStatistics(0.0, NaN)); assertThrows(() -> new DoubleStatistics(NaN, 0.0)); assertThrows(() -> new DoubleStatistics(NaN, NaN)); }
@Test public void testInvalidLike() { assertThrows(PrestoException.class, () -> optimize("unbound_string LIKE 'abc' ESCAPE ''")); assertThrows(PrestoException.class, () -> optimize("unbound_string LIKE 'abc' ESCAPE 'bc'")); assertThrows(PrestoException.class, () -> optimize("unbound_string LIKE '#' ESCAPE '#'")); assertThrows(PrestoException.class, () -> optimize("unbound_string LIKE '#abc' ESCAPE '#'")); assertThrows(PrestoException.class, () -> optimize("unbound_string LIKE 'ab#' ESCAPE '#'")); }
@Test public void testCheckValidColumnName() { checkValidName("abc01_def2"); assertThrows(() -> checkValidName(null)); assertThrows(() -> checkValidName("")); assertThrows(() -> checkValidName("Abc")); assertThrows(() -> checkValidName("0abc")); assertThrows(() -> checkValidName("_abc")); assertThrows(() -> checkValidName("aBc")); assertThrows(() -> checkValidName("ab-c")); } }
@Test public void testDictionaryBlockWithFailure() { assertThrows(NegativeValueException.class, () -> testFilter(createDictionaryBlockWithFailure(20, 100), LongArrayBlock.class)); }
private static void testProjectFails(Block block, Class<? extends Block> expectedResultType, boolean forceYield) { assertThrows(NegativeValueException.class, () -> testProjectRange(block, expectedResultType, createProjection(), forceYield)); assertThrows(NegativeValueException.class, () -> testProjectList(block, expectedResultType, createProjection(), forceYield)); assertThrows(NegativeValueException.class, () -> testProjectRange(lazyWrapper(block), expectedResultType, createProjection(), forceYield)); assertThrows(NegativeValueException.class, () -> testProjectList(lazyWrapper(block), expectedResultType, createProjection(), forceYield)); }
@Test public void testInvalidLikePattern() { assertThrows(PrestoException.class, () -> likePattern(utf8Slice("#"), utf8Slice("#"))); assertThrows(PrestoException.class, () -> likePattern(utf8Slice("abc#abc"), utf8Slice("#"))); assertThrows(PrestoException.class, () -> likePattern(utf8Slice("abc#"), utf8Slice("#"))); }
@Test public void testNoHangIfPartitionIsOffline() throws Exception { BackgroundHiveSplitLoader backgroundHiveSplitLoader = backgroundHiveSplitLoaderOfflinePartitions(); HiveSplitSource hiveSplitSource = hiveSplitSource(backgroundHiveSplitLoader, TupleDomain.all()); backgroundHiveSplitLoader.start(hiveSplitSource); assertThrows(RuntimeException.class, () -> drain(hiveSplitSource)); assertThrows(RuntimeException.class, () -> hiveSplitSource.isFinished()); }
private static void assertShortValueReadFails(BigInteger value) { assertThrows(OrcCorruptionException.class, () -> { DecimalInputStream stream = new DecimalInputStream(decimalInputStream(value)); stream.nextLong(); }); }
@Test public void testRleBlockWithFailure() { DictionaryAwarePageFilter filter = createDictionaryAwarePageFilter(true, LongArrayBlock.class); RunLengthEncodedBlock fail = new RunLengthEncodedBlock(createLongSequenceBlock(-10, -9), 100); assertThrows(NegativeValueException.class, () -> testFilter(filter, fail, true)); }
@Test public void testConfigureFromConfig() { final Config config = ConfigFactory.empty() .withValue(HttpClientConfiguratorLoader.HTTP_CLIENT_CONFIGURATOR_TYPE_KEY, ConfigValueFactory.fromAnyRef("blah")); Assert.assertThrows(new ThrowingRunnable() { @Override public void run() throws Throwable { new HttpClientConfiguratorLoader(config); } }); }
@Test public void testUnknownCost() { CostComparator costComparator = new CostComparator(1.0, 1.0, 1.0); Session session = testSessionBuilder().build(); assertThrows(IllegalArgumentException.class, () -> costComparator.compare(session, PlanNodeCostEstimate.zero(), PlanNodeCostEstimate.unknown())); assertThrows(IllegalArgumentException.class, () -> costComparator.compare(session, PlanNodeCostEstimate.unknown(), PlanNodeCostEstimate.zero())); assertThrows(IllegalArgumentException.class, () -> costComparator.compare(session, PlanNodeCostEstimate.unknown(), PlanNodeCostEstimate.unknown())); }
@Test public void testCursor() { ListBasedRecordSet recordSet = new ListBasedRecordSet( ImmutableList.of( Arrays.asList("1", null, "3"), Arrays.asList("ab", "c", null)), ImmutableList.of(BIGINT, VARCHAR)); assertEquals(recordSet.getColumnTypes(), ImmutableList.of(BIGINT, VARCHAR)); RecordCursor cursor = recordSet.cursor(); assertTrue(cursor.advanceNextPosition()); assertEquals(cursor.getType(0), BIGINT); assertEquals(cursor.getType(1), VARCHAR); assertThrows(IndexOutOfBoundsException.class, () -> cursor.getLong(2)); assertEquals(cursor.getLong(0), 1L); assertEquals(cursor.getSlice(1), Slices.utf8Slice("ab")); assertTrue(cursor.advanceNextPosition()); assertTrue(cursor.isNull(0)); assertEquals(cursor.getSlice(1), Slices.utf8Slice("c")); assertTrue(cursor.advanceNextPosition()); assertEquals(cursor.getLong(0), 3L); assertTrue(cursor.isNull(1)); assertFalse(cursor.advanceNextPosition()); assertThrows(IndexOutOfBoundsException.class, () -> cursor.getLong(0)); } }
private static void assertLongValueReadFails(BigInteger value) { Slice decimal = unscaledDecimal(); assertThrows(OrcCorruptionException.class, () -> { DecimalInputStream stream = new DecimalInputStream(decimalInputStream(value)); stream.nextLongDecimal(decimal); }); }
protected void assertMinMax(T min, T max) { assertMinMaxStatistics(min, min); assertMinMaxStatistics(max, max); assertMinMaxStatistics(min, max); assertMinMaxStatistics(min, null); assertMinMaxStatistics(null, max); if (!min.equals(max)) { assertThrows(() -> getCreateStatistics(max, min)); } }
@Test public void testIsLikePattern() { assertFalse(isLikePattern(utf8Slice("abc"), null)); assertFalse(isLikePattern(utf8Slice("abc#_def"), utf8Slice("#"))); assertFalse(isLikePattern(utf8Slice("abc##def"), utf8Slice("#"))); assertFalse(isLikePattern(utf8Slice("abc#%def"), utf8Slice("#"))); assertTrue(isLikePattern(utf8Slice("abc%def"), null)); assertTrue(isLikePattern(utf8Slice("abcdef_"), null)); assertTrue(isLikePattern(utf8Slice("abcdef##_"), utf8Slice("#"))); assertTrue(isLikePattern(utf8Slice("%abcdef#_"), utf8Slice("#"))); assertThrows(PrestoException.class, () -> isLikePattern(utf8Slice("#"), utf8Slice("#"))); assertThrows(PrestoException.class, () -> isLikePattern(utf8Slice("abc#abc"), utf8Slice("#"))); assertThrows(PrestoException.class, () -> isLikePattern(utf8Slice("abc#"), utf8Slice("#"))); }
@Test public void testSchemaOperations() { TransactionManager transactionManager = createTestTransactionManager(); AccessControlManager accessControlManager = newAccessControlManager(transactionManager, "catalog.json"); transaction(transactionManager, accessControlManager) .execute(transactionId -> { Set<String> aliceSchemas = ImmutableSet.of("schema"); assertEquals(accessControlManager.filterSchemas(transactionId, alice, "alice-catalog", aliceSchemas), aliceSchemas); assertEquals(accessControlManager.filterSchemas(transactionId, bob, "alice-catalog", aliceSchemas), ImmutableSet.of()); accessControlManager.checkCanCreateSchema(transactionId, alice, aliceSchema); accessControlManager.checkCanDropSchema(transactionId, alice, aliceSchema); accessControlManager.checkCanRenameSchema(transactionId, alice, aliceSchema, "new-schema"); accessControlManager.checkCanShowSchemas(transactionId, alice, "alice-catalog"); }); assertThrows(AccessDeniedException.class, () -> transaction(transactionManager, accessControlManager).execute(transactionId -> { accessControlManager.checkCanCreateSchema(transactionId, bob, aliceSchema); })); }
@Test public void testTableOperations() { TransactionManager transactionManager = createTestTransactionManager(); AccessControlManager accessControlManager = newAccessControlManager(transactionManager, "catalog.json"); transaction(transactionManager, accessControlManager) .execute(transactionId -> { Set<SchemaTableName> aliceTables = ImmutableSet.of(new SchemaTableName("schema", "table")); assertEquals(accessControlManager.filterTables(transactionId, alice, "alice-catalog", aliceTables), aliceTables); assertEquals(accessControlManager.filterTables(transactionId, bob, "alice-catalog", aliceTables), ImmutableSet.of()); accessControlManager.checkCanCreateTable(transactionId, alice, aliceTable); accessControlManager.checkCanDropTable(transactionId, alice, aliceTable); accessControlManager.checkCanSelectFromColumns(transactionId, alice, aliceTable, ImmutableSet.of()); accessControlManager.checkCanInsertIntoTable(transactionId, alice, aliceTable); accessControlManager.checkCanDeleteFromTable(transactionId, alice, aliceTable); accessControlManager.checkCanAddColumns(transactionId, alice, aliceTable); accessControlManager.checkCanRenameColumn(transactionId, alice, aliceTable); }); assertThrows(AccessDeniedException.class, () -> transaction(transactionManager, accessControlManager).execute(transactionId -> { accessControlManager.checkCanCreateTable(transactionId, bob, aliceTable); })); }
@Test public void testViewOperations() { TransactionManager transactionManager = createTestTransactionManager(); AccessControlManager accessControlManager = newAccessControlManager(transactionManager, "catalog.json"); transaction(transactionManager, accessControlManager) .execute(transactionId -> { accessControlManager.checkCanCreateView(transactionId, alice, aliceView); accessControlManager.checkCanDropView(transactionId, alice, aliceView); accessControlManager.checkCanSelectFromColumns(transactionId, alice, aliceView, ImmutableSet.of()); accessControlManager.checkCanCreateViewWithSelectFromColumns(transactionId, alice, aliceTable, ImmutableSet.of()); accessControlManager.checkCanCreateViewWithSelectFromColumns(transactionId, alice, aliceView, ImmutableSet.of()); accessControlManager.checkCanSetCatalogSessionProperty(transactionId, alice, "alice-catalog", "property"); accessControlManager.checkCanGrantTablePrivilege(transactionId, alice, SELECT, aliceTable, "grantee", true); accessControlManager.checkCanRevokeTablePrivilege(transactionId, alice, SELECT, aliceTable, "revokee", true); }); assertThrows(AccessDeniedException.class, () -> transaction(transactionManager, accessControlManager).execute(transactionId -> { accessControlManager.checkCanCreateView(transactionId, bob, aliceView); })); }