Commit 57c7445c authored by Matija Obreza's avatar Matija Obreza
Browse files

Disable ES indexing during tests

parent 60d1c82e
......@@ -15,6 +15,9 @@
*/
package org.genesys.test.config;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.elasticsearch.client.Client;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.dataset.Dataset;
......@@ -23,8 +26,6 @@ import org.genesys.catalog.model.traits.DescriptorList;
import org.genesys.catalog.model.vocab.ControlledVocabulary;
import org.genesys.catalog.model.vocab.VocabularyTerm;
import org.genesys.custom.elasticsearch.EmbeddedClientFactoryBean;
import org.genesys2.server.component.elastic.ElasticJPAListener;
import org.genesys2.server.component.elastic.ElasticReindexProcessor;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.ActivityPost;
import org.genesys2.server.model.impl.Article;
......@@ -34,6 +35,7 @@ import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.impl.ElasticsearchServiceImpl;
import org.genesys2.spring.config.ElasticsearchConfig;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Bean;
......@@ -44,10 +46,10 @@ import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
* ElasticsearchConfig for JUnit
*/
@Configuration
public class TestElasticsearchConfig implements InitializingBean {
public class TestElasticsearchConfig implements InitializingBean, DisposableBean {
/** The data path. */
private String dataPath;
private File dataPath;
/** The cluster name. */
private String clusterName;
......@@ -58,18 +60,25 @@ public class TestElasticsearchConfig implements InitializingBean {
@Override
public void afterPropertiesSet() throws Exception {
this.clusterName = "es-test-" + System.currentTimeMillis();
this.dataPath = "target/test-es/" + System.currentTimeMillis();
this.dataPath = new File(FileUtils.getTempDirectory(), "test-es-" + System.currentTimeMillis());
}
@Bean
public ElasticJPAListener listener() {
return new ElasticJPAListener();
@Override
public void destroy() throws Exception {
System.err.println("Deleting " + dataPath.getAbsolutePath());
FileUtils.deleteQuietly(dataPath);
}
@Bean
public ElasticReindexProcessor reindexProcessor() {
return new ElasticReindexProcessor();
}
// @Bean
// public ElasticJPAListener listener() {
// return new ElasticJPAListener();
// }
//
// @Bean
// public ElasticReindexProcessor reindexProcessor() {
// return new ElasticReindexProcessor();
// }
/**
* Node client.
......@@ -79,7 +88,7 @@ public class TestElasticsearchConfig implements InitializingBean {
@Bean
public FactoryBean<? extends Client> elasticClient() {
final EmbeddedClientFactoryBean embedded = new EmbeddedClientFactoryBean();
embedded.setDataHome(this.dataPath);
embedded.setDataHome(this.dataPath.getAbsolutePath());
embedded.setClusterName(clusterName);
embedded.setWithHttp(false);
return embedded;
......@@ -124,4 +133,5 @@ public class TestElasticsearchConfig implements InitializingBean {
return t;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment