Skip to content

Commit

Permalink
ignite-1089 Fixed tests for multi jvm mode. This closes apache#846.
Browse files Browse the repository at this point in the history
(cherry picked from commit bf57413)
  • Loading branch information
sboikov committed Jul 15, 2016
1 parent ade57ea commit d2198a1
Show file tree
Hide file tree
Showing 5 changed files with 317 additions and 289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.apache.ignite.internal.processors.resource.GridSpringResourceContext;
import org.apache.ignite.internal.util.lang.GridAbsPredicate;
import org.apache.ignite.internal.util.lang.GridAbsPredicateX;
import org.apache.ignite.internal.util.lang.IgnitePair;
import org.apache.ignite.internal.util.typedef.CIX1;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.PA;
Expand Down Expand Up @@ -3559,9 +3560,6 @@ public void testTtlNoTxOldEntry() throws Exception {
* @throws Exception If failed.
*/
private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {
if (isMultiJvm())
fail("https://issues.apache.org/jira/browse/IGNITE-1089");

if (memoryMode() == OFFHEAP_TIERED)
return;

Expand All @@ -3573,22 +3571,17 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {

final String key = primaryKeysForCache(jcache(), 1).get(0);

GridCacheAdapter<String, Integer> internalCache = internalCache(fullCache());

if (internalCache.isNear())
internalCache = internalCache.context().near().dht();

GridCacheEntryEx entry;
IgnitePair<Long> entryTtl;

if (oldEntry) {
c.put(key, 1);

entry = internalCache.peekEx(key);
entryTtl = entryTtl(fullCache(), key);

assert entry != null;

assertEquals(0, entry.ttl());
assertEquals(0, entry.expireTime());
assertNotNull(entryTtl.get1());
assertNotNull(entryTtl.get2());
assertEquals((Long)0L, entryTtl.get1());
assertEquals((Long)0L, entryTtl.get2());
}

long startTime = System.currentTimeMillis();
Expand All @@ -3605,10 +3598,10 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {
}

if (oldEntry) {
entry = internalCache.peekEx(key);
entryTtl = entryTtl(fullCache(), key);

assertEquals(0, entry.ttl());
assertEquals(0, entry.expireTime());
assertEquals((Long)0L, entryTtl.get1());
assertEquals((Long)0L, entryTtl.get2());
}
}

Expand All @@ -3630,18 +3623,14 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {

for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));

if (cache.context().isNear())
cache = cache.context().near().dht();

GridCacheEntryEx curEntry = cache.peekEx(key);
IgnitePair<Long> curEntryTtl = entryTtl(jcache(i), key);

assertEquals(ttl, curEntry.ttl());
assertNotNull(curEntryTtl.get1());
assertNotNull(curEntryTtl.get2());
assertEquals(ttl, (long) curEntryTtl.get1());
assertTrue(curEntryTtl.get2() > startTime);

assert curEntry.expireTime() > startTime;

expireTimes[i] = curEntry.expireTime();
expireTimes[i] = curEntryTtl.get2();
}
}

Expand All @@ -3663,18 +3652,14 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {

for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));

if (cache.context().isNear())
cache = cache.context().near().dht();

GridCacheEntryEx curEntry = cache.peekEx(key);
IgnitePair<Long> curEntryTtl = entryTtl(jcache(i), key);

assertEquals(ttl, curEntry.ttl());
assertNotNull(curEntryTtl.get1());
assertNotNull(curEntryTtl.get2());
assertEquals(ttl, (long) curEntryTtl.get1());
assertTrue(curEntryTtl.get2() > startTime);

assert curEntry.expireTime() > startTime;

expireTimes[i] = curEntry.expireTime();
expireTimes[i] = curEntryTtl.get2();
}
}

Expand All @@ -3696,18 +3681,14 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {

for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));

if (cache.context().isNear())
cache = cache.context().near().dht();
IgnitePair<Long> curEntryTtl = entryTtl(jcache(i), key);

GridCacheEntryEx curEntry = cache.peekEx(key);
assertNotNull(curEntryTtl.get1());
assertNotNull(curEntryTtl.get2());
assertEquals(ttl, (long) curEntryTtl.get1());
assertTrue(curEntryTtl.get2() > startTime);

assertEquals(ttl, curEntry.ttl());

