@Override protected void initMessage(CacheOperationMessage msg, DirectReplyProcessor p) { super.initMessage(msg, p); UpdateMessage m = (UpdateMessage) msg; EntryEventImpl ev = getEvent(); m.event = ev; m.eventId = ev.getEventId(); m.key = ev.getKey(); m.deserializationPolicy = DESERIALIZATION_POLICY_LAZY; ev.exportNewValue(m); }
@Test public void verifyExportNewValueWithByteArray() { LocalRegion region = mock(LocalRegion.class); byte[] newValue = new byte[] {1, 2, 3}; NewValueImporter nvImporter = mock(NewValueImporter.class); EntryEventImpl e = createEntryEvent(region, newValue); e.exportNewValue(nvImporter); verify(nvImporter).importNewBytes(newValue, false); }
@Test public void verifyExportNewValueWithByteArrayCachedDeserializable() { LocalRegion region = mock(LocalRegion.class); CachedDeserializable newValue = mock(CachedDeserializable.class); byte[] newValueBytes = new byte[] {1, 2, 3}; when(newValue.getValue()).thenReturn(newValueBytes); NewValueImporter nvImporter = mock(NewValueImporter.class); EntryEventImpl e = createEntryEvent(region, newValue); e.exportNewValue(nvImporter); verify(nvImporter).importNewBytes(newValueBytes, true); }
@Test public void verifyExportNewValueWithUnserializedStoredObject() { LocalRegion region = mock(LocalRegion.class); when(region.getOffHeap()).thenReturn(true); StoredObject newValue = mock(StoredObject.class); byte[] newValueBytes = new byte[] {1, 2, 3}; when(newValue.getValueAsHeapByteArray()).thenReturn(newValueBytes); NewValueImporter nvImporter = mock(NewValueImporter.class); EntryEventImpl e = createEntryEvent(region, newValue); e.exportNewValue(nvImporter); verify(nvImporter).importNewBytes(newValueBytes, false); }
@Test public void verifyExportNewValueWithStringIgnoresNewValueBytes() { LocalRegion region = mock(LocalRegion.class); String newValue = "newValue"; NewValueImporter nvImporter = mock(NewValueImporter.class); when(nvImporter.prefersNewSerialized()).thenReturn(true); EntryEventImpl e = createEntryEvent(region, newValue); byte[] newValueBytes = new byte[] {1, 2}; e.newValueBytes = newValueBytes; e.exportNewValue(nvImporter); verify(nvImporter).importNewBytes(newValueBytes, true); }
@Test public void verifyExportNewValueWithSerializedStoredObjectAndUnretainedNewReferenceOk() { LocalRegion region = mock(LocalRegion.class); when(region.getOffHeap()).thenReturn(true); StoredObject newValue = mock(StoredObject.class); when(newValue.isSerialized()).thenReturn(true); Object newValueDeserialized = "newValueDeserialized"; when(newValue.getValueAsDeserializedHeapObject()).thenReturn(newValueDeserialized); NewValueImporter nvImporter = mock(NewValueImporter.class); when(nvImporter.isUnretainedNewReferenceOk()).thenReturn(true); EntryEventImpl e = createEntryEvent(region, newValue); e.exportNewValue(nvImporter); verify(nvImporter).importNewObject(newValue, true); }
@Test public void verifyExportNewValueWithSerializedStoredObject() { LocalRegion region = mock(LocalRegion.class); when(region.getOffHeap()).thenReturn(true); StoredObject newValue = mock(StoredObject.class); when(newValue.isSerialized()).thenReturn(true); Object newValueDeserialized = "newValueDeserialized"; when(newValue.getValueAsDeserializedHeapObject()).thenReturn(newValueDeserialized); NewValueImporter nvImporter = mock(NewValueImporter.class); EntryEventImpl e = createEntryEvent(region, newValue); e.exportNewValue(nvImporter); verify(nvImporter).importNewObject(newValueDeserialized, true); }
@Test public void verifyExportNewValueWithSerializedStoredObjectAndImporterPrefersSerialized() { LocalRegion region = mock(LocalRegion.class); when(region.getOffHeap()).thenReturn(true); StoredObject newValue = mock(StoredObject.class); when(newValue.isSerialized()).thenReturn(true); byte[] newValueBytes = new byte[] {1, 2, 3}; when(newValue.getValueAsHeapByteArray()).thenReturn(newValueBytes); NewValueImporter nvImporter = mock(NewValueImporter.class); when(nvImporter.prefersNewSerialized()).thenReturn(true); EntryEventImpl e = createEntryEvent(region, newValue); e.exportNewValue(nvImporter); verify(nvImporter).importNewBytes(newValueBytes, true); }
@Test public void verifyExportNewValueWithStringCachedDeserializablePrefersNewValueBytes() { LocalRegion region = mock(LocalRegion.class); CachedDeserializable newValue = mock(CachedDeserializable.class); Object newValueObj = "newValueObj"; when(newValue.getValue()).thenReturn(newValueObj); NewValueImporter nvImporter = mock(NewValueImporter.class); when(nvImporter.prefersNewSerialized()).thenReturn(true); EntryEventImpl e = createEntryEvent(region, newValue); byte[] newValueBytes = new byte[] {1, 2}; e.newValueBytes = newValueBytes; e.exportNewValue(nvImporter); verify(nvImporter).importNewBytes(newValueBytes, true); }
@Test public void verifyExportNewValueWithStringCachedDeserializable() { LocalRegion region = mock(LocalRegion.class); CachedDeserializable newValue = mock(CachedDeserializable.class); Object newValueObj = "newValueObj"; when(newValue.getValue()).thenReturn(newValueObj); NewValueImporter nvImporter = mock(NewValueImporter.class); EntryEventImpl e = createEntryEvent(region, newValue); byte[] newValueBytes = new byte[] {1, 2}; e.newValueBytes = newValueBytes; e.setCachedSerializedNewValue(newValueBytes); e.exportNewValue(nvImporter); verify(nvImporter).importNewObject(newValueObj, true); }
@Test public void verifyExportNewValueWithStringCachedDeserializablePrefersCachedSerializedNewValue() { LocalRegion region = mock(LocalRegion.class); CachedDeserializable newValue = mock(CachedDeserializable.class); Object newValueObj = "newValueObj"; when(newValue.getValue()).thenReturn(newValueObj); NewValueImporter nvImporter = mock(NewValueImporter.class); when(nvImporter.prefersNewSerialized()).thenReturn(true); EntryEventImpl e = createEntryEvent(region, newValue); byte[] newValueBytes = new byte[] {1, 2}; e.setCachedSerializedNewValue(newValueBytes); e.exportNewValue(nvImporter); verify(nvImporter).importNewBytes(newValueBytes, true); }
PutMessage(Set recipients, boolean notifyOnly, int regionId, DirectReplyProcessor processor, EntryEventImpl event, final long lastModified, boolean ifNew, boolean ifOld, Object expectedOldValue, boolean requireOldValue) { super(recipients, regionId, processor, event); this.processor = processor; this.notificationOnly = notifyOnly; this.requireOldValue = requireOldValue; this.expectedOldValue = expectedOldValue; this.key = event.getKey(); if (event.hasNewValue()) { this.deserializationPolicy = DistributedCacheOperation.DESERIALIZATION_POLICY_LAZY; event.exportNewValue(this); } else { // assert that if !event.hasNewValue, then deserialization policy is NONE assert this.deserializationPolicy == DistributedCacheOperation.DESERIALIZATION_POLICY_NONE : this.deserializationPolicy; } this.event = event; this.cbArg = event.getRawCallbackArgument(); this.lastModified = lastModified; this.op = event.getOperation(); this.bridgeContext = event.getContext(); this.eventId = event.getEventId(); this.versionTag = event.getVersionTag(); Assert.assertTrue(this.eventId != null); this.ifNew = ifNew; this.ifOld = ifOld; }
EntryEventImpl entryEvent = (EntryEventImpl) event; entryEvent.exportNewValue(clientUpdateMsg);
event.exportNewValue(this); } else {