Skip to content

Conversation

mdeinum
Copy link
Contributor

@mdeinum mdeinum commented Mar 15, 2017

This commit introduces the @DataElasticSearchTest annotation.

See: gh-8544

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 15, 2017
Copy link
Member

@snicoll snicoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the mongdb copy/paste this looks sensible.

}
----

Embedded MongoDB generally works well for tests since it is fast and doesn't
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uh? :)

* tests. Most tests should consider using {@link DataElasticsearchTest @DataElasticsearchTest} rather
* than using this annotation directly.
*
* @author M. Deinum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency could you please use your full first name?

this.thrown.expect(NoSuchBeanDefinitionException.class);
this.applicationContext.getBean(BookService.class);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@snicoll snicoll self-assigned this Mar 16, 2017
@snicoll snicoll added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 16, 2017
@snicoll snicoll added this to the 1.5.3 milestone Mar 16, 2017
@philwebb
Copy link
Member

@snicoll did you mean to put this in the 1.5.x bucket?

@snicoll
Copy link
Member

snicoll commented Mar 16, 2017

Wrong call, should be 2.0 I suppose.

@philwebb philwebb modified the milestones: 2.0.0.M1, 1.5.3 Mar 16, 2017
@philwebb
Copy link
Member

It's tempting to try an sneak it into 1.5.x, but 2.0 is better I think.

snicoll added a commit to snicoll/spring-boot that referenced this pull request Mar 17, 2017
@snicoll
Copy link
Member

snicoll commented Mar 17, 2017

OK I've polished the PR (see my branch). @mdeinum could you please configure your IDE to at least use tabs?

So there is one thing I don't like is that the tests create an index and I really don't want that. Discussing with @wilkinsona we think it should probably default to something else with a property to specify it maybe.

If someone wants to work on that, feel free to submit a PR on my fork.

snicoll added a commit to snicoll/spring-boot that referenced this pull request Apr 14, 2017
@snicoll
Copy link
Member

snicoll commented Apr 14, 2017

@philwebb I tried to implement this and it looks like a lot of work. On DataElasticSearchTest we could have a property that specifies if we should attempt to relocate the data directory. We would probably need an extension of SpringBootTestContextBootstrapper to look for the annotation and create a PropertySource with a sensible precedence.

It's not very clear what we should do. Detect a target or build directory and create a sub-directory there? This feels a bit magic to me.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Apr 14, 2017
@philwebb
Copy link
Member

@snicoll What's creating the data directory? Is it something in ElasticsearchAutoConfiguration? I'm not sure I'm following what needs to happen with the SpringBootTestContextBootstrapper and additional property source. Is it because we need to dynamically detect the directory based on the target/build folder?

@snicoll
Copy link
Member

snicoll commented Apr 17, 2017

@philwebb our auto-configuration defaults to the current work directory.

