UpdateEntryProcessor extends AbstractRegionCacheEntryProcessor { @Override public Boolean process(Map.Entry<Object, Expirable> entry) { Expirable expirable = entry.getValue(); boolean updated; if (expirable == null) { expirable = new Value(newVersion, timestamp, newValue); updated = true; } else { if (expirable.matches(lock)) { final ExpiryMarker marker = (ExpiryMarker) expirable; if (marker.isConcurrent()) { expirable = marker.expire(timestamp); updated = false; } else { expirable = new Value(newVersion, timestamp, newValue); updated = true; } } else if (expirable.getValue() == null) { return false; } else { expirable = new ExpiryMarker(newVersion, timestamp, nextMarkerId).expire(timestamp); updated = false; } } entry.setValue(expirable); return updated; } UpdateEntryProcessor();  UpdateEntryProcessor(ExpiryMarker lock, Object newValue, Object newVersion, String nextMarkerId, long timestamp); @Override Boolean process(Map.Entry<Object, Expirable> entry); @Override void writeData(ObjectDataOutput out); @Override void readData(ObjectDataInput in); @Override int getId();  }
@Test public void testProcessWithNullEntry() throws Exception { Map.Entry<Object, Expirable> entry = mockEntry(null); UpdateEntryProcessor processor = new UpdateEntryProcessor(new ExpiryMarker(null, 100L, "the-marker-id"), "new-value", null, "next-marker-id", 150L); ArgumentCaptor<Expirable> captor = ArgumentCaptor.forClass(Expirable.class); assertTrue(processor.process(entry)); verify(entry).setValue(captor.capture()); Expirable result = captor.getValue(); assertThat(result, instanceOf(Value.class)); assertEquals("new-value", result.getValue()); }
@Test public void testProcessWithMatchingMarker() throws Exception { Map.Entry<Object, Expirable> entry = mockEntry(new ExpiryMarker(null, 100L, "the-marker-id")); UpdateEntryProcessor processor = new UpdateEntryProcessor(new ExpiryMarker(null, 100L, "the-marker-id"), "new-value", null, "next-marker-id", 150L); ArgumentCaptor<Expirable> captor = ArgumentCaptor.forClass(Expirable.class); assertTrue(processor.process(entry)); verify(entry).setValue(captor.capture()); Expirable result = captor.getValue(); assertThat(result, instanceOf(Value.class)); assertEquals("new-value", result.getValue()); }
@Test public void testProcessWithMatchingConcurrentMarker() throws Exception { Map.Entry<Object, Expirable> entry = mockEntry(new ExpiryMarker(null, 100L, "the-marker-id").markForExpiration(100L, "ignored")); UpdateEntryProcessor processor = new UpdateEntryProcessor(new ExpiryMarker(null, 100L, "the-marker-id"), "new-value", null, "next-marker-id", 150L); ArgumentCaptor<Expirable> captor = ArgumentCaptor.forClass(Expirable.class); assertFalse(processor.process(entry)); verify(entry).setValue(captor.capture()); Expirable result = captor.getValue(); assertThat(result, instanceOf(ExpiryMarker.class)); }
@Test public void testProcessWithDifferentMarker() throws Exception { Map.Entry<Object, Expirable> entry = mockEntry(new ExpiryMarker(null, 100L, "other-marker-id")); UpdateEntryProcessor processor = new UpdateEntryProcessor(new ExpiryMarker(null, 100L, "the-marker-id"), "new-value", null, "next-marker-id", 150L); assertFalse(processor.process(entry)); verify(entry, never()).setValue(any(Expirable.class)); }
@Test public void testProcessWithValue() throws Exception { Map.Entry<Object, Expirable> entry = mockEntry(new Value(null, 100L, "some-value")); UpdateEntryProcessor processor = new UpdateEntryProcessor(new ExpiryMarker(null, 100L, "the-marker-id"), "new-value", null, "next-marker-id", 150L); ArgumentCaptor<Expirable> captor = ArgumentCaptor.forClass(Expirable.class); assertFalse(processor.process(entry)); verify(entry).setValue(captor.capture()); Expirable result = captor.getValue(); assertThat(result, instanceOf(ExpiryMarker.class)); assertTrue("Marker should be expired", result.isReplaceableBy(151L, null, null)); }