Search in sources :

Example 16 with StoredObject

use of org.apache.geode.internal.offheap.StoredObject in project geode by apache.

the class EntryEventImplTest method verifyExportOldValueWithSerializedStoredObjectAndUnretainedOldReferenceOk.

@Test
public void verifyExportOldValueWithSerializedStoredObjectAndUnretainedOldReferenceOk() {
    LocalRegion region = mock(LocalRegion.class);
    when(region.getOffHeap()).thenReturn(true);
    StoredObject oldValue = mock(StoredObject.class);
    when(oldValue.isSerialized()).thenReturn(true);
    Object oldValueDeserialized = "oldValueDeserialized";
    when(oldValue.getValueAsDeserializedHeapObject()).thenReturn(oldValueDeserialized);
    OldValueImporter ovImporter = mock(OldValueImporter.class);
    when(ovImporter.isUnretainedOldReferenceOk()).thenReturn(true);
    EntryEventImpl e = createEntryEvent(region, null);
    e.setOldValue(oldValue);
    e.exportOldValue(ovImporter);
    verify(ovImporter).importOldObject(oldValue, true);
}
Also used : StoredObject(org.apache.geode.internal.offheap.StoredObject) OldValueImporter(org.apache.geode.internal.cache.EntryEventImpl.OldValueImporter) StoredObject(org.apache.geode.internal.offheap.StoredObject) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 17 with StoredObject

use of org.apache.geode.internal.offheap.StoredObject in project geode by apache.

the class OffHeapByteBufferByteSourceJUnitTest method createByteSource.

@Override
protected ByteSource createByteSource(byte[] bytes) {
    StoredObject so = MemoryAllocatorImpl.getAllocator().allocateAndInitialize(bytes, false, false);
    if (so instanceof OffHeapStoredObject) {
        OffHeapStoredObject c = (OffHeapStoredObject) so;
        ByteBuffer bb = c.createDirectByteBuffer();
        if (bb == null) {
            fail("could not create a direct ByteBuffer for an off-heap Chunk");
        }
        return ByteSourceFactory.create(bb);
    } else {
        // So for this test just wrap the original bytes.
        return ByteSourceFactory.wrap(bytes);
    }
}
Also used : OffHeapStoredObject(org.apache.geode.internal.offheap.OffHeapStoredObject) OffHeapStoredObject(org.apache.geode.internal.offheap.OffHeapStoredObject) StoredObject(org.apache.geode.internal.offheap.StoredObject) ByteBuffer(java.nio.ByteBuffer)

Example 18 with StoredObject

use of org.apache.geode.internal.offheap.StoredObject in project geode by apache.

the class AbstractRegionEntry method checkOffHeapEquals.

private static boolean checkOffHeapEquals(@Unretained StoredObject ohVal, @Unretained Object obj) {
    if (ohVal.isSerializedPdxInstance()) {
        PdxInstance pi = InternalDataSerializer.readPdxInstance(ohVal.getSerializedValue(), GemFireCacheImpl.getForPdx("Could not check value equality"));
        return checkPdxEquals(pi, obj);
    }
    if (obj instanceof StoredObject) {
        return ohVal.checkDataEquals((StoredObject) obj);
    } else {
        byte[] serializedObj;
        if (obj instanceof CachedDeserializable) {
            CachedDeserializable cdObj = (CachedDeserializable) obj;
            if (!ohVal.isSerialized()) {
                assert cdObj.isSerialized();
                return false;
            }
            serializedObj = cdObj.getSerializedValue();
        } else if (obj instanceof byte[]) {
            if (ohVal.isSerialized()) {
                return false;
            }
            serializedObj = (byte[]) obj;
        } else {
            if (!ohVal.isSerialized()) {
                return false;
            }
            if (obj == null || obj == Token.NOT_AVAILABLE || Token.isInvalidOrRemoved(obj)) {
                return false;
            }
            serializedObj = EntryEventImpl.serialize(obj);
        }
        return ohVal.checkDataEquals(serializedObj);
    }
}
Also used : PdxInstance(org.apache.geode.pdx.PdxInstance) StoredObject(org.apache.geode.internal.offheap.StoredObject)

Example 19 with StoredObject

use of org.apache.geode.internal.offheap.StoredObject in project geode by apache.

the class DummyQRegion method asList.

@Override
public List asList() {
    if (valueInList == null) {
        valueInList = new ArrayList(1);
    }
    valueInList.clear();
    Object val = this.entry.getValueOffHeapOrDiskWithoutFaultIn((LocalRegion) getRegion());
    if (val instanceof StoredObject) {
        @Retained @Released StoredObject ohval = (StoredObject) val;
        try {
            val = ohval.getDeserializedValue(getRegion(), this.entry);
        } finally {
            ohval.release();
        }
    } else if (val instanceof CachedDeserializable) {
        val = ((CachedDeserializable) val).getDeserializedValue(getRegion(), this.entry);
    }
    valueInList.add(val);
    return valueInList;
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) StoredObject(org.apache.geode.internal.offheap.StoredObject) Retained(org.apache.geode.internal.offheap.annotations.Retained) CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) ArrayList(java.util.ArrayList) StoredObject(org.apache.geode.internal.offheap.StoredObject)

Example 20 with StoredObject

use of org.apache.geode.internal.offheap.StoredObject in project geode by apache.

the class GetOperationContextImpl method getValue.

@Override
public Object getValue() {
    Object result = super.getValue();
    if (result instanceof StoredObject) {
        StoredObject so = (StoredObject) result;
        checkForReleasedOffHeapValue(so);
        // since they called getValue they don't care if it is serialized or deserialized so return it
        // as serialized
        result = so.getValueAsHeapByteArray();
    }
    return result;
}
Also used : StoredObject(org.apache.geode.internal.offheap.StoredObject) StoredObject(org.apache.geode.internal.offheap.StoredObject)

Aggregations

StoredObject (org.apache.geode.internal.offheap.StoredObject)34 Test (org.junit.Test)11 UnitTest (org.apache.geode.test.junit.categories.UnitTest)10 Retained (org.apache.geode.internal.offheap.annotations.Retained)7 Unretained (org.apache.geode.internal.offheap.annotations.Unretained)7 Released (org.apache.geode.internal.offheap.annotations.Released)6 CachedDeserializable (org.apache.geode.internal.cache.CachedDeserializable)5 NewValueImporter (org.apache.geode.internal.cache.EntryEventImpl.NewValueImporter)4 OldValueImporter (org.apache.geode.internal.cache.EntryEventImpl.OldValueImporter)4 IOException (java.io.IOException)3 PdxInstance (org.apache.geode.pdx.PdxInstance)2 InterruptedIOException (java.io.InterruptedIOException)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CacheException (org.apache.geode.cache.CacheException)1 CacheWriterException (org.apache.geode.cache.CacheWriterException)1 DiskAccessException (org.apache.geode.cache.DiskAccessException)1 EntryEvent (org.apache.geode.cache.EntryEvent)1 Region (org.apache.geode.cache.Region)1