0.4.0 release (#50)

This commit is contained in:
Pavel Popov 2017-06-22 18:14:09 +03:00 committed by GitHub
parent d0b8128308
commit ab86104b0a
15 changed files with 137 additions and 42 deletions

2
Jenkinsfile vendored
View File

@ -8,6 +8,6 @@ build('geck', 'docker-host') {
javaLibPipeline = load("build_utils/jenkins_lib/pipeJavaLib.groovy")
}
def buildImageTag = "3750c129119b83ea399dc4aa0ed923fb0e3bf0f0"
def buildImageTag = "4799280a02cb73761a3ba3641285aac8ec4ec482"
javaLibPipeline(buildImageTag)
}

View File

@ -2,16 +2,20 @@
Набор инструментов для сериализации, миграции, фильтрации и генерации **thrift**-овых объектов.
![default](https://cloud.githubusercontent.com/assets/5084395/23034038/cf7e5eb0-f493-11e6-8698-66262306ca81.png)
### В комплекте ```нужное зачеркнуть```:
## В комплекте:
- serializer (msgpack, jolt, thrift, xml, json)
- mock
- ~~migrator~~
- ~~filter~~
- migrator
- filter
## Выпуск новой версии
Версии _geck-pom_ и всех его модулей должны совпадать, для этого перед началом работы над новой версией библиотеки нужно увеличить версию _geck-pom_ и в корневой директории проекта выполнить команду:
`mvn versions:update-child-modules -DgenerateBackupPoms=false`
Параметр `generateBackupPoms` можно опустить, если нужны резервные копии изменяемых файлов.
### HOW-TO
## HOW-TO
Собрать и инсталировать jar(s) в локальный мавен репозиторий(без локально установленного трифта):
* make wc_java_install LOCAL_BUILD=true SETTINGS_XML=path_to_rbk_maven_settings
```
make wc_java_install LOCAL_BUILD=true SETTINGS_XML=path_to_rbk_maven_settings
```

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.rbkmoney.geck</groupId>
<artifactId>parent</artifactId>
<version>0.3.0-SNAPSHOT</version>
<version>0.4.0</version>
</parent>
<artifactId>common</artifactId>

View File

@ -13,7 +13,6 @@ import java.util.stream.Collectors;
/**
* Created by vpankrashkin on 22.03.17.
* Based on http://stackoverflow.com/a/15519745/3007501
*/

View File

@ -28,7 +28,7 @@ public final class ObjectCache<T> {
/**
* @param updateDelay use -1 to disable delay, use 0 to always update, greater than 0 to set fixed delay
* */
*/
public ObjectCache(Supplier<T> cacheCreator, long updateDelay) {
Objects.requireNonNull(cacheCreator);
this.cacheCreator = cacheCreator;

View File

@ -2,10 +2,12 @@ package com.rbkmoney.geck.common.util;
import org.apache.thrift.TBase;
import org.apache.thrift.TFieldIdEnum;
import org.apache.thrift.TUnion;
import org.apache.thrift.meta_data.FieldMetaData;
import org.apache.thrift.meta_data.FieldValueMetaData;
import java.util.Map;
import java.util.Objects;
/**
* Created by tolkonepiu on 08/02/2017.
@ -40,4 +42,9 @@ public class TBaseUtil {
return size;
}
public static <T extends Enum<T>> T unionFieldToEnum(TUnion union, Class<T> enumType) {
Objects.requireNonNull(union, "Union must be set");
return Enum.valueOf(enumType, union.getSetField().getFieldName());
}
}

View File

@ -1,5 +1,9 @@
package com.rbkmoney.geck.common.util;
import java.time.DateTimeException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
@ -12,6 +16,26 @@ public class TypeUtil {
private static final DateTimeFormatter FORMATTER = ISO_INSTANT;
public static LocalDateTime stringToLocalDateTime(String dateTimeStr) throws IllegalArgumentException {
return stringToLocalDateTime(dateTimeStr, ZoneOffset.UTC);
}
public static LocalDateTime stringToLocalDateTime(String dateTimeStr, ZoneOffset zoneOffset) throws IllegalArgumentException {
try {
return LocalDateTime.ofInstant(stringToInstant(dateTimeStr), zoneOffset);
} catch (DateTimeException e) {
throw new IllegalArgumentException("Failed to convert in LocalDateTime: " + dateTimeStr, e);
}
}
public static Instant stringToInstant(String dateTimeStr) throws IllegalArgumentException {
try {
return Instant.from(stringToTemporal(dateTimeStr));
} catch (DateTimeException e) {
throw new IllegalArgumentException("Failed to convert in Instant: " + dateTimeStr, e);
}
}
public static TemporalAccessor stringToTemporal(String dateTimeStr) throws IllegalArgumentException {
try {
return FORMATTER.parse(dateTimeStr);
@ -20,6 +44,14 @@ public class TypeUtil {
}
}
public static String temporalToString(LocalDateTime localDateTime) throws IllegalArgumentException {
return temporalToString(localDateTime.toInstant(ZoneOffset.UTC));
}
public static String temporalToString(LocalDateTime localDateTime, ZoneOffset zoneOffset) throws IllegalArgumentException {
return temporalToString(localDateTime.toInstant(zoneOffset));
}
public static String temporalToString(TemporalAccessor temporalAccessor) throws IllegalArgumentException {
try {
return FORMATTER.format(temporalAccessor);

View File

@ -0,0 +1,57 @@
package com.rbkmoney.geck.common.util;
import org.junit.Test;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import static org.junit.Assert.assertEquals;
/**
* Created by tolkonepiu on 22/06/2017.
*/
public class TypeUtilTest {
String dateTime = "2017-06-19T10:21:09.539909Z";
LocalDateTime localDateTime = LocalDateTime.of(
2017, 6, 19, 10, 21, 9, 539909 * 1000
);
@Test
public void stringToLocalDateTimeTest() {
assertEquals(localDateTime, TypeUtil.stringToLocalDateTime(dateTime));
}
@Test
public void stringToLocalDateTimeWithNonUTCOffsetTest() {
assertEquals(localDateTime.plusHours(17).plusMinutes(55),
TypeUtil.stringToLocalDateTime(dateTime, ZoneOffset.of("+17:55")));
}
@Test
public void stringToInstantTest() {
assertEquals(localDateTime.toInstant(ZoneOffset.UTC), TypeUtil.stringToInstant(dateTime));
}
@Test
public void localDateTimeToStringTest() {
assertEquals(TypeUtil.temporalToString(localDateTime), dateTime);
}
@Test(expected = IllegalArgumentException.class)
public void byteOverflowTest() {
TypeUtil.toByteExact(Byte.MAX_VALUE + 1);
}
@Test(expected = IllegalArgumentException.class)
public void shortOverflowTest() {
TypeUtil.toShortExact(Short.MAX_VALUE + 1);
}
@Test(expected = IllegalArgumentException.class)
public void intOverflowTest() {
TypeUtil.toIntExact((long) Integer.MAX_VALUE + 1);
}
}

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.rbkmoney.geck</groupId>
<artifactId>parent</artifactId>
<version>0.2.0-SNAPSHOT</version>
<version>0.4.0</version>
</parent>
<artifactId>filter</artifactId>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.rbkmoney.geck</groupId>
<artifactId>parent</artifactId>
<version>0.2.0-SNAPSHOT</version>
<version>0.4.0</version>
</parent>
<artifactId>migrator</artifactId>

12
pom.xml
View File

@ -12,7 +12,7 @@
<groupId>com.rbkmoney.geck</groupId>
<artifactId>parent</artifactId>
<version>0.4.0-SNAPSHOT</version>
<version>0.4.0</version>
<packaging>pom</packaging>
<modules>
@ -47,12 +47,12 @@
<dependency>
<groupId>com.rbkmoney.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>0.9.3-4</version>
<version>0.9.3-5</version>
</dependency>
<dependency>
<groupId>org.msgpack</groupId>
<artifactId>msgpack-core</artifactId>
<version>0.8.11</version>
<version>0.8.13</version>
</dependency>
<dependency>
<groupId>net.sf.trove4j</groupId>
@ -74,12 +74,6 @@
<artifactId>reflections</artifactId>
<version>0.9.11</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

View File

@ -7,7 +7,7 @@
<parent>
<groupId>com.rbkmoney.geck</groupId>
<artifactId>parent</artifactId>
<version>0.3.0-SNAPSHOT</version>
<version>0.4.0</version>
</parent>
<artifactId>serializer</artifactId>
@ -48,11 +48,6 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>damsel</artifactId>

View File

@ -1,6 +1,5 @@
package com.rbkmoney.geck.serializer;
import com.rbkmoney.geck.serializer.test.TestObject;
import com.rbkmoney.geck.serializer.handler.HandlerStub;
import com.rbkmoney.geck.serializer.kit.msgpack.MsgPackHandler;
import com.rbkmoney.geck.serializer.kit.msgpack.MsgPackProcessor;
@ -9,6 +8,7 @@ import com.rbkmoney.geck.serializer.kit.object.ObjectProcessor;
import com.rbkmoney.geck.serializer.kit.tbase.TBaseHandler;
import com.rbkmoney.geck.serializer.kit.tbase.TBaseProcessor;
import com.rbkmoney.geck.serializer.test.Status;
import com.rbkmoney.geck.serializer.test.TestObject;
import com.rbkmoney.geck.serializer.test.Unknown;
import org.apache.thrift.TException;
import org.apache.thrift.TSerializer;
@ -26,7 +26,6 @@ import java.util.zip.GZIPOutputStream;
import static com.rbkmoney.geck.serializer.GeckTestUtil.getTestObject;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Created by tolkonepiu on 25/01/2017.

View File

@ -1,12 +1,13 @@
package com.rbkmoney.geck.serializer;
import com.rbkmoney.damsel.v130.payment_processing.InvoicePaymentStarted;
import com.rbkmoney.geck.serializer.test.Status;
import com.rbkmoney.geck.serializer.test.TestObject;
import com.rbkmoney.geck.serializer.kit.mock.MockTBaseProcessor;
import com.rbkmoney.geck.serializer.kit.tbase.TBaseHandler;
import com.rbkmoney.geck.serializer.test.Status;
import com.rbkmoney.geck.serializer.test.TestObject;
import java.io.IOException;
import java.util.*;
import java.util.List;
import java.util.function.IntFunction;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

View File

@ -2,6 +2,7 @@ package com.rbkmoney.geck.serializer.kit.damsel;
import com.bazaarvoice.jolt.Chainr;
import com.bazaarvoice.jolt.JsonUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rbkmoney.damsel.v113.domain.Invoice;
import com.rbkmoney.damsel.v113.payment_processing.*;
import com.rbkmoney.damsel.v130.payment_processing.InvoicePaymentStarted;
@ -18,36 +19,40 @@ import com.rbkmoney.geck.serializer.kit.tbase.TBaseHandler;
import com.rbkmoney.geck.serializer.kit.tbase.TBaseProcessor;
import com.rbkmoney.geck.serializer.kit.xml.XMLHandler;
import com.rbkmoney.geck.serializer.kit.xml.XMLProcessor;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;
import javax.xml.transform.*;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* Created by inalarsanukaev on 22.02.17.
*/
public class DamselTest {
@Test
public void jsonInvoiceTest() throws JSONException, IOException {
public void jsonInvoiceTest() throws IOException {
//com.rbkmoney.damsel.v113.payment_processing.InvoicePaymentStarted invoice = new MockTBaseProcessor().process(new com.rbkmoney.damsel.v113.payment_processing.InvoicePaymentStarted(), new TBaseHandler<>(com.rbkmoney.damsel.v113.payment_processing.InvoicePaymentStarted.class));
com.rbkmoney.damsel.v130.payment_processing.InvoicePaymentStarted invoice = new MockTBaseProcessor().process(new com.rbkmoney.damsel.v130.payment_processing.InvoicePaymentStarted(), new TBaseHandler<>(com.rbkmoney.damsel.v130.payment_processing.InvoicePaymentStarted.class));
String json = new TBaseProcessor().process(invoice, new JsonHandler()).toString();
System.out.println(json);
new JSONObject(json);
new ObjectMapper().readTree(json);
}
@Test
public void xmlInvoiceTest() throws Exception {
com.rbkmoney.damsel.v130.payment_processing.InvoicePaymentStarted invoice = new MockTBaseProcessor(MockMode.ALL, new FixedValueGenerator()).process(new com.rbkmoney.damsel.v130.payment_processing.InvoicePaymentStarted(), new TBaseHandler<>(com.rbkmoney.damsel.v130.payment_processing.InvoicePaymentStarted.class));
String xml = new TBaseProcessor().process(invoice, new XMLHandler()).toString();
System.out.println(xml);
}
@Test
public void testInvoiceMsgPack() throws IOException {
InvoicePaymentStarted invoice = GeckTestUtil.getInvoicePaymentStarted();
@ -69,6 +74,7 @@ public class DamselTest {
new TBaseHandler<>(InvoicePaymentStarted.class));
Assert.assertEquals(invoice1, invoice2);
}
@Test
public void testInvoiceBackTransform2() throws IOException {
InvoicePaymentStarted invoice1 = GeckTestUtil.getInvoicePaymentStarted();
@ -151,8 +157,9 @@ public class DamselTest {
Object inputJSON_v113 = JsonUtils.jsonToObject(json_v113);
System.out.println(json_v113);
Assert.assertEquals(inputJSON_v113,transformedOutput);
Assert.assertEquals(inputJSON_v113, transformedOutput);
}
@Test
public void testXslt() throws IOException, TransformerException {
com.rbkmoney.damsel.v130.payment_processing.InvoicePaymentStarted invoice_v130 =
@ -163,7 +170,7 @@ public class DamselTest {
TransformerFactory factory = TransformerFactory.newInstance();
Source xslt = new StreamSource(this.getClass().getResourceAsStream("/transform.xslt"));
Transformer transformer = factory.newTransformer(xslt);
// StringWriter string_v130 = new StringWriter();
// StringWriter string_v130 = new StringWriter();
DOMResult domResult_t_v113 = new DOMResult();
transformer.transform(new DOMSource(domResult_v130.getNode()), domResult_t_v113);
com.rbkmoney.damsel.v113.payment_processing.InvoicePaymentStarted invoice_t_v113 =