Search in sources :

Example 46 with GridCacheVersion

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

the class GridCacheMvccPartitionedSelfTest method checkSerializableAdd.

/**
 * @param incVer If {@code true} lock version is incremented.
 * @throws Exception If failed.
 */
private void checkSerializableAdd(boolean incVer) throws Exception {
    GridCacheAdapter<String, String> cache = grid.internalCache(DEFAULT_CACHE_NAME);
    UUID nodeId = UUID.randomUUID();
    GridCacheMvcc mvcc = new GridCacheMvcc(cache.context());
    GridCacheTestEntryEx e = new GridCacheTestEntryEx(cache.context(), "1");
    GridCacheVersion serOrder1 = new GridCacheVersion(0, 10, 1);
    GridCacheVersion serOrder2 = new GridCacheVersion(0, 20, 1);
    GridCacheVersion serOrder3 = new GridCacheVersion(0, 15, 1);
    GridCacheVersion serOrder4 = new GridCacheVersion(0, 30, 1);
    GridCacheVersion ver1 = incVer ? version(1) : version(4);
    GridCacheVersion ver2 = incVer ? version(2) : version(3);
    GridCacheVersion ver3 = incVer ? version(3) : version(2);
    GridCacheVersion ver4 = incVer ? version(4) : version(1);
    GridCacheMvccCandidate cand1 = mvcc.addLocal(e, nodeId, null, 1, ver1, 0, serOrder1, false, true, false, true, false);
    assertNotNull(cand1);
    GridCacheMvccCandidate cand2 = mvcc.addLocal(e, nodeId, null, 2, ver2, 0, serOrder2, false, true, false, true, false);
    assertNotNull(cand2);
    GridCacheMvccCandidate cand3 = mvcc.addLocal(e, nodeId, null, 3, ver3, 0, serOrder3, false, true, false, true, false);
    assertNull(cand3);
    GridCacheMvccCandidate cand4 = mvcc.addLocal(e, nodeId, null, 4, ver4, 0, serOrder4, false, true, false, true, false);
    assertNotNull(cand4);
    CacheLockCandidates owners = mvcc.recheck();
    assertNull(owners);
    cand2.setReady();
    owners = mvcc.recheck();
    assertNull(owners);
    cand1.setReady();
    owners = mvcc.recheck();
    assertSame(cand1, owners);
    owners = mvcc.recheck();
    assertSame(cand1, owners);
    mvcc.remove(cand1.version());
    owners = mvcc.recheck();
    assertSame(cand2, owners);
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) UUID(java.util.UUID)

Example 47 with GridCacheVersion

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

the class GridCacheMvccPartitionedSelfTest method testNearLocalsWithCommitted.

/**
 * Tests remote candidates.
 */
@Test
public void testNearLocalsWithCommitted() {
    GridCacheAdapter<String, String> cache = grid.internalCache(DEFAULT_CACHE_NAME);
    GridCacheTestEntryEx entry = new GridCacheTestEntryEx(cache.context(), "1");
    UUID node1 = UUID.randomUUID();
    GridCacheVersion ver1 = version(1);
    GridCacheVersion ver2 = version(2);
    GridCacheMvccCandidate c1 = entry.addNearLocal(node1, 1, ver1, true);
    GridCacheMvccCandidate c2 = entry.addRemote(node1, 1, ver2, true);
    Collection<GridCacheMvccCandidate> rmtCands = entry.remoteMvccSnapshot();
    Collection<GridCacheMvccCandidate> nearLocCands = entry.localCandidates();
    assertEquals(1, nearLocCands.size());
    assertEquals(ver1, nearLocCands.iterator().next().version());
    assertEquals(1, rmtCands.size());
    assertEquals(ver2, rmtCands.iterator().next().version());
    entry.readyNearLocal(ver1, ver1, Arrays.asList(ver2), empty(), empty());
    checkLocal(c1, ver1, true, false, false);
    checkRemote(c2, ver2, true, false);
    assertNull(entry.anyOwner());
}
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 48 with GridCacheVersion

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