assert curEntry.expireTime() > startTime;

expireTimes[i] = curEntry.expireTime();
expireTimes[i] = curEntryTtl.get2();
}
}

Expand All @@ -3733,15 +3714,12 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {

for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(null).isPrimaryOrBackup(grid(i).localNode(), key)) {
GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));

if (cache.context().isNear())
cache = cache.context().near().dht();
IgnitePair<Long> curEntryTtl = entryTtl(jcache(i), key);

GridCacheEntryEx curEntry = cache.peekEx(key);

assertEquals(ttl, curEntry.ttl());
assertEquals(expireTimes[i], curEntry.expireTime());
assertNotNull(curEntryTtl.get1());
assertNotNull(curEntryTtl.get2());
assertEquals(ttl, (long)curEntryTtl.get1());
assertEquals(expireTimes[i], (long)curEntryTtl.get2());
}
}

Expand Down Expand Up @@ -3777,21 +3755,24 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {
}
}, Math.min(ttl * 10, getTestTimeout())));

if (internalCache.isLocal())
return;
IgniteCache fullCache = fullCache();

assert c.get(key) == null;
if (!isMultiJvmObject(fullCache)) {
GridCacheAdapter internalCache = internalCache(fullCache);

internalCache = internalCache(fullCache());
if (internalCache.isLocal())
return;
}

if (internalCache.isNear())
internalCache = internalCache.context().near().dht();
assert c.get(key) == null;

// Ensure that old TTL and expire time are not longer "visible".
entry = internalCache.peekEx(key);
entryTtl = entryTtl(fullCache(), key);

assertEquals(0, entry.ttl());
assertEquals(0, entry.expireTime());
assertNotNull(entryTtl.get1());
assertNotNull(entryTtl.get2());
assertEquals(0, (long)entryTtl.get1());
assertEquals(0, (long)entryTtl.get2());

// Ensure that next update will not pick old expire time.

Expand All @@ -3810,12 +3791,14 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {

U.sleep(2000);

entry = internalCache.peekEx(key);
entryTtl = entryTtl(fullCache(), key);

assertEquals((Integer)10, c.get(key));

assertEquals(0, entry.ttl());
assertEquals(0, entry.expireTime());
assertNotNull(entryTtl.get1());
assertNotNull(entryTtl.get2());
assertEquals(0, (long)entryTtl.get1());
assertEquals(0, (long)entryTtl.get2());
}

/**
Expand Down Expand Up @@ -4318,6 +4301,15 @@ protected List<String> primaryKeysForCache(IgniteCache<String, Integer> cache, i
return primaryKeysForCache(cache, cnt, 1);
}

/**
* @param cache Cache.
* @param key Entry key.
* @return Pair [ttl, expireTime]; both values null if entry not found
*/
protected IgnitePair<Long> entryTtl(IgniteCache cache, String key) {
return executeOnLocalOrRemoteJvm(cache, new EntryTtlTask(key, true));
}

/**
* @throws Exception If failed.
*/
Expand Down Expand Up @@ -5610,6 +5602,40 @@ public CheckPrimaryKeysTask(int startFrom, int cnt) {
}
}

/**
*
*/
public static class EntryTtlTask implements TestCacheCallable<String, Integer, IgnitePair<Long>> {
/** Entry key. */
private final String key;

/** Check cache for nearness, use DHT cache if it is near. */
private final boolean useDhtForNearCache;

/**
* @param key Entry key.
* @param useDhtForNearCache Check cache for nearness, use DHT cache if it is near.
*/
public EntryTtlTask(String key, boolean useDhtForNearCache) {
this.key = key;
this.useDhtForNearCache = useDhtForNearCache;
}

/** {@inheritDoc} */
@Override public IgnitePair<Long> call(Ignite ignite, IgniteCache<String, Integer> cache) throws Exception {
GridCacheAdapter<?, ?> internalCache = internalCache0(cache);

if (useDhtForNearCache && internalCache.context().isNear())
internalCache = internalCache.context().near().dht();

GridCacheEntryEx entry = internalCache.peekEx(key);

return entry != null ?
new IgnitePair<>(entry.ttl(), entry.expireTime()) :
new IgnitePair<Long>(null, null);
}
}

/**
*
*/
Expand Down

0 comments on commit d2198a1

Please sign in to comment.