import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonar.process.MessageException;
import org.sonar.process.Props;
import org.sonar.process.System2;
private static final Logger LOGGER = LoggerFactory.getLogger(EsSettings.class);
private static final String STANDALONE_NODE_NAME = "sonarqube";
private static final String SECCOMP_PROPERTY = "bootstrap.system_call_filter";
- private static final String ALLOW_MMAP = "node.store.allow_mmapfs";
+ private static final String ALLOW_MMAP = "node.store.allow_mmap";
private final Props props;
private final EsInstallation fileSystem;
builder.put(SECCOMP_PROPERTY, "false");
}
- // to be used with HA QA, where we can't easily set mmap size when running with docker.
+ if (props.value("sonar.search.javaAdditionalOpts", "").contains("-Dnode.store.allow_mmapfs=false")) {
+ throw new MessageException("Property 'node.store.allow_mmapfs' is no longer supported. Use 'node.store.allow_mmap' instead.");
+ }
+
if (props.value("sonar.search.javaAdditionalOpts", "").contains("-D" + ALLOW_MMAP + "=false")) {
builder.put(ALLOW_MMAP, "false");
}
import ch.qos.logback.classic.spi.ILoggingEvent;
import com.google.common.collect.ImmutableSet;
+import com.tngtech.java.junit.dataprovider.DataProvider;
+import com.tngtech.java.junit.dataprovider.DataProviderRunner;
+import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
import org.sonar.application.logging.ListAppender;
import org.sonar.core.extension.ServiceLoaderWrapper;
+import org.sonar.process.MessageException;
import org.sonar.process.ProcessProperties;
import org.sonar.process.ProcessProperties.Property;
import org.sonar.process.Props;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.process.ProcessProperties.Property.CLUSTER_NAME;
import static org.sonar.process.ProcessProperties.Property.SEARCH_MINIMUM_MASTER_NODES;
import static org.sonar.process.ProcessProperties.Property.SEARCH_PORT;
+@RunWith(DataProviderRunner.class)
public class EsSettingsTest {
private static final boolean CLUSTER_ENABLED = true;
@Test
public void disable_mmap_if_configured_in_search_additional_props() throws Exception {
Props props = minProps(CLUSTER_DISABLED);
- props.set("sonar.search.javaAdditionalOpts", "-Dnode.store.allow_mmapfs=false");
+ props.set("sonar.search.javaAdditionalOpts", "-Dnode.store.allow_mmap=false");
Map<String, String> settings = new EsSettings(props, new EsInstallation(props), system).build();
- assertThat(settings.get("node.store.allow_mmapfs")).isEqualTo("false");
+ assertThat(settings).containsEntry("node.store.allow_mmap", "false");
+ }
+
+ @Test
+ @UseDataProvider("clusterEnabledOrNot")
+ public void throw_exception_if_old_mmap_property_is_used(boolean clusterEnabled) throws Exception {
+ Props props = minProps(clusterEnabled);
+ props.set("sonar.search.javaAdditionalOpts", "-Dnode.store.allow_mmapfs=false");
+ EsSettings settings = new EsSettings(props, new EsInstallation(props), system);
+
+ assertThatThrownBy(settings::build)
+ .isInstanceOf(MessageException.class)
+ .hasMessage("Property 'node.store.allow_mmapfs' is no longer supported. Use 'node.store.allow_mmap' instead.");
+ }
+
+ @DataProvider
+ public static Object[][] clusterEnabledOrNot() {
+ return new Object[][] {
+ {false},
+ {true}
+ };
}
private Props minProps(boolean cluster) throws IOException {