sanjeet006py commented on code in PR #2594:
URL: https://github.com/apache/phoenix/pull/2594#discussion_r4179174211


##########
phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionQueryServicesImplTest.java:
##########
@@ -410,6 +420,111 @@ public void testDropTablesTableEnabled() throws Exception 
{
     verify(mockConn).getAdmin();
   }
 
+  @Test
+  public void testEnableTableAlreadyEnabledSwallowsException() throws 
Exception {
+    // PHOENIX-7788: enableTable helper must swallow TableNotDisabledException,
+    // so a concurrent client that already re-enabled the table does not fail 
the CREATE.
+    TableName tableName = TableName.valueOf("TEST_TABLE");
+    doThrow(new 
TableNotDisabledException(tableName)).when(mockAdmin).enableTable(tableName);
+    invokeEnableTable(mockCqs, mockAdmin, tableName);
+    verify(mockAdmin, Mockito.times(1)).enableTable(tableName);
+  }
+
+  @Test
+  public void testEnableTablePropagatesOtherIOException() throws Exception {
+    TableName tableName = TableName.valueOf("TEST_TABLE");
+    IOException expected = new IOException("boom");
+    doThrow(expected).when(mockAdmin).enableTable(tableName);
+    try {
+      invokeEnableTable(mockCqs, mockAdmin, tableName);
+      fail("Expected IOException to propagate");
+    } catch (InvocationTargetException e) {
+      assertSame(expected, e.getCause());
+    }
+  }
+
+  private static void invokeEnableTable(ConnectionQueryServicesImpl cqs, Admin 
admin,
+    TableName tableName) throws Exception {
+    Method m = 
ConnectionQueryServicesImpl.class.getDeclaredMethod("enableTable", Admin.class,
+      TableName.class);
+    m.setAccessible(true);
+    m.invoke(cqs, admin, tableName);
+  }
+
+  @Test
+  public void 
testReenableOrphanedDisabledHBaseTableLeavesTableDisabledWhenMetadataPresent()

Review Comment:
   We have an IT for this so, is there an advantage we get by having UT?



##########
phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionQueryServicesImplTest.java:
##########
@@ -410,6 +420,111 @@ public void testDropTablesTableEnabled() throws Exception 
{
     verify(mockConn).getAdmin();
   }
 
+  @Test
+  public void testEnableTableAlreadyEnabledSwallowsException() throws 
Exception {
+    // PHOENIX-7788: enableTable helper must swallow TableNotDisabledException,
+    // so a concurrent client that already re-enabled the table does not fail 
the CREATE.
+    TableName tableName = TableName.valueOf("TEST_TABLE");
+    doThrow(new 
TableNotDisabledException(tableName)).when(mockAdmin).enableTable(tableName);
+    invokeEnableTable(mockCqs, mockAdmin, tableName);
+    verify(mockAdmin, Mockito.times(1)).enableTable(tableName);
+  }
+
+  @Test
+  public void testEnableTablePropagatesOtherIOException() throws Exception {
+    TableName tableName = TableName.valueOf("TEST_TABLE");
+    IOException expected = new IOException("boom");
+    doThrow(expected).when(mockAdmin).enableTable(tableName);
+    try {
+      invokeEnableTable(mockCqs, mockAdmin, tableName);
+      fail("Expected IOException to propagate");
+    } catch (InvocationTargetException e) {
+      assertSame(expected, e.getCause());
+    }
+  }
+
+  private static void invokeEnableTable(ConnectionQueryServicesImpl cqs, Admin 
admin,
+    TableName tableName) throws Exception {
+    Method m = 
ConnectionQueryServicesImpl.class.getDeclaredMethod("enableTable", Admin.class,
+      TableName.class);
+    m.setAccessible(true);
+    m.invoke(cqs, admin, tableName);
+  }
+
+  @Test
+  public void 
testReenableOrphanedDisabledHBaseTableLeavesTableDisabledWhenMetadataPresent()
+    throws Exception {
+    // PHOENIX-7788: disabled physical table with existing SYSTEM.CATALOG 
metadata must NOT be
+    // re-enabled; an admin may have disabled a registered table 
intentionally, and
+    // CREATE TABLE IF NOT EXISTS must preserve that.
+    byte[] name = "TEST_TABLE".getBytes(StandardCharsets.UTF_8);
+    TableName physical = TableName.valueOf(name);
+    MetaDataMutationResult existing =
+      new MetaDataMutationResult(MutationCode.TABLE_ALREADY_EXISTS, 0L, 
Mockito.mock(PTable.class));
+    doReturn(existing).when(mockCqs).getTable(Mockito.<PName> any(), 
any(byte[].class),
+      any(byte[].class), anyLong(), anyLong());
+    invokeReenableOrphanedDisabledHBaseTable(mockCqs, name, mockAdmin);
+    verify(mockAdmin, never()).enableTable(physical);
+  }
+
+  @Test
+  public void testReenableOrphanedDisabledHBaseTableReenablesOrphanedTable() 
throws Exception {

Review Comment:
   Same as above, we have an IT for this, do we get an advantage by having a UT?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to