the class GridCacheMvccPartitionedSelfTest method checkCandidates.

/**
 * @param all Candidates list.
 * @param vers Expected candidates.
 */
private void checkCandidates(CacheLockCandidates all, GridCacheVersion... vers) {
    assertNotNull(all);
    assertEquals(vers.length, all.size());
    for (GridCacheVersion ver : vers) assertTrue(all.hasCandidate(ver));
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion)

Example 49 with GridCacheVersion

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

the class GridCacheMvccPartitionedSelfTest method testNearLocalsWithPending.

/**
 * Tests remote candidates.
 */
@Test
public void testNearLocalsWithPending() {
    GridCacheAdapter<String, String> cache = grid.internalCache(DEFAULT_CACHE_NAME);
    GridCacheTestEntryEx entry = new GridCacheTestEntryEx(cache.context(), "1");
    UUID node1 = UUID.randomUUID();
    GridCacheVersion ver1 = version(1);
    GridCacheVersion ver2 = version(2);
    GridCacheMvccCandidate c1 = entry.addRemote(node1, 1, ver1, true);
    GridCacheMvccCandidate c2 = entry.addNearLocal(node1, 1, ver2, true);
    Collection<GridCacheMvccCandidate> rmtCands = entry.remoteMvccSnapshot();
    Collection<GridCacheMvccCandidate> nearLocCands = entry.localCandidates();
    assertEquals(1, nearLocCands.size());
    assertEquals(ver2, nearLocCands.iterator().next().version());
    assertEquals(1, rmtCands.size());
    assertEquals(ver1, rmtCands.iterator().next().version());
    entry.readyNearLocal(ver2, ver2, empty(), empty(), Arrays.asList(ver1));
    checkLocalOwner(c2, ver2, false);
    checkRemote(c1, ver1, false, false);
    assertNotNull(entry.anyOwner());
    assertEquals(ver2, entry.anyOwner().version());
}
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 50 with GridCacheVersion

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

the class GridCacheMvccSelfTest method testLocal.

/**
 * Tests remote candidates.
 */
@Test
public void testLocal() {
    GridCacheAdapter<String, String> cache = grid.internalCache(DEFAULT_CACHE_NAME);
    GridCacheTestEntryEx entry = new GridCacheTestEntryEx(cache.context(), "1");
    GridCacheVersion ver3 = version(3);
    GridCacheVersion ver4 = version(4);
    GridCacheVersion ver5 = version(5);
    entry.addLocal(3, ver3, 0, true, true);
    Collection<GridCacheMvccCandidate> cands = entry.localCandidates();
    assert cands.size() == 1;
    assert cands.iterator().next().version().equals(ver3);
    entry.addLocal(5, ver5, 0, true, true);
    cands = entry.localCandidates();
    assert cands.size() == 2;
    info(cands);
    // Check order.
    checkOrder(cands, ver3, ver5);
    assert entry.anyOwner() == null;
    entry.readyLocal(ver3);
    checkLocalOwner(entry.anyOwner(), ver3, false);
    // Reentry.
    entry.addLocal(3, ver4, 0, true, true);
    checkLocalOwner(entry.anyOwner(), ver4, true);
    assert entry.localCandidates().size() == 2;
    assert entry.localCandidates(true).size() == 3;
    // Check order.
    checkOrder(entry.localCandidates(true), ver4, ver3, ver5);
    entry.removeLock(ver4);
    assert entry.localCandidates(true).size() == 2;
    entry.readyLocal(ver5);
    checkLocalOwner(entry.anyOwner(), ver3, false);
    // Check order.
    checkOrder(entry.localCandidates(true), ver3, ver5);
    entry.removeLock(ver3);
    assert entry.localCandidates(true).size() == 1;
    checkLocalOwner(entry.anyOwner(), ver5, false);
    assert !entry.lockedByAny(ver5);
    entry.removeLock(ver5);
    assert !entry.lockedByAny();
    assert entry.anyOwner() == null;
    assert entry.localCandidates(true).isEmpty();
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) 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