import org.sonar.core.profiling.Profiling;
import org.sonar.server.search.ClusterHealth;
import org.sonar.server.search.SearchClient;
-import org.sonar.server.search.request.ProxyBulkRequestBuilder;
-import org.sonar.server.search.request.ProxyClusterHealthRequestBuilder;
-import org.sonar.server.search.request.ProxyClusterStateRequestBuilder;
-import org.sonar.server.search.request.ProxyClusterStatsRequestBuilder;
-import org.sonar.server.search.request.ProxyCountRequestBuilder;
-import org.sonar.server.search.request.ProxyCreateIndexRequestBuilder;
-import org.sonar.server.search.request.ProxyDeleteByQueryRequestBuilder;
-import org.sonar.server.search.request.ProxyDeleteRequestBuilder;
-import org.sonar.server.search.request.ProxyFlushRequestBuilder;
-import org.sonar.server.search.request.ProxyGetRequestBuilder;
-import org.sonar.server.search.request.ProxyIndexRequestBuilder;
-import org.sonar.server.search.request.ProxyIndicesExistsRequestBuilder;
-import org.sonar.server.search.request.ProxyIndicesStatsRequestBuilder;
-import org.sonar.server.search.request.ProxyMultiGetRequestBuilder;
-import org.sonar.server.search.request.ProxyNodesStatsRequestBuilder;
-import org.sonar.server.search.request.ProxyPutMappingRequestBuilder;
-import org.sonar.server.search.request.ProxyRefreshRequestBuilder;
-import org.sonar.server.search.request.ProxySearchRequestBuilder;
-import org.sonar.server.search.request.ProxySearchScrollRequestBuilder;
+import org.sonar.server.es.request.ProxyBulkRequestBuilder;
+import org.sonar.server.es.request.ProxyClusterHealthRequestBuilder;
+import org.sonar.server.es.request.ProxyClusterStateRequestBuilder;
+import org.sonar.server.es.request.ProxyClusterStatsRequestBuilder;
+import org.sonar.server.es.request.ProxyCountRequestBuilder;
+import org.sonar.server.es.request.ProxyCreateIndexRequestBuilder;
+import org.sonar.server.es.request.ProxyDeleteByQueryRequestBuilder;
+import org.sonar.server.es.request.ProxyDeleteRequestBuilder;
+import org.sonar.server.es.request.ProxyFlushRequestBuilder;
+import org.sonar.server.es.request.ProxyGetRequestBuilder;
+import org.sonar.server.es.request.ProxyIndexRequestBuilder;
+import org.sonar.server.es.request.ProxyIndicesExistsRequestBuilder;
+import org.sonar.server.es.request.ProxyIndicesStatsRequestBuilder;
+import org.sonar.server.es.request.ProxyMultiGetRequestBuilder;
+import org.sonar.server.es.request.ProxyNodesStatsRequestBuilder;
+import org.sonar.server.es.request.ProxyPutMappingRequestBuilder;
+import org.sonar.server.es.request.ProxyRefreshRequestBuilder;
+import org.sonar.server.es.request.ProxySearchRequestBuilder;
+import org.sonar.server.es.request.ProxySearchScrollRequestBuilder;
/**
* Facade to connect to Elasticsearch node. Handles correctly errors (logging + exceptions
prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForStatus(status).get();
}
- public IndicesExistsRequestBuilder prepareExists(String... indices) {
+ public IndicesExistsRequestBuilder prepareIndicesExist(String... indices) {
return new ProxyIndicesExistsRequestBuilder(client, profiling, indices);
}
return new ProxyDeleteRequestBuilder(profiling, client, index).setType(type).setId(id);
}
+
public DeleteByQueryRequestBuilder prepareDeleteByQuery(String... indices) {
return new ProxyDeleteByQueryRequestBuilder(client, profiling).setIndices(indices);
}
public void start() {
// create indices that do not exist or that have a new definition (different mapping, cluster enabled, ...)
for (IndexRegistry.Index index : registry.getIndices().values()) {
- boolean exists = client.prepareExists(index.getName()).get().isExists();
+ boolean exists = client.prepareIndicesExist(index.getName()).get().isExists();
if (exists && needsToDeleteIndex(index)) {
LOGGER.info(String.format("Delete index %s (settings changed)", index.getName()));
deleteIndex(index.getName());
import java.util.Map;
import java.util.SortedMap;
+/**
+ * Hash of index definition is stored in the index itself in order to detect changes of mappings
+ * between SonarQube versions. In this case, contrary to database tables, indices are dropped
+ * and re-populated from scratch. There's no attempt to migrate existing data.
+ */
class IndexDefinitionHash {
private static final char DELIMITER = ',';
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.action.ActionRequest;
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.bulk.BulkRequestBuilder;
+import org.elasticsearch.action.bulk.BulkResponse;
+import org.elasticsearch.action.delete.DeleteRequest;
+import org.elasticsearch.action.index.IndexRequest;
+import org.elasticsearch.action.update.UpdateRequest;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyBulkRequestBuilder extends BulkRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxyBulkRequestBuilder(Client client, Profiling profiling) {
+ super(client);
+ this.profiling = profiling;
+ }
+
+ @Override
+ public BulkResponse get() {
+ StopWatch fullProfile = profiling.start("bulk", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public BulkResponse get(TimeValue timeout) {
+ throw unsupported();
+ }
+
+ @Override
+ public BulkResponse get(String timeout) {
+ // easy to implement if needed (copy get())
+ throw unsupported();
+ }
+
+ @Override
+ public ListenableActionFuture<BulkResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ private UnsupportedOperationException unsupported() {
+ throw new UnsupportedOperationException("See " + ProxyBulkRequestBuilder.class.getName());
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder();
+ message.append("Bulk[");
+ for (int i=0 ; i<request.requests().size() ; i++) {
+ ActionRequest item = request.requests().get(i);
+ if (item instanceof IndexRequest) {
+ IndexRequest request = (IndexRequest) item;
+ message.append(String.format("index id '%s' in %s/%s", request.id(), request.index(), request.type()));
+ } else if (item instanceof UpdateRequest) {
+ UpdateRequest request = (UpdateRequest) item;
+ message.append(String.format("update id '%s' in %s/%s", request.id(), request.index(), request.type()));
+ } else if (item instanceof DeleteRequest) {
+ DeleteRequest request = (DeleteRequest) item;
+ message.append(String.format("delete id '%s' from %s/%s", request.id(), request.index(), request.type()));
+ }
+ if (i < request.requests().size()-1) {
+ message.append(", ");
+ }
+ }
+ message.append("]");
+ return message.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.apache.commons.lang.StringUtils;
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder;
+import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyClusterHealthRequestBuilder extends ClusterHealthRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxyClusterHealthRequestBuilder(Client client, Profiling profiling) {
+ super(client.admin().cluster());
+ this.profiling = profiling;
+ }
+
+ @Override
+ public ClusterHealthResponse get() {
+ StopWatch fullProfile = profiling.start("cluster health", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public ClusterHealthResponse get(TimeValue timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ClusterHealthResponse get(String timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<ClusterHealthResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder();
+ message.append("ES cluster health request");
+ if (request.indices().length > 0) {
+ message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
+ }
+ return message.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.apache.commons.lang.StringUtils;
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder;
+import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyClusterStateRequestBuilder extends ClusterStateRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxyClusterStateRequestBuilder(Client client, Profiling profiling) {
+ super(client.admin().cluster());
+ this.profiling = profiling;
+ }
+
+ @Override
+ public ClusterStateResponse get() {
+ StopWatch fullProfile = profiling.start("cluster state", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public ClusterStateResponse get(TimeValue timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ClusterStateResponse get(String timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<ClusterStateResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder();
+ message.append("ES cluster state request");
+ if (request.indices().length > 0) {
+ message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
+ }
+ return message.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.apache.commons.lang.StringUtils;
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequestBuilder;
+import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyClusterStatsRequestBuilder extends ClusterStatsRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxyClusterStatsRequestBuilder(Client client, Profiling profiling) {
+ super(client.admin().cluster());
+ this.profiling = profiling;
+ }
+
+ @Override
+ public ClusterStatsResponse get() {
+ StopWatch fullProfile = profiling.start("cluster stats", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public ClusterStatsResponse get(TimeValue timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ClusterStatsResponse get(String timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<ClusterStatsResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder();
+ message.append("ES cluster stats request");
+ if (request.nodesIds().length > 0) {
+ message.append(String.format(" on nodes '%s'", StringUtils.join(request.nodesIds(), ",")));
+ }
+ return message.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.apache.commons.lang.StringUtils;
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.count.CountRequestBuilder;
+import org.elasticsearch.action.count.CountResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyCountRequestBuilder extends CountRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxyCountRequestBuilder(Client client, Profiling profiling) {
+ super(client);
+ this.profiling = profiling;
+ }
+
+ @Override
+ public CountResponse get() {
+ StopWatch fullProfile = profiling.start("count", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public CountResponse get(TimeValue timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public CountResponse get(String timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<CountResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder();
+ message.append("ES count request");
+ if (request.indices().length > 0) {
+ message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
+ }
+ if (request.types().length > 0) {
+ message.append(String.format(" on types '%s'", StringUtils.join(request.types(), ",")));
+ }
+ return message.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
+import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyCreateIndexRequestBuilder extends CreateIndexRequestBuilder {
+
+ private final Profiling profiling;
+ private final String index;
+
+ public ProxyCreateIndexRequestBuilder(Client client, Profiling profiling, String index) {
+ super(client.admin().indices(), index);
+ this.profiling = profiling;
+ this.index = index;
+ }
+
+ @Override
+ public CreateIndexResponse get() {
+ StopWatch fullProfile = profiling.start("create index", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public CreateIndexResponse get(TimeValue timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public CreateIndexResponse get(String timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<CreateIndexResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ return String.format("ES create index '%s'", index);
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.apache.commons.lang.StringUtils;
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.deletebyquery.DeleteByQueryRequestBuilder;
+import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyDeleteByQueryRequestBuilder extends DeleteByQueryRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxyDeleteByQueryRequestBuilder(Client client, Profiling profiling) {
+ super(client);
+ this.profiling = profiling;
+ }
+
+ @Override
+ public DeleteByQueryResponse get() {
+ StopWatch fullProfile = profiling.start("delete by query", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public DeleteByQueryResponse get(TimeValue timeout) {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public DeleteByQueryResponse get(String timeout) {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<DeleteByQueryResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder();
+ message.append("ES delete by query request");
+ if (request.indices().length > 0) {
+ message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
+ }
+ return message.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.es.request;
+
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.delete.DeleteRequestBuilder;
+import org.elasticsearch.action.delete.DeleteResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyDeleteRequestBuilder extends DeleteRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxyDeleteRequestBuilder(Profiling profiling, Client client, String index) {
+ super(client, index);
+ this.profiling = profiling;
+ }
+
+ @Override
+ public DeleteResponse get() {
+ StopWatch fullProfile = profiling.start("delete", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public DeleteResponse get(TimeValue timeout) {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public DeleteResponse get(String timeout) {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<DeleteResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder();
+ message
+ .append("ES delete request of doc ")
+ .append(request.id())
+ .append(" in index ")
+ .append(request.index())
+ .append("/")
+ .append(request.type());
+ return message.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.apache.commons.lang.StringUtils;
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.indices.flush.FlushRequestBuilder;
+import org.elasticsearch.action.admin.indices.flush.FlushResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyFlushRequestBuilder extends FlushRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxyFlushRequestBuilder(Client client, Profiling profiling) {
+ super(client.admin().indices());
+ this.profiling = profiling;
+ }
+
+ @Override
+ public FlushResponse get() {
+ StopWatch fullProfile = profiling.start("flush", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public FlushResponse get(TimeValue timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public FlushResponse get(String timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<FlushResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder();
+ message.append("ES flush request");
+ if (request.indices().length > 0) {
+ message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
+ }
+ return message.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.get.GetRequestBuilder;
+import org.elasticsearch.action.get.GetResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyGetRequestBuilder extends GetRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxyGetRequestBuilder(Client client, Profiling profiling) {
+ super(client);
+ this.profiling = profiling;
+ }
+
+ @Override
+ public GetResponse get() {
+ StopWatch fullProfile = profiling.start("get", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public GetResponse get(TimeValue timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public GetResponse get(String timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<GetResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder().append("ES get request");
+ message.append(String.format(" for key '%s'", request.id()));
+ message.append(String.format(" on index '%s'", request.index()));
+ message.append(String.format(" on type '%s'", request.type()));
+ return message.toString();
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.es.request;
+
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.index.IndexRequestBuilder;
+import org.elasticsearch.action.index.IndexResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyIndexRequestBuilder extends IndexRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxyIndexRequestBuilder(Client client, Profiling profiling) {
+ super(client);
+ this.profiling = profiling;
+ }
+
+ @Override
+ public IndexResponse get() {
+ StopWatch fullProfile = profiling.start("index", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.FULL)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public IndexResponse get(TimeValue timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public IndexResponse get(String timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<IndexResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder().append("ES index request");
+ message.append(String.format(" for key '%s'", request.id()));
+ message.append(String.format(" on index '%s'", request.index()));
+ message.append(String.format(" on type '%s'", request.type()));
+ return message.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.apache.commons.lang.StringUtils;
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder;
+import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyIndicesExistsRequestBuilder extends IndicesExistsRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxyIndicesExistsRequestBuilder(Client client, Profiling profiling, String... indices) {
+ super(client.admin().indices(), indices);
+ this.profiling = profiling;
+ }
+
+ @Override
+ public IndicesExistsResponse get() {
+ StopWatch fullProfile = profiling.start("indices exists", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public IndicesExistsResponse get(TimeValue timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public IndicesExistsResponse get(String timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<IndicesExistsResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder();
+ message.append("ES indices exists request");
+ if (request.indices().length > 0) {
+ message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
+ }
+ return message.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.apache.commons.lang.StringUtils;
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder;
+import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyIndicesStatsRequestBuilder extends IndicesStatsRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxyIndicesStatsRequestBuilder(Client client, Profiling profiling) {
+ super(client.admin().indices());
+ this.profiling = profiling;
+ }
+
+ @Override
+ public IndicesStatsResponse get() {
+ StopWatch fullProfile = profiling.start("indices stats", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public IndicesStatsResponse get(TimeValue timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public IndicesStatsResponse get(String timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<IndicesStatsResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder();
+ message.append("ES indices stats request");
+ if (request.indices().length > 0) {
+ message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
+ }
+ return message.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.get.MultiGetRequest;
+import org.elasticsearch.action.get.MultiGetRequestBuilder;
+import org.elasticsearch.action.get.MultiGetResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyMultiGetRequestBuilder extends MultiGetRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxyMultiGetRequestBuilder(Client client, Profiling profiling) {
+ super(client);
+ this.profiling = profiling;
+ }
+
+ @Override
+ public MultiGetResponse get() {
+ StopWatch fullProfile = profiling.start("get", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public MultiGetResponse get(TimeValue timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public MultiGetResponse get(String timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<MultiGetResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder();
+ message.append("ES multi get request");
+ for (MultiGetRequest.Item item : request) {
+ message.append(String.format(" [key '%s'", item.id()));
+ message.append(String.format(", index '%s'", item.index()));
+ String type = item.type();
+ if (type != null) {
+ message.append(String.format(", type '%s'", type));
+ }
+ message.append("],");
+ }
+ return message.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.apache.commons.lang.StringUtils;
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequestBuilder;
+import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyNodesStatsRequestBuilder extends NodesStatsRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxyNodesStatsRequestBuilder(Client client, Profiling profiling) {
+ super(client.admin().cluster());
+ this.profiling = profiling;
+ }
+
+ @Override
+ public NodesStatsResponse get() {
+ StopWatch fullProfile = profiling.start("nodes stats", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public NodesStatsResponse get(TimeValue timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public NodesStatsResponse get(String timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<NodesStatsResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder();
+ message.append("ES nodes stats request");
+ if (request.nodesIds().length > 0) {
+ message.append(String.format(" on nodes '%s'", StringUtils.join(request.nodesIds(), ",")));
+ }
+ return message.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.apache.commons.lang.StringUtils;
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder;
+import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyPutMappingRequestBuilder extends PutMappingRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxyPutMappingRequestBuilder(Client client, Profiling profiling) {
+ super(client.admin().indices());
+ this.profiling = profiling;
+ }
+
+ @Override
+ public PutMappingResponse get() {
+ StopWatch fullProfile = profiling.start("put mapping", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public PutMappingResponse get(TimeValue timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public PutMappingResponse get(String timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<PutMappingResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder();
+ message.append("ES put mapping request");
+ if (request.indices().length > 0) {
+ message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
+ }
+ String type = request.type();
+ if (type != null) {
+ message.append(String.format(" on type '%s'", type));
+ }
+ String source = request.source();
+ if (source != null) {
+ message.append(String.format(" with source '%s'", source));
+ }
+
+ return message.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.apache.commons.lang.StringUtils;
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder;
+import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxyRefreshRequestBuilder extends RefreshRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxyRefreshRequestBuilder(Client client, Profiling profiling) {
+ super(client.admin().indices());
+ this.profiling = profiling;
+ }
+
+ @Override
+ public RefreshResponse get() {
+ StopWatch fullProfile = profiling.start("refresh", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public RefreshResponse get(TimeValue timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public RefreshResponse get(String timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<RefreshResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder();
+ message.append("ES refresh request");
+ if (request.indices().length > 0) {
+ message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
+ }
+ return message.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.search.SearchRequestBuilder;
+import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.elasticsearch.common.xcontent.ToXContent;
+import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentFactory;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+public class ProxySearchRequestBuilder extends SearchRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxySearchRequestBuilder(Client client, Profiling profiling) {
+ super(client);
+ this.profiling = profiling;
+ }
+
+ @Override
+ public SearchResponse get() {
+ StopWatch fullProfile = profiling.start("search", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public SearchResponse get(TimeValue timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public SearchResponse get(String timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<SearchResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder message = new StringBuilder();
+ message.append(String.format("ES search request '%s'", xContentToString(super.internalBuilder())));
+ if (request.indices().length > 0) {
+ message.append(String.format(" on indices '%s'", Arrays.toString(request.indices())));
+ }
+ if (request.types().length > 0) {
+ message.append(String.format(" on types '%s'", Arrays.toString(request.types())));
+ }
+ return message.toString();
+ }
+
+ private String xContentToString(ToXContent toXContent) {
+ try {
+ XContentBuilder builder = XContentFactory.jsonBuilder();
+ toXContent.toXContent(builder, ToXContent.EMPTY_PARAMS);
+ return builder.string();
+ } catch (IOException e) {
+ throw new IllegalStateException("Fail to convert request to string", e);
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.action.search.SearchScrollRequestBuilder;
+import org.elasticsearch.client.Client;
+import org.elasticsearch.common.unit.TimeValue;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.core.profiling.StopWatch;
+
+public class ProxySearchScrollRequestBuilder extends SearchScrollRequestBuilder {
+
+ private final Profiling profiling;
+
+ public ProxySearchScrollRequestBuilder(String scrollId, Client client, Profiling profiling) {
+ super(client, scrollId);
+ this.profiling = profiling;
+ }
+
+ @Override
+ public SearchResponse get() {
+ StopWatch fullProfile = profiling.start("search scroll", Profiling.Level.FULL);
+ try {
+ return super.execute().actionGet();
+ } catch (Exception e) {
+ throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
+ } finally {
+ if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
+ fullProfile.stop("%s", toString());
+ }
+ }
+ }
+
+ @Override
+ public SearchResponse get(TimeValue timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public SearchResponse get(String timeout) {
+ throw new IllegalStateException("Not yet implemented");
+ }
+
+ @Override
+ public ListenableActionFuture<SearchResponse> execute() {
+ throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
+ }
+
+ @Override
+ public String toString() {
+ return String.format("ES search scroll request for scroll id '%s'", super.request().scroll());
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.server.es.request;
+
+import javax.annotation.ParametersAreNonnullByDefault;
protected void initializeIndex() {
String index = this.getIndexName();
- IndicesExistsResponse indexExistsResponse = client.prepareExists(index).get();
+ IndicesExistsResponse indexExistsResponse = client.prepareIndicesExist(index).get();
try {
if (!indexExistsResponse.isExists()) {
package org.sonar.server.search;
-import org.sonar.server.search.request.ProxyIndexRequestBuilder;
-
import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequestBuilder;
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder;
import org.sonar.core.profiling.Profiling;
import org.sonar.process.LoopbackAddress;
import org.sonar.process.ProcessConstants;
-import org.sonar.server.search.request.ProxyBulkRequestBuilder;
-import org.sonar.server.search.request.ProxyClusterHealthRequestBuilder;
-import org.sonar.server.search.request.ProxyClusterStateRequestBuilder;
-import org.sonar.server.search.request.ProxyClusterStatsRequestBuilder;
-import org.sonar.server.search.request.ProxyCountRequestBuilder;
-import org.sonar.server.search.request.ProxyCreateIndexRequestBuilder;
-import org.sonar.server.search.request.ProxyDeleteByQueryRequestBuilder;
-import org.sonar.server.search.request.ProxyDeleteRequestBuilder;
-import org.sonar.server.search.request.ProxyFlushRequestBuilder;
-import org.sonar.server.search.request.ProxyGetRequestBuilder;
-import org.sonar.server.search.request.ProxyIndicesExistsRequestBuilder;
-import org.sonar.server.search.request.ProxyIndicesStatsRequestBuilder;
-import org.sonar.server.search.request.ProxyMultiGetRequestBuilder;
-import org.sonar.server.search.request.ProxyNodesStatsRequestBuilder;
-import org.sonar.server.search.request.ProxyPutMappingRequestBuilder;
-import org.sonar.server.search.request.ProxyRefreshRequestBuilder;
-import org.sonar.server.search.request.ProxySearchRequestBuilder;
-import org.sonar.server.search.request.ProxySearchScrollRequestBuilder;
+import org.sonar.server.es.request.ProxyBulkRequestBuilder;
+import org.sonar.server.es.request.ProxyClusterStateRequestBuilder;
+import org.sonar.server.es.request.ProxyClusterStatsRequestBuilder;
+import org.sonar.server.es.request.ProxyCountRequestBuilder;
+import org.sonar.server.es.request.ProxyCreateIndexRequestBuilder;
+import org.sonar.server.es.request.ProxyDeleteByQueryRequestBuilder;
+import org.sonar.server.es.request.ProxyDeleteRequestBuilder;
+import org.sonar.server.es.request.ProxyFlushRequestBuilder;
+import org.sonar.server.es.request.ProxyGetRequestBuilder;
+import org.sonar.server.es.request.ProxyIndicesExistsRequestBuilder;
+import org.sonar.server.es.request.ProxyIndicesStatsRequestBuilder;
+import org.sonar.server.es.request.ProxyMultiGetRequestBuilder;
+import org.sonar.server.es.request.ProxyNodesStatsRequestBuilder;
+import org.sonar.server.es.request.ProxyPutMappingRequestBuilder;
+import org.sonar.server.es.request.ProxyRefreshRequestBuilder;
+import org.sonar.server.es.request.ProxySearchRequestBuilder;
+import org.sonar.server.es.request.ProxySearchScrollRequestBuilder;
/**
* ElasticSearch Node used to connect to index.
return new ProxyClusterStateRequestBuilder(this, profiling);
}
- public ClusterHealthRequestBuilder prepareHealth(String... indices) {
- return new ProxyClusterHealthRequestBuilder(this, profiling).setIndices(indices);
- }
-
- public IndicesExistsRequestBuilder prepareExists(String... indices) {
+ public IndicesExistsRequestBuilder prepareIndicesExist(String... indices) {
return new ProxyIndicesExistsRequestBuilder(this, profiling, indices);
}
return new ProxyGetRequestBuilder(this, profiling);
}
- @Override
- public GetRequestBuilder prepareGet(String index, String type, String id) {
- return new ProxyGetRequestBuilder(this, profiling).setIndex(index).setType(type).setId(id);
- }
-
@Override
public MultiGetRequestBuilder prepareMultiGet() {
return new ProxyMultiGetRequestBuilder(this, profiling);
return new ProxyDeleteByQueryRequestBuilder(this, profiling).setIndices(indices);
}
+ // ****************************************************************************************************************
+ // Not yet implemented methods
+ // ****************************************************************************************************************
+
+ @Override
+ public GetRequestBuilder prepareGet(String index, String type, String id) {
+ throw throwNotYetImplemented();
+ }
+
@Override
public IndexRequestBuilder prepareIndex() {
- return new ProxyIndexRequestBuilder(this, profiling);
+ throw throwNotYetImplemented();
}
@Override
public IndexRequestBuilder prepareIndex(String index, String type) {
- return new ProxyIndexRequestBuilder(this, profiling).setIndex(index).setType(type);
+ throw throwNotYetImplemented();
}
@Override
public IndexRequestBuilder prepareIndex(String index, String type, @Nullable String id) {
- return new ProxyIndexRequestBuilder(this, profiling).setIndex(index).setType(type).setId(id);
+ throw throwNotYetImplemented();
}
- // ****************************************************************************************************************
- // Not yet implemented methods
- // ****************************************************************************************************************
-
@Override
public MultiSearchRequestBuilder prepareMultiSearch() {
throw throwNotYetImplemented();
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.ActionRequest;
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.bulk.BulkRequestBuilder;
-import org.elasticsearch.action.bulk.BulkResponse;
-import org.elasticsearch.action.delete.DeleteRequest;
-import org.elasticsearch.action.index.IndexRequest;
-import org.elasticsearch.action.update.UpdateRequest;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyBulkRequestBuilder extends BulkRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxyBulkRequestBuilder(Client client, Profiling profiling) {
- super(client);
- this.profiling = profiling;
- }
-
- @Override
- public BulkResponse get() {
- StopWatch fullProfile = profiling.start("bulk", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public BulkResponse get(TimeValue timeout) {
- throw unsupported();
- }
-
- @Override
- public BulkResponse get(String timeout) {
- // easy to implement if needed (copy get())
- throw unsupported();
- }
-
- @Override
- public ListenableActionFuture<BulkResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- private UnsupportedOperationException unsupported() {
- throw new UnsupportedOperationException("See " + ProxyBulkRequestBuilder.class.getName());
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder();
- message.append("ES bulk request for ");
- for (ActionRequest item : request.requests()) {
- message.append(String.format("[Action '%s' ", item.getClass().getSimpleName()));
- if (item instanceof IndexRequest) {
- IndexRequest request = (IndexRequest) item;
- message.append(String.format("for key '%s'", request.id()));
- message.append(String.format(" on index '%s'", request.index()));
- message.append(String.format(" on type '%s'", request.type()));
- } else if (item instanceof UpdateRequest) {
- UpdateRequest request = (UpdateRequest) item;
- message.append(String.format("for key '%s'", request.id()));
- message.append(String.format(" on index '%s'", request.index()));
- message.append(String.format(" on type '%s'", request.type()));
- } else if (item instanceof DeleteRequest) {
- DeleteRequest request = (DeleteRequest) item;
- message.append(String.format("for key '%s'", request.id()));
- message.append(String.format(" on index '%s'", request.index()));
- message.append(String.format(" on type '%s'", request.type()));
- }
- message.append("],");
- }
- return message.toString();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder;
-import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyClusterHealthRequestBuilder extends ClusterHealthRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxyClusterHealthRequestBuilder(Client client, Profiling profiling) {
- super(client.admin().cluster());
- this.profiling = profiling;
- }
-
- @Override
- public ClusterHealthResponse get() {
- StopWatch fullProfile = profiling.start("cluster health", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public ClusterHealthResponse get(TimeValue timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ClusterHealthResponse get(String timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<ClusterHealthResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder();
- message.append("ES cluster health request");
- if (request.indices().length > 0) {
- message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
- }
- return message.toString();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder;
-import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyClusterStateRequestBuilder extends ClusterStateRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxyClusterStateRequestBuilder(Client client, Profiling profiling) {
- super(client.admin().cluster());
- this.profiling = profiling;
- }
-
- @Override
- public ClusterStateResponse get() {
- StopWatch fullProfile = profiling.start("cluster state", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public ClusterStateResponse get(TimeValue timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ClusterStateResponse get(String timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<ClusterStateResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder();
- message.append("ES cluster state request");
- if (request.indices().length > 0) {
- message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
- }
- return message.toString();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequestBuilder;
-import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyClusterStatsRequestBuilder extends ClusterStatsRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxyClusterStatsRequestBuilder(Client client, Profiling profiling) {
- super(client.admin().cluster());
- this.profiling = profiling;
- }
-
- @Override
- public ClusterStatsResponse get() {
- StopWatch fullProfile = profiling.start("cluster stats", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public ClusterStatsResponse get(TimeValue timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ClusterStatsResponse get(String timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<ClusterStatsResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder();
- message.append("ES cluster stats request");
- if (request.nodesIds().length > 0) {
- message.append(String.format(" on nodes '%s'", StringUtils.join(request.nodesIds(), ",")));
- }
- return message.toString();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.count.CountRequestBuilder;
-import org.elasticsearch.action.count.CountResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyCountRequestBuilder extends CountRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxyCountRequestBuilder(Client client, Profiling profiling) {
- super(client);
- this.profiling = profiling;
- }
-
- @Override
- public CountResponse get() {
- StopWatch fullProfile = profiling.start("count", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public CountResponse get(TimeValue timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public CountResponse get(String timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<CountResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder();
- message.append("ES count request");
- if (request.indices().length > 0) {
- message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
- }
- if (request.types().length > 0) {
- message.append(String.format(" on types '%s'", StringUtils.join(request.types(), ",")));
- }
- return message.toString();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
-import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyCreateIndexRequestBuilder extends CreateIndexRequestBuilder {
-
- private final Profiling profiling;
- private final String index;
-
- public ProxyCreateIndexRequestBuilder(Client client, Profiling profiling, String index) {
- super(client.admin().indices(), index);
- this.profiling = profiling;
- this.index = index;
- }
-
- @Override
- public CreateIndexResponse get() {
- StopWatch fullProfile = profiling.start("create index", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public CreateIndexResponse get(TimeValue timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public CreateIndexResponse get(String timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<CreateIndexResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- return String.format("ES create index '%s'", index);
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.deletebyquery.DeleteByQueryRequestBuilder;
-import org.elasticsearch.action.deletebyquery.DeleteByQueryResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyDeleteByQueryRequestBuilder extends DeleteByQueryRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxyDeleteByQueryRequestBuilder(Client client, Profiling profiling) {
- super(client);
- this.profiling = profiling;
- }
-
- @Override
- public DeleteByQueryResponse get() {
- StopWatch fullProfile = profiling.start("delete by query", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public DeleteByQueryResponse get(TimeValue timeout) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- @Override
- public DeleteByQueryResponse get(String timeout) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<DeleteByQueryResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder();
- message.append("ES delete by query request");
- if (request.indices().length > 0) {
- message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
- }
- return message.toString();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.delete.DeleteRequestBuilder;
-import org.elasticsearch.action.delete.DeleteResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyDeleteRequestBuilder extends DeleteRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxyDeleteRequestBuilder(Profiling profiling, Client client, String index) {
- super(client, index);
- this.profiling = profiling;
- }
-
- @Override
- public DeleteResponse get() {
- StopWatch fullProfile = profiling.start("delete", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public DeleteResponse get(TimeValue timeout) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- @Override
- public DeleteResponse get(String timeout) {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<DeleteResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder();
- message
- .append("ES delete request of doc ")
- .append(request.id())
- .append(" in index ")
- .append(request.index())
- .append("/")
- .append(request.type());
- return message.toString();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.admin.indices.flush.FlushRequestBuilder;
-import org.elasticsearch.action.admin.indices.flush.FlushResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyFlushRequestBuilder extends FlushRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxyFlushRequestBuilder(Client client, Profiling profiling) {
- super(client.admin().indices());
- this.profiling = profiling;
- }
-
- @Override
- public FlushResponse get() {
- StopWatch fullProfile = profiling.start("flush", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public FlushResponse get(TimeValue timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public FlushResponse get(String timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<FlushResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder();
- message.append("ES flush request");
- if (request.indices().length > 0) {
- message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
- }
- return message.toString();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.get.GetRequestBuilder;
-import org.elasticsearch.action.get.GetResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyGetRequestBuilder extends GetRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxyGetRequestBuilder(Client client, Profiling profiling) {
- super(client);
- this.profiling = profiling;
- }
-
- @Override
- public GetResponse get() {
- StopWatch fullProfile = profiling.start("get", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public GetResponse get(TimeValue timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public GetResponse get(String timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<GetResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder().append("ES get request");
- message.append(String.format(" for key '%s'", request.id()));
- message.append(String.format(" on index '%s'", request.index()));
- message.append(String.format(" on type '%s'", request.type()));
- return message.toString();
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.index.IndexRequestBuilder;
-import org.elasticsearch.action.index.IndexResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyIndexRequestBuilder extends IndexRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxyIndexRequestBuilder(Client client, Profiling profiling) {
- super(client);
- this.profiling = profiling;
- }
-
- @Override
- public IndexResponse get() {
- StopWatch fullProfile = profiling.start("index", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.FULL)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public IndexResponse get(TimeValue timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public IndexResponse get(String timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<IndexResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder().append("ES index request");
- message.append(String.format(" for key '%s'", request.id()));
- message.append(String.format(" on index '%s'", request.index()));
- message.append(String.format(" on type '%s'", request.type()));
- return message.toString();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder;
-import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyIndicesExistsRequestBuilder extends IndicesExistsRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxyIndicesExistsRequestBuilder(Client client, Profiling profiling, String... indices) {
- super(client.admin().indices(), indices);
- this.profiling = profiling;
- }
-
- @Override
- public IndicesExistsResponse get() {
- StopWatch fullProfile = profiling.start("indices exists", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public IndicesExistsResponse get(TimeValue timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public IndicesExistsResponse get(String timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<IndicesExistsResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder();
- message.append("ES indices exists request");
- if (request.indices().length > 0) {
- message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
- }
- return message.toString();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder;
-import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyIndicesStatsRequestBuilder extends IndicesStatsRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxyIndicesStatsRequestBuilder(Client client, Profiling profiling) {
- super(client.admin().indices());
- this.profiling = profiling;
- }
-
- @Override
- public IndicesStatsResponse get() {
- StopWatch fullProfile = profiling.start("indices stats", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public IndicesStatsResponse get(TimeValue timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public IndicesStatsResponse get(String timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<IndicesStatsResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder();
- message.append("ES indices stats request");
- if (request.indices().length > 0) {
- message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
- }
- return message.toString();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.get.MultiGetRequest;
-import org.elasticsearch.action.get.MultiGetRequestBuilder;
-import org.elasticsearch.action.get.MultiGetResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyMultiGetRequestBuilder extends MultiGetRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxyMultiGetRequestBuilder(Client client, Profiling profiling) {
- super(client);
- this.profiling = profiling;
- }
-
- @Override
- public MultiGetResponse get() {
- StopWatch fullProfile = profiling.start("get", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public MultiGetResponse get(TimeValue timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public MultiGetResponse get(String timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<MultiGetResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder();
- message.append("ES multi get request");
- for (MultiGetRequest.Item item : request) {
- message.append(String.format(" [key '%s'", item.id()));
- message.append(String.format(", index '%s'", item.index()));
- String type = item.type();
- if (type != null) {
- message.append(String.format(", type '%s'", type));
- }
- message.append("],");
- }
- return message.toString();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequestBuilder;
-import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyNodesStatsRequestBuilder extends NodesStatsRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxyNodesStatsRequestBuilder(Client client, Profiling profiling) {
- super(client.admin().cluster());
- this.profiling = profiling;
- }
-
- @Override
- public NodesStatsResponse get() {
- StopWatch fullProfile = profiling.start("nodes stats", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public NodesStatsResponse get(TimeValue timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public NodesStatsResponse get(String timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<NodesStatsResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder();
- message.append("ES nodes stats request");
- if (request.nodesIds().length > 0) {
- message.append(String.format(" on nodes '%s'", StringUtils.join(request.nodesIds(), ",")));
- }
- return message.toString();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder;
-import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyPutMappingRequestBuilder extends PutMappingRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxyPutMappingRequestBuilder(Client client, Profiling profiling) {
- super(client.admin().indices());
- this.profiling = profiling;
- }
-
- @Override
- public PutMappingResponse get() {
- StopWatch fullProfile = profiling.start("put mapping", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public PutMappingResponse get(TimeValue timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public PutMappingResponse get(String timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<PutMappingResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder();
- message.append("ES put mapping request");
- if (request.indices().length > 0) {
- message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
- }
- String type = request.type();
- if (type != null) {
- message.append(String.format(" on type '%s'", type));
- }
- String source = request.source();
- if (source != null) {
- message.append(String.format(" with source '%s'", source));
- }
-
- return message.toString();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.apache.commons.lang.StringUtils;
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder;
-import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxyRefreshRequestBuilder extends RefreshRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxyRefreshRequestBuilder(Client client, Profiling profiling) {
- super(client.admin().indices());
- this.profiling = profiling;
- }
-
- @Override
- public RefreshResponse get() {
- StopWatch fullProfile = profiling.start("refresh", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public RefreshResponse get(TimeValue timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public RefreshResponse get(String timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<RefreshResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder();
- message.append("ES refresh request");
- if (request.indices().length > 0) {
- message.append(String.format(" on indices '%s'", StringUtils.join(request.indices(), ",")));
- }
- return message.toString();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.search.SearchRequestBuilder;
-import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.elasticsearch.common.xcontent.ToXContent;
-import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentFactory;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-import java.io.IOException;
-import java.util.Arrays;
-
-public class ProxySearchRequestBuilder extends SearchRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxySearchRequestBuilder(Client client, Profiling profiling) {
- super(client);
- this.profiling = profiling;
- }
-
- @Override
- public SearchResponse get() {
- StopWatch fullProfile = profiling.start("search", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public SearchResponse get(TimeValue timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public SearchResponse get(String timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<SearchResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- StringBuilder message = new StringBuilder();
- message.append(String.format("ES search request '%s'", xContentToString(super.internalBuilder())));
- if (request.indices().length > 0) {
- message.append(String.format(" on indices '%s'", Arrays.toString(request.indices())));
- }
- if (request.types().length > 0) {
- message.append(String.format(" on types '%s'", Arrays.toString(request.types())));
- }
- return message.toString();
- }
-
- private String xContentToString(ToXContent toXContent) {
- try {
- XContentBuilder builder = XContentFactory.jsonBuilder();
- toXContent.toXContent(builder, ToXContent.EMPTY_PARAMS);
- return builder.string();
- } catch (IOException e) {
- throw new IllegalStateException("Fail to convert request to string", e);
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.action.search.SearchScrollRequestBuilder;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.common.unit.TimeValue;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.core.profiling.StopWatch;
-
-public class ProxySearchScrollRequestBuilder extends SearchScrollRequestBuilder {
-
- private final Profiling profiling;
-
- public ProxySearchScrollRequestBuilder(String scrollId, Client client, Profiling profiling) {
- super(client, scrollId);
- this.profiling = profiling;
- }
-
- @Override
- public SearchResponse get() {
- StopWatch fullProfile = profiling.start("search scroll", Profiling.Level.FULL);
- try {
- return super.execute().actionGet();
- } catch (Exception e) {
- throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
- } finally {
- if (profiling.isProfilingEnabled(Profiling.Level.BASIC)) {
- fullProfile.stop("%s", toString());
- }
- }
- }
-
- @Override
- public SearchResponse get(TimeValue timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public SearchResponse get(String timeout) {
- throw new IllegalStateException("Not yet implemented");
- }
-
- @Override
- public ListenableActionFuture<SearchResponse> execute() {
- throw new UnsupportedOperationException("execute() should not be called as it's used for asynchronous");
- }
-
- @Override
- public String toString() {
- return String.format("ES search scroll request for scroll id '%s'", super.request().scroll());
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-@ParametersAreNonnullByDefault
-package org.sonar.server.search.request;
-
-import javax.annotation.ParametersAreNonnullByDefault;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.server.search.request.ProxyBulkRequestBuilder;
-import org.sonar.server.search.request.ProxyClusterHealthRequestBuilder;
-import org.sonar.server.search.request.ProxyClusterStateRequestBuilder;
-import org.sonar.server.search.request.ProxyClusterStatsRequestBuilder;
-import org.sonar.server.search.request.ProxyCountRequestBuilder;
-import org.sonar.server.search.request.ProxyCreateIndexRequestBuilder;
-import org.sonar.server.search.request.ProxyDeleteByQueryRequestBuilder;
-import org.sonar.server.search.request.ProxyDeleteRequestBuilder;
-import org.sonar.server.search.request.ProxyFlushRequestBuilder;
-import org.sonar.server.search.request.ProxyGetRequestBuilder;
-import org.sonar.server.search.request.ProxyIndicesExistsRequestBuilder;
-import org.sonar.server.search.request.ProxyIndicesStatsRequestBuilder;
-import org.sonar.server.search.request.ProxyMultiGetRequestBuilder;
-import org.sonar.server.search.request.ProxyNodesStatsRequestBuilder;
-import org.sonar.server.search.request.ProxyPutMappingRequestBuilder;
-import org.sonar.server.search.request.ProxyRefreshRequestBuilder;
-import org.sonar.server.search.request.ProxySearchRequestBuilder;
-import org.sonar.server.search.request.ProxySearchScrollRequestBuilder;
+import org.sonar.server.es.request.ProxyBulkRequestBuilder;
+import org.sonar.server.es.request.ProxyClusterHealthRequestBuilder;
+import org.sonar.server.es.request.ProxyClusterStateRequestBuilder;
+import org.sonar.server.es.request.ProxyClusterStatsRequestBuilder;
+import org.sonar.server.es.request.ProxyCountRequestBuilder;
+import org.sonar.server.es.request.ProxyCreateIndexRequestBuilder;
+import org.sonar.server.es.request.ProxyDeleteByQueryRequestBuilder;
+import org.sonar.server.es.request.ProxyDeleteRequestBuilder;
+import org.sonar.server.es.request.ProxyFlushRequestBuilder;
+import org.sonar.server.es.request.ProxyGetRequestBuilder;
+import org.sonar.server.es.request.ProxyIndicesExistsRequestBuilder;
+import org.sonar.server.es.request.ProxyIndicesStatsRequestBuilder;
+import org.sonar.server.es.request.ProxyMultiGetRequestBuilder;
+import org.sonar.server.es.request.ProxyNodesStatsRequestBuilder;
+import org.sonar.server.es.request.ProxyPutMappingRequestBuilder;
+import org.sonar.server.es.request.ProxyRefreshRequestBuilder;
+import org.sonar.server.es.request.ProxySearchRequestBuilder;
+import org.sonar.server.es.request.ProxySearchScrollRequestBuilder;
import static org.fest.assertions.Assertions.assertThat;
assertThat(client.prepareCreate("fakes")).isInstanceOf(ProxyCreateIndexRequestBuilder.class);
assertThat(client.prepareDeleteByQuery()).isInstanceOf(ProxyDeleteByQueryRequestBuilder.class);
assertThat(client.prepareDelete("fakes", "fake", "my_id")).isInstanceOf(ProxyDeleteRequestBuilder.class);
- assertThat(client.prepareExists()).isInstanceOf(ProxyIndicesExistsRequestBuilder.class);
+ assertThat(client.prepareIndicesExist()).isInstanceOf(ProxyIndicesExistsRequestBuilder.class);
assertThat(client.prepareFlush()).isInstanceOf(ProxyFlushRequestBuilder.class);
assertThat(client.prepareGet()).isInstanceOf(ProxyGetRequestBuilder.class);
assertThat(client.prepareGet("fakes", "fake", "1")).isInstanceOf(ProxyGetRequestBuilder.class);
private Node node;
private EsClient client;
private final List<IndexDefinition> definitions = Lists.newArrayList();
+ private Settings settings = new Settings();
public EsTester addDefinitions(IndexDefinition... defs) {
Collections.addAll(definitions, defs);
DeleteIndexResponse response = node.client().admin().indices().prepareDelete("_all").get();
assertThat(response.isAcknowledged()).isTrue();
- client = new EsClient(new Profiling(new Settings()), node.client());
+ client = new EsClient(new Profiling(settings), node.client());
client.start();
if (!definitions.isEmpty()) {
node.stop();
node.close();
}
+ settings = null;
+ }
+
+ /**
+ * Default level is NONE.
+ */
+ public EsTester setProfilingLevel(Profiling.Level level) {
+ settings.setProperty(Profiling.CONFIG_PROFILING_LEVEL, level.name());
+ return this;
}
public void truncateIndices() {
*/
package org.sonar.server.es;
+import com.google.common.collect.ImmutableMap;
import org.elasticsearch.cluster.metadata.IndexMetaData;
+import java.util.Map;
+
public class FakeIndexDefinition implements IndexDefinition {
public static final String INDEX = "fakes";
NewIndex.NewIndexType type = index.createType(TYPE);
type.createIntegerField(INT_FIELD);
}
+
+ public static Map<String,Object> newDoc(int value) {
+ return ImmutableMap.<String,Object>of(INT_FIELD, value);
+ }
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.action.bulk.BulkRequestBuilder;
+import org.elasticsearch.action.bulk.BulkResponse;
+import org.elasticsearch.action.delete.DeleteRequest;
+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.Test;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.es.FakeIndexDefinition;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class ProxyBulkRequestBuilderTest {
+
+ @Rule
+ public EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+
+ @Test
+ public void bulk() {
+ testBulk(Profiling.Level.NONE);
+ }
+
+ @Test
+ public void with_profiling_basic() {
+ testBulk(Profiling.Level.BASIC);
+ // TODO assert profiling
+ }
+
+ private void testBulk(Profiling.Level profilingLevel) {
+ esTester.setProfilingLevel(profilingLevel);
+
+ BulkRequestBuilder req = esTester.client().prepareBulk();
+ req.add(new UpdateRequest(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE, "key1")
+ .doc(FakeIndexDefinition.newDoc(1)));
+ req.add(new DeleteRequest(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE, "key2"));
+ req.add(new IndexRequest(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE, "key3")
+ .source(FakeIndexDefinition.newDoc(3)));
+
+ BulkResponse response = req.get();
+ assertThat(response.getItems()).hasSize(3);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ esTester.client().prepareBulk().get("1");
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
+ esTester.client().prepareBulk().get(TimeValue.timeValueMinutes(1));
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void execute_is_not_yet_implemented() throws Exception {
+ esTester.client().prepareBulk().execute();
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder;
+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.Test;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.server.es.EsTester;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
+
+public class ProxyClusterHealthRequestBuilderTest {
+
+ @Rule
+ public EsTester esTester = new EsTester();
+
+ @Test
+ public void state() {
+ ClusterHealthRequestBuilder requestBuilder = esTester.client().prepareHealth();
+ ClusterHealthResponse state = requestBuilder.get();
+ assertThat(state.getStatus()).isEqualTo(ClusterHealthStatus.GREEN);
+ }
+
+ @Test
+ public void to_string() {
+ assertThat(esTester.client().prepareHealth("rules").toString()).isEqualTo("ES cluster health request on indices 'rules'");
+ assertThat(esTester.client().prepareHealth().toString()).isEqualTo("ES cluster health request");
+ }
+
+ @Test
+ public void with_profiling_basic() {
+ esTester.setProfilingLevel(Profiling.Level.BASIC);
+
+ ClusterHealthRequestBuilder requestBuilder = esTester.client().prepareHealth();
+ ClusterHealthResponse state = requestBuilder.get();
+ assertThat(state.getStatus()).isEqualTo(ClusterHealthStatus.GREEN);
+
+ // TODO assert profiling
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ esTester.client().prepareHealth().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 {
+ esTester.client().prepareHealth().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 {
+ esTester.client().prepareHealth().execute();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder;
+import org.elasticsearch.common.unit.TimeValue;
+import org.junit.After;
+import org.junit.Test;
+import org.sonar.api.config.Settings;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.server.search.SearchClient;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.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);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @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");
+ }
+ }
+
+ @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");
+ }
+
+ @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();
+
+ // 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");
+ }
+
+ // TODO assert profiling
+ searchClient.stop();
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ searchClient.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));
+ 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequestBuilder;
+import org.elasticsearch.common.unit.TimeValue;
+import org.junit.After;
+import org.junit.Test;
+import org.sonar.api.config.Settings;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.server.search.SearchClient;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.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);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @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");
+ }
+ }
+
+ @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");
+ }
+
+ @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 {
+ 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");
+ }
+
+ // TODO assert profiling
+ searchClient.stop();
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ searchClient.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));
+ 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.common.unit.TimeValue;
+import org.junit.After;
+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 static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.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);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @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'");
+ }
+ }
+
+ @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");
+ }
+
+ @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.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'");
+ }
+
+ // 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class);
+ assertThat(e.getMessage()).contains("Fail to execute ES count request on indices 'unknown_index1, unknown_index2' on types 'unknown_type'");
+ }
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ searchClient.prepareCount(IndexDefinition.RULE.getIndexName()).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));
+ 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
+import org.elasticsearch.common.unit.TimeValue;
+import org.junit.After;
+import org.junit.Test;
+import org.sonar.api.config.Settings;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.server.search.SearchClient;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.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);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @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'");
+ }
+ }
+
+ @Test
+ public void to_string() {
+ assertThat(searchClient.prepareCreate("new").toString()).isEqualTo("ES create index 'new'");
+ }
+
+ @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();
+
+ // 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'");
+ }
+
+ // TODO assert profiling
+ searchClient.stop();
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ searchClient.prepareCreate("new").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));
+ 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.common.unit.TimeValue;
+import org.elasticsearch.index.query.QueryBuilders;
+import org.junit.After;
+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 static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.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);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @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'");
+ }
+ }
+
+ @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");
+ }
+
+ @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.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'");
+ }
+
+ // TODO assert profiling
+ searchClient.stop();
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ searchClient.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));
+ 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.es.request;
+
+import org.elasticsearch.common.unit.TimeValue;
+import org.junit.After;
+import org.junit.Test;
+import org.sonar.api.config.Settings;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.server.search.SearchClient;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.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);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @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");
+ }
+ }
+
+ @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");
+ }
+
+ @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");
+ }
+
+ // 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");
+ 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));
+ 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();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ assertThat(e).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.common.unit.TimeValue;
+import org.junit.After;
+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 static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.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);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @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'");
+ }
+ }
+
+ @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");
+ }
+
+ @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.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'");
+ }
+
+ // TODO assert profiling
+ searchClient.stop();
+ }
+
+ @Test
+ public void fail_to_refresh() throws Exception {
+ try {
+ searchClient.prepareFlush("unknown").get();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class);
+ assertThat(e.getMessage()).contains("Fail to execute ES flush request on indices 'unknown'");
+ }
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ searchClient.prepareFlush(IndexDefinition.RULE.getIndexName()).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));
+ 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.action.get.GetRequestBuilder;
+import org.elasticsearch.common.unit.TimeValue;
+import org.junit.After;
+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 static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.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);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @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'");
+ }
+ }
+
+ @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.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'");
+ }
+
+ // TODO assert profiling
+ searchClient.stop();
+ }
+
+ @Test
+ public void fail_to_get_bad_query() throws Exception {
+ GetRequestBuilder requestBuilder = searchClient.prepareGet()
+ .setIndex("unknown")
+ .setType("test")
+ .setId("rule1");
+ try {
+ requestBuilder.get();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class);
+ assertThat(e.getMessage()).contains("Fail to execute ES get request for key 'rule1' on index 'unknown' on type 'test'");
+ }
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ searchClient.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));
+ 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+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.Test;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.server.es.EsTester;
+import org.sonar.server.es.FakeIndexDefinition;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
+
+public class ProxyIndexRequestBuilderTest {
+
+ @Rule
+ public EsTester esTester = new EsTester().addDefinitions(new FakeIndexDefinition());
+
+ @Test
+ public void index_with_index_type_and_id() {
+ IndexResponse response = esTester.client().prepareIndex(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE)
+ .setSource(FakeIndexDefinition.newDoc(42))
+ .get();
+ assertThat(response.isCreated()).isTrue();
+ }
+
+ @Test
+ public void with_profiling_basic() {
+ esTester.setProfilingLevel(Profiling.Level.BASIC);
+ IndexResponse response = esTester.client().prepareIndex(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE)
+ .setSource(FakeIndexDefinition.newDoc(42))
+ .get();
+ assertThat(response.isCreated()).isTrue();
+ // TODO assert profiling
+ }
+
+ @Test
+ public void fail_if_bad_query() throws Exception {
+ IndexRequestBuilder requestBuilder = esTester.client().prepareIndex("unknownIndex", "unknownType");
+ try {
+ requestBuilder.get();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class);
+ assertThat(e.getMessage()).contains("Fail to execute ES index request for key 'null' on index 'unknownIndex' on type 'unknownType'");
+ }
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ esTester.client().prepareIndex(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE).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 {
+ esTester.client().prepareIndex(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE).get(TimeValue.timeValueMinutes(1));
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
+ }
+ }
+
+ @Test
+ public void do_not_support_execute_method() throws Exception {
+ try {
+ esTester.client().prepareIndex(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE).execute();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.common.unit.TimeValue;
+import org.junit.After;
+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 static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.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);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @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'");
+ }
+ }
+
+ @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.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'");
+ }
+
+ // TODO assert profiling
+ searchClient.stop();
+ }
+
+ @Test
+ public void fail_to_exists() throws Exception {
+ try {
+ searchClient.prepareIndicesExist().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 indices exists request");
+ }
+ }
+
+ @Test
+ public void to_string() {
+ assertThat(searchClient.prepareIndicesExist(IndexDefinition.RULE.getIndexName()).toString()).isEqualTo("ES indices exists request on indices 'rules'");
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ searchClient.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));
+ 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.common.unit.TimeValue;
+import org.junit.After;
+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 static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.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);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @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'");
+ }
+ }
+
+ @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");
+ }
+
+ @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.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'");
+ }
+
+ // TODO assert profiling
+ searchClient.stop();
+ }
+
+ @Test
+ public void fail_to_stats() throws Exception {
+ try {
+ searchClient.prepareStats("unknown").get();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class);
+ assertThat(e.getMessage()).contains("Fail to execute ES indices stats request on indices 'unknown'");
+ }
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ searchClient.prepareStats(IndexDefinition.RULE.getIndexName()).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));
+ 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.action.get.MultiGetRequest;
+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.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 static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.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);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @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();
+
+ // 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'],");
+ }
+
+ @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 {
+ 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");
+ }
+
+ // TODO assert profiling
+ searchClient.stop();
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ searchClient.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));
+ 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.common.unit.TimeValue;
+import org.junit.After;
+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 static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.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);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @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");
+ }
+ }
+
+ @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");
+ }
+
+ @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.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");
+ }
+
+ // 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");
+ 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));
+ 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+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.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 java.util.HashMap;
+import java.util.Map;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
+
+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);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @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");
+ }
+ }
+
+ @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}}'");
+ }
+
+ @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 {
+ 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");
+ }
+
+ // TODO assert profiling
+ searchClient.stop();
+ }
+
+ @Test
+ public void fail_on_bad_query() throws Exception {
+ try {
+ searchClient.preparePutMapping().get();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class);
+ assertThat(e.getMessage()).contains("Fail to execute ES put mapping request");
+ }
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ searchClient.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));
+ 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+
+ protected static Map mapDomain() {
+ Map<String, Object> mapping = new HashMap<String, Object>();
+ mapping.put("dynamic", false);
+ mapping.put("_all", ImmutableMap.of("enabled", false));
+ return mapping;
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder;
+import org.elasticsearch.common.unit.TimeValue;
+import org.junit.After;
+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 static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.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);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @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'");
+ }
+ }
+
+ @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");
+ }
+
+ @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 {
+ 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'");
+ }
+
+ // TODO assert profiling
+ searchClient.stop();
+ }
+
+ @Test
+ public void fail_to_refresh() throws Exception {
+ try {
+ searchClient.prepareRefresh("unknown").get();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class);
+ assertThat(e.getMessage()).contains("Fail to execute ES refresh request on indices 'unknown'");
+ }
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ searchClient.prepareRefresh(IndexDefinition.RULE.getIndexName()).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));
+ 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.common.unit.TimeValue;
+import org.junit.After;
+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 static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.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);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @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]'");
+ }
+ }
+
+ @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");
+ }
+
+ @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.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]'");
+ }
+
+ // 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class);
+ assertThat(e.getMessage()).contains("Fail to execute ES search request '{").contains("}' on indices '[rules]'");
+ }
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ searchClient.prepareSearch(IndexDefinition.RULE.getIndexName()).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));
+ 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.es.request;
+
+import org.elasticsearch.common.unit.TimeValue;
+import org.junit.After;
+import org.junit.Test;
+import org.sonar.api.config.Settings;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.server.search.SearchClient;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.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);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @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'");
+ }
+ }
+
+ @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();
+
+ // 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();
+ }
+
+ @Test
+ public void fail_to_search_bad_query() throws Exception {
+ try {
+ searchClient.prepareSearchScroll("unknown").get();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class);
+ assertThat(e.getMessage()).contains("Fail to execute ES search scroll request for scroll id 'null'");
+ }
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ searchClient.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));
+ 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();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.bulk.BulkRequestBuilder;
-import org.elasticsearch.action.delete.DeleteRequest;
-import org.elasticsearch.action.index.IndexRequest;
-import org.elasticsearch.action.update.UpdateRequest;
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
-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 java.util.Collections;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
-public class ProxyBulkRequestBuilderTest {
-
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @Test
- public void bulk() {
- BulkRequestBuilder bulkRequestBuilder = searchClient.prepareBulk();
- bulkRequestBuilder.add(new UpdateRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1").doc(Collections.emptyMap()));
- bulkRequestBuilder.add(new DeleteRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1"));
- bulkRequestBuilder.add(new IndexRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1").source(Collections.emptyMap()));
- try {
- bulkRequestBuilder.get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage())
- .contains("Fail to execute ES bulk request for [Action 'UpdateRequest' for key 'rule1' on index 'rules' on type 'rules'],")
- .contains("[Action 'DeleteRequest' for key 'rule1' on index 'rules' on type 'rules'],")
- .contains("[Action 'IndexRequest' for key 'rule1' on index 'rules' on type 'rules'],");
- }
-
- // TODO assert profiling
- }
-
- @Test
- public void to_string() {
- BulkRequestBuilder bulkRequestBuilder = searchClient.prepareBulk();
- bulkRequestBuilder.add(new UpdateRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1").doc(Collections.emptyMap()));
- bulkRequestBuilder.add(new DeleteRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1"));
- bulkRequestBuilder.add(new IndexRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1").source(Collections.emptyMap()));
-
- assertThat(bulkRequestBuilder.toString()).contains("ES bulk request for [Action 'UpdateRequest' for key 'rule1' on index 'rules' on type 'rules'],")
- .contains("[Action 'DeleteRequest' for key 'rule1' on index 'rules' on type 'rules'],")
- .contains("[Action 'IndexRequest' for key 'rule1' on index 'rules' on type 'rules'],");
- }
-
- @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);
-
- BulkRequestBuilder bulkRequestBuilder = searchClient.prepareBulk();
- bulkRequestBuilder.add(new UpdateRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1").doc(Collections.emptyMap()));
- bulkRequestBuilder.add(new DeleteRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1"));
- bulkRequestBuilder.add(new IndexRequest(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexName(), "rule1").source(Collections.emptyMap()));
- try {
- bulkRequestBuilder.get();
-
- // expected to fail because elasticsearch is not correctly configured, but that does not matter
- fail();
- } catch (IllegalStateException e) {
- assertThat(e.getMessage())
- .contains("Fail to execute ES bulk request for [Action 'UpdateRequest' for key 'rule1' on index 'rules' on type 'rules'],")
- .contains("[Action 'DeleteRequest' for key 'rule1' on index 'rules' on type 'rules'],")
- .contains("[Action 'IndexRequest' for key 'rule1' on index 'rules' on type 'rules'],");
- }
-
- // TODO assert profiling
- searchClient.stop();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- searchClient.prepareBulk().get("1");
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
- searchClient.prepareBulk().get(TimeValue.timeValueMinutes(1));
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void execute_is_not_yet_implemented() throws Exception {
- searchClient.prepareBulk().execute();
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder;
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
-import org.junit.Test;
-import org.sonar.api.config.Settings;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.SearchClient;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
-public class ProxyClusterHealthRequestBuilderTest {
-
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @Test
- public void state() {
- try {
- ClusterHealthRequestBuilder requestBuilder = searchClient.prepareHealth();
- 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 health request");
- }
- }
-
- @Test
- public void to_string() {
- assertThat(searchClient.prepareHealth("rules").toString()).isEqualTo("ES cluster health request on indices 'rules'");
- assertThat(searchClient.prepareHealth().toString()).isEqualTo("ES cluster health 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 {
- ClusterHealthRequestBuilder requestBuilder = searchClient.prepareHealth();
- 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 health request");
- }
-
- // TODO assert profiling
- searchClient.stop();
- }
-
- @Test
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- try {
- searchClient.prepareHealth().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.prepareHealth().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.prepareHealth().execute();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder;
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
-import org.junit.Test;
-import org.sonar.api.config.Settings;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.SearchClient;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.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);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @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");
- }
- }
-
- @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");
- }
-
- @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();
-
- // 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");
- }
-
- // TODO assert profiling
- searchClient.stop();
- }
-
- @Test
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- try {
- searchClient.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));
- 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();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequestBuilder;
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
-import org.junit.Test;
-import org.sonar.api.config.Settings;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.SearchClient;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.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);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @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");
- }
- }
-
- @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");
- }
-
- @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 {
- 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");
- }
-
- // TODO assert profiling
- searchClient.stop();
- }
-
- @Test
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- try {
- searchClient.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));
- 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();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
-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 static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.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);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @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'");
- }
- }
-
- @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");
- }
-
- @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.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'");
- }
-
- // 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();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES count request on indices 'unknown_index1, unknown_index2' on types 'unknown_type'");
- }
- }
-
- @Test
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- try {
- searchClient.prepareCount(IndexDefinition.RULE.getIndexName()).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));
- 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();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
-import org.junit.Test;
-import org.sonar.api.config.Settings;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.SearchClient;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.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);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @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'");
- }
- }
-
- @Test
- public void to_string() {
- assertThat(searchClient.prepareCreate("new").toString()).isEqualTo("ES create index 'new'");
- }
-
- @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();
-
- // 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'");
- }
-
- // TODO assert profiling
- searchClient.stop();
- }
-
- @Test
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- try {
- searchClient.prepareCreate("new").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));
- 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();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.common.unit.TimeValue;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.junit.After;
-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 static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.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);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @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'");
- }
- }
-
- @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");
- }
-
- @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.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'");
- }
-
- // TODO assert profiling
- searchClient.stop();
- }
-
- @Test
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- try {
- searchClient.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));
- 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();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.search.request;
-
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
-import org.junit.Test;
-import org.sonar.api.config.Settings;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.SearchClient;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.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);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @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");
- }
- }
-
- @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");
- }
-
- @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");
- }
-
- // 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");
- 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));
- 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();
- fail();
- } catch (UnsupportedOperationException e) {
- assertThat(e).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
-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 static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.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);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @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'");
- }
- }
-
- @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");
- }
-
- @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.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'");
- }
-
- // TODO assert profiling
- searchClient.stop();
- }
-
- @Test
- public void fail_to_refresh() throws Exception {
- try {
- searchClient.prepareFlush("unknown").get();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES flush request on indices 'unknown'");
- }
- }
-
- @Test
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- try {
- searchClient.prepareFlush(IndexDefinition.RULE.getIndexName()).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));
- 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();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.get.GetRequestBuilder;
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
-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 static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.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);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @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'");
- }
- }
-
- @Test
- public void get_with_index_type_and_id() {
- try {
- searchClient.prepareGet(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexType(), "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'");
- }
- }
-
- @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.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'");
- }
-
- // TODO assert profiling
- searchClient.stop();
- }
-
- @Test
- public void fail_to_get_bad_query() throws Exception {
- GetRequestBuilder requestBuilder = searchClient.prepareGet()
- .setIndex("unknown")
- .setType("test")
- .setId("rule1");
- try {
- requestBuilder.get();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES get request for key 'rule1' on index 'unknown' on type 'test'");
- }
- }
-
- @Test
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- try {
- searchClient.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));
- 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();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.index.IndexRequestBuilder;
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
-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 static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
-public class ProxyIndexRequestBuilderTest {
-
- Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
- SearchClient searchClient = new SearchClient(new Settings(), profiling);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @Test
- public void index_with_index_type_and_id() {
- try {
- searchClient.prepareIndex(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexType(), "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 index request for key 'ruleKey' on index 'rules' on type 'rule'");
- }
- }
-
- @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.prepareIndex()
- .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 index request for key 'ruleKey' on index 'rules' on type 'rule'");
- }
-
- // TODO assert profiling
- searchClient.stop();
- }
-
- @Test
- public void fail_to_get_bad_query() throws Exception {
- IndexRequestBuilder requestBuilder = searchClient.prepareIndex()
- .setIndex("unknown")
- .setType("test")
- .setId("rule1");
- try {
- requestBuilder.get();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES index request for key 'rule1' on index 'unknown' on type 'test'");
- }
- }
-
- @Test
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- try {
- searchClient.prepareIndex().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.prepareIndex().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.prepareIndex().execute();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
-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 static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.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);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @Test
- public void exists() {
- try {
- searchClient.prepareExists(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'");
- }
- }
-
- @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.prepareExists(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'");
- }
-
- // TODO assert profiling
- searchClient.stop();
- }
-
- @Test
- public void fail_to_exists() throws Exception {
- try {
- searchClient.prepareExists().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 indices exists request");
- }
- }
-
- @Test
- public void to_string() {
- assertThat(searchClient.prepareExists(IndexDefinition.RULE.getIndexName()).toString()).isEqualTo("ES indices exists request on indices 'rules'");
- }
-
- @Test
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- try {
- searchClient.prepareExists().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.prepareExists().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.prepareExists().execute();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
-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 static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.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);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @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'");
- }
- }
-
- @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");
- }
-
- @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.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'");
- }
-
- // TODO assert profiling
- searchClient.stop();
- }
-
- @Test
- public void fail_to_stats() throws Exception {
- try {
- searchClient.prepareStats("unknown").get();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES indices stats request on indices 'unknown'");
- }
- }
-
- @Test
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- try {
- searchClient.prepareStats(IndexDefinition.RULE.getIndexName()).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));
- 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();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.get.MultiGetRequest;
-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.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 static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.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);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @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();
-
- // 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'],");
- }
-
- @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 {
- 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");
- }
-
- // TODO assert profiling
- searchClient.stop();
- }
-
- @Test
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- try {
- searchClient.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));
- 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();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
-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 static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.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);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @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");
- }
- }
-
- @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");
- }
-
- @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.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");
- }
-
- // 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");
- 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));
- 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();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-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.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 java.util.HashMap;
-import java.util.Map;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
-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);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @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");
- }
- }
-
- @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}}'");
- }
-
- @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 {
- 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");
- }
-
- // TODO assert profiling
- searchClient.stop();
- }
-
- @Test
- public void fail_on_bad_query() throws Exception {
- try {
- searchClient.preparePutMapping().get();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES put mapping request");
- }
- }
-
- @Test
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- try {
- searchClient.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));
- 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();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-
- protected static Map mapDomain() {
- Map<String, Object> mapping = new HashMap<String, Object>();
- mapping.put("dynamic", false);
- mapping.put("_all", ImmutableMap.of("enabled", false));
- return mapping;
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder;
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
-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 static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.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);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @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'");
- }
- }
-
- @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");
- }
-
- @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 {
- 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'");
- }
-
- // TODO assert profiling
- searchClient.stop();
- }
-
- @Test
- public void fail_to_refresh() throws Exception {
- try {
- searchClient.prepareRefresh("unknown").get();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES refresh request on indices 'unknown'");
- }
- }
-
- @Test
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- try {
- searchClient.prepareRefresh(IndexDefinition.RULE.getIndexName()).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));
- 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();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
-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 static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.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);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @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]'");
- }
- }
-
- @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");
- }
-
- @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.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]'");
- }
-
- // 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();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES search request '{").contains("}' on indices '[rules]'");
- }
- }
-
- @Test
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- try {
- searchClient.prepareSearch(IndexDefinition.RULE.getIndexName()).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));
- 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();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.search.request;
-
-import org.elasticsearch.common.unit.TimeValue;
-import org.junit.After;
-import org.junit.Test;
-import org.sonar.api.config.Settings;
-import org.sonar.core.profiling.Profiling;
-import org.sonar.server.search.SearchClient;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.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);
-
- @After
- public void tearDown() throws Exception {
- searchClient.stop();
- }
-
- @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'");
- }
- }
-
- @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();
-
- // 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();
- }
-
- @Test
- public void fail_to_search_bad_query() throws Exception {
- try {
- searchClient.prepareSearchScroll("unknown").get();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class);
- assertThat(e.getMessage()).contains("Fail to execute ES search scroll request for scroll id 'null'");
- }
- }
-
- @Test
- public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
- try {
- searchClient.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));
- 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();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
- }
- }
-}