3 * Copyright (C) 2009-2017 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.es.request;
22 import org.elasticsearch.action.search.SearchResponse;
23 import org.elasticsearch.action.search.SearchType;
24 import org.elasticsearch.common.unit.TimeValue;
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.sonar.api.utils.log.LogTester;
28 import org.sonar.api.utils.log.LoggerLevel;
29 import org.sonar.server.es.EsTester;
30 import org.sonar.server.es.FakeIndexDefinition;
32 import static org.assertj.core.api.Assertions.assertThat;
33 import static org.junit.Assert.fail;
35 public class ProxySearchScrollRequestBuilderTest {
38 public EsTester esTester = new EsTester(new FakeIndexDefinition());
41 public LogTester logTester = new LogTester();
44 public void trace_logs() {
45 logTester.setLevel(LoggerLevel.TRACE);
47 SearchResponse response = esTester.client().prepareSearch(FakeIndexDefinition.INDEX)
48 .setSearchType(SearchType.SCAN)
49 .setScroll(TimeValue.timeValueMinutes(1))
52 esTester.client().prepareSearchScroll(response.getScrollId()).get();
53 assertThat(logTester.logs()).hasSize(1);
57 public void no_trace_logs() {
58 logTester.setLevel(LoggerLevel.DEBUG);
60 SearchResponse response = esTester.client().prepareSearch(FakeIndexDefinition.INDEX)
61 .setSearchType(SearchType.SCAN)
62 .setScroll(TimeValue.timeValueMinutes(1))
65 esTester.client().prepareSearchScroll(response.getScrollId()).get();
66 assertThat(logTester.logs()).isEmpty();
70 public void fail_to_search_bad_query() {
72 esTester.client().prepareSearchScroll("unknown").get();
74 } catch (Exception e) {
75 assertThat(e).isInstanceOf(IllegalStateException.class);
76 assertThat(e.getMessage()).contains("Fail to execute ES search scroll request for scroll id 'null'");
81 public void get_with_string_timeout_is_not_yet_implemented() {
83 esTester.client().prepareSearchScroll("scrollId").get("1");
85 } catch (Exception e) {
86 assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
91 public void get_with_time_value_timeout_is_not_yet_implemented() {
93 esTester.client().prepareSearchScroll("scrollId").get(TimeValue.timeValueMinutes(1));
95 } catch (Exception e) {
96 assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
101 public void execute_should_throw_an_unsupported_operation_exception() {
103 esTester.client().prepareSearchScroll("scrollId").execute();
105 } catch (Exception e) {
106 assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");