LockEntryProcessor extends AbstractRegionCacheEntryProcessor { @Override public Expirable process(Map.Entry<Object, Expirable> entry) { Expirable expirable = entry.getValue(); if (expirable == null) { expirable = new ExpiryMarker(version, timeout, nextMarkerId); } else { expirable = expirable.markForExpiration(timeout, nextMarkerId); } entry.setValue(expirable); return expirable; } LockEntryProcessor();  LockEntryProcessor(String nextMarkerId, long timeout, Object version); @Override Expirable 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); LockEntryProcessor processor = new LockEntryProcessor("next-marker-id", 100L, null); ArgumentCaptor<Expirable> captor = ArgumentCaptor.forClass(Expirable.class); processor.process(entry); verify(entry).setValue(captor.capture()); Expirable result = captor.getValue(); assertThat(result, instanceOf(ExpiryMarker.class)); ExpiryMarker marker = (ExpiryMarker) result; assertTrue(marker.matches(new ExpiryMarker(null, 0L, "next-marker-id"))); }
@Test public void testProcessWithValueEntry() throws Exception { Map.Entry<Object, Expirable> entry = mockEntry(new Value(null, 500L, "blah")); LockEntryProcessor processor = new LockEntryProcessor("next-marker-id", 100L, null); ArgumentCaptor<Expirable> captor = ArgumentCaptor.forClass(Expirable.class); processor.process(entry); verify(entry).setValue(captor.capture()); Expirable result = captor.getValue(); assertThat(result, instanceOf(ExpiryMarker.class)); ExpiryMarker marker = (ExpiryMarker) result; assertTrue(marker.matches(new ExpiryMarker(null, 0L, "next-marker-id"))); }
@Test public void testProcessWithMarkerEntry() throws Exception { ExpiryMarker original = new ExpiryMarker(null, 0L, "the-marker-id"); Map.Entry<Object, Expirable> entry = mockEntry(original); LockEntryProcessor processor = new LockEntryProcessor("next-marker-id", 100L, null); ArgumentCaptor<Expirable> captor = ArgumentCaptor.forClass(Expirable.class); processor.process(entry); verify(entry).setValue(captor.capture()); Expirable result = captor.getValue(); assertThat(result, instanceOf(ExpiryMarker.class)); ExpiryMarker marker = (ExpiryMarker) result; assertFalse(marker.matches(new ExpiryMarker(null, 0L, "next-marker-id"))); assertTrue(marker.matches(original)); assertTrue(marker.isConcurrent()); }