3 * Copyright (C) 2009-2023 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.es.newindex;
22 import org.elasticsearch.cluster.metadata.IndexMetadata;
23 import org.sonar.api.config.internal.MapSettings;
24 import org.sonar.server.es.FakeDoc;
25 import org.sonar.server.es.Index;
26 import org.sonar.server.es.IndexDefinition;
27 import org.sonar.server.es.IndexType;
28 import org.sonar.server.es.IndexType.IndexMainType;
30 import static org.sonar.server.es.newindex.SettingsConfiguration.newBuilder;
32 public class FakeIndexDefinition implements IndexDefinition {
34 public static final String INDEX = "fakes";
35 public static final String TYPE = "fake";
36 public static final Index DESCRIPTOR = Index.simple(INDEX);
37 public static final IndexMainType TYPE_FAKE = IndexType.main(DESCRIPTOR, TYPE);
38 public static final String INT_FIELD = "intField";
40 private int replicas = 0;
42 public FakeIndexDefinition setReplicas(int replicas) {
43 this.replicas = replicas;
48 public void define(IndexDefinitionContext context) {
49 NewIndex index = context.create(DESCRIPTOR, newBuilder(new MapSettings().asConfig()).build());
50 index.getSettings().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, replicas);
51 index.getSettings().put("index.refresh_interval", "-1");
52 index.createTypeMapping(TYPE_FAKE)
53 .createIntegerField(INT_FIELD);
56 public static FakeDoc newDoc(int value) {
57 return new FakeDoc().setInt(value);