Search in sources :

Example 1 with OldValueImporter

use of org.apache.geode.internal.cache.EntryEventImpl.OldValueImporter in project geode by apache.

the class EntryEventImplTest method verifyExportOldValueWithCacheDeserializableByteArray.

@Test
public void verifyExportOldValueWithCacheDeserializableByteArray() {
    LocalRegion region = mock(LocalRegion.class);
    CachedDeserializable oldValue = mock(CachedDeserializable.class);
    byte[] oldValueBytes = new byte[] { 1, 2, 3 };
    when(oldValue.getValue()).thenReturn(oldValueBytes);
    OldValueImporter ovImporter = mock(OldValueImporter.class);
    EntryEventImpl e = createEntryEvent(region, null);
    e.setOldValue(oldValue);
    e.exportOldValue(ovImporter);
    verify(ovImporter).importOldBytes(oldValueBytes, true);
}
Also used : OldValueImporter(org.apache.geode.internal.cache.EntryEventImpl.OldValueImporter) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 2 with OldValueImporter

use of org.apache.geode.internal.cache.EntryEventImpl.OldValueImporter in project geode by apache.

the class EntryEventImplTest method verifyExportOldValueWithStringIgnoresOldValueBytes.

@Test
public void verifyExportOldValueWithStringIgnoresOldValueBytes() {
    LocalRegion region = mock(LocalRegion.class);
    String oldValue = "oldValue";
    OldValueImporter ovImporter = mock(OldValueImporter.class);
    when(ovImporter.prefersOldSerialized()).thenReturn(true);
    EntryEventImpl e = createEntryEvent(region, null);
    byte[] oldValueBytes = new byte[] { 1, 2, 3 };
    e.setSerializedOldValue(oldValueBytes);
    e.setOldValue(oldValue);
    e.exportOldValue(ovImporter);
    verify(ovImporter).importOldObject(oldValue, true);
}
Also used : OldValueImporter(org.apache.geode.internal.cache.EntryEventImpl.OldValueImporter) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 3 with OldValueImporter

use of org.apache.geode.internal.cache.EntryEventImpl.OldValueImporter 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 4 with OldValueImporter

use of org.apache.geode.internal.cache.EntryEventImpl.OldValueImporter in project geode by apache.

the class EntryEventImplTest method verifyExportOldValueWithCacheDeserializableOk.

@Test
public void verifyExportOldValueWithCacheDeserializableOk() {
    LocalRegion region = mock(LocalRegion.class);
    CachedDeserializable oldValue = mock(CachedDeserializable.class);
    Object oldValueObj = "oldValueObj";
    when(oldValue.getValue()).thenReturn(oldValueObj);
    OldValueImporter ovImporter = mock(OldValueImporter.class);
    when(ovImporter.isCachedDeserializableValueOk()).thenReturn(true);
    EntryEventImpl e = createEntryEvent(region, null);
    e.setOldValue(oldValue);
    e.exportOldValue(ovImporter);
    verify(ovImporter).importOldObject(oldValue, true);
}
Also used : 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 5 with OldValueImporter

use of org.apache.geode.internal.cache.EntryEventImpl.OldValueImporter in project geode by apache.

the class OldValueImporterTestBase method testValueSerialization.

