Skip to content

Commit 7e538d5

Browse files
author
wuqida
committed
fix the test case
1 parent 53dc33e commit 7e538d5

File tree

1 file changed

+19
-13
lines changed
  • seatunnel-e2e/seatunnel-connector-v2-e2e/connector-elasticsearch-e2e/src/test/java/org/apache/seatunnel/e2e/connector/elasticsearch

1 file changed

+19
-13
lines changed

seatunnel-e2e/seatunnel-connector-v2-e2e/connector-elasticsearch-e2e/src/test/java/org/apache/seatunnel/e2e/connector/elasticsearch/ElasticsearchIT.java

+19-13
Original file line numberDiff line numberDiff line change
@@ -447,28 +447,33 @@ public void tearDown() {
447447
}
448448

449449
@Test
450-
public void testCatalog() throws IOException, InterruptedException {
450+
public void testCatalog() throws InterruptedException, JsonProcessingException {
451451
Map<String, Object> configMap = new HashMap<>();
452452
configMap.put("username", "elastic");
453453
configMap.put("password", "elasticsearch");
454-
configMap.put("hosts", Arrays.asList("https://" + container.getHttpHostAddress()));
454+
configMap.put(
455+
"hosts", Collections.singletonList("https://" + container.getHttpHostAddress()));
455456
configMap.put("index", "st_index3");
456457
configMap.put("tls_verify_certificate", false);
457458
configMap.put("tls_verify_hostname", false);
458459
configMap.put("index_type", "st");
460+
459461
final ElasticSearchCatalog elasticSearchCatalog =
460462
new ElasticSearchCatalog("Elasticsearch", "", ReadonlyConfig.fromMap(configMap));
461463
elasticSearchCatalog.open();
464+
462465
TablePath tablePath = TablePath.of("", "st_index3");
463-
// index exists
466+
467+
// Verify index does not exist initially
464468
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
467472
elasticSearchCatalog.createTable(tablePath, null, false);
468473
final boolean existsAfter = elasticSearchCatalog.tableExists(tablePath);
469-
Assertions.assertTrue(existsAfter);
474+
Assertions.assertTrue(existsAfter, "Index should be created");
470475

471-
// Add multiple records
476+
// Generate and add multiple records
472477
List<String> data = generateTestData();
473478
StringBuilder requestBody = new StringBuilder();
474479
String indexHeader = "{\"index\":{\"_index\":\"st_index3\"}}\n";
@@ -488,19 +493,20 @@ public void testCatalog() throws IOException, InterruptedException {
488493
esRestClient.searchByScroll("st_index3", sourceFields, query, "1m", 100);
489494
Assertions.assertFalse(scrollResult.getDocs().isEmpty(), "Data should exist in the index");
490495

491-
// truncate
496+
// Truncate the table
492497
elasticSearchCatalog.truncateTable(tablePath, false);
493-
Assertions.assertTrue(elasticSearchCatalog.tableExists(tablePath));
498+
Thread.sleep(2000); // Wait for data to be indexed
494499

495500
// Verify data is deleted
496501
scrollResult = esRestClient.searchByScroll("st_index3", sourceFields, query, "1m", 100);
497502
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");
500504

501-
// drop
505+
// Drop the table
502506
elasticSearchCatalog.dropTable(tablePath, false);
503-
Assertions.assertFalse(elasticSearchCatalog.tableExists(tablePath));
507+
Assertions.assertFalse(
508+
elasticSearchCatalog.tableExists(tablePath), "Index should be dropped");
509+
504510
elasticSearchCatalog.close();
505511
}
506512

0 commit comments

Comments
 (0)