use of org.apache.geode.pdx.internal.EnumId in project geode by apache.
the class PdxAttributesJUnitTest method testDuplicatePdxTypeId.
@Test
public void testDuplicatePdxTypeId() throws Exception {
int dsId = 5;
CacheFactory cf = new CacheFactory();
cf.set(MCAST_PORT, "0");
cf.set(ConfigurationProperties.DISTRIBUTED_SYSTEM_ID, String.valueOf(dsId));
Cache cache = cf.create();
// define a type.
defineAType();
Region pdxRegion = cache.getRegion(PeerTypeRegistration.REGION_NAME);
Iterator itr = pdxRegion.entrySet().iterator();
boolean foundException = false;
boolean foundEnumException = false;
while (itr.hasNext()) {
Map.Entry ent = (Map.Entry) itr.next();
if (ent.getKey() instanceof Integer) {
int pdxTypeId = (int) ent.getKey();
try {
pdxRegion.put(pdxTypeId, new PdxType());
} catch (CacheWriterException cwe) {
foundException = true;
}
} else {
EnumId enumId = (EnumId) ent.getKey();
EnumInfo enumInfo = new EnumInfo(SimpleEnum.ONE);
try {
pdxRegion.put(enumId, enumInfo);
} catch (CacheWriterException cwe) {
foundEnumException = true;
}
}
}
assertEquals(true, foundException);
assertEquals(true, foundEnumException);
cache.close();
}
use of org.apache.geode.pdx.internal.EnumId in project geode by apache.
the class PdxAttributesJUnitTest method testPdxTypeIdWithNegativeDsId.
@Test
public void testPdxTypeIdWithNegativeDsId() throws Exception {
// in this case geode will use 0 as dsId
int dsId = -1;
CacheFactory cf = new CacheFactory();
cf.set(MCAST_PORT, "0");
cf.set(ConfigurationProperties.DISTRIBUTED_SYSTEM_ID, String.valueOf(dsId));
Cache cache = cf.create();
// define a type.
defineAType();
Region pdxRegion = cache.getRegion(PeerTypeRegistration.REGION_NAME);
Iterator itr = pdxRegion.entrySet().iterator();
boolean found = false;
boolean foundEnum = false;
while (itr.hasNext()) {
Map.Entry ent = (Map.Entry) itr.next();
if (ent.getKey() instanceof Integer) {
int pdxTypeId = (int) ent.getKey();
PdxType pdxType = (PdxType) ent.getValue();
int pdxTypeHashcode = pdxType.hashCode();
System.out.println("pdx hashcode " + pdxTypeHashcode);
int expectedPdxTypeId = PeerTypeRegistration.PLACE_HOLDER_FOR_TYPE_ID & pdxTypeHashcode;
assertEquals(expectedPdxTypeId, pdxTypeId);
found = true;
} else {
EnumId enumId = (EnumId) ent.getKey();
EnumInfo enumInfo = (EnumInfo) ent.getValue();
EnumInfo expectedEnumInfo = new EnumInfo(SimpleEnum.TWO);
int expectKey = PeerTypeRegistration.PLACE_HOLDER_FOR_TYPE_ID & expectedEnumInfo.hashCode();
;
assertEquals(expectKey, enumId.intValue());
foundEnum = true;
}
}
assertEquals(true, found);
cache.close();
}
use of org.apache.geode.pdx.internal.EnumId in project geode by apache.
the class GatewayReceiverCommand method addPdxType.
private boolean addPdxType(CachedRegionHelper crHelper, Object key, Object value) throws Exception {
if (key instanceof EnumId) {
EnumId enumId = (EnumId) key;
value = BlobHelper.deserializeBlob((byte[]) value);
crHelper.getCache().getPdxRegistry().addRemoteEnum(enumId.intValue(), (EnumInfo) value);
} else {
value = BlobHelper.deserializeBlob((byte[]) value);
crHelper.getCache().getPdxRegistry().addRemoteType((int) key, (PdxType) value);
}
return true;
}
use of org.apache.geode.pdx.internal.EnumId in project geode by apache.
the class PdxAttributesJUnitTest method testPdxTypeId.
@Test
public void testPdxTypeId() throws Exception {
int dsId = 5;
CacheFactory cf = new CacheFactory();
cf.set(MCAST_PORT, "0");
cf.set(ConfigurationProperties.DISTRIBUTED_SYSTEM_ID, String.valueOf(dsId));
Cache cache = cf.create();
// define a type.
defineAType();
Region pdxRegion = cache.getRegion(PeerTypeRegistration.REGION_NAME);
Iterator itr = pdxRegion.entrySet().iterator();
boolean found = false;
boolean foundEnum = false;
while (itr.hasNext()) {
Map.Entry ent = (Map.Entry) itr.next();
if (ent.getKey() instanceof Integer) {
int pdxTypeId = (int) ent.getKey();
PdxType pdxType = (PdxType) ent.getValue();
int pdxTypeHashcode = pdxType.hashCode();
System.out.println("pdx hashcode " + pdxTypeHashcode);
int expectedPdxTypeId = (dsId << 24) | (PeerTypeRegistration.PLACE_HOLDER_FOR_TYPE_ID & pdxTypeHashcode);
assertEquals(expectedPdxTypeId, pdxTypeId);
found = true;
} else {
EnumId enumId = (EnumId) ent.getKey();
EnumInfo enumInfo = (EnumInfo) ent.getValue();
EnumInfo expectedEnumInfo = new EnumInfo(SimpleEnum.TWO);
int expectKey = (dsId << 24) | (PeerTypeRegistration.PLACE_HOLDER_FOR_TYPE_ID & expectedEnumInfo.hashCode());
;
assertEquals(expectKey, enumId.intValue());
foundEnum = true;
}
}
assertEquals(true, found);
assertEquals(true, foundEnum);
cache.close();
}
Aggregations