use of org.apache.geode.pdx.internal.TypeRegistry in project geode by apache.
the class PdxSerializableJUnitTest method testFieldInsert.
@Test
public void testFieldInsert() throws Exception {
MyEvolvablePdx.setVersion(1);
MyEvolvablePdx pdx = new MyEvolvablePdx(7);
assertEquals(7, pdx.f1);
assertEquals(0, pdx.f2);
MyEvolvablePdx.setVersion(3);
pdx = new MyEvolvablePdx(7);
assertEquals(7, pdx.f1);
assertEquals(8, pdx.f2);
byte[] v3actual = createBlob(pdx);
int v3typeId = getBlobPdxTypeId(v3actual);
c.getPdxRegistry().removeLocal(pdx);
MyEvolvablePdx.setVersion(1);
MyEvolvablePdx pdxv1 = deblob(v3actual);
assertEquals(7, pdxv1.f1);
assertEquals(0, pdxv1.f2);
int numPdxTypes = getNumPdxTypes();
// now reserialize and make sure f2 is preserved
byte[] v1actual = createBlob(pdxv1);
int mergedTypeId = getBlobPdxTypeId(v1actual);
assertEquals(numPdxTypes + 1, getNumPdxTypes());
TypeRegistry tr = c.getPdxRegistry();
PdxType v3Type = tr.getType(v3typeId);
PdxType mergedType = tr.getType(mergedTypeId);
assertFalse(mergedType.equals(v3Type));
assertTrue(mergedType.compatible(v3Type));
MyEvolvablePdx.setVersion(3);
c.getPdxRegistry().removeLocal(pdxv1);
MyEvolvablePdx pdxv3 = deblob(v1actual);
assertEquals(7, pdxv3.f1);
assertEquals(8, pdxv3.f2);
}
use of org.apache.geode.pdx.internal.TypeRegistry in project geode by apache.
the class PdxSerializableJUnitTest method testFieldRemove.
@Test
public void testFieldRemove() throws Exception {
// this test pretends that version 1 is newer than version2
// so it look like a field was removed.
MyEvolvablePdx.setVersion(1);
MyEvolvablePdx pdx = new MyEvolvablePdx(7);
assertEquals(7, pdx.f1);
assertEquals(0, pdx.f2);
byte[] v1actual = createBlob(pdx);
int v1typeId = getBlobPdxTypeId(v1actual);
c.getPdxRegistry().removeLocal(pdx);
MyEvolvablePdx.setVersion(2);
MyEvolvablePdx pdxv2 = deblob(v1actual);
assertEquals(7, pdxv2.f1);
assertEquals(0, pdxv2.f2);
pdxv2.f2 = 23;
int numPdxTypes = getNumPdxTypes();
// now reserialize and make sure it is version2 and not version1
byte[] v2actual = createBlob(pdxv2);
int v2typeId = getBlobPdxTypeId(v2actual);
assertEquals(numPdxTypes + 1, getNumPdxTypes());
TypeRegistry tr = c.getPdxRegistry();
PdxType v2Type = tr.getType(v2typeId);
PdxType v1Type = tr.getType(v1typeId);
assertFalse(v1Type.equals(v2Type));
assertFalse(v1Type.compatible(v2Type));
assertNotNull(v1Type.getPdxField("f1"));
assertNull(v1Type.getPdxField("f2"));
assertNotNull(v2Type.getPdxField("f1"));
assertNotNull(v2Type.getPdxField("f2"));
MyEvolvablePdx.setVersion(1);
c.getPdxRegistry().removeLocal(pdx);
MyEvolvablePdx pdxv3 = deblob(v2actual);
assertEquals(7, pdxv3.f1);
assertEquals(0, pdxv3.f2);
}
use of org.apache.geode.pdx.internal.TypeRegistry in project geode by apache.
the class DataTypeJUnitTest method getDataTypeShouldReturnUnknownIfPDXTypeIsNull.
@Test
public void getDataTypeShouldReturnUnknownIfPDXTypeIsNull() throws IOException {
int somePdxTypeInt = 1;
PdxType somePdxType = null;
TypeRegistry mockTypeRegistry = mock(TypeRegistry.class);
when(mockTypeRegistry.getType(somePdxTypeInt)).thenReturn(somePdxType);
GemFireCacheImpl pdxInstance = mock(GemFireCacheImpl.class);
when(pdxInstance.getPdxRegistry()).thenReturn(mockTypeRegistry);
PowerMockito.mockStatic(GemFireCacheImpl.class);
when(GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed.")).thenReturn(pdxInstance);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos);
out.writeByte(DSCODE.PDX);
out.writeInt(somePdxTypeInt);
byte[] bytes = baos.toByteArray();
String type = DataType.getDataType(bytes);
assertThat(type).isEqualTo("org.apache.geode.pdx.PdxInstance: unknown id=" + somePdxTypeInt);
}
use of org.apache.geode.pdx.internal.TypeRegistry in project geode by apache.
the class DataTypeJUnitTest method getDataTypeShouldReturnPDXType.
@Test
public void getDataTypeShouldReturnPDXType() throws IOException {
int somePdxTypeInt = 1;
PdxType somePdxType = mock(PdxType.class);
doReturn("PDXType").when(somePdxType).getClassName();
TypeRegistry mockTypeRegistry = mock(TypeRegistry.class);
when(mockTypeRegistry.getType(somePdxTypeInt)).thenReturn(somePdxType);
GemFireCacheImpl pdxInstance = mock(GemFireCacheImpl.class);
when(pdxInstance.getPdxRegistry()).thenReturn(mockTypeRegistry);
PowerMockito.mockStatic(GemFireCacheImpl.class);
when(GemFireCacheImpl.getForPdx(anyString())).thenReturn(pdxInstance);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos);
out.writeByte(DSCODE.PDX);
out.writeInt(somePdxTypeInt);
byte[] bytes = baos.toByteArray();
String type = DataType.getDataType(bytes);
assertThat(type).isEqualTo("org.apache.geode.pdx.PdxInstance:PDXType");
}
Aggregations