Search in sources :

Example 1 with EnumId

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();
}
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) CacheWriterException(org.apache.geode.cache.CacheWriterException) 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)

Example 2 with EnumId

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();
}
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)

Example 3 with EnumId

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;
}
Also used : EnumId(org.apache.geode.pdx.internal.EnumId)

Example 4 with EnumId

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();
}
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

EnumId (org.apache.geode.pdx.internal.EnumId)4 Iterator (java.util.Iterator)3 Map (java.util.Map)3 Cache (org.apache.geode.cache.Cache)3 CacheFactory (org.apache.geode.cache.CacheFactory)3 Region (org.apache.geode.cache.Region)3 EnumInfo (org.apache.geode.pdx.internal.EnumInfo)3 PdxType (org.apache.geode.pdx.internal.PdxType)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)3 Test (org.junit.Test)3 CacheWriterException (org.apache.geode.cache.CacheWriterException)1