@@ -447,7 +447,7 @@ public void tearDown() {
447
447
}
448
448
449
449
@ Test
450
- public void testCatalog () {
450
+ public void testCatalog () throws IOException , InterruptedException {
451
451
Map <String , Object > configMap = new HashMap <>();
452
452
configMap .put ("username" , "elastic" );
453
453
configMap .put ("password" , "elasticsearch" );
@@ -467,15 +467,52 @@ public void testCatalog() {
467
467
elasticSearchCatalog .createTable (tablePath , null , false );
468
468
final boolean existsAfter = elasticSearchCatalog .tableExists (tablePath );
469
469
Assertions .assertTrue (existsAfter );
470
- // data exists?
471
- final boolean existsData = elasticSearchCatalog .isExistsData (tablePath );
472
- Assertions .assertFalse (existsData );
470
+
471
+ // Add multiple records
472
+ List <String > data = generateTestData ();
473
+ StringBuilder requestBody = new StringBuilder ();
474
+ String indexHeader = "{\" index\" :{\" _index\" :\" st_index3\" }}\n " ;
475
+ for (String record : data ) {
476
+ requestBody .append (indexHeader );
477
+ requestBody .append (record );
478
+ requestBody .append ("\n " );
479
+ }
480
+ esRestClient .bulk (requestBody .toString ());
481
+ Thread .sleep (2000 ); // Wait for data to be indexed
482
+
483
+ // Verify data exists
484
+ List <String > sourceFields = Arrays .asList ("field1" , "field2" );
485
+ Map <String , Object > query = new HashMap <>();
486
+ query .put ("match_all" , new HashMap <>());
487
+ ScrollResult scrollResult =
488
+ esRestClient .searchByScroll ("st_index3" , sourceFields , query , "1m" , 100 );
489
+ Assertions .assertFalse (scrollResult .getDocs ().isEmpty (), "Data should exist in the index" );
490
+
473
491
// truncate
474
492
elasticSearchCatalog .truncateTable (tablePath , false );
475
493
Assertions .assertTrue (elasticSearchCatalog .tableExists (tablePath ));
494
+
495
+ // Verify data is deleted
496
+ scrollResult = esRestClient .searchByScroll ("st_index3" , sourceFields , query , "1m" , 100 );
497
+ Assertions .assertTrue (
498
+ scrollResult .getDocs ().isEmpty (),
499
+ "Data was not successfully deleted from the index" );
500
+
476
501
// drop
477
502
elasticSearchCatalog .dropTable (tablePath , false );
478
503
Assertions .assertFalse (elasticSearchCatalog .tableExists (tablePath ));
479
504
elasticSearchCatalog .close ();
480
505
}
506
+
507
+ private List <String > generateTestData () throws JsonProcessingException {
508
+ List <String > data = new ArrayList <>();
509
+ ObjectMapper objectMapper = new ObjectMapper ();
510
+ for (int i = 0 ; i < 10 ; i ++) {
511
+ Map <String , Object > record = new HashMap <>();
512
+ record .put ("field1" , "value" + i );
513
+ record .put ("field2" , i );
514
+ data .add (objectMapper .writeValueAsString (record ));
515
+ }
516
+ return data ;
517
+ }
481
518
}
0 commit comments