@@ -447,28 +447,33 @@ public void tearDown() {
447
447
}
448
448
449
449
@ Test
450
- public void testCatalog () throws IOException , InterruptedException {
450
+ public void testCatalog () throws InterruptedException , JsonProcessingException {
451
451
Map <String , Object > configMap = new HashMap <>();
452
452
configMap .put ("username" , "elastic" );
453
453
configMap .put ("password" , "elasticsearch" );
454
- configMap .put ("hosts" , Arrays .asList ("https://" + container .getHttpHostAddress ()));
454
+ configMap .put (
455
+ "hosts" , Collections .singletonList ("https://" + container .getHttpHostAddress ()));
455
456
configMap .put ("index" , "st_index3" );
456
457
configMap .put ("tls_verify_certificate" , false );
457
458
configMap .put ("tls_verify_hostname" , false );
458
459
configMap .put ("index_type" , "st" );
460
+
459
461
final ElasticSearchCatalog elasticSearchCatalog =
460
462
new ElasticSearchCatalog ("Elasticsearch" , "" , ReadonlyConfig .fromMap (configMap ));
461
463
elasticSearchCatalog .open ();
464
+
462
465
TablePath tablePath = TablePath .of ("" , "st_index3" );
463
- // index exists
466
+
467
+ // Verify index does not exist initially
464
468
final boolean existsBefore = elasticSearchCatalog .tableExists (tablePath );
465
- Assertions .assertFalse (existsBefore );
466
- // create index
469
+ Assertions .assertFalse (existsBefore , "Index should not exist initially" );
470
+
471
+ // Create index
467
472
elasticSearchCatalog .createTable (tablePath , null , false );
468
473
final boolean existsAfter = elasticSearchCatalog .tableExists (tablePath );
469
- Assertions .assertTrue (existsAfter );
474
+ Assertions .assertTrue (existsAfter , "Index should be created" );
470
475
471
- // Add multiple records
476
+ // Generate and add multiple records
472
477
List <String > data = generateTestData ();
473
478
StringBuilder requestBody = new StringBuilder ();
474
479
String indexHeader = "{\" index\" :{\" _index\" :\" st_index3\" }}\n " ;
@@ -488,19 +493,20 @@ public void testCatalog() throws IOException, InterruptedException {
488
493
esRestClient .searchByScroll ("st_index3" , sourceFields , query , "1m" , 100 );
489
494
Assertions .assertFalse (scrollResult .getDocs ().isEmpty (), "Data should exist in the index" );
490
495
491
- // truncate
496
+ // Truncate the table
492
497
elasticSearchCatalog .truncateTable (tablePath , false );
493
- Assertions . assertTrue ( elasticSearchCatalog . tableExists ( tablePath ));
498
+ Thread . sleep ( 2000 ); // Wait for data to be indexed
494
499
495
500
// Verify data is deleted
496
501
scrollResult = esRestClient .searchByScroll ("st_index3" , sourceFields , query , "1m" , 100 );
497
502
Assertions .assertTrue (
498
- scrollResult .getDocs ().isEmpty (),
499
- "Data was not successfully deleted from the index" );
503
+ scrollResult .getDocs ().isEmpty (), "Data should be deleted from the index" );
500
504
501
- // drop
505
+ // Drop the table
502
506
elasticSearchCatalog .dropTable (tablePath , false );
503
- Assertions .assertFalse (elasticSearchCatalog .tableExists (tablePath ));
507
+ Assertions .assertFalse (
508
+ elasticSearchCatalog .tableExists (tablePath ), "Index should be dropped" );
509
+
504
510
elasticSearchCatalog .close ();
505
511
}
506
512
0 commit comments