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

Disable ES indexing during tests

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