Search in sources :

Example 26 with PdxType

use of org.apache.geode.pdx.internal.PdxType 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);
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 27 with PdxType

use of org.apache.geode.pdx.internal.PdxType in project geode by apache.

the class DiskStoreImpl method pdxDeleteField.

private Collection<PdxType> pdxDeleteField(String className, String fieldName) throws IOException {
    // Since we are recovering a disk store, the cast from DiskRegionView -->
    // PlaceHolderDiskRegion
    // and from RegionEntry --> DiskEntry should be ok.
    // In offline mode, we need to schedule the regions to be recovered
    // explicitly.
    DiskRegionView foundPdx = null;
    for (DiskRegionView drv : getKnown()) {
        if (drv.getName().equals(PeerTypeRegistration.REGION_FULL_PATH)) {
            foundPdx = drv;
            scheduleForRecovery((PlaceHolderDiskRegion) drv);
        }
    }
    if (foundPdx == null) {
        throw new IllegalStateException("The disk store does not contain any PDX types.");
    }
    recoverRegionsThatAreReady();
    PersistentOplogSet oplogSet = (PersistentOplogSet) getOplogSet(foundPdx);
    ArrayList<PdxType> result = new ArrayList<PdxType>();
    for (RegionEntry re : foundPdx.getRecoveredEntryMap().regionEntries()) {
        Object value = re._getValueRetain(foundPdx, true);
        if (Token.isRemoved(value)) {
            continue;
        }
        if (value instanceof CachedDeserializable) {
            value = ((CachedDeserializable) value).getDeserializedForReading();
        }
        if (value instanceof EnumInfo) {
            // nothing to delete in an enum
            continue;
        }
        PdxType type = (PdxType) value;
        if (type.getClassName().equals(className)) {
            PdxField field = type.getPdxField(fieldName);
            if (field != null) {
                field.setDeleted(true);
                type.setHasDeletedField(true);
                result.add(type);
                oplogSet.offlineModify(foundPdx, (DiskEntry) re, BlobHelper.serializeToBlob(type), true);
            }
        }
    }
    return result;
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) ArrayList(java.util.ArrayList) PdxField(org.apache.geode.pdx.internal.PdxField) DiskRegionView(org.apache.geode.internal.cache.persistence.DiskRegionView)

Example 28 with PdxType

use of org.apache.geode.pdx.internal.PdxType in project geode by apache.

the class DiskStoreImpl method pdxRename.

private Collection<Object> pdxRename(String oldBase, String newBase) throws IOException {
    // Since we are recovering a disk store, the cast from DiskRegionView -->
    // PlaceHolderDiskRegion
    // and from RegionEntry --> DiskEntry should be ok.
    // In offline mode, we need to schedule the regions to be recovered
    // explicitly.
    DiskRegionView foundPdx = null;
    for (DiskRegionView drv : getKnown()) {
        if (drv.getName().equals(PeerTypeRegistration.REGION_FULL_PATH)) {
            foundPdx = drv;
            scheduleForRecovery((PlaceHolderDiskRegion) drv);
        }
    }
    if (foundPdx == null) {
        throw new IllegalStateException("The disk store does not contain any PDX types.");
    }
    recoverRegionsThatAreReady();
    PersistentOplogSet oplogSet = (PersistentOplogSet) getOplogSet(foundPdx);
    ArrayList<Object> result = new ArrayList<>();
    Pattern pattern = createPdxRenamePattern(oldBase);
    for (RegionEntry re : foundPdx.getRecoveredEntryMap().regionEntries()) {
        Object value = re._getValueRetain(foundPdx, true);
        if (Token.isRemoved(value)) {
            continue;
        }
        if (value instanceof CachedDeserializable) {
            value = ((CachedDeserializable) value).getDeserializedForReading();
        }
        if (value instanceof EnumInfo) {
            EnumInfo ei = (EnumInfo) value;
            String newName = replacePdxRenamePattern(pattern, ei.getClassName(), newBase);
            if (newName != null) {
                ei.setClassName(newName);
                result.add(ei);
                oplogSet.offlineModify(foundPdx, (DiskEntry) re, BlobHelper.serializeToBlob(ei), true);
            }
        } else {
            PdxType type = (PdxType) value;
            String newName = replacePdxRenamePattern(pattern, type.getClassName(), newBase);
            if (newName != null) {
                type.setClassName(newName);
                result.add(type);
                oplogSet.offlineModify(foundPdx, (DiskEntry) re, BlobHelper.serializeToBlob(type), true);
            }
        }
    }
    return result;
}
Also used : Pattern(java.util.regex.Pattern) PersistentMemberPattern(org.apache.geode.internal.cache.persistence.PersistentMemberPattern) PdxType(org.apache.geode.pdx.internal.PdxType) EnumInfo(org.apache.geode.pdx.internal.EnumInfo) ArrayList(java.util.ArrayList) DiskRegionView(org.apache.geode.internal.cache.persistence.DiskRegionView)

