Search in sources :

Example 21 with EnumInfo

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();
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) CacheFactory(org.apache.geode.cache.CacheFactory) Map(java.util.Map) Cache(org.apache.geode.cache.Cache) EnumId(org.apache.geode.pdx.internal.EnumId) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

EnumInfo (org.apache.geode.pdx.internal.EnumInfo)21 PdxType (org.apache.geode.pdx.internal.PdxType)14 IOException (java.io.IOException)8 Test (org.junit.Test)8 Cache (org.apache.geode.cache.Cache)6 Region (org.apache.geode.cache.Region)6 TypeRegistry (org.apache.geode.pdx.internal.TypeRegistry)6 CacheFactory (org.apache.geode.cache.CacheFactory)5 InternalCache (org.apache.geode.internal.cache.InternalCache)5 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)5 File (java.io.File)4 Map (java.util.Map)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 Properties (java.util.Properties)3 Message (org.apache.geode.internal.cache.tier.sockets.Message)3 EnumId (org.apache.geode.pdx.internal.EnumId)3 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2