Search in sources :

Example 56 with GridCacheVersion

use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.

the class GridCacheMvccSelfTest method testRemotes.

/**
 * Tests remote candidates.
 */
@Test
public void testRemotes() {
    GridCacheAdapter<String, String> cache = grid.internalCache(DEFAULT_CACHE_NAME);
    GridCacheTestEntryEx entry = new GridCacheTestEntryEx(cache.context(), "1");
    UUID node1 = UUID.randomUUID();
    UUID node2 = UUID.randomUUID();
    GridCacheVersion ver1 = version(1);
    GridCacheVersion ver2 = version(2);
    GridCacheVersion ver3 = version(3);
    GridCacheVersion ver4 = version(4);
    GridCacheVersion ver5 = version(5);
    entry.addRemote(node1, 1, ver1, true);
    Collection<GridCacheMvccCandidate> cands = entry.remoteMvccSnapshot();
    assert cands.size() == 1;
    assert cands.iterator().next().version().equals(ver1);
    entry.addRemote(node2, 5, ver5, true);
    cands = entry.remoteMvccSnapshot();
    assert cands.size() == 2;
    info(cands);
    // Check order.
    checkOrder(cands, ver1, ver5);
    entry.addRemote(node1, 3, ver3, true);
    cands = entry.remoteMvccSnapshot();
    info(cands);
    assert cands.size() == 3;
    // No reordering happens.
    checkOrder(cands, ver1, ver5, ver3);
    entry.doneRemote(ver3);
    checkDone(entry.candidate(ver3));
    entry.addRemote(node1, 2, ver2, true);
    cands = entry.remoteMvccSnapshot();
    info(cands);
    assert cands.size() == 4;
    // Check order.
    checkOrder(cands, ver1, ver5, ver3, ver2);
    entry.orderCompleted(new GridCacheVersion(1, 2, 0, 0), Arrays.asList(new GridCacheVersion(1, 3, 4, 0), ver2, new GridCacheVersion(1, 5, 6, 0)), Collections.<GridCacheVersion>emptyList());
    cands = entry.remoteMvccSnapshot();
    info(cands);
    assert cands.size() == 4;
    // Done ver 2.
    checkOrder(cands, ver1, ver2, ver5, ver3);
    checkRemote(entry.candidate(ver1), ver1, false, false);
    checkRemote(entry.candidate(ver2), ver2, true, false);
    checkRemote(entry.candidate(ver3), ver3, true, true);
    checkRemote(entry.candidate(ver5), ver5, false, false);
    entry.doneRemote(ver5);
    checkDone(entry.candidate(ver5));
    entry.addRemote(node1, 4, ver4, true);
    cands = entry.remoteMvccSnapshot();
    info(cands);
    assert cands.size() == 5;
    // Check order.
    checkOrder(cands, ver1, ver2, ver5, ver3, ver4);
    entry.orderCompleted(ver3, Arrays.asList(ver2, ver5), Collections.<GridCacheVersion>emptyList());
    cands = entry.remoteMvccSnapshot();
    info(cands);
    assert cands.size() == 5;
    checkOrder(cands, ver1, ver2, ver5, ver3, ver4);
    assert entry.anyOwner() == null;
    entry.doneRemote(ver1);
    checkRemoteOwner(entry.anyOwner(), ver1);
    entry.removeLock(ver1);
    assert entry.remoteMvccSnapshot().size() == 4;
    assert entry.anyOwner() == null;
    entry.doneRemote(ver2);
    checkRemoteOwner(entry.anyOwner(), ver2);
    entry.removeLock(ver2);
    assert entry.remoteMvccSnapshot().size() == 3;
    checkRemoteOwner(entry.anyOwner(), ver5);
    entry.removeLock(ver3);
    assert entry.remoteMvccSnapshot().size() == 2;
    checkRemoteOwner(entry.anyOwner(), ver5);
    entry.removeLock(ver5);
    assert entry.remoteMvccSnapshot().size() == 1;
    assert entry.anyOwner() == null;
    entry.doneRemote(ver4);
    checkRemoteOwner(entry.anyOwner(), ver4);
    entry.removeLock(ver4);
    assert entry.remoteMvccSnapshot().isEmpty();
    assert entry.anyOwner() == null;
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 57 with GridCacheVersion

use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.

the class GridCacheMvccSelfTest method testLocalWithRemote.

/**
 * Tests assignment of local candidates when remote exist.
 */
@Test
public void testLocalWithRemote() {
    GridCacheAdapter<String, String> cache = grid.internalCache(DEFAULT_CACHE_NAME);
    GridCacheTestEntryEx entry = new GridCacheTestEntryEx(cache.context(), "1");
    UUID nodeId = UUID.randomUUID();
    GridCacheVersion ver2 = version(2);
    GridCacheVersion ver3 = version(3);
    entry.addRemote(nodeId, 1, ver2, true);
    entry.addLocal(3, ver3, 0, false, true);
    assert entry.anyOwner() == null;
    entry.readyLocal(ver3);
    assert entry.anyOwner() == null;
    entry.removeLock(ver2);
    assert entry.localCandidates().size() == 1;
    checkLocalOwner(entry.anyOwner(), ver3, false);
    entry.removeLock(ver3);
    assert !entry.lockedByAny();
    assert entry.anyOwner() == null;
    assert entry.localCandidates(true).isEmpty();
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 58 with GridCacheVersion

use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.

the class GridCacheMvccSelfTest method testCompletedWithBaseInTheEndNoChange.

/**
 * This case should never happen, nevertheless we need to test for it.
 */
@Test
public void testCompletedWithBaseInTheEndNoChange() {
    GridCacheAdapter<String, String> cache = grid.internalCache(DEFAULT_CACHE_NAME);
    GridCacheTestEntryEx entry = new GridCacheTestEntryEx(cache.context(), "1");
    UUID node1 = UUID.randomUUID();
    UUID node2 = UUID.randomUUID();
    GridCacheVersion ver1 = version(1);
    GridCacheVersion ver2 = version(2);
    GridCacheVersion ver3 = version(3);
    GridCacheVersion ver4 = version(4);
    GridCacheVersion ver5 = version(5);
    GridCacheVersion ver6 = version(6);
    GridCacheVersion ver7 = version(7);
    entry.addRemote(node1, 1, ver1, false);
    entry.addRemote(node2, 2, ver2, false);
    entry.addRemote(node1, 3, ver3, false);
    entry.addRemote(node2, 4, ver4, false);
    entry.addRemote(node1, 5, ver5, false);
    List<GridCacheVersion> committed = Arrays.asList(ver6, ver7);
    entry.orderCompleted(ver5, committed, Collections.<GridCacheVersion>emptyList());
    checkOrder(entry.remoteMvccSnapshot(), ver1, ver2, ver3, ver4, ver5);
    // Nothing set to owner since there is no change.
    checkRemote(entry.candidate(ver1), ver1, false, false);
    checkRemote(entry.candidate(ver2), ver2, false, false);
    checkRemote(entry.candidate(ver3), ver3, false, false);
    checkRemote(entry.candidate(ver4), ver4, false, false);
    checkRemote(entry.candidate(ver5), ver5, false, false);
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 59 with GridCacheVersion

use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.

the class GridCacheMvccSelfTest method testCompletedWithBaseNotPresentInTheMiddle.

/**
 */
@Test
public void testCompletedWithBaseNotPresentInTheMiddle() {
    GridCacheAdapter<String, String> cache = grid.internalCache(DEFAULT_CACHE_NAME);
    GridCacheTestEntryEx entry = new GridCacheTestEntryEx(cache.context(), "1");
    UUID node1 = UUID.randomUUID();
    UUID node2 = UUID.randomUUID();
    GridCacheVersion ver1 = version(1);
    GridCacheVersion ver2 = version(2);
    GridCacheVersion ver3 = version(3);
    GridCacheVersion ver4 = version(4);
    GridCacheVersion ver5 = version(5);
    GridCacheVersion ver6 = version(6);
    GridCacheVersion ver7 = version(7);
    // Don't add version 2.
    entry.addRemote(node1, 1, ver1, true);
    entry.addRemote(node1, 3, ver3, true);
    entry.addRemote(node2, 4, ver4, true);
    entry.addRemote(node1, 5, ver5, true);
    entry.addRemote(node2, 6, ver6, true);
    entry.addRemote(node2, 7, ver7, true);
    List<GridCacheVersion> committed = Arrays.asList(ver6, ver4);
    entry.orderCompleted(ver2, committed, Collections.<GridCacheVersion>emptyList());
    checkOrder(entry.remoteMvccSnapshot(), ver1, ver4, ver6, ver3, ver5, ver7);
    checkRemote(entry.candidate(ver1), ver1, false, false);
    checkRemote(entry.candidate(ver3), ver3, false, false);
    checkRemote(entry.candidate(ver4), ver4, true, false);
    checkRemote(entry.candidate(ver5), ver5, false, false);
    checkRemote(entry.candidate(ver6), ver6, true, false);
    checkRemote(entry.candidate(ver7), ver7, false, false);
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 60 with GridCacheVersion

use of org.apache.ignite.internal.processors.cache.version.GridCacheVersion in project ignite by apache.

the class GridCacheMvccSelfTest method testReverseOrder2.

/**
 * Test 2 keys with candidates in reverse order.
 *
 * @throws Exception If failed.
 */
@Test
public void testReverseOrder2() throws Exception {
    UUID id = UUID.randomUUID();
    GridCacheAdapter<String, String> cache = grid.internalCache(DEFAULT_CACHE_NAME);
    GridCacheContext<String, String> ctx = cache.context();
    GridCacheTestEntryEx entry1 = new GridCacheTestEntryEx(ctx, "1");
    GridCacheTestEntryEx entry2 = new GridCacheTestEntryEx(ctx, "2");
    GridCacheVersion ver1 = version(1);
    GridCacheVersion ver2 = version(2);
    GridCacheVersion ver3 = version(3);
    // Local with higher version.
    GridCacheMvccCandidate v3k1 = entry1.addLocal(3, ver3, 0, true, true);
    GridCacheMvccCandidate v3k2 = entry2.addLocal(3, ver3, 0, true, true);
    // Link up.
    linkCandidates(ctx, v3k1, v3k2);
    entry1.readyLocal(v3k1);
    checkLocal(v3k1, ver3, true, true, false);
    checkLocal(v3k2, ver3, false, false, false);
    // Remote locks.
    GridCacheMvccCandidate v2k1 = entry1.addRemote(id, 3, ver2, false);
    GridCacheMvccCandidate v2k2 = entry2.addRemote(id, 3, ver2, false);
    checkRemote(v2k1, ver2, false, false);
    checkRemote(v2k2, ver2, false, false);
    // Local with lower version.
    GridCacheMvccCandidate v1k1 = entry1.addLocal(4, ver1, 0, true, true);
    GridCacheMvccCandidate v1k2 = entry2.addLocal(4, ver1, 0, true, true);
    // Link up.
    linkCandidates(ctx, v1k1, v1k2);
    entry1.readyLocal(v1k1);
    entry2.readyLocal(v1k2);
    checkLocal(v1k1, ver1, true, false, false);
    checkLocal(v1k2, ver1, true, false, false);
    checkLocal(v3k2, ver3, false, false, false);
    entry2.readyLocal(v3k2);
    // Note, ver3 should be acquired before ver1 (i.e. in reverse order from natural versions order).
    checkLocal(v3k2, ver3, true, true, false);
    checkLocal(v1k1, ver1, true, false, false);
    checkLocal(v1k2, ver1, true, false, false);
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)247 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)81 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)70 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)60 UUID (java.util.UUID)58 Test (org.junit.Test)58 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)55 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)51 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)34 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)32 Map (java.util.Map)30 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)30 ArrayList (java.util.ArrayList)29 ClusterNode (org.apache.ignite.cluster.ClusterNode)26 Collection (java.util.Collection)24 HashMap (java.util.HashMap)24 IgniteException (org.apache.ignite.IgniteException)22 Nullable (org.jetbrains.annotations.Nullable)22 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)21 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)20