From e1bcd9b7bbd8ae01d79dae5fb28b257d0624d5a8 Mon Sep 17 00:00:00 2001 From: John McClean Date: Tue, 8 Nov 2016 13:12:30 +0000 Subject: [PATCH] pcollections support --- gradle.properties | 17 ++-- .../com/aol/micro/server/EventRunnerTest.java | 2 +- .../micro/server/{Job.java => EventsJob.java} | 2 +- .../{Schedular.java => EventsSchedular.java} | 6 +- .../event/metrics/MetricsCatcherTest.java | 2 +- micro-events/src/test/java/NoPackageTest.java | 2 +- micro-guava/build.gradle | 1 - micro-hibernate/build.gradle | 2 +- micro-jackson-configuration/build.gradle | 4 +- micro-jackson-configuration/readme.md | 2 + .../micro/server/jackson/JacksonPlugin.java | 27 ++++--- .../micro/server/rest/JacksonUtilTest.java | 79 +++++++++++-------- .../aol/micro/server/testing/RestAgent.java | 55 +++++++++++++ 13 files changed, 140 insertions(+), 61 deletions(-) rename micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/{Job.java => EventsJob.java} (88%) rename micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/{Schedular.java => EventsSchedular.java} (77%) create mode 100644 micro-log-streamer/src/test/java/com/aol/micro/server/testing/RestAgent.java diff --git a/gradle.properties b/gradle.properties index 19b31bb22..d37508cd1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,19 +1,20 @@ version=0.90 -springVersion=4.3.2.RELEASE -springBootVersion=1.4.0.RELEASE -jerseyVersion=2.23.2 -grizzlyVersion=2.3.26 +springVersion=4.3.3.RELEASE +springBootVersion=1.4.1.RELEASE +jerseyVersion=2.24 +grizzlyVersion=2.3.28 cyclopsReactVersion=1.0.2 cyclopsVersion=8.2.1 hamcrestVersion=1.3 hibernateVersion=5.1.0.Final hibernateValidator=5.2.4.Final -springDataJPA=1.10.1.RELEASE -guavaVersion=19.0 +springDataJPA=1.10.5.RELEASE +guavaVersion=20.0 javaslangDatatypeVersion=2.0.4 javaslangVersion=2.0.4 -jacksonVersion=2.6.3 -guavaDatatypeVersion=2.6.3 +jacksonVersion=2.8.4 +guavaDatatypeVersion=2.8.4 +pcollectionsDatatypeVersion=2.8.4 logbackVersion=1.1.3 slf4jVersion=1.7.13 aspectJVersion=1.8.7 diff --git a/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventRunnerTest.java b/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventRunnerTest.java index aade5414f..725080083 100644 --- a/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventRunnerTest.java +++ b/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventRunnerTest.java @@ -55,7 +55,7 @@ public void runAppAndBasicTest() throws InterruptedException, ExecutionException String json2 = rest.getJson("http://localhost:8080/event-app/status/meters"); Map map2 = JacksonUtil.convertFromJson(json2, Map.class); - assertThat(json2, map2.get("com.aol.micro.server.event.metrics.MetricsCatcher.request-start-default"), + assertThat(json2, map2.get("com.aol.micro.server.event.metrics.MetricsCatcher.request-start-default-meter"), greaterThan(0)); } diff --git a/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/Job.java b/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventsJob.java similarity index 88% rename from micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/Job.java rename to micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventsJob.java index 77baaba02..3f91e3bdf 100644 --- a/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/Job.java +++ b/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventsJob.java @@ -6,7 +6,7 @@ import com.aol.micro.server.events.SystemData; @Component -public class Job implements ScheduledJob { +public class EventsJob implements ScheduledJob { @Override public SystemData scheduleAndLog() { diff --git a/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/Schedular.java b/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventsSchedular.java similarity index 77% rename from micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/Schedular.java rename to micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventsSchedular.java index 5ad344799..6e672c690 100644 --- a/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/Schedular.java +++ b/micro-event-metrics/src/test/java/app/event/metrics/com/aol/micro/server/EventsSchedular.java @@ -5,12 +5,12 @@ import org.springframework.stereotype.Component; @Component -public class Schedular { +public class EventsSchedular { - private final Job job; + private final EventsJob job; @Autowired - public Schedular(final Job job) { + public EventsSchedular(final EventsJob job) { this.job = job; } diff --git a/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherTest.java b/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherTest.java index 81f0e11bb..03d9ef740 100644 --- a/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherTest.java +++ b/micro-event-metrics/src/test/java/com/aol/micro/server/event/metrics/MetricsCatcherTest.java @@ -41,7 +41,7 @@ public void queriesStartMeterInc() { .correlationId(10l) .type("test") .build())); - assertThat(registry.meter(this.config.getPrefix() + ".request-start-test") + assertThat(registry.meter(this.config.getPrefix() + ".request-start-test-meter") .getMeanRate(), greaterThan(0.0)); } diff --git a/micro-events/src/test/java/NoPackageTest.java b/micro-events/src/test/java/NoPackageTest.java index d3a965fea..ecbba48d0 100644 --- a/micro-events/src/test/java/NoPackageTest.java +++ b/micro-events/src/test/java/NoPackageTest.java @@ -11,6 +11,6 @@ public class NoPackageTest { @Test public void testPackageNone() { - assertThat(one.getType(NoPackageTest.class), equalTo("NoPackage")); + assertThat(one.getType(NoPackageTest.class), equalTo("NoPackageTest")); } } diff --git a/micro-guava/build.gradle b/micro-guava/build.gradle index dd6c45883..b32077166 100644 --- a/micro-guava/build.gradle +++ b/micro-guava/build.gradle @@ -2,7 +2,6 @@ description = 'micro-guava' dependencies { compile 'com.aol.cyclops:cyclops-guava:'+cyclopsVersion compile 'com.fasterxml.jackson.datatype:jackson-datatype-guava:'+guavaDatatypeVersion - compile project(':micro-core') compile project(':micro-jackson-configuration') testCompile project(':micro-grizzly') diff --git a/micro-hibernate/build.gradle b/micro-hibernate/build.gradle index ef945da2e..ba680dff1 100644 --- a/micro-hibernate/build.gradle +++ b/micro-hibernate/build.gradle @@ -5,7 +5,7 @@ dependencies { exclude group: 'org.jboss.logging' } compile 'javax.transaction:jta:'+jtaVersion - compile group: 'org.hibernate', name: 'hibernate-core', version:hibernateVersion + compile (group: 'org.hibernate', name: 'hibernate-core', version:hibernateVersion) compile group: 'org.hibernate', name: 'hibernate-entitymanager', version:hibernateVersion compile group: 'org.springframework', name: 'spring-orm', version:"${springVersion}" diff --git a/micro-jackson-configuration/build.gradle b/micro-jackson-configuration/build.gradle index b59394f63..e654033e4 100644 --- a/micro-jackson-configuration/build.gradle +++ b/micro-jackson-configuration/build.gradle @@ -1,6 +1,8 @@ description = 'micro-jackson-configuration' dependencies { - compile project(':micro-core') + // compile 'com.fasterxml.jackson.datatype:jackson-datatype-pcollections'+pcollectionsDatatypeVersion + compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-pcollections', version: '2.8.4' + compile project(':micro-core') } diff --git a/micro-jackson-configuration/readme.md b/micro-jackson-configuration/readme.md index 1927b1605..e399c7f91 100644 --- a/micro-jackson-configuration/readme.md +++ b/micro-jackson-configuration/readme.md @@ -5,6 +5,8 @@ Add Jackson Serialization to Microserver apps & add custom configurations as neccessary. +Includes serializers and deserializers for pCollections. + ## Configurable Properties properties = default diff --git a/micro-jackson-configuration/src/main/java/com/aol/micro/server/jackson/JacksonPlugin.java b/micro-jackson-configuration/src/main/java/com/aol/micro/server/jackson/JacksonPlugin.java index 619484bb8..5ada02d38 100644 --- a/micro-jackson-configuration/src/main/java/com/aol/micro/server/jackson/JacksonPlugin.java +++ b/micro-jackson-configuration/src/main/java/com/aol/micro/server/jackson/JacksonPlugin.java @@ -3,21 +3,28 @@ import com.aol.cyclops.data.collections.extensions.persistent.PSetX; import com.aol.micro.server.Plugin; import com.aol.micro.server.rest.jackson.JacksonFeature; +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.datatype.pcollections.PCollectionsModule; public class JacksonPlugin implements Plugin { - @Override - public PSetX> jaxRsResources() { + @Override + public PSetX> jaxRsResources() { - return PSetX.of(JacksonFeature.class); - - } + return PSetX.of(JacksonFeature.class); - @Override - public PSetX springClasses() { + } - return PSetX.of(CoreJacksonConfigurator.class,JacksonConfigurers.class); - - } + @Override + public PSetX springClasses() { + + return PSetX.of(CoreJacksonConfigurator.class, JacksonConfigurers.class); + + } + + @Override + public PSetX jacksonModules() { + return PSetX.of(new PCollectionsModule()); + } } diff --git a/micro-jackson-configuration/src/test/java/com/aol/micro/server/rest/JacksonUtilTest.java b/micro-jackson-configuration/src/test/java/com/aol/micro/server/rest/JacksonUtilTest.java index 9451f895b..ca1aedfaa 100644 --- a/micro-jackson-configuration/src/test/java/com/aol/micro/server/rest/JacksonUtilTest.java +++ b/micro-jackson-configuration/src/test/java/com/aol/micro/server/rest/JacksonUtilTest.java @@ -1,7 +1,8 @@ package com.aol.micro.server.rest; - import static junit.framework.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; import java.util.ArrayList; import java.util.List; @@ -12,38 +13,52 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; -import lombok.Getter; -import lombok.Setter; - import org.junit.Test; +import org.pcollections.ConsPStack; +import org.pcollections.PStack; +import com.aol.cyclops.data.collections.extensions.persistent.PStackX; import com.aol.micro.server.rest.jackson.JacksonUtil; +import lombok.Getter; +import lombok.Setter; public class JacksonUtilTest { - - - @Test - public void generateSampleRequest() { - - DummyQueryRequest request = new DummyQueryRequest(); - request.getData().add("blah"); - - assertTrue(JacksonUtil.serializeToJson(request).contains("strData")); - - } - - - @Test - public void serialiseAndDeserialise(){ - DummyQueryRequest request = new DummyQueryRequest(); - request.getData().add("blah"); - String requestStr = (String) JacksonUtil.serializeToJsonLogFailure(request); - DummyQueryRequest requestDeserialised = JacksonUtil.convertFromJson(requestStr, DummyQueryRequest.class); - assertTrue(request.getData().contains("blah")); - } - - + + @Test + public void generateSampleRequest() { + + DummyQueryRequest request = new DummyQueryRequest(); + request.getData() + .add("blah"); + + assertTrue(JacksonUtil.serializeToJson(request) + .contains("strData")); + + } + + @Test + public void serialiseAndDeserialise() { + DummyQueryRequest request = new DummyQueryRequest(); + request.getData() + .add("blah"); + String requestStr = (String) JacksonUtil.serializeToJsonLogFailure(request); + DummyQueryRequest requestDeserialised = JacksonUtil.convertFromJson(requestStr, DummyQueryRequest.class); + assertTrue(request.getData() + .contains("blah")); + } + + @Test + public void serializeToPStack() { + + PStackX list = PStackX.of(1, 2, 3, 4); + String jsonString = JacksonUtil.serializeToJson(list); + + PStack stack = JacksonUtil.convertFromJson(jsonString, ConsPStack.class); + + assertThat(stack, equalTo(list.reverse())); + } + } @XmlAccessorType(XmlAccessType.FIELD) @@ -51,11 +66,9 @@ public void serialiseAndDeserialise(){ @XmlType(name = "") class DummyQueryRequest { - @XmlElement(name = "strData") - @Getter - @Setter - private List data = new ArrayList(); + @XmlElement(name = "strData") + @Getter + @Setter + private List data = new ArrayList(); - } - diff --git a/micro-log-streamer/src/test/java/com/aol/micro/server/testing/RestAgent.java b/micro-log-streamer/src/test/java/com/aol/micro/server/testing/RestAgent.java new file mode 100644 index 000000000..ce204f810 --- /dev/null +++ b/micro-log-streamer/src/test/java/com/aol/micro/server/testing/RestAgent.java @@ -0,0 +1,55 @@ +package com.aol.micro.server.testing; + +import java.util.List; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import com.aol.micro.server.rest.jackson.JacksonUtil; + +public class RestAgent { + + + public String getJson(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.get(String.class); + + } + + public String get(String url) { + + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.TEXT_PLAIN); + + return request.get(String.class); + + } + + public T post(String url, Object payload,Class type) { + Client client = ClientBuilder.newClient(); + + WebTarget resource = client.target(url); + + Builder request = resource.request(); + request.accept(MediaType.APPLICATION_JSON); + + return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type); + } + + +}