import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.Rule;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.core.profiling.Profiling;
import org.sonar.server.es.EsTester;
public class ProxyBulkRequestBuilderTest {
- @Rule
- public EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+ @ClassRule
+ public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
+ }
@Test
public void bulk() {
}
@Test
- public void with_profiling_basic() {
- testBulk(Profiling.Level.BASIC);
+ public void with_profiling_full() {
+ testBulk(Profiling.Level.FULL);
// TODO assert profiling
}
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.Rule;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
import org.sonar.server.es.EsTester;
-import org.sonar.server.search.SearchClient;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxyClearCacheRequestBuilderTest {
- @Rule
- public EsTester esTester = new EsTester();
+ @ClassRule
+ public static EsTester esTester = new EsTester();
+
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
+ }
@Test
public void clear_cache() {
}
@Test
- public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
-
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
ClearIndicesCacheRequestBuilder requestBuilder = esTester.client().prepareClearCache();
requestBuilder.get();
// TODO assert profiling
- searchClient.stop();
}
@Test
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.Rule;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.core.profiling.Profiling;
import org.sonar.server.es.EsTester;
public class ProxyClusterHealthRequestBuilderTest {
- @Rule
- public EsTester esTester = new EsTester();
+ @ClassRule
+ public static EsTester esTester = new EsTester();
+
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
+ }
@Test
public void state() {
}
@Test
- public void with_profiling_basic() {
- esTester.setProfilingLevel(Profiling.Level.BASIC);
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
ClusterHealthRequestBuilder requestBuilder = esTester.client().prepareHealth();
ClusterHealthResponse state = requestBuilder.get();
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.SearchClient;
+import org.sonar.server.es.EsTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxyClusterStateRequestBuilderTest {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ @ClassRule
+ public static EsTester esTester = new EsTester();
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
}
@Test
public void state() {
- try {
- ClusterStateRequestBuilder requestBuilder = searchClient.prepareState();
- requestBuilder.get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES cluster state request");
- }
+ ClusterStateRequestBuilder requestBuilder = esTester.client().prepareState();
+ requestBuilder.get();
}
@Test
public void to_string() {
- assertThat(searchClient.prepareState().setIndices("rules").toString()).isEqualTo("ES cluster state request on indices 'rules'");
- assertThat(searchClient.prepareState().toString()).isEqualTo("ES cluster state request");
+ assertThat(esTester.client().prepareState().setIndices("rules").toString()).isEqualTo("ES cluster state request on indices 'rules'");
+ assertThat(esTester.client().prepareState().toString()).isEqualTo("ES cluster state request");
}
@Test
- public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
- try {
-
- ClusterStateRequestBuilder requestBuilder = searchClient.prepareState();
- requestBuilder.get();
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES cluster state request");
- }
+ ClusterStateRequestBuilder requestBuilder = esTester.client().prepareState();
+ requestBuilder.get();
// TODO assert profiling
- searchClient.stop();
}
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareState().get("1");
+ esTester.client().prepareState().get("1");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareState().get(TimeValue.timeValueMinutes(1));
+ esTester.client().prepareState().get(TimeValue.timeValueMinutes(1));
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
try {
- searchClient.prepareState().execute();
+ esTester.client().prepareState().execute();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.SearchClient;
+import org.sonar.server.es.EsTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxyClusterStatsRequestBuilderTest {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ @ClassRule
+ public static EsTester esTester = new EsTester();
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
}
@Test
public void stats() {
- try {
- ClusterStatsRequestBuilder requestBuilder = searchClient.prepareClusterStats();
- requestBuilder.get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES cluster stats request");
- }
+ ClusterStatsRequestBuilder requestBuilder = esTester.client().prepareClusterStats();
+ requestBuilder.get();
}
@Test
public void to_string() {
- assertThat(searchClient.prepareClusterStats().setNodesIds("node1").toString()).isEqualTo("ES cluster stats request on nodes 'node1'");
- assertThat(searchClient.prepareClusterStats().toString()).isEqualTo("ES cluster stats request");
+ assertThat(esTester.client().prepareClusterStats().setNodesIds("node1").toString()).isEqualTo("ES cluster stats request on nodes 'node1'");
+ assertThat(esTester.client().prepareClusterStats().toString()).isEqualTo("ES cluster stats request");
}
@Test
- public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
- try {
- ClusterStatsRequestBuilder requestBuilder = searchClient.prepareClusterStats();
- requestBuilder.get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES cluster stats request");
- }
+ ClusterStatsRequestBuilder requestBuilder = esTester.client().prepareClusterStats();
+ requestBuilder.get();
// TODO assert profiling
- searchClient.stop();
}
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareClusterStats().get("1");
+ esTester.client().prepareClusterStats().get("1");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareClusterStats().get(TimeValue.timeValueMinutes(1));
+ esTester.client().prepareClusterStats().get(TimeValue.timeValueMinutes(1));
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
try {
- searchClient.prepareClusterStats().execute();
+ esTester.client().prepareClusterStats().execute();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
package org.sonar.server.es.request;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.IndexDefinition;
-import org.sonar.server.search.SearchClient;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.es.FakeIndexDefinition;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxyCountRequestBuilderTest {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ @ClassRule
+ public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
}
@Test
public void count() {
- try {
- searchClient.prepareCount(IndexDefinition.RULE.getIndexName()).get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES count request on indices 'rules'");
- }
+ esTester.client().prepareCount(FakeIndexDefinition.INDEX).get();
}
@Test
public void to_string() {
- assertThat(searchClient.prepareCount(IndexDefinition.RULE.getIndexName()).setTypes("rule").toString()).isEqualTo("ES count request on indices 'rules' on types 'rule'");
- assertThat(searchClient.prepareCount(IndexDefinition.RULE.getIndexName()).toString()).isEqualTo("ES count request on indices 'rules'");
- assertThat(searchClient.prepareCount().toString()).isEqualTo("ES count request");
+ assertThat(esTester.client().prepareCount(FakeIndexDefinition.INDEX).setTypes(FakeIndexDefinition.TYPE).toString()).isEqualTo("ES count request on indices 'fakes' on types 'fake'");
+ assertThat(esTester.client().prepareCount(FakeIndexDefinition.INDEX).toString()).isEqualTo("ES count request on indices 'fakes'");
+ assertThat(esTester.client().prepareCount().toString()).isEqualTo("ES count request");
}
@Test
- public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
- try {
- searchClient.prepareCount(IndexDefinition.RULE.getIndexName()).get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES count request on indices 'rules'");
- }
+ esTester.client().prepareCount(FakeIndexDefinition.INDEX).get();
// TODO assert profiling
- searchClient.stop();
}
@Test
public void fail_to_count_bad_query() throws Exception {
try {
- searchClient.prepareCount("unknown_index1, unknown_index2").setTypes("unknown_type").get();
+ esTester.client().prepareCount("unknown_index1, unknown_index2").setTypes("unknown_type").get();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class);
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareCount(IndexDefinition.RULE.getIndexName()).get("1");
+ esTester.client().prepareCount(FakeIndexDefinition.INDEX).get("1");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareCount(IndexDefinition.RULE.getIndexName()).get(TimeValue.timeValueMinutes(1));
+ esTester.client().prepareCount(FakeIndexDefinition.INDEX).get(TimeValue.timeValueMinutes(1));
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
try {
- searchClient.prepareCount(IndexDefinition.RULE.getIndexName()).execute();
+ esTester.client().prepareCount(FakeIndexDefinition.INDEX).execute();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
+import org.sonar.api.utils.System2;
import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.SearchClient;
+import org.sonar.server.es.EsTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxyCreateIndexRequestBuilderTest {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ @ClassRule
+ public static EsTester esTester = new EsTester();
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
}
@Test
public void create_index() {
- try {
- CreateIndexRequestBuilder requestBuilder = searchClient.prepareCreate("new");
- requestBuilder.get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES create index 'new'");
- }
+ CreateIndexRequestBuilder requestBuilder = esTester.client().prepareCreate(generateNewIndexName());
+ requestBuilder.get();
}
@Test
public void to_string() {
- assertThat(searchClient.prepareCreate("new").toString()).isEqualTo("ES create index 'new'");
+ String indexName = generateNewIndexName();
+ assertThat(esTester.client().prepareCreate(indexName).toString()).contains("ES create index '" + indexName + "'");
}
@Test
- public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
-
- try {
- CreateIndexRequestBuilder requestBuilder = searchClient.prepareCreate("new");
- requestBuilder.get();
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES create index 'new'");
- }
+ CreateIndexRequestBuilder requestBuilder = esTester.client().prepareCreate(generateNewIndexName());
+ requestBuilder.get();
// TODO assert profiling
- searchClient.stop();
}
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareCreate("new").get("1");
+ esTester.client().prepareCreate(generateNewIndexName()).get("1");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareCreate("new").get(TimeValue.timeValueMinutes(1));
+ esTester.client().prepareCreate(generateNewIndexName()).get(TimeValue.timeValueMinutes(1));
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
try {
- searchClient.prepareCreate("new").execute();
+ esTester.client().prepareCreate(generateNewIndexName()).execute();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
}
}
+ private static String generateNewIndexName(){
+ return "index_" + Long.toString(System2.INSTANCE.now());
+ }
+
}
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.QueryBuilders;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.IndexDefinition;
-import org.sonar.server.search.SearchClient;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.es.FakeIndexDefinition;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxyDeleteByQueryRequestBuilderTest {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ @ClassRule
+ public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
}
@Test
- public void expect_failure() {
- try {
- searchClient.prepareDeleteByQuery(IndexDefinition.RULE.getIndexName()).setQuery(QueryBuilders.matchAllQuery()).get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES delete by query request on indices 'rules'");
- }
+ public void delete_by_query() {
+ esTester.client().prepareDeleteByQuery(FakeIndexDefinition.INDEX).setQuery(QueryBuilders.matchAllQuery()).get();
}
@Test
public void to_string() {
- assertThat(searchClient.prepareDeleteByQuery(IndexDefinition.RULE.getIndexName()).toString()).isEqualTo("ES delete by query request on indices 'rules'");
- assertThat(searchClient.prepareDeleteByQuery().toString()).isEqualTo("ES delete by query request");
+ assertThat(esTester.client().prepareDeleteByQuery(FakeIndexDefinition.INDEX).toString()).isEqualTo("ES delete by query request on indices 'fakes'");
+ assertThat(esTester.client().prepareDeleteByQuery().toString()).isEqualTo("ES delete by query request");
}
@Test
- public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
- try {
- searchClient.prepareDeleteByQuery(IndexDefinition.RULE.getIndexName()).setQuery(QueryBuilders.matchAllQuery()).get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES delete by query request on indices 'rules'");
- }
+ esTester.client().prepareDeleteByQuery(FakeIndexDefinition.INDEX).setQuery(QueryBuilders.matchAllQuery()).get();
// TODO assert profiling
- searchClient.stop();
}
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareDeleteByQuery().get("1");
+ esTester.client().prepareDeleteByQuery().get("1");
fail();
} catch (UnsupportedOperationException e) {
assertThat(e).hasMessage("Not yet implemented");
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareDeleteByQuery().get(TimeValue.timeValueMinutes(1));
+ esTester.client().prepareDeleteByQuery().get(TimeValue.timeValueMinutes(1));
fail();
} catch (UnsupportedOperationException e) {
assertThat(e).hasMessage("Not yet implemented");
@Test
public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
try {
- searchClient.prepareDeleteByQuery().execute();
+ esTester.client().prepareDeleteByQuery().execute();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
package org.sonar.server.es.request;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.SearchClient;
+import org.sonar.server.es.EsTester;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxyDeleteRequestBuilderTest {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ @ClassRule
+ public static EsTester esTester = new EsTester();
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
}
@Test
- public void expect_failure() {
- try {
- searchClient.prepareDelete("fakes", "fake", "the_id").get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES delete request of doc the_id in index fakes/fake");
- }
+ public void delete() {
+ esTester.client().prepareDelete("fakes", "fake", "the_id").get();
}
@Test
public void to_string() {
- assertThat(searchClient.prepareDelete("fakes", "fake", "the_id").toString()).isEqualTo("ES delete request of doc the_id in index fakes/fake");
+ assertThat(esTester.client().prepareDelete("fakes", "fake", "the_id").toString()).isEqualTo("ES delete request of doc the_id in index fakes/fake");
}
@Test
- public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
-
- try {
- searchClient.prepareDelete("fakes", "fake", "the_id").get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES delete request of doc the_id in index fakes/fake");
- }
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
+ esTester.client().prepareDelete("fakes", "fake", "the_id").get();
// TODO assert profiling
- searchClient.stop();
}
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareDelete("fakes", "fake", "the_id").get("1");
+ esTester.client().prepareDelete("fakes", "fake", "the_id").get("1");
fail();
} catch (UnsupportedOperationException e) {
assertThat(e).hasMessage("Not yet implemented");
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareDelete("fakes", "fake", "the_id").get(TimeValue.timeValueMinutes(1));
+ esTester.client().prepareDelete("fakes", "fake", "the_id").get(TimeValue.timeValueMinutes(1));
fail();
} catch (UnsupportedOperationException e) {
assertThat(e).hasMessage("Not yet implemented");
@Test
public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
try {
- searchClient.prepareDelete("fakes", "fake", "the_id").execute();
+ esTester.client().prepareDelete("fakes", "fake", "the_id").execute();
fail();
} catch (UnsupportedOperationException e) {
assertThat(e).hasMessage("execute() should not be called as it's used for asynchronous");
package org.sonar.server.es.request;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.IndexDefinition;
-import org.sonar.server.search.SearchClient;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.es.FakeIndexDefinition;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxyFlushRequestBuilderTest {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ @ClassRule
+ public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
}
@Test
public void flush() {
- try {
- searchClient.prepareFlush(IndexDefinition.RULE.getIndexName()).get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES flush request on indices 'rules'");
- }
+ esTester.client().prepareFlush(FakeIndexDefinition.INDEX).get();
}
@Test
public void to_string() {
- assertThat(searchClient.prepareFlush(IndexDefinition.RULE.getIndexName()).toString()).isEqualTo("ES flush request on indices 'rules'");
- assertThat(searchClient.prepareFlush().toString()).isEqualTo("ES flush request");
+ assertThat(esTester.client().prepareFlush(FakeIndexDefinition.INDEX).toString()).isEqualTo("ES flush request on indices 'fakes'");
+ assertThat(esTester.client().prepareFlush().toString()).isEqualTo("ES flush request");
}
@Test
- public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
- try {
- searchClient.prepareFlush(IndexDefinition.RULE.getIndexName()).get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES flush request on indices 'rules'");
- }
+ esTester.client().prepareFlush(FakeIndexDefinition.INDEX).get();
// TODO assert profiling
- searchClient.stop();
}
@Test
public void fail_to_refresh() throws Exception {
try {
- searchClient.prepareFlush("unknown").get();
+ esTester.client().prepareFlush("unknown").get();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class);
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareFlush(IndexDefinition.RULE.getIndexName()).get("1");
+ esTester.client().prepareFlush(FakeIndexDefinition.INDEX).get("1");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareFlush(IndexDefinition.RULE.getIndexName()).get(TimeValue.timeValueMinutes(1));
+ esTester.client().prepareFlush(FakeIndexDefinition.INDEX).get(TimeValue.timeValueMinutes(1));
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
try {
- searchClient.prepareFlush(IndexDefinition.RULE.getIndexName()).execute();
+ esTester.client().prepareFlush(FakeIndexDefinition.INDEX).execute();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
import org.elasticsearch.action.get.GetRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.IndexDefinition;
-import org.sonar.server.search.SearchClient;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.es.FakeIndexDefinition;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxyGetRequestBuilderTest {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ @ClassRule
+ public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
}
@Test
public void get() {
- try {
- searchClient.prepareGet()
- .setIndex(IndexDefinition.RULE.getIndexName())
- .setType(IndexDefinition.RULE.getIndexType())
- .setId("ruleKey")
- .get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES get request for key 'ruleKey' on index 'rules' on type 'rule'");
- }
+ esTester.client().prepareGet()
+ .setIndex(FakeIndexDefinition.INDEX)
+ .setType(FakeIndexDefinition.TYPE)
+ .setId("ruleKey")
+ .get();
}
@Test
public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ esTester.setProfilingLevel(Profiling.Level.FULL);
- try {
- searchClient.prepareGet()
- .setIndex(IndexDefinition.RULE.getIndexName())
- .setType(IndexDefinition.RULE.getIndexType())
- .setId("ruleKey")
- .get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES get request for key 'ruleKey' on index 'rules' on type 'rule'");
- }
+ esTester.client().prepareGet()
+ .setIndex(FakeIndexDefinition.INDEX)
+ .setType(FakeIndexDefinition.TYPE)
+ .setId("ruleKey")
+ .get();
// TODO assert profiling
- searchClient.stop();
}
@Test
public void fail_to_get_bad_query() throws Exception {
- GetRequestBuilder requestBuilder = searchClient.prepareGet()
+ GetRequestBuilder requestBuilder = esTester.client().prepareGet()
.setIndex("unknown")
.setType("test")
.setId("rule1");
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareGet().get("1");
+ esTester.client().prepareGet().get("1");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareGet().get(TimeValue.timeValueMinutes(1));
+ esTester.client().prepareGet().get(TimeValue.timeValueMinutes(1));
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
try {
- searchClient.prepareGet().execute();
+ esTester.client().prepareGet().execute();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.Rule;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.core.profiling.Profiling;
import org.sonar.server.es.EsTester;
public class ProxyIndexRequestBuilderTest {
- @Rule
- public EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+ @ClassRule
+ public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
+ }
@Test
public void index_with_index_type_and_id() {
- esTester.setProfilingLevel(Profiling.Level.FULL);
IndexResponse response = esTester.client().prepareIndex(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE)
.setSource(FakeIndexDefinition.newDoc(42))
.get();
}
@Test
- public void with_profiling_basic() {
- esTester.setProfilingLevel(Profiling.Level.BASIC);
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
IndexResponse response = esTester.client().prepareIndex(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE)
.setSource(FakeIndexDefinition.newDoc(42))
.get();
@Test
public void fail_if_bad_query() throws Exception {
- esTester.setProfilingLevel(Profiling.Level.FULL);
IndexRequestBuilder requestBuilder = esTester.client().prepareIndex("unknownIndex", "unknownType");
try {
requestBuilder.get();
@Test
public void fail_if_bad_query_with_basic_profiling() throws Exception {
- esTester.setProfilingLevel(Profiling.Level.BASIC);
IndexRequestBuilder requestBuilder = esTester.client().prepareIndex("unknownIndex", "unknownType");
try {
requestBuilder.get();
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- esTester.setProfilingLevel(Profiling.Level.FULL);
try {
esTester.client().prepareIndex(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE).get("1");
fail();
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
- esTester.setProfilingLevel(Profiling.Level.FULL);
try {
esTester.client().prepareIndex(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE).get(TimeValue.timeValueMinutes(1));
fail();
@Test
public void do_not_support_execute_method() throws Exception {
- esTester.setProfilingLevel(Profiling.Level.FULL);
try {
esTester.client().prepareIndex(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE).execute();
fail();
package org.sonar.server.es.request;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.IndexDefinition;
-import org.sonar.server.search.SearchClient;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.es.FakeIndexDefinition;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxyIndicesExistsRequestBuilderTest {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ @ClassRule
+ public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
}
@Test
public void exists() {
- try {
- searchClient.prepareIndicesExist(IndexDefinition.RULE.getIndexName()).get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES indices exists request on indices 'rules'");
- }
+ assertThat(esTester.client().prepareIndicesExist(FakeIndexDefinition.INDEX).get().isExists()).isTrue();
+ assertThat(esTester.client().prepareIndicesExist("unknown").get().isExists()).isFalse();
}
@Test
- public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
- try {
- searchClient.prepareIndicesExist(IndexDefinition.RULE.getIndexName()).get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES indices exists request on indices 'rules'");
- }
+ esTester.client().prepareIndicesExist(FakeIndexDefinition.INDEX).get();
// TODO assert profiling
- searchClient.stop();
}
@Test
public void fail_to_exists() throws Exception {
try {
- searchClient.prepareIndicesExist().get();
+ esTester.client().prepareIndicesExist().get();
// expected to fail because elasticsearch is not correctly configured, but that does not matter
fail();
@Test
public void to_string() {
- assertThat(searchClient.prepareIndicesExist(IndexDefinition.RULE.getIndexName()).toString()).isEqualTo("ES indices exists request on indices 'rules'");
+ assertThat(esTester.client().prepareIndicesExist(FakeIndexDefinition.INDEX).toString()).isEqualTo("ES indices exists request on indices 'fakes'");
}
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareIndicesExist().get("1");
+ esTester.client().prepareIndicesExist().get("1");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareIndicesExist().get(TimeValue.timeValueMinutes(1));
+ esTester.client().prepareIndicesExist().get(TimeValue.timeValueMinutes(1));
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
try {
- searchClient.prepareIndicesExist().execute();
+ esTester.client().prepareIndicesExist().execute();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
package org.sonar.server.es.request;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.IndexDefinition;
-import org.sonar.server.search.SearchClient;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.es.FakeIndexDefinition;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxyIndicesStatsRequestBuilderTest {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ @ClassRule
+ public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
}
@Test
public void stats() {
- try {
- searchClient.prepareStats(IndexDefinition.RULE.getIndexName()).get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES indices stats request on indices 'rules'");
- }
+ esTester.client().prepareStats(FakeIndexDefinition.INDEX).get();
}
@Test
public void to_string() {
- assertThat(searchClient.prepareStats(IndexDefinition.RULE.getIndexName()).setIndices("rules").toString()).isEqualTo("ES indices stats request on indices 'rules'");
- assertThat(searchClient.prepareStats().toString()).isEqualTo("ES indices stats request");
+ assertThat(esTester.client().prepareStats(FakeIndexDefinition.INDEX).setIndices("rules").toString()).isEqualTo("ES indices stats request on indices 'rules'");
+ assertThat(esTester.client().prepareStats().toString()).isEqualTo("ES indices stats request");
}
@Test
- public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
- try {
- searchClient.prepareStats(IndexDefinition.RULE.getIndexName()).get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage()).isEqualTo("Fail to execute ES indices stats request on indices 'rules'");
- }
+ esTester.client().prepareStats(FakeIndexDefinition.INDEX).get();
// TODO assert profiling
- searchClient.stop();
}
@Test
public void fail_to_stats() throws Exception {
try {
- searchClient.prepareStats("unknown").get();
+ esTester.client().prepareStats("unknown").get();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class);
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareStats(IndexDefinition.RULE.getIndexName()).get("1");
+ esTester.client().prepareStats(FakeIndexDefinition.INDEX).get("1");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareStats(IndexDefinition.RULE.getIndexName()).get(TimeValue.timeValueMinutes(1));
+ esTester.client().prepareStats(FakeIndexDefinition.INDEX).get(TimeValue.timeValueMinutes(1));
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
try {
- searchClient.prepareStats(IndexDefinition.RULE.getIndexName()).execute();
+ esTester.client().prepareStats(FakeIndexDefinition.INDEX).execute();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
import org.elasticsearch.action.get.MultiGetRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.search.fetch.source.FetchSourceContext;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.IndexDefinition;
-import org.sonar.server.search.SearchClient;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.es.FakeIndexDefinition;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxyMultiGetRequestBuilderTest {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ @ClassRule
+ public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
}
@Test
public void multi_get() {
- try {
- MultiGetRequestBuilder request = searchClient.prepareMultiGet();
- request.add(new MultiGetRequest.Item(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexType(), "ruleKey")
- .fetchSourceContext(FetchSourceContext.FETCH_SOURCE));
- request.get();
+ MultiGetRequestBuilder request = esTester.client().prepareMultiGet();
+ request.add(new MultiGetRequest.Item(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE, "ruleKey")
+ .fetchSourceContext(FetchSourceContext.FETCH_SOURCE));
+ request.get();
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES multi get request");
- }
}
@Test
public void to_string() {
- assertThat(searchClient.prepareMultiGet().toString()).isEqualTo("ES multi get request");
- assertThat(searchClient.prepareMultiGet().add(new MultiGetRequest.Item(IndexDefinition.RULE.getIndexName(), null, "ruleKey")
- .fetchSourceContext(FetchSourceContext.FETCH_SOURCE)).toString()).isEqualTo("ES multi get request [key 'ruleKey', index 'rules'],");
- assertThat(searchClient.prepareMultiGet().add(new MultiGetRequest.Item(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexType(), "ruleKey")
- .fetchSourceContext(FetchSourceContext.FETCH_SOURCE)).toString()).isEqualTo("ES multi get request [key 'ruleKey', index 'rules', type 'rule'],");
+ assertThat(esTester.client().prepareMultiGet().toString()).isEqualTo("ES multi get request");
+ assertThat(esTester.client().prepareMultiGet().add(new MultiGetRequest.Item(FakeIndexDefinition.INDEX, null, "fake1")
+ .fetchSourceContext(FetchSourceContext.FETCH_SOURCE)).toString()).isEqualTo("ES multi get request [key 'fake1', index 'fakes'],");
+ assertThat(esTester.client().prepareMultiGet().add(new MultiGetRequest.Item(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE, "fake1")
+ .fetchSourceContext(FetchSourceContext.FETCH_SOURCE)).toString()).isEqualTo("ES multi get request [key 'fake1', index 'fakes', type 'fake'],");
}
@Test
- public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
- try {
- MultiGetRequestBuilder request = searchClient.prepareMultiGet();
- request.add(new MultiGetRequest.Item(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexType(), "ruleKey")
- .fetchSourceContext(FetchSourceContext.FETCH_SOURCE));
- request.get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES multi get request");
- }
+ MultiGetRequestBuilder request = esTester.client().prepareMultiGet();
+ request.add(new MultiGetRequest.Item(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE, "ruleKey")
+ .fetchSourceContext(FetchSourceContext.FETCH_SOURCE));
+ request.get();
// TODO assert profiling
- searchClient.stop();
}
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareMultiGet().get("1");
+ esTester.client().prepareMultiGet().get("1");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareMultiGet().get(TimeValue.timeValueMinutes(1));
+ esTester.client().prepareMultiGet().get(TimeValue.timeValueMinutes(1));
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
try {
- searchClient.prepareMultiGet().execute();
+ esTester.client().prepareMultiGet().execute();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
package org.sonar.server.es.request;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.IndexDefinition;
-import org.sonar.server.search.SearchClient;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.es.FakeIndexDefinition;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxyNodesStatsRequestBuilderTest {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ @ClassRule
+ public static EsTester esTester = new EsTester();
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
}
@Test
public void stats() {
- try {
- searchClient.prepareNodesStats().get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES nodes stats request");
- }
+ esTester.client().prepareNodesStats().get();
}
@Test
public void to_string() {
- assertThat(searchClient.prepareNodesStats().setNodesIds("node1").toString()).isEqualTo("ES nodes stats request on nodes 'node1'");
- assertThat(searchClient.prepareNodesStats().toString()).isEqualTo("ES nodes stats request");
+ assertThat(esTester.client().prepareNodesStats().setNodesIds("node1").toString()).isEqualTo("ES nodes stats request on nodes 'node1'");
+ assertThat(esTester.client().prepareNodesStats().toString()).isEqualTo("ES nodes stats request");
}
@Test
- public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
- try {
- searchClient.prepareNodesStats().get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES nodes stats request");
- }
+ esTester.client().prepareNodesStats().get();
// TODO assert profiling
- searchClient.stop();
}
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareNodesStats(IndexDefinition.RULE.getIndexName()).get("1");
+ esTester.client().prepareNodesStats(FakeIndexDefinition.INDEX).get("1");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareNodesStats(IndexDefinition.RULE.getIndexName()).get(TimeValue.timeValueMinutes(1));
+ esTester.client().prepareNodesStats(FakeIndexDefinition.INDEX).get(TimeValue.timeValueMinutes(1));
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
try {
- searchClient.prepareNodesStats(IndexDefinition.RULE.getIndexName()).execute();
+ esTester.client().prepareNodesStats(FakeIndexDefinition.INDEX).execute();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.IndexDefinition;
-import org.sonar.server.search.SearchClient;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.es.FakeIndexDefinition;
import java.util.HashMap;
import java.util.Map;
public class ProxyPutMappingRequestBuilderTest {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ @ClassRule
+ public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
}
@Test
public void put_mapping() {
- try {
- PutMappingRequestBuilder requestBuilder = searchClient.preparePutMapping(IndexDefinition.RULE.getIndexName())
- .setType(IndexDefinition.RULE.getIndexType())
- .setIgnoreConflicts(true)
- .setSource(mapDomain());
- requestBuilder.get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES put mapping request");
- }
+ PutMappingRequestBuilder requestBuilder = esTester.client().preparePutMapping(FakeIndexDefinition.INDEX)
+ .setType(FakeIndexDefinition.TYPE)
+ .setIgnoreConflicts(true)
+ .setSource(mapDomain());
+ requestBuilder.get();
}
@Test
public void to_string() {
- assertThat(searchClient.preparePutMapping(IndexDefinition.RULE.getIndexName()).setSource(mapDomain()).toString())
- .isEqualTo("ES put mapping request on indices 'rules' with source '{\"dynamic\":false,\"_all\":{\"enabled\":false}}'");
- assertThat(searchClient.preparePutMapping(IndexDefinition.RULE.getIndexName()).setType(IndexDefinition.RULE.getIndexType()).setSource(mapDomain()).toString())
- .isEqualTo("ES put mapping request on indices 'rules' on type 'rule' with source '{\"dynamic\":false,\"_all\":{\"enabled\":false}}'");
+ assertThat(esTester.client().preparePutMapping(FakeIndexDefinition.INDEX).setSource(mapDomain()).toString())
+ .isEqualTo("ES put mapping request on indices 'fakes' with source '{\"dynamic\":false,\"_all\":{\"enabled\":false}}'");
+ assertThat(esTester.client().preparePutMapping(FakeIndexDefinition.INDEX).setType(FakeIndexDefinition.TYPE).setSource(mapDomain()).toString())
+ .isEqualTo("ES put mapping request on indices 'fakes' on type 'fake' with source '{\"dynamic\":false,\"_all\":{\"enabled\":false}}'");
}
@Test
- public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
- try {
- PutMappingRequestBuilder requestBuilder = searchClient.preparePutMapping(IndexDefinition.RULE.getIndexName())
- .setType(IndexDefinition.RULE.getIndexType())
- .setIgnoreConflicts(true)
- .setSource(mapDomain());
- requestBuilder.get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES put mapping request");
- }
+ PutMappingRequestBuilder requestBuilder = esTester.client().preparePutMapping(FakeIndexDefinition.INDEX)
+ .setType(FakeIndexDefinition.TYPE)
+ .setIgnoreConflicts(true)
+ .setSource(mapDomain());
+ requestBuilder.get();
// TODO assert profiling
- searchClient.stop();
}
@Test
public void fail_on_bad_query() throws Exception {
try {
- searchClient.preparePutMapping().get();
+ esTester.client().preparePutMapping().get();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class);
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.preparePutMapping().get("1");
+ esTester.client().preparePutMapping().get("1");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.preparePutMapping().get(TimeValue.timeValueMinutes(1));
+ esTester.client().preparePutMapping().get(TimeValue.timeValueMinutes(1));
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
try {
- searchClient.preparePutMapping().execute();
+ esTester.client().preparePutMapping().execute();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.IndexDefinition;
-import org.sonar.server.search.SearchClient;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.es.FakeIndexDefinition;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxyRefreshRequestBuilderTest {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ @ClassRule
+ public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
}
@Test
public void refresh() {
- try {
- RefreshRequestBuilder requestBuilder = searchClient.prepareRefresh(IndexDefinition.RULE.getIndexName());
- requestBuilder.get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES refresh request on indices 'rules'");
- }
+ RefreshRequestBuilder requestBuilder = esTester.client().prepareRefresh(FakeIndexDefinition.INDEX);
+ requestBuilder.get();
}
@Test
public void to_string() {
- assertThat(searchClient.prepareRefresh(IndexDefinition.RULE.getIndexName()).toString()).isEqualTo("ES refresh request on indices 'rules'");
- assertThat(searchClient.prepareRefresh().toString()).isEqualTo("ES refresh request");
+ assertThat(esTester.client().prepareRefresh(FakeIndexDefinition.INDEX).toString()).isEqualTo("ES refresh request on indices 'fakes'");
+ assertThat(esTester.client().prepareRefresh().toString()).isEqualTo("ES refresh request");
}
@Test
- public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
- try {
- RefreshRequestBuilder requestBuilder = searchClient.prepareRefresh(IndexDefinition.RULE.getIndexName());
- requestBuilder.get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES refresh request on indices 'rules'");
- }
+ RefreshRequestBuilder requestBuilder = esTester.client().prepareRefresh(FakeIndexDefinition.INDEX);
+ requestBuilder.get();
// TODO assert profiling
- searchClient.stop();
}
@Test
public void fail_to_refresh() throws Exception {
try {
- searchClient.prepareRefresh("unknown").get();
+ esTester.client().prepareRefresh("unknown").get();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class);
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareRefresh(IndexDefinition.RULE.getIndexName()).get("1");
+ esTester.client().prepareRefresh(FakeIndexDefinition.INDEX).get("1");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareRefresh(IndexDefinition.RULE.getIndexName()).get(TimeValue.timeValueMinutes(1));
+ esTester.client().prepareRefresh(FakeIndexDefinition.INDEX).get(TimeValue.timeValueMinutes(1));
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
try {
- searchClient.prepareRefresh(IndexDefinition.RULE.getIndexName()).execute();
+ esTester.client().prepareRefresh(FakeIndexDefinition.INDEX).execute();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
package org.sonar.server.es.request;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.IndexDefinition;
-import org.sonar.server.search.SearchClient;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.es.FakeIndexDefinition;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxySearchRequestBuilderTest {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ @ClassRule
+ public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
}
@Test
public void search() {
- try {
- searchClient.prepareSearch(IndexDefinition.RULE.getIndexName()).get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES search request '{").contains("}' on indices '[rules]'");
- }
+ esTester.client().prepareSearch(FakeIndexDefinition.INDEX).get();
}
@Test
public void to_string() {
- assertThat(searchClient.prepareSearch(IndexDefinition.RULE.getIndexName()).setTypes("rule").toString()).contains("ES search request '").contains(
- "' on indices '[rules]' on types '[rule]'");
- assertThat(searchClient.prepareSearch(IndexDefinition.RULE.getIndexName()).toString()).contains("ES search request '").contains("' on indices '[rules]'");
- assertThat(searchClient.prepareSearch().toString()).contains("ES search request");
+ assertThat(esTester.client().prepareSearch(FakeIndexDefinition.INDEX).setTypes(FakeIndexDefinition.TYPE).toString()).contains("ES search request '").contains(
+ "' on indices '[fakes]' on types '[fake]'");
+ assertThat(esTester.client().prepareSearch(FakeIndexDefinition.INDEX).toString()).contains("ES search request '").contains("' on indices '[fakes]'");
+ assertThat(esTester.client().prepareSearch().toString()).contains("ES search request");
}
@Test
- public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
- try {
- searchClient.prepareSearch(IndexDefinition.RULE.getIndexName()).get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES search request '{").contains("}' on indices '[rules]'");
- }
+ esTester.client().prepareSearch(FakeIndexDefinition.INDEX).get();
// TODO assert profiling
- searchClient.stop();
}
@Test
public void fail_to_search_bad_query() throws Exception {
try {
- searchClient.prepareSearch(IndexDefinition.RULE.getIndexName()).setQuery("bad query").get();
+ esTester.client().prepareSearch(FakeIndexDefinition.INDEX).setQuery("bad query").get();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES search request '{").contains("}' on indices '[rules]'");
+ assertThat(e.getMessage()).contains("Fail to execute ES search request '{").contains("}' on indices '[fakes]'");
}
}
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareSearch(IndexDefinition.RULE.getIndexName()).get("1");
+ esTester.client().prepareSearch(FakeIndexDefinition.INDEX).get("1");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareSearch(IndexDefinition.RULE.getIndexName()).get(TimeValue.timeValueMinutes(1));
+ esTester.client().prepareSearch(FakeIndexDefinition.INDEX).get(TimeValue.timeValueMinutes(1));
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
try {
- searchClient.prepareSearch(IndexDefinition.RULE.getIndexName()).execute();
+ esTester.client().prepareSearch(FakeIndexDefinition.INDEX).execute();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
package org.sonar.server.es.request;
+import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.SearchClient;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.es.FakeIndexDefinition;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class ProxySearchScrollRequestBuilderTest {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
+ @ClassRule
+ public static EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
+ @Before
+ public void setUp() throws Exception {
+ esTester.setProfilingLevel(Profiling.Level.NONE);
}
@Test
public void search_scroll() {
- try {
- searchClient.prepareSearchScroll("scrollId").get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES search scroll request for scroll id 'null'");
- }
+ SearchResponse response = esTester.client().prepareSearch(FakeIndexDefinition.INDEX)
+ .setSearchType(SearchType.SCAN)
+ .setScroll(TimeValue.timeValueMinutes(1))
+ .get();
+ esTester.client().prepareSearchScroll(response.getScrollId()).get();
}
@Test
- public void with_profiling_basic() {
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
- try {
- searchClient.prepareSearchScroll("scrollId").get();
+ public void with_profiling_full() {
+ esTester.setProfilingLevel(Profiling.Level.FULL);
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES search scroll request for scroll id 'null'");
- }
- searchClient.stop();
+ SearchResponse response = esTester.client().prepareSearch(FakeIndexDefinition.INDEX)
+ .setSearchType(SearchType.SCAN)
+ .setScroll(TimeValue.timeValueMinutes(1))
+ .get();
+ esTester.client().prepareSearchScroll(response.getScrollId()).get();
+
+ // TODO assert profiling
}
@Test
public void fail_to_search_bad_query() throws Exception {
try {
- searchClient.prepareSearchScroll("unknown").get();
+ esTester.client().prepareSearchScroll("unknown").get();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class);
@Test
public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareSearchScroll("scrollId").get("1");
+ esTester.client().prepareSearchScroll("scrollId").get("1");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
try {
- searchClient.prepareSearchScroll("scrollId").get(TimeValue.timeValueMinutes(1));
+ esTester.client().prepareSearchScroll("scrollId").get(TimeValue.timeValueMinutes(1));
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@Test
public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
try {
- searchClient.prepareSearchScroll("scrollId").execute();
+ esTester.client().prepareSearchScroll("scrollId").execute();
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");