Skip to content

Commit

Permalink
ignite-1089 Fixed tests for multi jvm mode. This closes #846.
Browse files Browse the repository at this point in the history
  • Loading branch information
sboikov committed Jul 4, 2016
1 parent e0ac099 commit bf57413
Show file tree
Hide file tree
Showing 5 changed files with 317 additions and 289 deletions.
Expand Up @@ -73,6 +73,7 @@
import org.apache.ignite.internal.util.future.GridFutureAdapter; import org.apache.ignite.internal.util.future.GridFutureAdapter;
import org.apache.ignite.internal.util.lang.GridAbsPredicate; import org.apache.ignite.internal.util.lang.GridAbsPredicate;
import org.apache.ignite.internal.util.lang.GridAbsPredicateX; 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.CIX1;
import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.PA; import org.apache.ignite.internal.util.typedef.PA;
Expand Down Expand Up @@ -3563,9 +3564,6 @@ public void testTtlNoTxOldEntry() throws Exception {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
private void checkTtl(boolean inTx, boolean oldEntry) throws Exception { private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {
if (isMultiJvm())
fail("https://issues.apache.org/jira/browse/IGNITE-1089");

if (memoryMode() == OFFHEAP_TIERED) if (memoryMode() == OFFHEAP_TIERED)
return; return;


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


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


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

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

GridCacheEntryEx entry;


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


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


assert entry != null; assertNotNull(entryTtl.get1());

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


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


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


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


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


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

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

GridCacheEntryEx curEntry = cache.peekEx(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] = curEntryTtl.get2();

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


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


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

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

GridCacheEntryEx curEntry = cache.peekEx(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] = curEntryTtl.get2();

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


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


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

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


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


assertEquals(ttl, curEntry.ttl()); expireTimes[i] = curEntryTtl.get2();

assert curEntry.expireTime() > startTime;

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


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


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

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


GridCacheEntryEx curEntry = cache.peekEx(key); assertNotNull(curEntryTtl.get1());

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


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


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


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


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


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


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


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


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


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


U.sleep(2000); U.sleep(2000);


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


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


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


/** /**
Expand Down Expand Up @@ -4322,6 +4305,15 @@ protected List<String> primaryKeysForCache(IgniteCache<String, Integer> cache, i
return primaryKeysForCache(cache, cnt, 1); 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. * @throws Exception If failed.
*/ */
Expand Down Expand Up @@ -5660,6 +5652,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 bf57413

Please sign in to comment.