Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HH-76991 remove jdebug dependency, rename properties file #82

Merged
merged 1 commit into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
Но и полное следование этим заметкам ничего не гарантирует, будьте внимательны!
Если обнаружите, что Вам пришлось что-то сделать не описанное тут - добавьте.

#### [3.1]

```
- Удалили зависимость от jdebug, т.к. он не используется, но мешает использовать фреймворк за пределами hh.ru
- Удалили зависимость от timings, т.к. пока не используется
- Удалили зависимости от guava и guice
- Небольшой рефакторинг FileSettings для совместимости с hh.ru
```

#### [3.0]

```
Expand Down
24 changes: 7 additions & 17 deletions nab-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
<version>1</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>

<!-- Jersey -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
Expand Down Expand Up @@ -147,11 +141,6 @@
<artifactId>hh-metrics</artifactId>
<version>0.12</version>
</dependency>
<dependency>
<groupId>ru.hh.jdebug</groupId>
<artifactId>jdebug-addon-jdbc</artifactId>
<version>${jdebug.version}</version>
</dependency>
<!-- MX4J -->
<dependency>
<groupId>mx4j</groupId>
Expand Down Expand Up @@ -191,17 +180,18 @@
</exclusions>
</dependency>

<dependency>
<groupId>ru.hh</groupId>
<artifactId>timings</artifactId>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пока не используются.

<version>1.5</version>
</dependency>

<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>3.0.7</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CoreProdConfig {

@Bean
FileSettings fileSettings() throws Exception {
Properties properties = fromFilesInSettingsDir("settings.properties", "settings.properties.dev");
Properties properties = fromFilesInSettingsDir("service.properties", "service.properties.dev");
return new FileSettings(properties);
}

Expand Down
30 changes: 18 additions & 12 deletions nab-core/src/main/java/ru/hh/nab/core/util/FileSettings.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package ru.hh.nab.core.util;

import com.google.common.base.Strings;

import java.util.ArrayList;
import static java.util.Arrays.asList;
import java.util.List;
import java.util.Properties;
import static org.springframework.util.Assert.hasLength;

public class FileSettings {
private final Properties properties;
Expand Down Expand Up @@ -31,25 +33,29 @@ public Boolean getBoolean(String key) {
}

public Properties getSubProperties(String prefix) {
return getSubProperties(prefix, null);
}

public Properties getSubProperties(String prefix, String newPrefix) {
final String namespacePrefix = Strings.isNullOrEmpty(prefix) ? "" : prefix + ".";
hasLength(prefix, "prefix should not be null or empty");
final Properties subProperties = new Properties();

properties.stringPropertyNames().stream()
.filter(key -> key.startsWith(namespacePrefix))
.filter(key -> key.startsWith(prefix + "."))
.forEach(key -> {
String newKey = Strings.isNullOrEmpty(newPrefix) ? "" : newPrefix + ".";
newKey += prefix.isEmpty() ? key : key.substring(prefix.length() + 1);
String newKey = prefix.isEmpty() ? key : key.substring(prefix.length() + 1);
subProperties.put(newKey, properties.getProperty(key));
});

return subProperties;
}

public FileSettings getSubSettings(String prefix) {
return new FileSettings(getSubProperties(prefix));
}

public List<String> getStringList(String key) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для совместимости с hh.ru

String value = getString(key);
return value != null ? asList(value.split("[,\\s]+")) : new ArrayList<>();
}

public Properties getProperties() {
Properties propertiesCopy = new Properties();
propertiesCopy.putAll(this.properties);
return propertiesCopy;
}
}
2 changes: 1 addition & 1 deletion nab-core/src/main/resources/shared-logback.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<included>

<property file="${settingsDir}/settings.properties"/>
<property file="${settingsDir}/service.properties"/>
<property scope="context" name="log.dir" value="${log.dir:-logs}"/>
<property scope="context" name="log.immediate.flush" value="${log.immediate.flush:-true}"/>
<property scope="context" name="log.toConsole" value="${log.toConsole:-false}"/>
Expand Down
101 changes: 101 additions & 0 deletions nab-core/src/test/java/ru/hh/nab/core/util/FileSettingsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package ru.hh.nab.core.util;

import java.util.List;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.BeforeClass;
import org.junit.Test;

public class FileSettingsTest {
private static FileSettings fileSettings;

@BeforeClass
public static void setUpClass() {
Properties properties = new Properties();
properties.put("strProperty", "value");
properties.put("intProperty1", "0");
properties.put("intProperty2", "123");
properties.put("namespace.boolProperty1", "true");
properties.put("namespace.boolProperty2", "false");
properties.put("listProperty", "value1, value2,value3");

fileSettings = new FileSettings(properties);
}

@Test
public void testGetString() {
assertEquals("value", fileSettings.getString("strProperty"));
assertNull(fileSettings.getString("missingKey"));
}

@Test
public void testGetInteger() {
assertEquals(0, fileSettings.getInteger("intProperty1").intValue());
assertEquals(123, fileSettings.getInteger("intProperty2").intValue());
}

@Test
public void testGetBoolean() {
assertTrue(fileSettings.getBoolean("namespace.boolProperty1"));
assertFalse(fileSettings.getBoolean("namespace.boolProperty2"));
}

@Test
public void testGetSubProperties() {
Properties subProperties = fileSettings.getSubProperties("namespace");
assertEquals(2, subProperties.size());
assertTrue(subProperties.containsKey("boolProperty1"));
assertTrue(subProperties.containsKey("boolProperty2"));
}

@Test(expected = IllegalArgumentException.class)
public void testGetSubPropertiesThrowsExceptionIfPrefixIsEmpty() {
fileSettings.getSubProperties("");
}

@Test(expected = IllegalArgumentException.class)
public void testGetSubPropertiesThrowsExceptionIfPrefixIsNull() {
fileSettings.getSubProperties(null);
}

@Test
public void testGetSubSettings() {
FileSettings subSettings = fileSettings.getSubSettings("namespace");
assertNotNull(subSettings.getString("boolProperty1"));
assertNotNull(subSettings.getString("boolProperty2"));
}

@Test(expected = IllegalArgumentException.class)
public void testGetSubSettingsThrowsExceptionIfPrefixIsEmpty() {
fileSettings.getSubSettings("");
}

@Test(expected = IllegalArgumentException.class)
public void testGetSubSettingsThrowsExceptionIfPrefixIsNull() {
fileSettings.getSubSettings(null);
}

@Test
public void testGetStringList() {
List<String> settings = fileSettings.getStringList("listProperty");
assertEquals(3, settings.size());
assertEquals("value1", settings.get(0));
assertEquals("value2", settings.get(1));
assertEquals("value3", settings.get(2));
}

@Test
public void testGetProperties() {
Properties properties = fileSettings.getProperties();
assertEquals("value", properties.getProperty("strProperty"));

properties.setProperty("strProperty", "newValue");
assertEquals("newValue", properties.getProperty("strProperty"));

assertEquals("value", fileSettings.getString("strProperty"));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ru.hh.nab.hibernate.transaction;

import com.google.common.annotations.VisibleForTesting;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import ru.hh.nab.hibernate.datasource.DataSourceType;
import ru.hh.nab.core.util.MDC;
Expand Down Expand Up @@ -63,12 +62,10 @@ private static void updateMDC(DataSourceType dataSourceType) {
MDC.setKey(DATA_SOURCE_MDC_KEY, dataSourceType != null ? dataSourceType.getId() : DataSourceType.DEFAULT.getId());
}

@VisibleForTesting
static void disableTransactionCheck() {
checkNoTransaction = false;
}

@VisibleForTesting
static void enableTransactionCheck() {
checkNoTransaction = true;
}
Expand Down
2 changes: 1 addition & 1 deletion nab-testbase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>${junit.version}</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ru.hh.nab.testbase;

import com.google.common.collect.Maps;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
Expand All @@ -25,7 +25,7 @@
public abstract class JerseyTest extends AbstractJUnit4SpringContextTests {

private static final Logger LOGGER = LoggerFactory.getLogger(JerseyTest.class);
private static final ConcurrentMap<Class<? extends JerseyTest>, Holder<Instance>> INSTANCES = Maps.newConcurrentMap();
private static final ConcurrentMap<Class<? extends JerseyTest>, Holder<Instance>> INSTANCES = new ConcurrentHashMap<>();

@Before
public void setUp() {
Expand Down
7 changes: 1 addition & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
</modules>

<properties>
<jdebug.version>0.0.23</jdebug.version>
<spring.version>5.0.3.RELEASE</spring.version>
<hibernate.version>5.2.10.Final</hibernate.version>
<junit.version>4.12</junit.version>
</properties>

<dependencyManagement>
Expand All @@ -34,11 +34,6 @@
<artifactId>hh-metrics</artifactId>
<version>0.12</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>${guice.version}</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
Expand Down