use of org.apache.geode.pdx.internal.EnumInfo 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