use of org.apache.geode.internal.cache.OffHeapRegionEntry in project geode by apache.
the class OffHeapRegionEntryHelperJUnitTest method getValueAsTokenShouldReturnNotATokenIfValueIsOnOffHeap.
@Test
public void getValueAsTokenShouldReturnNotATokenIfValueIsOnOffHeap() {
// mock region entry
OffHeapRegionEntry re = mock(OffHeapRegionEntry.class);
OffHeapStoredObject chunk = createChunk(Long.MAX_VALUE);
// mock region entry methods required for test
when(re.getAddress()).thenReturn(chunk.getAddress());
Token token = OffHeapRegionEntryHelper.getValueAsToken(re);
assertThat(token).isEqualTo(Token.NOT_A_TOKEN);
}
use of org.apache.geode.internal.cache.OffHeapRegionEntry in project geode by apache.
the class OffHeapRegionEntryHelperJUnitTest method setValueShouldChangeTheRegionEntryAddressToNewAddressAndReleaseOldValueIfItsOnOffHeap.
@Test
public void setValueShouldChangeTheRegionEntryAddressToNewAddressAndReleaseOldValueIfItsOnOffHeap() {
// mock region entry
OffHeapRegionEntry re = mock(OffHeapRegionEntry.class);
OffHeapStoredObject oldValue = createChunk(Long.MAX_VALUE);
OffHeapStoredObject newValue = createChunk(Long.MAX_VALUE - 1);
// mock Chunk static methods - in-order to verify that release is called
PowerMockito.spy(OffHeapStoredObject.class);
PowerMockito.doNothing().when(OffHeapStoredObject.class);
OffHeapStoredObject.release(oldValue.getAddress());
// mock region entry methods required for test
when(re.getAddress()).thenReturn(oldValue.getAddress());
when(re.setAddress(oldValue.getAddress(), newValue.getAddress())).thenReturn(Boolean.TRUE);
// invoke the method under test
OffHeapRegionEntryHelper.setValue(re, newValue);
// verify oldAddress is changed to newAddress
verify(re, times(1)).setAddress(oldValue.getAddress(), newValue.getAddress());
// verify oldAddress is released
PowerMockito.verifyStatic();
OffHeapStoredObject.release(oldValue.getAddress());
}
use of org.apache.geode.internal.cache.OffHeapRegionEntry in project geode by apache.
the class OffHeapRegionEntryHelperJUnitTest method setValueShouldChangeTheRegionEntryAddressToNewAddress.
@Test
public void setValueShouldChangeTheRegionEntryAddressToNewAddress() {
// mock region entry
OffHeapRegionEntry re = mock(OffHeapRegionEntry.class);
// some old address
long oldAddress = 1L;
// testing when the newValue is a chunk
OffHeapStoredObject newValue = createChunk(Long.MAX_VALUE);
// mock region entry methods required for test
when(re.getAddress()).thenReturn(oldAddress);
when(re.setAddress(oldAddress, newValue.getAddress())).thenReturn(Boolean.TRUE);
// invoke the method under test
OffHeapRegionEntryHelper.setValue(re, newValue);
// verify oldAddress is replaced with newAddress
verify(re, times(1)).setAddress(oldAddress, newValue.getAddress());
// resetting the spy in-order to re-use
reset(re);
// testing when the newValue is DataAsAddress
TinyStoredObject newAddress1 = new TinyStoredObject(2L);
// mock region entry methods required for test
when(re.getAddress()).thenReturn(oldAddress);
when(re.setAddress(oldAddress, newAddress1.getAddress())).thenReturn(Boolean.TRUE);
OffHeapRegionEntryHelper.setValue(re, newAddress1);
// verify oldAddress is replaced with newAddress
verify(re, times(1)).setAddress(oldAddress, newAddress1.getAddress());
reset(re);
// Testing when newValue is Token Objects
// mock region entry methods required for test
when(re.getAddress()).thenReturn(oldAddress);
when(re.setAddress(oldAddress, OffHeapRegionEntryHelper.NULL_ADDRESS)).thenReturn(Boolean.TRUE);
OffHeapRegionEntryHelper.setValue(re, null);
// verify oldAddress is replaced with newAddress
verify(re, times(1)).setAddress(oldAddress, OffHeapRegionEntryHelper.NULL_ADDRESS);
reset(re);
// mock region entry methods required for test
when(re.getAddress()).thenReturn(oldAddress);
when(re.setAddress(oldAddress, OffHeapRegionEntryHelper.INVALID_ADDRESS)).thenReturn(Boolean.TRUE);
OffHeapRegionEntryHelper.setValue(re, Token.INVALID);
// verify oldAddress is replaced with newAddress
verify(re, times(1)).setAddress(oldAddress, OffHeapRegionEntryHelper.INVALID_ADDRESS);
reset(re);
// mock region entry methods required for test
when(re.getAddress()).thenReturn(oldAddress);
when(re.setAddress(oldAddress, OffHeapRegionEntryHelper.LOCAL_INVALID_ADDRESS)).thenReturn(Boolean.TRUE);
OffHeapRegionEntryHelper.setValue(re, Token.LOCAL_INVALID);
// verify oldAddress is replaced with newAddress
verify(re, times(1)).setAddress(oldAddress, OffHeapRegionEntryHelper.LOCAL_INVALID_ADDRESS);
reset(re);
// mock region entry methods required for test
when(re.getAddress()).thenReturn(oldAddress);
when(re.setAddress(oldAddress, OffHeapRegionEntryHelper.DESTROYED_ADDRESS)).thenReturn(Boolean.TRUE);
OffHeapRegionEntryHelper.setValue(re, Token.DESTROYED);
// verify oldAddress is replaced with newAddress
verify(re, times(1)).setAddress(oldAddress, OffHeapRegionEntryHelper.DESTROYED_ADDRESS);
reset(re);
// mock region entry methods required for test
when(re.getAddress()).thenReturn(oldAddress);
when(re.setAddress(oldAddress, OffHeapRegionEntryHelper.REMOVED_PHASE1_ADDRESS)).thenReturn(Boolean.TRUE);
OffHeapRegionEntryHelper.setValue(re, Token.REMOVED_PHASE1);
// verify oldAddress is replaced with newAddress
verify(re, times(1)).setAddress(oldAddress, OffHeapRegionEntryHelper.REMOVED_PHASE1_ADDRESS);
reset(re);
// mock region entry methods required for test
when(re.getAddress()).thenReturn(oldAddress);
when(re.setAddress(oldAddress, OffHeapRegionEntryHelper.REMOVED_PHASE2_ADDRESS)).thenReturn(Boolean.TRUE);
OffHeapRegionEntryHelper.setValue(re, Token.REMOVED_PHASE2);
// verify oldAddress is replaced with newAddress
verify(re, times(1)).setAddress(oldAddress, OffHeapRegionEntryHelper.REMOVED_PHASE2_ADDRESS);
reset(re);
// mock region entry methods required for test
when(re.getAddress()).thenReturn(oldAddress);
when(re.setAddress(oldAddress, OffHeapRegionEntryHelper.END_OF_STREAM_ADDRESS)).thenReturn(Boolean.TRUE);
OffHeapRegionEntryHelper.setValue(re, Token.END_OF_STREAM);
// verify oldAddress is replaced with newAddress
verify(re, times(1)).setAddress(oldAddress, OffHeapRegionEntryHelper.END_OF_STREAM_ADDRESS);
reset(re);
// mock region entry methods required for test
when(re.getAddress()).thenReturn(oldAddress);
when(re.setAddress(oldAddress, OffHeapRegionEntryHelper.NOT_AVAILABLE_ADDRESS)).thenReturn(Boolean.TRUE);
OffHeapRegionEntryHelper.setValue(re, Token.NOT_AVAILABLE);
// verify oldAddress is replaced with newAddress
verify(re, times(1)).setAddress(oldAddress, OffHeapRegionEntryHelper.NOT_AVAILABLE_ADDRESS);
reset(re);
// mock region entry methods required for test
when(re.getAddress()).thenReturn(oldAddress);
when(re.setAddress(oldAddress, OffHeapRegionEntryHelper.TOMBSTONE_ADDRESS)).thenReturn(Boolean.TRUE);
OffHeapRegionEntryHelper.setValue(re, Token.TOMBSTONE);
// verify oldAddress is replaced with newAddress
verify(re, times(1)).setAddress(oldAddress, OffHeapRegionEntryHelper.TOMBSTONE_ADDRESS);
reset(re);
}
use of org.apache.geode.internal.cache.OffHeapRegionEntry in project geode by apache.
the class OffHeapRegionEntryHelperJUnitTest method releaseEntryShouldSetValueToRemovePhase2.
@Test
public void releaseEntryShouldSetValueToRemovePhase2() {
// mock region entry
OffHeapRegionEntry re = mock(OffHeapRegionEntry.class);
when(re.getAddress()).thenReturn(1L);
when(re.setAddress(1L, OffHeapRegionEntryHelper.REMOVED_PHASE2_ADDRESS)).thenReturn(Boolean.TRUE);
// mock required methods
PowerMockito.spy(OffHeapRegionEntryHelper.class);
PowerMockito.doNothing().when(OffHeapRegionEntryHelper.class);
OffHeapRegionEntryHelper.setValue(re, Token.REMOVED_PHASE2);
OffHeapRegionEntryHelper.releaseEntry(re);
PowerMockito.verifyStatic();
OffHeapRegionEntryHelper.setValue(re, Token.REMOVED_PHASE2);
}
use of org.apache.geode.internal.cache.OffHeapRegionEntry in project geode by apache.
the class OffHeapRegionEntryHelperJUnitTest method getValueAsTokenShouldReturnNotATokenIfValueIsEncoded.
@Test
public void getValueAsTokenShouldReturnNotATokenIfValueIsEncoded() {
// mock region entry
OffHeapRegionEntry re = mock(OffHeapRegionEntry.class);
byte[] data = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE).putInt(Integer.MAX_VALUE).array();
long address = OffHeapRegionEntryHelper.encodeDataAsAddress(data, false, false);
// mock region entry methods required for test
when(re.getAddress()).thenReturn(address);
Token token = OffHeapRegionEntryHelper.getValueAsToken(re);
assertThat(token).isEqualTo(Token.NOT_A_TOKEN);
}
Aggregations