Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8025223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:05:52+00:00 2026-06-04T23:05:52+00:00

My unit/integration tests includes tests for search functionality. My idea is to have empty

  • 0

My unit/integration tests includes tests for search functionality.

My idea is to have empty search index before each test. So, I’m trying to remove all elements in index on setup method (it’s Groovy code):

Client client = searchConnection.client

SearchResponse response = client.prepareSearch("item")
    .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
    .setQuery(termQuery('name', 'test')) //tried also matchAllQuery()
    .setFrom(0).setSize(100).setExplain(false).execute().actionGet()

List<String> ids = response.hits.hits.collect {
    return it.id
}
client.close()

client = searchConnection.client

ids.each {
    DeleteResponse delete = client.prepareDelete("item", "item", it)
        .setOperationThreaded(false)
        .execute().actionGet()
}

client.close()

Seems that it’s processing all deletions asynchronously, so I’ve added Thread.sleep(5000) after it. As you see i’m trying to open/close connection few times – it doesn’t help there.

The problem that sometimes it requires more time, sometimes it needs more that 5 seconds to delete, sometimes it can’t find just added data (from previous test), etc, etc. And most annoying that integration tests becomes unstable. Putting Thread.sleep() everywhere where it’s possible looks as not so good solution.

It there any way to commit last changes, or make an lock until all data will be written?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:05:53+00:00Added an answer on June 4, 2026 at 11:05 pm

    Found solution:

    IndicesAdminClient adminClient = searchConnection.client.admin().indices();
    String indexName = "location";
    DeleteIndexResponse delete = adminClient.delete(new DeleteIndexRequest(indexName)).actionGet()
    if (!delete.isAcknowledged()) {
        log.error("Index {} wasn't deleted", indexName);
    }
    

    and

    client.admin().indices().flush(new FlushRequest('location')).actionGet();
    

    after putting new data into index.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two kinds of Unit tests (not integration test). Because of some strange
I have the default src/test/java folder for our unit tests. A separate folder src/integration/java
I'm trying to do some unit/integration tests between pages of my ASP.NET site but
I have a set of Visual Studio Team System unit (integration really) tests that
Where to test routes in ruby on rails? unit tests? functional tests? integration tests?
Is it ok to have integration tests and unit tests in one assembly (project)
How can I skip the unit and integration tests in Grails when building? I
How to organize rspec 2 tests into 'unit' (fast) and 'integration' (slow) categories? I
I want to create a unit test for integration testing. What class should I
I have a number of tests failing in the following JUnit Task. <target name=test-main

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.