Skip to content

Conversation

@nk1506
Copy link
Contributor

@nk1506 nk1506 commented Apr 3, 2024

No description provided.

} catch (RuntimeException e) {
// any MetaException would be wrapped into RuntimeException during reflection, so let's
// double-check type here
if (e.getCause() instanceof MetaException) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nk1506 why is this being removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me lookout/add some tests which can catch these errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nk1506 this isn't fixed. The logic in the try-catch blocks changed. The only thing that should be changing is adding a null check before calling t.getMessage()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other try-catch block looks redundant . We were wrapping into MetaException and throwing and again wrapping into RuntimeMetaException .

Should I revert and add only null check ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, please revert. The scope within the PR should reflect what's being proposed in the commit msg

throw new RuntimeMetaException(e, "Failed to connect to Hive Metastore");
} catch (Throwable t) {
if (t.getMessage().contains("Another instance of Derby may have already booted")) {
if (t.getMessage() != null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having trouble to add tests for this. Since GET_CLIENT is static.
@nastra Any pointers will help.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to look at the existing tests in TestHiveClientPool and see how things could be mocked so that we get the right exception

try (MockedStatic<JdbcUtil> mockedStatic = Mockito.mockStatic(JdbcUtil.class)) {
mockedStatic
.when(() -> JdbcUtil.loadTable(any(), any(), any(), any()))
.thenThrow(new SQLException("constraint failed"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null message we are checking at other testCommitExceptionWithoutMessage.

}

@Test
public void testCommitExceptionWithoutMessage() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be simplified to

@Test
  public void testCommitExceptionWithoutMessage() {
    TableIdentifier tableIdent = TableIdentifier.of("db", "tbl");
    BaseTable table = (BaseTable) catalog.buildTable(tableIdent, SCHEMA).create();
    TableOperations ops = table.operations();
    TableMetadata metadataV1 = ops.current();

    table.updateSchema().addColumn("n", Types.IntegerType.get()).commit();
    ops.refresh();

    try (MockedStatic<JdbcUtil> mockedStatic = Mockito.mockStatic(JdbcUtil.class)) {
      mockedStatic
          .when(() -> JdbcUtil.loadTable(any(), any(), any(), any()))
          .thenThrow(new SQLException());
      assertThatThrownBy(() -> ops.commit(ops.current(), metadataV1))
          .isInstanceOf(UncheckedSQLException.class)
          .hasMessageStartingWith("Unknown failure");
    }
  }

please also update the other tests accordingly. The spying on ops isn't necessary here, because you're throwing the exception when the table/view is being loaded (which is different from #10069)

public void testCommitExceptionWithoutMessage() {
TableIdentifier tableIdent = TableIdentifier.of("db", "ns1", "ns2", "tbl");
BaseTable table = (BaseTable) catalog.buildTable(tableIdent, SCHEMA).create();
JdbcTableOperations ops = (JdbcTableOperations) table.operations();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for the casting here. See the simplified test version in my previous comment

@Test
public void testExceptionMessages() {
// Test Wrapped MetaException with a message
try (MockedStatic<MetaStoreUtils> mockedStatic = Mockito.mockStatic(MetaStoreUtils.class)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't find a way to mock calling method

return GET_CLIENT.invoke(
            hiveConf, (HiveMetaHookLoader) tbl -> null, HiveMetaStoreClient.class.getName());

and throw Exception. Had to trace and mock the class which is throwing error.


@Test
public void testExceptionMessages() {
// Test Wrapped MetaException with a message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think those comments are helpful. I would just remove all of those

@nastra nastra merged commit fab5e18 into apache:main Apr 5, 2024
sasankpagolu pushed a commit to sasankpagolu/iceberg that referenced this pull request Oct 27, 2024
zachdisc pushed a commit to zachdisc/iceberg that referenced this pull request Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants