Skip to content

Commit 4f2a10b

Browse files
authored
Merge pull request #3177 from mathieucarbou/json/master
Jackson => Gson
2 parents d0256d1 + cbabf9c commit 4f2a10b

File tree

5 files changed

+112
-43
lines changed

5 files changed

+112
-43
lines changed

clustered/ehcache-clustered/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ tasks.named('jar') {
107107
osgi {
108108
instruction Constants.BUNDLE_SYMBOLICNAME, 'org.ehcache.clustered'
109109
instruction Constants.EXPORT_PACKAGE, '!com.tc.*, !com.terracotta.*, !org.terracotta.*, !org.ehcache.*.internal.*, !sun.misc, org.ehcache.clustered.client.*, org.ehcache.clustered.common.*'
110-
instruction Constants.IMPORT_PACKAGE, '!sun.misc.*, org.ehcache.xml.*;resolution:=optional, jdk.jfr.*;resolution:=optional, !com.fasterxml.jackson.*, !org.terracotta.json, javax.xml.bind*;version="[2.2,3)", *'
110+
instruction Constants.IMPORT_PACKAGE, '!sun.misc.*, org.ehcache.xml.*;resolution:=optional, jdk.jfr.*;resolution:=optional, javax.xml.bind*;version="[2.2,3)", *'
111111
}
112112
}
113113

ehcache-management/build.gradle

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ dependencies {
4343

4444
testImplementation "org.terracotta.management:management-registry:$terracottaPlatformVersion"
4545
testImplementation project(':ehcache-xml')
46-
/*
47-
* Jackson BOMs are broken in a bunch of ways. One day we might be able to use the constraints provided through the
48-
* platform dependencies, today is not that day.
49-
*/
50-
testImplementation enforcedPlatform("com.fasterxml.jackson:jackson-bom:$jacksonVersion")
51-
testImplementation 'com.fasterxml.jackson.core:jackson-databind'
46+
testImplementation "org.terracotta.common:common-json-support:$terracottaPlatformVersion"
5247
testImplementation testFixtures(project(':ehcache-xml'))
5348
}

ehcache-management/src/test/java/org/ehcache/management/providers/settings/EhcacheSettingsProviderTest.java

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package org.ehcache.management.providers.settings;
1717

18-
import com.fasterxml.jackson.annotation.JsonIgnore;
19-
import com.fasterxml.jackson.databind.ObjectMapper;
2018
import org.ehcache.CacheManager;
2119
import org.ehcache.config.CacheConfiguration;
2220
import org.ehcache.config.builders.CacheConfigurationBuilder;
@@ -29,20 +27,23 @@
2927
import org.ehcache.management.registry.DefaultManagementRegistryConfiguration;
3028
import org.ehcache.management.registry.DefaultSharedManagementService;
3129
import org.junit.After;
32-
import org.junit.Before;
3330
import org.junit.ClassRule;
3431
import org.junit.Test;
3532
import org.junit.rules.TemporaryFolder;
3633
import org.junit.runner.RunWith;
3734
import org.junit.runners.JUnit4;
35+
import org.terracotta.json.DefaultJsonFactory;
36+
import org.terracotta.json.Json;
37+
import org.terracotta.json.gson.GsonModule;
3838
import org.terracotta.management.model.capabilities.Capability;
39-
import org.terracotta.management.model.capabilities.context.CapabilityContext;
39+
import org.terracotta.management.model.capabilities.descriptors.Descriptor;
4040

41-
import java.io.FileNotFoundException;
4241
import java.io.IOException;
42+
import java.net.URISyntaxException;
43+
import java.nio.charset.StandardCharsets;
44+
import java.nio.file.Files;
45+
import java.nio.file.Paths;
4346
import java.time.Duration;
44-
import java.util.Collection;
45-
import java.util.Scanner;
4647

