You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@geode.apache.org by "John Blum (Jira)" <ji...@apache.org> on 2020/06/09 23:23:00 UTC
[jira] [Commented] (GEODE-8235) Server should not be required to
have available a PDX type registry in ClientCache applications
[ https://issues.apache.org/jira/browse/GEODE-8235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17129885#comment-17129885 ]
John Blum commented on GEODE-8235:
----------------------------------
The following test case reproduces the problem:
{code:java}
@Test
public void jsonToPdxProcessingUsingApacheGeodeApi() {
ClientCache clientCache = null;
try {
Customer jonDoe = Customer.create(1L, "Jon Doe");
clientCache = new ClientCacheFactory().create();
Region<Object, Object> customers =
clientCache.createClientRegionFactory(ClientRegionShortcut.LOCAL)
.create("Customers");
String json = "{"
+ " \"@type\": \"example.app.model.Customer\","
+ " \"id\": 1,"
+ " \"name\": \"Jon Doe\""
+ "}";
PdxInstance pdxInstance = JSONFormatter.fromJSON(json);
customers.put(1, pdxInstance);
Object value = customers.get(1);
assertThat(value).isInstanceOf(PdxInstance.class);
assertThat(((PdxInstance) value).getObject()).isEqualTo(jonDoe);
}
finally {
Optional.ofNullable(clientCache).ifPresent(ClientCache::close);
}
}
{code}
The {{Customer}} class definition is simple:
{code:java}
package example.app.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
@Data
@ToString(of = "name")
@NoArgsConstructor
@AllArgsConstructor(staticName = "create")
public class Customer {
private Long id;
private String name;
}
{code}
While I do have a {{Customer}} class definition to match the JSON (Customer) object in this case, that is not always the case, but I also wanted to test another problem with {{PdxInstance.getObject()}}.
> Server should not be required to have available a PDX type registry in ClientCache applications
> -----------------------------------------------------------------------------------------------
>
> Key: GEODE-8235
> URL: https://issues.apache.org/jira/browse/GEODE-8235
> Project: Geode
> Issue Type: Bug
> Components: serialization
> Reporter: John Blum
> Priority: Major
>
> As application developer using Apache Geode, if I create a {{ClientCache}} application that contains client {{LOCAL}} (only) Regions (i.e. with {{ClientRegionShortcut.LOCAL}} and I attempt to store objects in PDX serialized form, then Geode will throw an Exception:
> ACTUAL:
> {code}
> Caused by: org.apache.geode.pdx.JSONFormatterException: Could not parse JSON document: [Source: (String)"{"@type":"example.app.model.Customer","id":1,"name":"Jon Doe"}"; line: 1, column: 63]
> at org.apache.geode.pdx.JSONFormatter.toPdxInstance(JSONFormatter.java:206) ~[geode-core-1.12.0.jar:na]
> at org.apache.geode.pdx.JSONFormatter.fromJSON(JSONFormatter.java:134) ~[geode-core-1.12.0.jar:na]
> at ...
> ... 39 common frames omitted
> Caused by: org.apache.geode.cache.CacheClosedException: Client pools have been closed so the PDX type registry is not available.
> at org.apache.geode.internal.cache.GemFireCacheImpl.getCacheClosedException(GemFireCacheImpl.java:1630) ~[geode-core-1.12.0.jar:na]
> at org.apache.geode.internal.cache.GemFireCacheImpl.getCacheClosedException(GemFireCacheImpl.java:1619) ~[geode-core-1.12.0.jar:na]
> at org.apache.geode.pdx.internal.ClientTypeRegistration.getAllPools(ClientTypeRegistration.java:153) ~[geode-core-1.12.0.jar:na]
> at org.apache.geode.pdx.internal.ClientTypeRegistration.defineType(ClientTypeRegistration.java:63) ~[geode-core-1.12.0.jar:na]
> at org.apache.geode.pdx.internal.TypeRegistry.defineType(TypeRegistry.java:202) ~[geode-core-1.12.0.jar:na]
> at org.apache.geode.pdx.internal.TypeRegistry.defineLocalType(TypeRegistry.java:250) ~[geode-core-1.12.0.jar:na]
> at org.apache.geode.pdx.internal.PdxWriterImpl.completeByteStreamGeneration(PdxWriterImpl.java:540) ~[geode-core-1.12.0.jar:na]
> at org.apache.geode.pdx.internal.PdxInstanceFactoryImpl.create(PdxInstanceFactoryImpl.java:64) ~[geode-core-1.12.0.jar:na]
> at org.apache.geode.pdx.internal.json.PdxInstanceHelper.endObjectField(PdxInstanceHelper.java:209) ~[geode-core-1.12.0.jar:na]
> at org.apache.geode.pdx.JSONFormatter.getPdxInstance(JSONFormatter.java:309) ~[geode-core-1.12.0.jar:na]
> at org.apache.geode.pdx.JSONFormatter.toPdxInstance(JSONFormatter.java:199) ~[geode-core-1.12.0.jar:na]
> ... 55 common frames omitted
> {code}
> First of all this is not even an appropriate Exception! {{CacheCloseException}} because my client had no open Pools to an available server with a PDX type registry.
> 1. Creating client local-only applications not connected to an entire cluster or server is a very useful and practical arrangement during development.
> 2. My application should not have to be a peer {{Cache}} to have an available PDX type registry to store PDX instances in client {{LOCAL}} Regions.
> 3. It is actually highly useful to run my application in local-only mode, in a local-only context (i.e. with only client {{LOCAL}} Regions) without a cluster or server for development, testing and debugging purposes.
> 4. It is also really useful if my application can also store PDX bytes, even in client {{LOCAL}} (only) Regions for development, testing and debugging purposes.
> Some find it hard to imagine why an application would want to do this, store PDX instead of POJOs. However, consider the fact that my application might be part of a larger Microservices architecture that communicate via a RESTful interfaces. They pass JSON back and forth, which might either be complex or unstructured. Either way, it is possible I don't have or don't want to create POJOs (types) matching the JSON that my Microservice consumes. I simply want access to certain bits of information which PDX is adequately suited for. These client LOCAL Regions might even be temporary. When connected, I might even want to share this data (or aggregated data) with Native Clients which most certainly won't have Java types matching the JSON content, raw or summarized.
> EXPECTED:
> As a developer using Apache Geode, I expected to be able to develop (primarily) {{ClientCache}} applications, run them locally with client {{LOCAL}} Regions, storing data in PDX format as necessary, all without requiring a complex setup (e.g. such as a cluster or a server).
--
This message was sent by Atlassian Jira
(v8.3.4#803005)