Skip to content

Commit

Permalink
IGNITE-96 - Fixed Full API test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Goncharuk committed Feb 10, 2015
1 parent 7a35d38 commit 2dd61e0
Show file tree
Hide file tree
Showing 6 changed files with 335 additions and 217 deletions.
Expand Up @@ -56,9 +56,6 @@
@SuppressWarnings({
"NonPrivateFieldAccessedInSynchronizedContext", "TooBroadScope", "FieldAccessedSynchronizedAndUnsynchronized"})
public abstract class GridCacheMapEntry<K, V> implements GridCacheEntryEx<K, V> {
/** */
private static final long serialVersionUID = 0L;

/** */
private static final sun.misc.Unsafe UNSAFE = GridUnsafe.unsafe();

Expand Down Expand Up @@ -1165,8 +1162,6 @@ else if (interceptorVal != val) {
subjId, null, taskName);
}

CacheMode mode = cctx.config().getCacheMode();

if (cctx.isLocal() || cctx.isReplicated() || (tx != null && tx.local() && !isNear()))
cctx.continuousQueries().onEntryUpdate(this, key, val, valueBytesUnlocked(), old, oldBytes, false);

Expand Down Expand Up @@ -1326,8 +1321,6 @@ else if (log.isDebugEnabled())
null, taskName);
}

CacheMode mode = cctx.config().getCacheMode();

if (cctx.isLocal() || cctx.isReplicated() || (tx != null && tx.local() && !isNear()))
cctx.continuousQueries().onEntryUpdate(this, key, null, null, old, oldBytes, false);

Expand Down Expand Up @@ -1674,16 +1667,12 @@ else if (log.isDebugEnabled())
if (isNew())
unswap(true, retval);

boolean newTtlResolved = false;

boolean drNeedResolve = false;

Object transformClo = null;

if (drResolve) {
GridCacheVersion oldDrVer = version().drVersion();

drNeedResolve = cctx.conflictNeedResolve(oldDrVer, drVer);
boolean drNeedResolve = cctx.conflictNeedResolve(oldDrVer, drVer);

if (drNeedResolve) {
// Get old value.
Expand Down Expand Up @@ -1714,8 +1703,6 @@ else if (log.isDebugEnabled())
newExpireTime = CU.toExpireTime(newTtl);
}

newTtlResolved = true;

GridCacheVersionedEntryEx<K, V> oldEntry = versionedEntry();
GridCacheVersionedEntryEx<K, V> newEntry =
new GridCachePlainVersionedEntry<>(k, (V)writeObj, newTtl, newExpireTime, drVer);
Expand Down Expand Up @@ -1870,7 +1857,7 @@ assert isNew() || ATOMIC_VER_COMPARATOR.compare(ver, newVer) <= 0 :
expiryPlc.ttlUpdated(key,
getOrMarshalKeyBytes(),
version(),
hasReaders() ? ((GridDhtCacheEntry) this).readers() : null);
hasReaders() ? ((GridDhtCacheEntry<K, V>) this).readers() : null);
}
}