4748
import static org.ehcache.config.builders.ResourcePoolsBuilder.newResourcePoolsBuilder;
4849
import static org.junit.Assert.assertEquals;
@@ -55,12 +56,10 @@ public class EhcacheSettingsProviderTest {
5556

5657
CacheManager cacheManager;
5758
SharedManagementService sharedManagementService = new DefaultSharedManagementService();
58-
ObjectMapper mapper = new ObjectMapper();
59-
60-
@Before
61-
public void before() {
62-
mapper.addMixIn(CapabilityContext.class, CapabilityContextMixin.class);
63-
}
59+
Json mapper = new DefaultJsonFactory()
60+
.withModule((GsonModule) config -> config.serializeSubtypes(Descriptor.class))
61+
.pretty()
62+
.create();
6463

6564
@After
6665
public void after() {
@@ -70,7 +69,7 @@ public void after() {
7069
}
7170

7271
@Test
73-
public void test_standalone_ehcache() throws IOException {
72+
public void test_standalone_ehcache() throws IOException, URISyntaxException {
7473
CacheConfiguration<String, String> cacheConfiguration1 = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
7574
newResourcePoolsBuilder()
7675
.heap(10, EntryUnit.ENTRIES)
@@ -103,12 +102,9 @@ public void test_standalone_ehcache() throws IOException {
103102

104103
cacheManager.init();
105104

106-
String expected = read("/settings-capability.json")
107-
.replaceAll("instance-id", serviceConfiguration.getInstanceId());
108-
String actual = mapper.writeValueAsString(getSettingsCapability())
109-
.replaceAll("\\\"cacheManagerDescription\\\":\\\".*\\\",\\\"instanceId\\\"", "\\\"cacheManagerDescription\\\":\\\"\\\",\\\"instanceId\\\"")
110-
.replaceAll("\\\"instanceId\\\":\\\".*\\\",\\\"managementContext\\\"", "\\\"instanceId\\\":\\\"UUID\\\",\\\"managementContext\\\"")
111-
.replaceAll("\\\"instanceId\\\":\\\".*\\\",\\\"cacheManagerName\\\"", "\\\"instanceId\\\":\\\"UUID\\\",\\\"cacheManagerName\\\"");
105+
String expected = read("/settings-capability.json").trim();
106+
String actual = mapper.toString(getSettingsCapability())
107+
.replaceAll("\"instanceId\": \"[0-9a-f-]+\"", "\"instanceId\": \"\"");
112108

113109
// assertThat for formatted string comparison: ide support is bad
114110
assertEquals(expected, actual);
@@ -123,18 +119,8 @@ private Capability getSettingsCapability() {
123119
throw new AssertionError();
124120
}
125121

126-
private String read(String path) throws FileNotFoundException {
127-
try (Scanner scanner = new Scanner(getClass().getResourceAsStream(path), "UTF-8")) {
128-
return scanner.nextLine();
129-
}
122+
private String read(String resource) throws IOException, URISyntaxException {
123+
return new String(Files.readAllBytes(Paths.get(getClass().getResource(resource).toURI())), StandardCharsets.UTF_8)
124+
.replaceAll("\r", "");
130125
}
131-
132-
public static abstract class CapabilityContextMixin {
133-
@JsonIgnore
134-
public abstract Collection<String> getRequiredAttributeNames();
135-
136-
@JsonIgnore
137-
public abstract Collection<CapabilityContext.Attribute> getRequiredAttributes();
138-
}
139-
140126
}
Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,90 @@
1-
{"name":"SettingsCapability","descriptors":[{"cacheName":"cache-1","keyType":"java.lang.String","valueType":"java.lang.String","resourcePools":{"heap":{"level":10000,"persistent":false,"type":"ENTRY","size":10,"unit":"entries"},"offheap":{"level":1000,"persistent":false,"type":"MEMORY","size":1,"unit":"MB"},"disk":{"level":100,"persistent":true,"type":"MEMORY","size":2,"unit":"MB"}}},{"cacheName":"cache-2","keyType":"java.lang.String","valueType":"java.lang.String","resourcePools":{"heap":{"level":10000,"persistent":false,"type":"ENTRY","size":10,"unit":"entries"},"offheap":{"level":1000,"persistent":false,"type":"MEMORY","size":1,"unit":"MB"},"disk":{"level":100,"persistent":true,"type":"MEMORY","size":2,"unit":"MB"}}},{"cacheManagerDescription":"","instanceId":"UUID","cacheManagerName":"my-cm-1"},"tags":["baz","boo","foo"]}],"capabilityContext":{"attributes":[{"name":"instanceId","required":true},{"name":"cacheManagerName","required":true},{"name":"cacheName","required":true}]}}
1+
{
2+
"capabilityContext": {
3+
"attributes": [
4+
{
5+
"name": "instanceId",
6+
"required": true
7+
},
8+
{
9+
"name": "cacheManagerName",
10+
"required": true
11+
},
12+
{
13+
"name": "cacheName",
14+
"required": true
15+
}
16+
]
17+
},
18+
"descriptors": [
19+
{
20+
"cacheName": "cache-1",
21+
"keyType": "java.lang.String",
22+
"resourcePools": {
23+
"disk": {
24+
"level": 100,
25+
"persistent": true,
26+
"size": 2,
27+
"type": "MEMORY",
28+
"unit": "MB"
29+
},
30+
"heap": {
31+
"level": 10000,
32+
"persistent": false,
33+
"size": 10,
34+
"type": "ENTRY",
35+
"unit": "entries"
36+
},
37+
"offheap": {
38+
"level": 1000,
39+
"persistent": false,
40+
"size": 1,
41+
"type": "MEMORY",
42+
"unit": "MB"
43+
}
44+
},
45+
"valueType": "java.lang.String"
46+
},
47+
{
48+
"cacheName": "cache-2",
49+
"keyType": "java.lang.String",
50+
"resourcePools": {
51+
"disk": {
52+
"level": 100,
53+
"persistent": true,
54+
"size": 2,
55+
"type": "MEMORY",
56+
"unit": "MB"
57+
},
58+
"heap": {
59+
"level": 10000,
60+
"persistent": false,
61+
"size": 10,
62+
"type": "ENTRY",
63+
"unit": "entries"
64+
},
65+
"offheap": {
66+
"level": 1000,
67+
"persistent": false,
68+
"size": 1,
69+
"type": "MEMORY",
70+
"unit": "MB"
71+
}
72+
},
73+
"valueType": "java.lang.String"
74+
},
75+
{
76+
"cacheManagerDescription": "caches:\n cache-1:\n keyType: java.lang.String\n valueType: java.lang.String\n serviceConfigurations: None\n evictionAdvisor: None\n expiry: No Expiry\n resourcePools: \n pools: \n heap: \n size: 10 entries \n tierHeight: 10000\n offheap: \n size: 1 MB \n tierHeight: 1000\n disk: \n size: 2 MB (persistent)\n tierHeight: 100\n cache-2:\n keyType: java.lang.String\n valueType: java.lang.String\n serviceConfigurations: None\n evictionAdvisor: None\n expiry: TTI of PT2H\n resourcePools: \n pools: \n heap: \n size: 10 entries \n tierHeight: 10000\n offheap: \n size: 1 MB \n tierHeight: 1000\n disk: \n size: 2 MB (persistent)\n tierHeight: 100\nservices: \n - org.ehcache.impl.config.persistence.DefaultPersistenceConfiguration\n - org.ehcache.management.registry.DefaultManagementRegistryConfiguration",
77+
"instanceId": "",
78+
"managementContext": {
79+
"cacheManagerName": "my-cm-1",
80+
"instanceId": ""
81+
},
82+
"tags": [
83+
"baz",
84+
"boo",
85+
"foo"
86+
]
87+
}
88+
],
89+
"name": "SettingsCapability"
90+
}

gradle.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ slf4jVersion = 1.7.36
99
sizeofVersion = 0.4.3
1010

1111
# Terracotta clustered
12-
terracottaPlatformVersion = 5.10.17
12+
terracottaPlatformVersion = 5.10.18
1313
terracottaApisVersion = 1.9.0
1414
terracottaCoreVersion = 5.10.14
1515
terracottaPassthroughTestingVersion = 1.9.0
@@ -20,7 +20,6 @@ junitVersion = 4.13.1
2020
assertjVersion = 3.22.0
2121
hamcrestVersion = 2.2
2222
mockitoVersion = 4.3.1
23-
jacksonVersion = 2.13.4
2423
jcacheTckVersion = 1.1.0
2524

2625
sonatypeUser = OVERRIDE_ME

0 commit comments

Comments
 (0)