]> source.dussan.org Git - sonarqube.git/commitdiff
Remove unused Elasticsearch code
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 12 Apr 2018 13:41:06 +0000 (15:41 +0200)
committerSonarTech <sonartech@sonarsource.com>
Tue, 8 May 2018 18:20:44 +0000 (20:20 +0200)
server/sonar-server/src/main/java/org/sonar/server/es/EsClient.java
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyBulkRequestBuilder.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyFlushRequestBuilder.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyMultiGetRequestBuilder.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/es/EsClientTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyBulkRequestBuilderTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyFlushRequestBuilderTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyGetRequestBuilderTest.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyMultiGetRequestBuilderTest.java [deleted file]

index 0ca25e35e085885ba47628ae44702abc3099e2ae..0e2952c12a08191d9c87f6b7b2db183ca7bf7adf 100644 (file)
@@ -27,39 +27,30 @@ import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequestBuilder;
 import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequestBuilder;
 import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
 import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder;
-import org.elasticsearch.action.admin.indices.flush.FlushRequestBuilder;
 import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequestBuilder;
 import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder;
 import org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder;
 import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder;
-import org.elasticsearch.action.bulk.BulkRequestBuilder;
 import org.elasticsearch.action.delete.DeleteRequestBuilder;
 import org.elasticsearch.action.get.GetRequestBuilder;
-import org.elasticsearch.action.get.MultiGetRequestBuilder;
 import org.elasticsearch.action.index.IndexRequestBuilder;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchScrollRequestBuilder;
 import org.elasticsearch.client.Client;
 import org.elasticsearch.cluster.health.ClusterHealthStatus;
 import org.elasticsearch.common.Priority;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.elasticsearch.search.aggregations.AggregationBuilders;
-import org.elasticsearch.search.aggregations.metrics.max.Max;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
-import org.sonar.server.es.request.ProxyBulkRequestBuilder;
 import org.sonar.server.es.request.ProxyClearCacheRequestBuilder;
 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.ProxyCreateIndexRequestBuilder;
 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;
@@ -90,10 +81,6 @@ public class EsClient implements Closeable {
     return new ProxyRefreshRequestBuilder(nativeClient()).setIndices(indices);
   }
 
-  public FlushRequestBuilder prepareFlush(String... indices) {
-    return new ProxyFlushRequestBuilder(nativeClient()).setIndices(indices);
-  }
-
   public IndicesStatsRequestBuilder prepareStats(String... indices) {
     return new ProxyIndicesStatsRequestBuilder(nativeClient()).setIndices(indices);
   }
@@ -144,22 +131,10 @@ public class EsClient implements Closeable {
     return new ProxySearchScrollRequestBuilder(scrollId, nativeClient());
   }
 
-  public GetRequestBuilder prepareGet() {
-    return new ProxyGetRequestBuilder(nativeClient());
-  }
-
   public GetRequestBuilder prepareGet(IndexType indexType, String id) {
     return new ProxyGetRequestBuilder(nativeClient()).setIndex(indexType.getIndex()).setType(indexType.getType()).setId(id);
   }
 
-  public MultiGetRequestBuilder prepareMultiGet() {
-    return new ProxyMultiGetRequestBuilder(nativeClient());
-  }
-
-  public BulkRequestBuilder prepareBulk() {
-    return new ProxyBulkRequestBuilder(nativeClient());
-  }
-
   public DeleteRequestBuilder prepareDelete(IndexType indexType, String id) {
     return new ProxyDeleteRequestBuilder(nativeClient(), indexType.getIndex()).setType(indexType.getType()).setId(id);
   }
@@ -182,31 +157,10 @@ public class EsClient implements Closeable {
     return new ProxyClearCacheRequestBuilder(nativeClient()).setIndices(indices);
   }
 