Expand Down Expand Up @@ -4349,20 +4336,38 @@ private IteratorEntry(K key) {
}

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public V getValue() {
for (;;) {
GridCacheEntryEx<K, V> e = cctx.cache().peekEx(key);
try {
IgniteInternalTx<K, V> tx = cctx.tm().userTx();

if (e == null)
return null;
if (tx != null) {
GridTuple<V> peek = tx.peek(cctx, false, key, null);

try {
return e.peek(GridCachePeekMode.GLOBAL, CU.<K, V>empty());
if (peek != null)
return peek.get();
}
catch (GridCacheEntryRemovedException ignored) {
// No-op.

if (detached())
return rawGet();

for (;;) {
GridCacheEntryEx<K, V> e = cctx.cache().peekEx(key);

if (e == null)
return null;

try {
return e.peek(GridCachePeekMode.GLOBAL, CU.<K, V>empty());
}
catch (GridCacheEntryRemovedException ignored) {
// No-op.
}
}
}
catch (GridCacheFilterFailedException ignored) {
throw new IgniteException("Should never happen.");
}
}

/** {@inheritDoc} */
Expand Down
Expand Up @@ -28,9 +28,6 @@
* Detached cache entry.
*/
public class GridDhtDetachedCacheEntry<K, V> extends GridDistributedCacheEntry<K, V> {
/** */
private static final long serialVersionUID = 0L;

/**
* @param ctx Cache context.
* @param key Cache key.
Expand Down
Expand Up @@ -161,6 +161,13 @@ protected boolean offHeapValues() {
dfltIgnite = null;
}

/**
* @return A not near-only cache.
*/
protected IgniteCache<String, Integer> fullCache() {
return jcache();
}

/**
* @throws Exception In case of error.
*/
Expand Down Expand Up @@ -1566,14 +1573,14 @@ public void testGetAndPutIfAbsentAsync() throws Exception {
IgniteFuture<Integer> fut1 = cacheAsync.future();

assert fut1.get() == null;
assert cache.get("key") != null && cache.get("key") == 1;
assertEquals((Integer)1, cache.get("key"));

cacheAsync.getAndPutIfAbsent("key", 2);

IgniteFuture<Integer> fut2 = cacheAsync.future();

assert fut2.get() != null && fut2.get() == 1;
assert cache.get("key") != null && cache.get("key") == 1;
assertEquals((Integer)1, fut2.get());
assertEquals((Integer)1, cache.get("key"));

if (tx != null)
tx.commit();
Expand Down Expand Up @@ -2987,20 +2994,23 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {

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

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

GridCacheAdapter<Object, Object> internalCache = ((IgniteKernal)grid(0)).internalCache();
GridCacheAdapter<String, Integer> internalCache = internalCache(fullCache());

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

GridCacheEntryEx entry = internalCache.peekEx(key);
GridCacheEntryEx entry;

assert entry != null;
if (oldEntry) {
c.put(key, 1);

assertEquals(0, entry.ttl());
assertEquals(0, entry.expireTime());
entry = internalCache.peekEx(key);

assert entry != null;

assertEquals(0, entry.ttl());
assertEquals(0, entry.expireTime());
}

long startTime = System.currentTimeMillis();

Expand All @@ -3015,10 +3025,12 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {
tx.rollback();
}

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

assertEquals(0, entry.ttl());
assertEquals(0, entry.expireTime());
assertEquals(0, entry.ttl());
assertEquals(0, entry.expireTime());
}
}

// Now commit transaction and check that ttl and expire time have been saved.
Expand All @@ -3039,8 +3051,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)) {
GridCacheEntryEx<Object, Object> curEntry =
internalCache.peekEx(key);
GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));

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

GridCacheEntryEx<String, Integer> curEntry = cache.peekEx(key);

assertEquals(ttl, curEntry.ttl());

Expand Down Expand Up @@ -3068,8 +3084,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)) {
GridCacheEntryEx<Object, Object> curEntry =
internalCache.peekEx(key);
GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));

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

GridCacheEntryEx<String, Integer> curEntry = cache.peekEx(key);

assertEquals(ttl, curEntry.ttl());

Expand Down Expand Up @@ -3097,8 +3117,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)) {
GridCacheEntryEx<Object, Object> curEntry =
internalCache.peekEx(key);
GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));

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

GridCacheEntryEx<String, Integer> curEntry = cache.peekEx(key);

assertEquals(ttl, curEntry.ttl());

Expand Down Expand Up @@ -3130,8 +3154,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)) {
GridCacheEntryEx<Object, Object> curEntry =
internalCache.peekEx(key);
GridCacheAdapter<String, Integer> cache = internalCache(jcache(i));

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

GridCacheEntryEx<String, Integer> curEntry = cache.peekEx(key);

assertEquals(ttl, curEntry.ttl());
assertEquals(expireTimes[i], curEntry.expireTime());
Expand All @@ -3143,7 +3171,7 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {

assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicateX() {
@SuppressWarnings("unchecked")
@Override public boolean applyx() throws IgniteCheckedException {
@Override public boolean applyx() {
try {
Integer val = c.get(key);

Expand Down Expand Up @@ -3173,11 +3201,16 @@ private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {
if (internalCache.isLocal())
return;

assert c.get(key) == null;

internalCache = internalCache(fullCache());

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

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

assert c.get(key) == null;

assertEquals(0, entry.ttl());
assertEquals(0, entry.expireTime());

Expand Down

0 comments on commit 2dd61e0

Please sign in to comment.