@Test
public void testValueSerialization() throws Exception {
    byte[] bytes = new byte[1024];
    HeapDataOutputStream hdos = new HeapDataOutputStream(bytes);
    OldValueImporter imsg = createImporter();
    // null byte array value
    {
        OldValueImporter omsg = createImporter();
        omsg.importOldBytes(null, false);
        toData(omsg, hdos);
        fromData(imsg, bytes);
        assertEquals(null, getOldValueFromImporter(imsg));
    }
    // null object value
    {
        OldValueImporter omsg = createImporter();
        omsg.importOldObject(null, true);
        toData(omsg, hdos);
        fromData(imsg, bytes);
        assertEquals(null, getOldValueFromImporter(imsg));
    }
    // simple byte array
    {
        byte[] baValue = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        OldValueImporter omsg = createImporter();
        omsg.importOldBytes(baValue, false);
        hdos = new HeapDataOutputStream(bytes);
        toData(omsg, hdos);
        fromData(imsg, bytes);
        assertArrayEquals(baValue, (byte[]) getOldValueFromImporter(imsg));
    }
    // String in serialized form
    {
        String stringValue = "1,2,3,4,5,6,7,8,9";
        byte[] stringValueBlob = EntryEventImpl.serialize(stringValue);
        OldValueImporter omsg = createImporter();
        omsg.importOldBytes(stringValueBlob, true);
        hdos = new HeapDataOutputStream(bytes);
        toData(omsg, hdos);
        fromData(imsg, bytes);
        assertArrayEquals(stringValueBlob, ((VMCachedDeserializable) getOldValueFromImporter(imsg)).getSerializedValue());
    }
    // String in object form
    {
        String stringValue = "1,2,3,4,5,6,7,8,9";
        byte[] stringValueBlob = EntryEventImpl.serialize(stringValue);
        OldValueImporter omsg = createImporter();
        omsg.importOldObject(stringValue, true);
        hdos = new HeapDataOutputStream(bytes);
        toData(omsg, hdos);
        fromData(imsg, bytes);
        assertArrayEquals(stringValueBlob, ((VMCachedDeserializable) getOldValueFromImporter(imsg)).getSerializedValue());
    }
    // off-heap DataAsAddress byte array
    {
        MemoryAllocatorImpl sma = MemoryAllocatorImpl.createForUnitTest(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new SlabImpl[] { new SlabImpl(1024 * 1024) });
        try {
            byte[] baValue = new byte[] { 1, 2 };
            TinyStoredObject baValueSO = (TinyStoredObject) sma.allocateAndInitialize(baValue, false, false);
            OldValueImporter omsg = createImporter();
            omsg.importOldObject(baValueSO, false);
            hdos = new HeapDataOutputStream(bytes);
            toData(omsg, hdos);
            fromData(imsg, bytes);
            assertArrayEquals(baValue, (byte[]) getOldValueFromImporter(imsg));
        } finally {
            MemoryAllocatorImpl.freeOffHeapMemory();
        }
    }
    // off-heap Chunk byte array
    {
        MemoryAllocatorImpl sma = MemoryAllocatorImpl.createForUnitTest(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new SlabImpl[] { new SlabImpl(1024 * 1024) });
        try {
            byte[] baValue = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 };
            OffHeapStoredObject baValueSO = (OffHeapStoredObject) sma.allocateAndInitialize(baValue, false, false);
            OldValueImporter omsg = createImporter();
            omsg.importOldObject(baValueSO, false);
            hdos = new HeapDataOutputStream(bytes);
            toData(omsg, hdos);
            fromData(imsg, bytes);
            assertArrayEquals(baValue, (byte[]) getOldValueFromImporter(imsg));
        } finally {
            MemoryAllocatorImpl.freeOffHeapMemory();
        }
    }
    // off-heap DataAsAddress String
    {
        MemoryAllocatorImpl sma = MemoryAllocatorImpl.createForUnitTest(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new SlabImpl[] { new SlabImpl(1024 * 1024) });
        try {
            String baValue = "12";
            byte[] baValueBlob = BlobHelper.serializeToBlob(baValue);
            TinyStoredObject baValueSO = (TinyStoredObject) sma.allocateAndInitialize(baValueBlob, true, false);
            OldValueImporter omsg = createImporter();
            omsg.importOldObject(baValueSO, true);
            hdos = new HeapDataOutputStream(bytes);
            toData(omsg, hdos);
            fromData(imsg, bytes);
            assertArrayEquals(baValueBlob, ((VMCachedDeserializable) getOldValueFromImporter(imsg)).getSerializedValue());
        } finally {
            MemoryAllocatorImpl.freeOffHeapMemory();
        }
    }
    // off-heap Chunk String
    {
        MemoryAllocatorImpl sma = MemoryAllocatorImpl.createForUnitTest(new NullOutOfOffHeapMemoryListener(), new NullOffHeapMemoryStats(), new SlabImpl[] { new SlabImpl(1024 * 1024) });
        try {
            String baValue = "12345678";
            byte[] baValueBlob = BlobHelper.serializeToBlob(baValue);
            OffHeapStoredObject baValueSO = (OffHeapStoredObject) sma.allocateAndInitialize(baValueBlob, true, false);
            OldValueImporter omsg = createImporter();
            omsg.importOldObject(baValueSO, true);
            hdos = new HeapDataOutputStream(bytes);
            toData(omsg, hdos);
            fromData(imsg, bytes);
            assertArrayEquals(baValueBlob, ((VMCachedDeserializable) getOldValueFromImporter(imsg)).getSerializedValue());
        } finally {
            MemoryAllocatorImpl.freeOffHeapMemory();
        }
    }
}
Also used : OffHeapStoredObject(org.apache.geode.internal.offheap.OffHeapStoredObject) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) OldValueImporter(org.apache.geode.internal.cache.EntryEventImpl.OldValueImporter) MemoryAllocatorImpl(org.apache.geode.internal.offheap.MemoryAllocatorImpl) NullOutOfOffHeapMemoryListener(org.apache.geode.internal.offheap.NullOutOfOffHeapMemoryListener) SlabImpl(org.apache.geode.internal.offheap.SlabImpl) NullOffHeapMemoryStats(org.apache.geode.internal.offheap.NullOffHeapMemoryStats) TinyStoredObject(org.apache.geode.internal.offheap.TinyStoredObject) Test(org.junit.Test)

Aggregations

OldValueImporter (org.apache.geode.internal.cache.EntryEventImpl.OldValueImporter)11 Test (org.junit.Test)11 UnitTest (org.apache.geode.test.junit.categories.UnitTest)10 StoredObject (org.apache.geode.internal.offheap.StoredObject)6 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)1 MemoryAllocatorImpl (org.apache.geode.internal.offheap.MemoryAllocatorImpl)1 NullOffHeapMemoryStats (org.apache.geode.internal.offheap.NullOffHeapMemoryStats)1 NullOutOfOffHeapMemoryListener (org.apache.geode.internal.offheap.NullOutOfOffHeapMemoryListener)1 OffHeapStoredObject (org.apache.geode.internal.offheap.OffHeapStoredObject)1 SlabImpl (org.apache.geode.internal.offheap.SlabImpl)1 TinyStoredObject (org.apache.geode.internal.offheap.TinyStoredObject)1