This is an automated email from the ASF dual-hosted git repository.
dschneider pushed a commit to branch feature/GEODE-6414
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/feature/GEODE-6414 by this
push:
new 4a1db9b TypeRegistry defineType will now return an existing PdxType
that it finds or the new type it defined.
4a1db9b is described below
commit 4a1db9ba61202973f1a66855e650d7a5b9f0d43d
Author: Darrel Schneider <[email protected]>
AuthorDate: Fri Feb 15 10:41:41 2019 -0800
TypeRegistry defineType will now return an existing PdxType that
it finds or the new type it defined.
---
.../geode/pdx/PdxInstanceFactoryJUnitTest.java | 14 ++++++++++
.../tier/sockets/command/GetPDXIdForType.java | 3 ++-
.../apache/geode/pdx/internal/PdxWriterImpl.java | 3 ++-
.../apache/geode/pdx/internal/TypeRegistry.java | 31 +++++++++++-----------
4 files changed, 34 insertions(+), 17 deletions(-)
diff --git
a/geode-core/src/integrationTest/java/org/apache/geode/pdx/PdxInstanceFactoryJUnitTest.java
b/geode-core/src/integrationTest/java/org/apache/geode/pdx/PdxInstanceFactoryJUnitTest.java
index 5e850f0..a94aa58 100644
---
a/geode-core/src/integrationTest/java/org/apache/geode/pdx/PdxInstanceFactoryJUnitTest.java
+++
b/geode-core/src/integrationTest/java/org/apache/geode/pdx/PdxInstanceFactoryJUnitTest.java
@@ -1424,4 +1424,18 @@ public class PdxInstanceFactoryJUnitTest {
assertThat(jsonPdxInstance.isDeserializable()).isTrue();
}
+
+ @Test
+ public void twoPdxInstancesWithTheSameClassAndFieldsHaveTheSamePdxType() {
+ PdxInstanceFactory factory = cache.createPdxInstanceFactory("className");
+ factory.writeString("fieldOne", "valueOne");
+ factory.writeString("fieldTwo", "valueTwo");
+ PdxInstanceImpl instance1 = (PdxInstanceImpl) factory.create();
+ factory = cache.createPdxInstanceFactory("className");
+ factory.writeString("fieldOne", "valueOne");
+ factory.writeString("fieldTwo", "valueTwo");
+ PdxInstanceImpl instance2 = (PdxInstanceImpl) factory.create();
+
+ assertThat(instance1.getPdxType()).isSameAs(instance2.getPdxType());
+ }
}
diff --git
a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/command/GetPDXIdForType.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/command/GetPDXIdForType.java
index dd9c8b9..57e6e4c 100644
---
a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/command/GetPDXIdForType.java
+++
b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/command/GetPDXIdForType.java
@@ -61,7 +61,8 @@ public class GetPDXIdForType extends BaseCommand {
try {
InternalCache cache = serverConnection.getCache();
TypeRegistry registry = cache.getPdxRegistry();
- pdxId = registry.defineType(type);
+ PdxType pdxType = registry.defineType(type);
+ pdxId = pdxType.getTypeId();
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
serverConnection.setAsTrue(RESPONDED);
diff --git
a/geode-core/src/main/java/org/apache/geode/pdx/internal/PdxWriterImpl.java
b/geode-core/src/main/java/org/apache/geode/pdx/internal/PdxWriterImpl.java
index dfe142f..9c9cdbc 100644
--- a/geode-core/src/main/java/org/apache/geode/pdx/internal/PdxWriterImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/pdx/internal/PdxWriterImpl.java
@@ -533,7 +533,8 @@ public class PdxWriterImpl implements PdxWriter {
// We created a new type that had unreadData.
// In this case we don't define a local type
// but we do set the serialized type.
- typeId = this.tr.defineType(newType);
+ this.newType = this.tr.defineType(newType);
+ typeId = this.newType.getTypeId();
this.unreadData.setSerializedType(newType);
} else {
this.newType = this.tr.defineLocalType(this.pdx, newType);
diff --git
a/geode-core/src/main/java/org/apache/geode/pdx/internal/TypeRegistry.java
b/geode-core/src/main/java/org/apache/geode/pdx/internal/TypeRegistry.java
index f0085c1..f388969 100644
--- a/geode-core/src/main/java/org/apache/geode/pdx/internal/TypeRegistry.java
+++ b/geode-core/src/main/java/org/apache/geode/pdx/internal/TypeRegistry.java
@@ -186,30 +186,32 @@ public class TypeRegistry {
/**
* Create a type id for a type that may come locally, or from a remote
member.
+ *
+ * @return the existing type or the new type
*/
- public int defineType(PdxType newType) {
+ public PdxType defineType(PdxType newType) {
Integer existingId = this.typeToId.get(newType);
if (existingId != null) {
- int eid = existingId;
- newType.setTypeId(eid);
- return eid;
+ return this.idToType.get(existingId);
}
int id = this.distributedTypeRegistry.defineType(newType);
- newType.setTypeId(id);
PdxType oldType = this.idToType.get(id);
if (oldType == null) {
+ newType.setTypeId(id);
this.idToType.put(id, newType);
this.typeToId.put(newType, id);
if (logger.isInfoEnabled()) {
logger.info("Caching {}", newType.toFormattedString());
}
- } else if (!oldType.equals(newType)) {
- Assert.fail("Old type does not equal new type for the same id. oldType="
+ oldType
- + " new type=" + newType);
+ return newType;
+ } else {
+ if (!oldType.equals(newType)) {
+ Assert.fail("Old type does not equal new type for the same id.
oldType=" + oldType
+ + " new type=" + newType);
+ }
+ return oldType;
}
-
- return id;
}
public void addRemoteType(int typeId, PdxType newType) {
@@ -236,14 +238,13 @@ public class TypeRegistry {
if (t != null) {
return t;
}
- defineType(newType);
- this.localTypeIds.put(o.getClass(), newType);
+ PdxType existingType = defineType(newType);
+ this.localTypeIds.put(o.getClass(), existingType);
+ return existingType;
} else {
// Defining a type for PdxInstanceFactory.
- defineType(newType);
+ return defineType(newType);
}
-
- return newType;
}
public TypeRegistration getTypeRegistration() {