So, yes. We need to add a PropertySource where that property is set with a sensible directory. I might argue you probably want a property on the annotation to be able to tune it (and that should create another context if it's changed).

@philwebb
Copy link
Member

@snicoll What if we offered some kind of ElasticsearchPropertiesPostProcessor or some plugable strategy that's specific to ElasticsearchAutoConfiguration. That would reduce the problem to register a bean and read some mapped property, hopefully saving the need for any SpringBootTestContextBootstrapper changes.

@snicoll
Copy link
Member

snicoll commented Apr 18, 2017

Perhaps the main auto-configuration should change then. Two things:

  • Nobody wants the indexes generated at the same level of their build file I suppose
  • There are cases where you want a fresh index and cases where you don't want to repeat the initialization of the index for every test class

if that was a feature of the auto-configuration, the test auto-config would just flip a switch.

@mdeinum
Copy link
Contributor Author

mdeinum commented Apr 19, 2017

In our specific situation, as we used gradle, we put the index in the build directory and recreate before every test. But as that isn't very portable that won't work here. We basically set the path.home using spring.data.elasticsearch.properties.path.home this will then override the default. At least it worked for us.

For testing this could, maybe, be put in the java.io.tmpdir or a sub directory in there instead of the current user.dir?

Could a specific TestExecutionListener be used to override/set the property?

@snicoll
Copy link
Member

snicoll commented Apr 19, 2017

recreate before every test.

How do you do that?

@mdeinum
Copy link
Contributor Author

mdeinum commented Apr 19, 2017

We basically used the sledge hammer approach and tapped into the dirties context support much like the ServletTestExecutionListener. It was better then the approach we had.

Would be nice if we could have something along the lines of @AutoConfigureTestDatabase and replace the client instead of the whole context.

@snicoll
Copy link
Member

snicoll commented Apr 20, 2017

I am not following. What do you mean by "context"?

@mdeinum
Copy link
Contributor Author

mdeinum commented Apr 20, 2017

My bad. When using the dirties context approach a new ApplicationContext is created, which is what I meant with context.

Would it make sense to create an @AutoConfigureTestElasticSearch with a separate namespace (like the @AutoConfigureTestDatabase which could be preconfigured to use a different default for the path.home? and maybe some other defaults to optimize an ElasticSearch instance for testing? maybe with reusing parts of the current ElasticSearchAutoConfiguration?

@snicoll snicoll modified the milestones: 2.0.0.M2, 2.0.0.M1 May 4, 2017
@snicoll
Copy link
Member

snicoll commented May 4, 2017

@mdeinum you're the one submitting this PR so if you know good defaults, by all means share them.

@snicoll snicoll removed this from the 2.0.0.M2 milestone May 29, 2017
@snicoll snicoll removed their assignment May 29, 2017
@snicoll
Copy link
Member

snicoll commented May 29, 2017

@mdeinum are you going to refine your PR with what we've discussed here?

@mdeinum mdeinum force-pushed the elastic-test-autoconfig branch from 01caa7a to 25a5d56 Compare May 29, 2017 18:26
This commit introduces the @DataElasticSearchTest annotation.

See: spring-projectsgh-8544
@mdeinum mdeinum force-pushed the elastic-test-autoconfig branch from 25a5d56 to 7991126 Compare May 29, 2017 18:28
@wilkinsona
Copy link
Member

In Elasticsearch 5 they have dropped official support for running embedded Elasticsearch. They do, however, provide EsIntegTestCase. Unfortunately, it's very picky about what's on the classpath and tests fail to launch if it finds any duplicate classes. For example it pulls in org.elasticsearc:securemock which contains lots of Mockito classes. This then prevents the use of Mockito itself within the same project. Even with lots of exclusions in place to tune the classpath, it still couldn't run a unit test in Eclipse as the check found a duplicate internal Eclipse class.

The alternative is to roll our own code to bootstrap an Elasticsearch node as part of @DataElasticsearchTest that skips the jar hell check. That would probably be sufficient for integration testing purposes.

@mdeinum
Copy link
Contributor Author

mdeinum commented Jun 15, 2017

That is too bad :( . I'm currently a bit swamped in work and finishing a book. If all goes well I probably have time next week to take another look at this.

Could we take some inspiration from the EsIntegTestCase (this is what I initially did for the 2.x version).

@wilkinsona
Copy link
Member

It looks like this has been scuppered by the current situation with embedding Elasticsearch and the severe restrictions of EsIntegTestCase. It doesn't look like that situation is going to change in the foreseeable future so, with some regret, I'm going to close this. Thanks anyway, @mdeinum. If another approach comes to light, we can resurrect this PR.

@wilkinsona wilkinsona closed this Feb 2, 2018
@wilkinsona wilkinsona added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-feedback We need additional information before we can continue type: enhancement A general enhancement labels Feb 2, 2018
@mdeinum mdeinum deleted the elastic-test-autoconfig branch April 29, 2021 12:23
@hantsy
Copy link

hantsy commented Nov 14, 2021

Oh, this PR finally missed merging into Spring Boot?

@wilkinsona
Copy link
Member

Yes. Please see the various comments above for the reasons why it could not be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants