UnlockEntryProcessor extends AbstractRegionCacheEntryProcessor { @Override public Void process(Map.Entry<Object, Expirable> entry) { Expirable expirable = entry.getValue(); if (expirable != null) { if (expirable.matches(lock)) { expirable = ((ExpiryMarker) expirable).expire(timestamp); } else if (expirable.getValue() != null) { expirable = new ExpiryMarker(null, timestamp, nextMarkerId).expire(timestamp); } else { return null; } entry.setValue(expirable); } return null; } UnlockEntryProcessor();  UnlockEntryProcessor(ExpiryMarker lock, String nextMarkerId, long timestamp); @Override Void 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); UnlockEntryProcessor processor = new UnlockEntryProcessor(new ExpiryMarker(null, 100L, "other-marker-id"), "next-marker-id", 100L); processor.process(entry); verify(entry, never()).setValue(any(Expirable.class)); }
@Test public void testProcessWithDifferentMarker() throws Exception { Map.Entry<Object, Expirable> entry = mockEntry(new ExpiryMarker(null, 100L, "the-marker-id")); UnlockEntryProcessor processor = new UnlockEntryProcessor(new ExpiryMarker(null, 100L, "other-marker-id"), "next-marker-id", 100L); 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")); UnlockEntryProcessor processor = new UnlockEntryProcessor(new ExpiryMarker(null, 100L, "other-marker-id"), "next-marker-id", 150L); 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("market must be expirable after timestamp", marker.isReplaceableBy(150L, null, null)); assertTrue("market must be expirable after timestamp", marker.isReplaceableBy(151L, null, null)); }
@Test public void testProcessMatchingLock() throws Exception { ExpiryMarker original = new ExpiryMarker(null, 100L, "the-marker-id").markForExpiration(100L, "some-marker-id"); Map.Entry<Object, Expirable> entry = mockEntry(original); UnlockEntryProcessor processor = new UnlockEntryProcessor(new ExpiryMarker(null, 100L, "the-marker-id"), "next-marker-id", 150L); ArgumentCaptor<Expirable> captor = ArgumentCaptor.forClass(Expirable.class); processor.process(entry); verify(entry).setValue(captor.capture()); Expirable result = captor.getValue(); assertNotSame(original, result); assertThat(result, instanceOf(ExpiryMarker.class)); ExpiryMarker marker = (ExpiryMarker) result; assertTrue(marker.matches(original)); }