use of org.apache.geode.internal.cache.Token in project geode by apache.
the class ServerResponseMatrix method checkForValidStateAfterNotification.
public static boolean checkForValidStateAfterNotification(LocalRegion region, Object key, int operation) {
// 4 nonexistent/destroyed , valid , invalid,local-invalid ,
// 4 create , update , invalidate, destroy
boolean[][] matrix = { { true, true, true, true }, { true, true, true, true }, { true, true, true, true }, { true, true, true, true } };
int cacheEntryState = -1;
RegionEntry re = region.entries.getEntry(key);
if (re == null) {
// nonexistent or destroyed
cacheEntryState = 0;
} else {
Token token = re.getValueAsToken();
if (token == Token.DESTROYED || token == Token.REMOVED_PHASE1 || token == Token.REMOVED_PHASE2 || token == Token.TOMBSTONE) {
// destroyed
cacheEntryState = 0;
} else if (token == Token.LOCAL_INVALID) {
// local-invalid
cacheEntryState = 3;
} else if (token == Token.INVALID) {
// invalid
cacheEntryState = 2;
} else {
// valid
cacheEntryState = 1;
}
}
int notificationState = -1;
switch(operation) {
case MessageType.LOCAL_CREATE:
notificationState = 0;
break;
case MessageType.LOCAL_UPDATE:
notificationState = 1;
break;
case MessageType.LOCAL_INVALIDATE:
notificationState = 2;
break;
case MessageType.LOCAL_DESTROY:
notificationState = 3;
break;
}
return matrix[cacheEntryState][notificationState];
}
use of org.apache.geode.internal.cache.Token in project geode by apache.
the class ServerResponseMatrix method checkForValidStateAfterRegisterInterest.
public static boolean checkForValidStateAfterRegisterInterest(LocalRegion region, Object key, Object serverValue) {
int cacheEntryState = -1;
RegionEntry re = region.entries.getEntry(key);
if (re == null) {
// nonexistent
cacheEntryState = 0;
} else {
Token token = re.getValueAsToken();
if (token == Token.DESTROYED) {
// destroyed
cacheEntryState = 3;
} else if (token == Token.INVALID) {
// invalid
cacheEntryState = 2;
} else {
// valid
cacheEntryState = 1;
}
}
// A matrix During register interest response processing
// 4 nonexistent, valid , invalid,destroyed
// 2 invalid, valid
boolean[][] matrix = { { true, true }, { false, false }, { true, true }, { true, true } };
// invalid
int registerInterstResState = 0;
if (serverValue != null) {
// valid
registerInterstResState = 1;
}
return matrix[cacheEntryState][registerInterstResState];
}
use of org.apache.geode.internal.cache.Token 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.Token in project geode by apache.
the class OffHeapRegionEntryHelperJUnitTest method addressToObjectShouldReturnToken.
@Test
public void addressToObjectShouldReturnToken() {
Token token = (Token) OffHeapRegionEntryHelper.addressToObject(OffHeapRegionEntryHelper.NULL_ADDRESS, false, null);
assertThat(token).isNull();
token = (Token) OffHeapRegionEntryHelper.addressToObject(OffHeapRegionEntryHelper.INVALID_ADDRESS, false, null);
assertThat(token).isEqualTo(Token.INVALID);
token = (Token) OffHeapRegionEntryHelper.addressToObject(OffHeapRegionEntryHelper.LOCAL_INVALID_ADDRESS, false, null);
assertThat(token).isEqualTo(Token.LOCAL_INVALID);
token = (Token) OffHeapRegionEntryHelper.addressToObject(OffHeapRegionEntryHelper.DESTROYED_ADDRESS, false, null);
assertThat(token).isEqualTo(Token.DESTROYED);
token = (Token) OffHeapRegionEntryHelper.addressToObject(OffHeapRegionEntryHelper.REMOVED_PHASE1_ADDRESS, false, null);
assertThat(token).isEqualTo(Token.REMOVED_PHASE1);
token = (Token) OffHeapRegionEntryHelper.addressToObject(OffHeapRegionEntryHelper.REMOVED_PHASE2_ADDRESS, false, null);
assertThat(token).isEqualTo(Token.REMOVED_PHASE2);
token = (Token) OffHeapRegionEntryHelper.addressToObject(OffHeapRegionEntryHelper.END_OF_STREAM_ADDRESS, false, null);
assertThat(token).isEqualTo(Token.END_OF_STREAM);
token = (Token) OffHeapRegionEntryHelper.addressToObject(OffHeapRegionEntryHelper.NOT_AVAILABLE_ADDRESS, false, null);
assertThat(token).isEqualTo(Token.NOT_AVAILABLE);
token = (Token) OffHeapRegionEntryHelper.addressToObject(OffHeapRegionEntryHelper.TOMBSTONE_ADDRESS, false, null);
assertThat(token).isEqualTo(Token.TOMBSTONE);
}
use of org.apache.geode.internal.cache.Token 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