Search in sources :

Example 66 with Props

use of org.sonar.process.Props in project sonarqube by SonarSource.

the class TomcatConnectorsTest method bind_to_specific_address.

@Test
public void bind_to_specific_address() {
    Properties p = new Properties();
    p.setProperty("sonar.web.port", "9000");
    p.setProperty("sonar.web.host", "1.2.3.4");
    TomcatConnectors.configure(tomcat, new Props(p));
    verify(tomcat.getService()).addConnector(argThat(c -> c.getScheme().equals("http") && c.getPort() == 9000 && ((InetAddress) c.getProperty("address")).getHostAddress().equals("1.2.3.4")));
}
Also used : Properties(java.util.Properties) Props(org.sonar.process.Props) ImmutableMap(com.google.common.collect.ImmutableMap) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) InetAddress(java.net.InetAddress) Tomcat(org.apache.catalina.startup.Tomcat) Mockito(org.mockito.Mockito) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) Mockito.mock(org.mockito.Mockito.mock) Properties(java.util.Properties) Props(org.sonar.process.Props) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 67 with Props

use of org.sonar.process.Props in project sonarqube by SonarSource.

the class TomcatConnectorsTest method fail_with_ISE_if_http_port_is_invalid.

@Test
public void fail_with_ISE_if_http_port_is_invalid() {
    Properties p = new Properties();
    p.setProperty("sonar.web.port", "-1");
    try {
        TomcatConnectors.configure(tomcat, new Props(p));
        fail();
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("HTTP port '-1' is invalid");
    }
}
Also used : Properties(java.util.Properties) Props(org.sonar.process.Props) Test(org.junit.Test)

Example 68 with Props

use of org.sonar.process.Props in project sonarqube by SonarSource.

the class TomcatConnectorsTest method test_max_post_size_for_http_connection.

@Test
public void test_max_post_size_for_http_connection() {
    Properties properties = new Properties();
    Props props = new Props(properties);
    TomcatConnectors.configure(tomcat, props);
    verify(tomcat.getService()).addConnector(argThat(c -> c.getMaxPostSize() == -1));
}
Also used : Properties(java.util.Properties) Props(org.sonar.process.Props) ImmutableMap(com.google.common.collect.ImmutableMap) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) InetAddress(java.net.InetAddress) Tomcat(org.apache.catalina.startup.Tomcat) Mockito(org.mockito.Mockito) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) Mockito.mock(org.mockito.Mockito.mock) Properties(java.util.Properties) Props(org.sonar.process.Props) Test(org.junit.Test)

Example 69 with Props

use of org.sonar.process.Props in project sonarqube by SonarSource.

the class TomcatConnectorsTest method different_thread_pools_for_connectors.

@Test
public void different_thread_pools_for_connectors() {
    Properties p = new Properties();
    p.setProperty("sonar.web.http.minThreads", "2");
    Props props = new Props(p);
    TomcatConnectors.configure(tomcat, props);
    verifyHttpConnector(DEFAULT_PORT, ImmutableMap.of("minSpareThreads", 2));
}
Also used : Properties(java.util.Properties) Props(org.sonar.process.Props) Test(org.junit.Test)

Example 70 with Props

use of org.sonar.process.Props in project sonarqube by SonarSource.

the class EmbeddedTomcatTest method start.

@Test
public void start() throws Exception {
    Props props = new Props(new Properties());
    // prepare file system
    File home = temp.newFolder();
    File data = temp.newFolder();
    File webDir = new File(home, "web");
    FileUtils.write(new File(home, "web/WEB-INF/web.xml"), "<web-app/>");
    props.set("sonar.path.home", home.getAbsolutePath());
    props.set("sonar.path.data", data.getAbsolutePath());
    props.set("sonar.path.web", webDir.getAbsolutePath());
    props.set("sonar.path.logs", temp.newFolder().getAbsolutePath());
    // start server on a random port
    InetAddress address = InetAddress.getLoopbackAddress();
    int httpPort = NetworkUtilsImpl.INSTANCE.getNextLoopbackAvailablePort();
    props.set("sonar.web.host", address.getHostAddress());
    props.set("sonar.web.port", String.valueOf(httpPort));
    EmbeddedTomcat tomcat = new EmbeddedTomcat(props);
    assertThat(tomcat.getStatus()).isEqualTo(EmbeddedTomcat.Status.DOWN);
    tomcat.start();
    assertThat(tomcat.getStatus()).isEqualTo(EmbeddedTomcat.Status.UP);
    // check that http connector accepts requests
    URL url = new URL("http://" + address.getHostAddress() + ":" + httpPort);
    url.openConnection().connect();
    // stop server
    tomcat.terminate();
    // tomcat.isUp() must not be called. It is used to wait for server startup, not shutdown.
    try {
        url.openConnection().connect();
        fail();
    } catch (ConnectException e) {
    // expected
    }
}
Also used : Props(org.sonar.process.Props) Properties(java.util.Properties) File(java.io.File) InetAddress(java.net.InetAddress) URL(java.net.URL) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Aggregations

Props (org.sonar.process.Props)143 Test (org.junit.Test)119 Properties (java.util.Properties)71 File (java.io.File)44 MessageException (org.sonar.process.MessageException)21 ProcessProperties (org.sonar.process.ProcessProperties)19 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)13 Settings (org.elasticsearch.common.settings.Settings)7 NodeHealth (org.sonar.process.cluster.health.NodeHealth)6 InetAddress (java.net.InetAddress)5 LoggerContext (ch.qos.logback.classic.LoggerContext)4 Tomcat (org.apache.catalina.startup.Tomcat)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Map (java.util.Map)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assert.fail (org.junit.Assert.fail)3 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)3 Mockito (org.mockito.Mockito)3 Mockito.mock (org.mockito.Mockito.mock)3 Mockito.verify (org.mockito.Mockito.verify)3