Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/HH-87320'
Browse files Browse the repository at this point in the history
  • Loading branch information
kullfar committed Jan 21, 2019
2 parents da11fa3 + 295fcf3 commit 67dc88c
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 16 deletions.
2 changes: 1 addition & 1 deletion nab-data-source/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions nab-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.1</version>
<version>2.3.2</version>
</dependency>

<!--Monitoring-->
Expand All @@ -206,7 +206,7 @@
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-logback</artifactId>
<version>1.7.9</version>
<version>1.7.16</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package ru.hh.nab.starter.server.jetty;

import java.time.Duration;
import static java.util.Optional.ofNullable;
import static ru.hh.nab.starter.server.jetty.JettyServer.JETTY;

import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.BlockingArrayQueue;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
Expand All @@ -13,6 +13,8 @@

public final class JettyServerFactory {

private static final int DEFAULT_IDLE_TIMEOUT_MS = (int) Duration.ofMinutes(1).toMillis();

public static JettyServer create(FileSettings fileSettings, ThreadPool threadPool, WebAppInitializer webAppInitializer) {

FileSettings jettySettings = fileSettings.getSubSettings(JETTY);
Expand All @@ -29,8 +31,7 @@ public static ThreadPool createJettyThreadPool(FileSettings jettySettings) throw
int minThreads = ofNullable(jettySettings.getInteger("minThreads")).orElse(4);
int maxThreads = ofNullable(jettySettings.getInteger("maxThreads")).orElse(12);
int queueSize = ofNullable(jettySettings.getInteger("queueSize")).orElse(maxThreads);
int idleTimeoutMs = ofNullable(jettySettings.getInteger("threadPoolIdleTimeoutMs"))
.orElseGet(() -> new Long(TimeUnit.MINUTES.toMillis(1)).intValue());
int idleTimeoutMs = ofNullable(jettySettings.getInteger("threadPoolIdleTimeoutMs")).orElse(DEFAULT_IDLE_TIMEOUT_MS);
QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads, minThreads, idleTimeoutMs, new BlockingArrayQueue<>(queueSize));
threadPool.start();
return threadPool;
Expand Down
8 changes: 6 additions & 2 deletions nab-testbase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<dependency>
<groupId>com.opentable.components</groupId>
<artifactId>otj-pg-embedded</artifactId>
<version>0.12.5</version>
<version>0.13.0</version>
<exclusions>
<exclusion>
<groupId>org.postgresql</groupId>
Expand Down Expand Up @@ -62,7 +62,11 @@
<artifactId>jersey-test-framework-core</artifactId>
<version>${jersey.version}</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</dependency>
</dependencies>

</project>

Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.UUID;
import org.apache.commons.text.StringSubstitutor;

import static ru.hh.nab.datasource.DataSourceSettings.JDBC_URL;
import static ru.hh.nab.datasource.DataSourceSettings.PASSWORD;
import static ru.hh.nab.datasource.DataSourceSettings.USER;

public class EmbeddedPostgresDataSourceFactory extends DataSourceFactory {
public static final String DEFAULT_JDBC_URL = "jdbc:postgresql://localhost:%s/postgres";
public static final String DEFAULT_JDBC_URL = "jdbc:postgresql://${host}:${port}/${user}";
public static final String DEFAULT_USER = "postgres";

private static final String PG_DIR = "embedded-pg";
Expand All @@ -35,9 +38,17 @@ public EmbeddedPostgresDataSourceFactory(MetricsTrackerFactoryProvider metricsTr
super(metricsTrackerFactoryProvider);
}

@Override
protected DataSource createDataSource(String dataSourceName, boolean isReadonly, FileSettings settings) {
Properties properties = settings.getProperties();
properties.setProperty(JDBC_URL, String.format(DEFAULT_JDBC_URL, getEmbeddedPostgres().getPort()));

final StringSubstitutor jdbcUrlParamsSubstitutor = new StringSubstitutor(Map.of(
"port", getEmbeddedPostgres().getPort(),
"host", "localhost",
"user", DEFAULT_USER
));
String jdbcUrl = jdbcUrlParamsSubstitutor.replace(Optional.ofNullable(settings.getString(JDBC_URL)).orElse(DEFAULT_JDBC_URL));
properties.setProperty(JDBC_URL, jdbcUrl);
properties.setProperty(USER, DEFAULT_USER);
properties.setProperty(PASSWORD, "");
return super.createDataSource(dataSourceName, isReadonly, new FileSettings(properties));
Expand Down
7 changes: 6 additions & 1 deletion nab-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>1.18.0</version>
<version>1.19.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import javax.sql.DataSource;

import com.zaxxer.hikari.HikariDataSource;
import java.util.Map;
import org.apache.commons.text.StringSubstitutor;
import org.junit.BeforeClass;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -107,8 +109,14 @@ private static Properties createTestProperties() {

private static Properties createIncompleteTestProperties() {
Properties properties = new Properties();
String jdbcUrl = String.format(EmbeddedPostgresDataSourceFactory.DEFAULT_JDBC_URL, testDb.getPort());
properties.put(getProperty(DataSourceSettings.JDBC_URL), jdbcUrl);

final StringSubstitutor jdbcUrlParamsSubstitutor = new StringSubstitutor(Map.of(
"port", testDb.getPort(),
"host", "localhost",
"user", EmbeddedPostgresDataSourceFactory.DEFAULT_USER
));
properties.put(getProperty(DataSourceSettings.JDBC_URL), jdbcUrlParamsSubstitutor.replace(EmbeddedPostgresDataSourceFactory.DEFAULT_JDBC_URL));

properties.put(getProperty(DataSourceSettings.USER), EmbeddedPostgresDataSourceFactory.DEFAULT_USER);
properties.put(getProperty(DataSourceSettings.PASSWORD), EmbeddedPostgresDataSourceFactory.DEFAULT_USER);
return properties;
Expand Down
12 changes: 9 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
</modules>

<properties>
<spring.version>5.0.10.RELEASE</spring.version>
<spring.version>5.1.4.RELEASE</spring.version>
<jersey.version>2.27</jersey.version>
<hibernate.version>5.2.10.Final</hibernate.version>
<postgres.jdbc.version>42.2.5</postgres.jdbc.version>
<hhmetrics.version>0.16</hhmetrics.version>
<jetty.version>9.4.8.v20171121</jetty.version>
<jackson.version>2.9.7</jackson.version>
<jackson.version>2.9.8</jackson.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>11</java.version>
</properties>
Expand All @@ -53,7 +53,13 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.0</version>
<version>2.23.4</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.6</version>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down

0 comments on commit 67dc88c

Please sign in to comment.