-  public long getMaxFieldValue(IndexType indexType, String fieldName) {
-    SearchRequestBuilder request = prepareSearch(indexType)
-      .setQuery(QueryBuilders.matchAllQuery())
-      .setSize(0)
-      .addAggregation(AggregationBuilders.max("latest").field(fieldName));
-
-    Max max = request.get().getAggregations().get("latest");
-    return (long) max.getValue();
-  }
-
   public Client nativeClient() {
     return nativeClient;
   }
 
-  /**
-   * Checks whether there is any document in any mentioned type.
-   */
-  public boolean isEmpty(IndexType indexType) {
-    return count(indexType) <= 0;
-  }
-
-  private long count(IndexType indexType) {
-    return prepareSearch(indexType).setSize(0).get().getHits().getTotalHits();
-  }
-
   @Override
   public void close() {
     nativeClient.close();
diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyBulkRequestBuilder.java b/server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyBulkRequestBuilder.java
deleted file mode 100644 (file)
index 08d49d8..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.LinkedHashMultiset;
-import com.google.common.collect.Multiset;
-import java.util.Set;
-import org.elasticsearch.action.DocWriteRequest;
-import org.elasticsearch.action.ListenableActionFuture;
-import org.elasticsearch.action.bulk.BulkAction;
-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.api.utils.log.Profiler;
-import org.sonar.server.es.EsClient;
-
-public class ProxyBulkRequestBuilder extends BulkRequestBuilder {
-
-  public ProxyBulkRequestBuilder(Client client) {
-    super(client, BulkAction.INSTANCE);
-  }
-
-  @Override
-  public BulkResponse get() {
-    Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start();
-    try {
-      return super.execute().actionGet();
-    } catch (Exception e) {
-      throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
-    } finally {
-      if (profiler.isTraceEnabled()) {
-        profiler.stopTrace(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 unsupported();
-  }
-
-  private static UnsupportedOperationException unsupported() {
-    throw new UnsupportedOperationException("See " + ProxyBulkRequestBuilder.class.getName());
-  }
-
-  @Override
-  public String toString() {
-    StringBuilder message = new StringBuilder();
-    message.append("Bulk[");
-    Multiset<BulkRequestKey> groupedRequests = LinkedHashMultiset.create();
-    for (int i = 0; i < request.requests().size(); i++) {
-      DocWriteRequest item = request.requests().get(i);
-      String requestType;
-      String index;
-      String docType;
-      if (item instanceof IndexRequest) {
-        IndexRequest request = (IndexRequest) item;
-        requestType = "index";
-        index = request.index();
-        docType = request.type();
-      } else if (item instanceof UpdateRequest) {
-        UpdateRequest request = (UpdateRequest) item;
-        requestType = "update";
-        index = request.index();
-        docType = request.type();
-      } else if (item instanceof DeleteRequest) {
-        DeleteRequest request = (DeleteRequest) item;
-        requestType = "delete";
-        index = request.index();
-        docType = request.type();
-      } else {
-        // Cannot happen, not allowed by BulkRequest's contract
-        throw new IllegalStateException("Unsupported bulk request type: " + item.getClass());
-      }
-      groupedRequests.add(new BulkRequestKey(requestType, index, docType));
-    }
-
-    Set<Multiset.Entry<BulkRequestKey>> entrySet = groupedRequests.entrySet();
-    int size = entrySet.size();
-    int current = 0;
-    for (Multiset.Entry<BulkRequestKey> requestEntry : entrySet) {
-      message.append(requestEntry.getCount()).append(" ").append(requestEntry.getElement().toString());
-      current++;
-      if (current < size) {
-        message.append(", ");
-      }
-    }
-
-    message.append("]");
-    return message.toString();
-  }
-
-  private static class BulkRequestKey {
-    private String requestType;
-    private String index;
-    private String docType;
-
-    private BulkRequestKey(String requestType, String index, String docType) {
-      this.requestType = requestType;
-      this.index = index;
-      this.docType = docType;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-      if (this == o) {
-        return true;
-      }
-      if (o == null || getClass() != o.getClass()) {
-        return false;
-      }
-      BulkRequestKey that = (BulkRequestKey) o;
-      if (!docType.equals(that.docType)) {
-        return false;
-      }
-      if (!index.equals(that.index)) {
-        return false;
-      }
-      return requestType.equals(that.requestType);
-    }
-
-    @Override
-    public int hashCode() {
-      int result = requestType.hashCode();
-      result = 31 * result + index.hashCode();
-      result = 31 * result + docType.hashCode();
-      return result;
-    }
-
-    @Override
-    public String toString() {
-      return String.format("%s request(s) on index %s and type %s", requestType, index, docType);
-    }
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyFlushRequestBuilder.java b/server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyFlushRequestBuilder.java
deleted file mode 100644 (file)
index 8b2b0a9..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.FlushAction;
-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.api.utils.log.Profiler;
-import org.sonar.server.es.EsClient;
-
-public class ProxyFlushRequestBuilder extends FlushRequestBuilder {
-
-  public ProxyFlushRequestBuilder(Client client) {
-    super(client.admin().indices(), FlushAction.INSTANCE);
-  }
-
-  @Override
-  public FlushResponse get() {
-    Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start();
-    try {
-      return super.execute().actionGet();
-    } catch (Exception e) {
-      throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
-    } finally {
-      if (profiler.isTraceEnabled()) {
-        profiler.stopTrace(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();
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyMultiGetRequestBuilder.java b/server/sonar-server/src/main/java/org/sonar/server/es/request/ProxyMultiGetRequestBuilder.java
deleted file mode 100644 (file)
index 0f59ced..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.MultiGetAction;
-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.api.utils.log.Profiler;
-import org.sonar.server.es.EsClient;
-
-public class ProxyMultiGetRequestBuilder extends MultiGetRequestBuilder {
-
-  public ProxyMultiGetRequestBuilder(Client client) {
-    super(client, MultiGetAction.INSTANCE);
-  }
-
-  @Override
-  public MultiGetResponse get() {
-    Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start();
-    try {
-      return super.execute().actionGet();
-    } catch (Exception e) {
-      throw new IllegalStateException(String.format("Fail to execute %s", toString()), e);
-    } finally {
-      if (profiler.isTraceEnabled()) {
-        profiler.stopTrace(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();
-  }
-}
index 3e658270f5e11af81ae459a018b60f58ad05249e..e677e8082950afd2fcc7c8aada1b5c3126ff99af 100644 (file)
@@ -21,17 +21,14 @@ package org.sonar.server.es;
 
 import org.junit.Rule;
 import org.junit.Test;
-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.ProxyCreateIndexRequestBuilder;
 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;
@@ -39,7 +36,6 @@ import org.sonar.server.es.request.ProxySearchRequestBuilder;
 import org.sonar.server.es.request.ProxySearchScrollRequestBuilder;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.server.es.FakeIndexDefinition.INDEX_TYPE_FAKE;
 
 public class EsClientTest {
 
@@ -50,16 +46,12 @@ public class EsClientTest {
   public void proxify_requests() {
     EsClient underTest = es.client();
     assertThat(underTest.nativeClient()).isNotNull();
-    assertThat(underTest.prepareBulk()).isInstanceOf(ProxyBulkRequestBuilder.class);
     assertThat(underTest.prepareClusterStats()).isInstanceOf(ProxyClusterStatsRequestBuilder.class);
     assertThat(underTest.prepareCreate("fakes")).isInstanceOf(ProxyCreateIndexRequestBuilder.class);
     assertThat(underTest.prepareDelete("fakes", "fake", "my_id")).isInstanceOf(ProxyDeleteRequestBuilder.class);
     assertThat(underTest.prepareIndicesExist()).isInstanceOf(ProxyIndicesExistsRequestBuilder.class);
-    assertThat(underTest.prepareFlush()).isInstanceOf(ProxyFlushRequestBuilder.class);
-    assertThat(underTest.prepareGet()).isInstanceOf(ProxyGetRequestBuilder.class);
     assertThat(underTest.prepareGet(new IndexType("fakes", "fake"), "1")).isInstanceOf(ProxyGetRequestBuilder.class);
     assertThat(underTest.prepareHealth()).isInstanceOf(ProxyClusterHealthRequestBuilder.class);
-    assertThat(underTest.prepareMultiGet()).isInstanceOf(ProxyMultiGetRequestBuilder.class);
     assertThat(underTest.prepareNodesStats()).isInstanceOf(ProxyNodesStatsRequestBuilder.class);
     assertThat(underTest.preparePutMapping()).isInstanceOf(ProxyPutMappingRequestBuilder.class);
     assertThat(underTest.prepareRefresh()).isInstanceOf(ProxyRefreshRequestBuilder.class);
@@ -70,15 +62,4 @@ public class EsClientTest {
 
     underTest.close();
   }
-
-  @Test
-  public void isEmpty_should_return_true_if_index_is_empty() {
-    assertThat(es.client().isEmpty(INDEX_TYPE_FAKE)).isTrue();
-  }
-
-  @Test
-  public void isEmpty_should_return_false_if_index_is_not_empty() {
-    es.putDocuments(INDEX_TYPE_FAKE, new FakeDoc());
-    assertThat(es.client().isEmpty(INDEX_TYPE_FAKE)).isFalse();
-  }
 }
diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyBulkRequestBuilderTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyBulkRequestBuilderTest.java
deleted file mode 100644 (file)
index 71e873e..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.api.utils.log.LogTester;
-import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.server.es.EsTester;
-import org.sonar.server.es.FakeIndexDefinition;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class ProxyBulkRequestBuilderTest {
-
-  @Rule
-  public EsTester es = EsTester.createCustom(new FakeIndexDefinition());
-
-  @Rule
-  public LogTester logTester = new LogTester();
-
-  @Test
-  public void no_trace_logs() {
-    logTester.setLevel(LoggerLevel.INFO);
-    testBulk();
-    assertThat(logTester.logs(LoggerLevel.TRACE)).isEmpty();
-  }
-
-  @Test
-  public void trace_logs() {
-    logTester.setLevel(LoggerLevel.TRACE);
-    testBulk();
-    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
-  }
-
-  private void testBulk() {
-    BulkRequestBuilder req = es.client().prepareBulk();
-    req.add(new UpdateRequest(FakeIndexDefinition.INDEX, FakeIndexDefinition.INDEX_TYPE_FAKE.getType(), "key1")
-      .doc(FakeIndexDefinition.newDoc(1).getFields()));
-    req.add(new DeleteRequest(FakeIndexDefinition.INDEX, FakeIndexDefinition.INDEX_TYPE_FAKE.getType(), "key2"));
-    req.add(new IndexRequest(FakeIndexDefinition.INDEX, FakeIndexDefinition.INDEX_TYPE_FAKE.getType(), "key3")
-      .source(FakeIndexDefinition.newDoc(3).getFields()));
-
-    assertThat(req.toString()).isEqualTo(
-      "Bulk[1 update request(s) on index fakes and type fake, 1 delete request(s) on index fakes and type fake, 1 index request(s) on index fakes and type fake]");
-
-    BulkResponse response = req.get();
-    assertThat(response.getItems()).hasSize(3);
-  }
-
-  @Test(expected = UnsupportedOperationException.class)
-  public void get_with_string_timeout_is_not_yet_implemented() {
-    es.client().prepareBulk().get("1");
-  }
-
-  @Test(expected = UnsupportedOperationException.class)
-  public void get_with_time_value_timeout_is_not_yet_implemented() {
-    es.client().prepareBulk().get(TimeValue.timeValueMinutes(1));
-  }
-
-  @Test(expected = UnsupportedOperationException.class)
-  public void execute_is_not_yet_implemented() {
-    es.client().prepareBulk().execute();
-  }
-
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyFlushRequestBuilderTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyFlushRequestBuilderTest.java
deleted file mode 100644 (file)
index 2781358..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.log.LogTester;
-import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.server.es.EsTester;
-import org.sonar.server.es.FakeIndexDefinition;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
-
-public class ProxyFlushRequestBuilderTest {
-
-  @Rule
-  public EsTester es = EsTester.createCustom(new FakeIndexDefinition());
-
-  @Rule
-  public LogTester logTester = new LogTester();
-
-  @Test
-  public void flush() {
-    es.client().prepareFlush(FakeIndexDefinition.INDEX).get();
-  }
-
-  @Test
-  public void to_string() {
-    assertThat(es.client().prepareFlush(FakeIndexDefinition.INDEX).toString()).isEqualTo("ES flush request on indices 'fakes'");
-    assertThat(es.client().prepareFlush().toString()).isEqualTo("ES flush request");
-  }
-
-  @Test
-  public void trace_logs() {
-    logTester.setLevel(LoggerLevel.TRACE);
-
-    es.client().prepareFlush(FakeIndexDefinition.INDEX).get();
-    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
-  }
-
-  @Test
-  public void fail_to_refresh() {
-    try {
-      es.client().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() {
-    try {
-      es.client().prepareFlush(FakeIndexDefinition.INDEX).get("1");
-      fail();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
-    }
-  }
-
-  @Test
-  public void get_with_time_value_timeout_is_not_yet_implemented() {
-    try {
-      es.client().prepareFlush(FakeIndexDefinition.INDEX).get(TimeValue.timeValueMinutes(1));
-      fail();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
-    }
-  }
-
-  @Test
-  public void execute_should_throw_an_unsupported_operation_exception() {
-    try {
-      es.client().prepareFlush(FakeIndexDefinition.INDEX).execute();
-      fail();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
-    }
-  }
-
-}
index cc73bbc8400f9d93d9ca101a254c90aa4c062233..a05997a1079df7614c0c05e0ccc8efd52dd57020 100644 (file)
@@ -27,9 +27,11 @@ import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.server.es.EsTester;
 import org.sonar.server.es.FakeIndexDefinition;
+import org.sonar.server.es.IndexType;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.fail;
+import static org.sonar.server.es.FakeIndexDefinition.INDEX_TYPE_FAKE;
 
 public class ProxyGetRequestBuilderTest {
 
@@ -39,33 +41,18 @@ public class ProxyGetRequestBuilderTest {
   @Rule
   public LogTester logTester = new LogTester();
 
-  @Test
-  public void get() {
-    es.client().prepareGet()
-      .setIndex(FakeIndexDefinition.INDEX)
-      .setType(FakeIndexDefinition.TYPE)
-      .setId("ruleKey")
-      .get();
-  }
-
   @Test
   public void trace_logs() {
     logTester.setLevel(LoggerLevel.TRACE);
 
-    es.client().prepareGet()
-      .setIndex(FakeIndexDefinition.INDEX)
-      .setType(FakeIndexDefinition.TYPE)
-      .setId("ruleKey")
+    es.client().prepareGet(INDEX_TYPE_FAKE, "ruleKey")
       .get();
     assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
   }
 
   @Test
   public void fail_to_get_bad_query() {
-    GetRequestBuilder requestBuilder = es.client().prepareGet()
-      .setIndex("unknown")
-      .setType("test")
-      .setId("rule1");
+    GetRequestBuilder requestBuilder = es.client().prepareGet(new IndexType("unknown", "test"), "rule1");
     try {
       requestBuilder.get();
       fail();
@@ -76,9 +63,9 @@ public class ProxyGetRequestBuilderTest {
   }
 
   @Test
-  public void get_with_string_timeout_is_not_yet_implemented() {
+  public void get_with_string_timeout_is_not_implemented() {
     try {
-      es.client().prepareGet().get("1");
+      es.client().prepareGet(INDEX_TYPE_FAKE, "ruleKey").get("1");
       fail();
     } catch (Exception e) {
       assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@@ -88,7 +75,7 @@ public class ProxyGetRequestBuilderTest {
   @Test
   public void get_with_time_value_timeout_is_not_yet_implemented() {
     try {
-      es.client().prepareGet().get(TimeValue.timeValueMinutes(1));
+      es.client().prepareGet(INDEX_TYPE_FAKE, "ruleKey").get(TimeValue.timeValueMinutes(1));
       fail();
     } catch (Exception e) {
       assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
@@ -98,7 +85,7 @@ public class ProxyGetRequestBuilderTest {
   @Test
   public void execute_should_throw_an_unsupported_operation_exception() {
     try {
-      es.client().prepareGet().execute();
+      es.client().prepareGet(INDEX_TYPE_FAKE, "ruleKey").execute();
       fail();
     } catch (Exception e) {
       assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyMultiGetRequestBuilderTest.java b/server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyMultiGetRequestBuilderTest.java
deleted file mode 100644 (file)
index 6c21338..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.subphase.FetchSourceContext;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.utils.log.LogTester;
-import org.sonar.api.utils.log.LoggerLevel;
-import org.sonar.server.es.EsTester;
-import org.sonar.server.es.FakeIndexDefinition;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
-
-public class ProxyMultiGetRequestBuilderTest {
-
-  @Rule
-  public EsTester es = EsTester.createCustom(new FakeIndexDefinition());
-
-  @Rule
-  public LogTester logTester = new LogTester();
-
-  @Test
-  public void multi_get() {
-    MultiGetRequestBuilder request = es.client().prepareMultiGet();
-    request.add(new MultiGetRequest.Item(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE, "ruleKey")
-      .fetchSourceContext(FetchSourceContext.FETCH_SOURCE));
-    request.get();
-
-  }
-
-  @Test
-  public void to_string() {
-    assertThat(es.client().prepareMultiGet().toString()).isEqualTo("ES multi get request");
-    assertThat(es.client().prepareMultiGet().add(new MultiGetRequest.Item(FakeIndexDefinition.INDEX, null, "fake1")
-      .fetchSourceContext(FetchSourceContext.FETCH_SOURCE)).toString()).isEqualTo("ES multi get request [key 'fake1', index 'fakes'],");
-    assertThat(es.client().prepareMultiGet().add(new MultiGetRequest.Item(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE, "fake1")
-      .fetchSourceContext(FetchSourceContext.FETCH_SOURCE)).toString()).isEqualTo("ES multi get request [key 'fake1', index 'fakes', type 'fake'],");
-  }
-
-  @Test
-  public void trace_logs() {
-    logTester.setLevel(LoggerLevel.TRACE);
-
-    MultiGetRequestBuilder request = es.client().prepareMultiGet();
-    request.add(new MultiGetRequest.Item(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE, "ruleKey")
-      .fetchSourceContext(FetchSourceContext.FETCH_SOURCE));
-    request.get();
-
-    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
-  }
-
-  @Test
-  public void get_with_string_timeout_is_not_yet_implemented() {
-    try {
-      es.client().prepareMultiGet().get("1");
-      fail();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
-    }
-  }
-
-  @Test
-  public void get_with_time_value_timeout_is_not_yet_implemented() {
-    try {
-      es.client().prepareMultiGet().get(TimeValue.timeValueMinutes(1));
-      fail();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
-    }
-  }
-
-  @Test
-  public void execute_should_throw_an_unsupported_operation_exception() {
-    try {
-      es.client().prepareMultiGet().execute();
-      fail();
-    } catch (Exception e) {
-      assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
-    }
-  }
-
-}