Search in sources :

Example 1 with Token

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];
}
Also used : RegionEntry(org.apache.geode.internal.cache.RegionEntry) Token(org.apache.geode.internal.cache.Token)

Example 2 with Token

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];
}
Also used : RegionEntry(org.apache.geode.internal.cache.RegionEntry) Token(org.apache.geode.internal.cache.Token)

Example 3 with Token

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);
}
Also used : Token(org.apache.geode.internal.cache.Token) OffHeapRegionEntry(org.apache.geode.internal.cache.OffHeapRegionEntry) UnitTest(org.apache.geode.test.junit.categories.UnitTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with 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);
}
Also used : Token(org.apache.geode.internal.cache.Token) UnitTest(org.apache.geode.test.junit.categories.UnitTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with Token

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);
}
Also used : Token(org.apache.geode.internal.cache.Token) OffHeapRegionEntry(org.apache.geode.internal.cache.OffHeapRegionEntry) UnitTest(org.apache.geode.test.junit.categories.UnitTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Token (org.apache.geode.internal.cache.Token)10 UnitTest (org.apache.geode.test.junit.categories.UnitTest)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 OffHeapRegionEntry (org.apache.geode.internal.cache.OffHeapRegionEntry)4 RegionEntry (org.apache.geode.internal.cache.RegionEntry)2 DataOutput (java.io.DataOutput)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 AccessibleObject (java.lang.reflect.AccessibleObject)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Member (java.lang.reflect.Member)1 Method (java.lang.reflect.Method)1 ByteBuffer (java.nio.ByteBuffer)1 InvalidDeltaException (org.apache.geode.InvalidDeltaException)1 EntryDestroyedException (org.apache.geode.cache.EntryDestroyedException)1 Operation (org.apache.geode.cache.Operation)1 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)1 ResourceException (org.apache.geode.cache.ResourceException)1