Example 29 with PdxType

use of org.apache.geode.pdx.internal.PdxType in project geode by apache.

the class AddPdxType method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException {
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received get pdx id for type request ({} parts) from {}", serverConnection.getName(), clientMessage.getNumberOfParts(), serverConnection.getSocketString());
    }
    int noOfParts = clientMessage.getNumberOfParts();
    PdxType type = (PdxType) clientMessage.getPart(0).getObject();
    int typeId = clientMessage.getPart(1).getInt();
    // The native client needs this line
    // because it doesn't set the type id on the
    // client side.
    type.setTypeId(typeId);
    try {
        InternalCache cache = serverConnection.getCache();
        TypeRegistry registry = cache.getPdxRegistry();
        registry.addRemoteType(typeId, type);
    } catch (Exception e) {
        writeException(clientMessage, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    writeReply(clientMessage, serverConnection);
    serverConnection.setAsTrue(RESPONDED);
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) InternalCache(org.apache.geode.internal.cache.InternalCache) TypeRegistry(org.apache.geode.pdx.internal.TypeRegistry) IOException(java.io.IOException)

Example 30 with PdxType

use of org.apache.geode.pdx.internal.PdxType in project geode by apache.

the class ExportedRegistry method fromData.

public void fromData(DataInput in) throws IOException, ClassNotFoundException {
    int typeCount = in.readInt();
    for (int i = 0; i < typeCount; i++) {
        PdxType type = DataSerializer.readObject(in);
        types.put(type.getTypeId(), type);
    }
    int enumCount = in.readInt();
    for (int i = 0; i < enumCount; i++) {
        int id = in.readInt();
        EnumInfo ei = DataSerializer.readObject(in);
        enums.put(id, ei);
    }
}
Also used : PdxType(org.apache.geode.pdx.internal.PdxType) EnumInfo(org.apache.geode.pdx.internal.EnumInfo)

Aggregations

PdxType (org.apache.geode.pdx.internal.PdxType)32 Test (org.junit.Test)18 EnumInfo (org.apache.geode.pdx.internal.EnumInfo)14 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)11 TypeRegistry (org.apache.geode.pdx.internal.TypeRegistry)10 IOException (java.io.IOException)9 Cache (org.apache.geode.cache.Cache)9 CacheFactory (org.apache.geode.cache.CacheFactory)9 Region (org.apache.geode.cache.Region)8 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)8 File (java.io.File)7 Properties (java.util.Properties)6 InternalCache (org.apache.geode.internal.cache.InternalCache)6 Map (java.util.Map)5 DiskStoreFactory (org.apache.geode.cache.DiskStoreFactory)5 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)5 PdxInstance (org.apache.geode.pdx.PdxInstance)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 ArrayList (java.util.ArrayList)4 PdxInstanceImpl (org.apache.geode.pdx.internal.PdxInstanceImpl)4