@@ -67,6 +67,58 @@ public OHTablePool setUpPool() throws IOException {
67
67
return ohTablePool ;
68
68
}
69
69
70
+ enum ErrSimPoint {
71
+ EN_CREATE_HTABLE_TG_FINISH_ERR (2621 ),
72
+ EN_CREATE_HTABLE_CF_FINISH_ERR (2622 ),
73
+ EN_DISABLE_HTABLE_CF_FINISH_ERR (2623 ),
74
+ EN_DELETE_HTABLE_CF_FINISH_ERR (2624 );
75
+
76
+ private final int errCode ;
77
+
78
+ ErrSimPoint (int errCode ) {
79
+ this .errCode = errCode ;
80
+ }
81
+
82
+ public int getErrCode () {
83
+ return errCode ;
84
+ }
85
+ }
86
+
87
+ private void setErrSimPoint (ErrSimPoint errSimPoint , boolean enable ) {
88
+ java .sql .Connection connection = null ;
89
+ java .sql .Statement statement = null ;
90
+
91
+ try {
92
+ connection = ObHTableTestUtil .getSysTenantConnection ();
93
+ statement = connection .createStatement ();
94
+
95
+ String sql = String .format (
96
+ "alter system set_tp tp_no = %d, error_code = 4016, frequency = %d" ,
97
+ errSimPoint .getErrCode (),
98
+ enable ? 1 : 0
99
+ );
100
+
101
+ statement .execute (sql );
102
+ } catch (Exception e ) {
103
+ throw new RuntimeException ("Error injection setup failed" , e );
104
+ } finally {
105
+ if (statement != null ) {
106
+ try {
107
+ statement .close ();
108
+ } catch (Exception e ) {
109
+ // ignore
110
+ }
111
+ }
112
+ if (connection != null ) {
113
+ try {
114
+ connection .close ();
115
+ } catch (Exception e ) {
116
+ // ignore
117
+ }
118
+ }
119
+ }
120
+ }
121
+
70
122
@ Test
71
123
public void testGetStartEndKeysOHTableClientRange () throws Exception {
72
124
// Init OHTableClient
@@ -1209,4 +1261,72 @@ void checkKVAttributes(String tableName, String kvAttributes) throws Exception {
1209
1261
Assert .assertEquals (kvAttributes , value );
1210
1262
Assert .assertFalse (resultSet .next ());
1211
1263
}
1264
+
1265
+ // NOTE: observer should build with `-DOB_ERRSIM=ON` option, otherwise the test will fail
1266
+ // This test verifies error injection scenarios for table operations
1267
+ @ Test
1268
+ public void testCreateTableInjectError () throws Exception {
1269
+ Configuration conf = ObHTableTestUtil .newConfiguration ();
1270
+ Connection connection = ConnectionFactory .createConnection (conf );
1271
+ Admin admin = connection .getAdmin ();
1272
+
1273
+ byte [] tableName = Bytes .toBytes ("test_create_table_inject_error" );
1274
+ byte [] cf1 = Bytes .toBytes ("cf1" );
1275
+ byte [] cf2 = Bytes .toBytes ("cf2" );
1276
+ byte [] cf3 = Bytes .toBytes ("cf3" );
1277
+
1278
+ HColumnDescriptor hcd1 = new HColumnDescriptor (cf1 );
1279
+ HColumnDescriptor hcd2 = new HColumnDescriptor (cf2 );
1280
+ HColumnDescriptor hcd3 = new HColumnDescriptor (cf3 );
1281
+
1282
+ HTableDescriptor htd = new HTableDescriptor (TableName .valueOf (tableName ));
1283
+ htd .addFamily (hcd1 );
1284
+ htd .addFamily (hcd2 );
1285
+ htd .addFamily (hcd3 );
1286
+
1287
+ // 1. open err EN_CREATE_HTABLE_TG_FINISH_ERR
1288
+ setErrSimPoint (ErrSimPoint .EN_CREATE_HTABLE_TG_FINISH_ERR , true );
1289
+ ObHTableTestUtil .executeIgnoreUnexpectedError (() -> admin .createTable (htd ));
1290
+ assertFalse ("Table should not exist after TG error injection" ,
1291
+ admin .tableExists (TableName .valueOf (tableName )));
1292
+ setErrSimPoint (ErrSimPoint .EN_CREATE_HTABLE_TG_FINISH_ERR , false );
1293
+
1294
+ // 2. open err EN_CREATE_HTABLE_CF_FINISH_ERR
1295
+ setErrSimPoint (ErrSimPoint .EN_CREATE_HTABLE_CF_FINISH_ERR , true );
1296
+ ObHTableTestUtil .executeIgnoreUnexpectedError (() -> admin .createTable (htd ));
1297
+ assertFalse ("Table should not exist after CF error injection" ,
1298
+ admin .tableExists (TableName .valueOf (tableName )));
1299
+ setErrSimPoint (ErrSimPoint .EN_CREATE_HTABLE_CF_FINISH_ERR , false );
1300
+
1301
+ // 3. create table without error
1302
+ admin .createTable (htd );
1303
+ assertTrue ("Table should exist after normal creation" ,
1304
+ admin .tableExists (TableName .valueOf (tableName )));
1305
+ assertEquals ("Table should have 3 column families" , 3 ,
1306
+ admin .getTableDescriptor (TableName .valueOf (tableName )).getFamilies ().size ());
1307
+
1308
+ // 4. open err EN_DISABLE_HTABLE_CF_FINISH_ERR
1309
+ setErrSimPoint (ErrSimPoint .EN_DISABLE_HTABLE_CF_FINISH_ERR , true );
1310
+ admin .disableTable (TableName .valueOf (tableName ));
1311
+ assertFalse ("Table should not be disabled after disable error injection" ,
1312
+ admin .isTableDisabled (TableName .valueOf (tableName )));
1313
+ setErrSimPoint (ErrSimPoint .EN_DISABLE_HTABLE_CF_FINISH_ERR , false );
1314
+
1315
+ // 5. disable table without error
1316
+ admin .disableTable (TableName .valueOf (tableName ));
1317
+ assertTrue ("Table should be disabled after normal disable" ,
1318
+ admin .isTableDisabled (TableName .valueOf (tableName )));
1319
+
1320
+ // 6. open err EN_DELETE_HTABLE_CF_FINISH_ERR
1321
+ setErrSimPoint (ErrSimPoint .EN_DELETE_HTABLE_CF_FINISH_ERR , true );
1322
+ admin .deleteTable (TableName .valueOf (tableName ));
1323
+ assertTrue ("Table should still exist after delete error injection" ,
1324
+ admin .tableExists (TableName .valueOf (tableName )));
1325
+ setErrSimPoint (ErrSimPoint .EN_DELETE_HTABLE_CF_FINISH_ERR , false );
1326
+
1327
+ // 7. delete table without error
1328
+ admin .deleteTable (TableName .valueOf (tableName ));
1329
+ assertFalse ("Table should not exist after normal delete" ,
1330
+ admin .tableExists (TableName .valueOf (tableName )));
1331
+ }
1212
1332
}
0 commit comments