You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/05/19 20:33:01 UTC
[8/8] incubator-ignite git commit: ignite-916 Eviction policy should
evict cache entries when memory size limit is reached
ignite-916 Eviction policy should evict cache entries when memory size limit is reached
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/86ed8b82
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/86ed8b82
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/86ed8b82
Branch: refs/heads/ignite-916
Commit: 86ed8b82514152cd9e119e11498ff45d6e49be4e
Parents: 9d89d9c
Author: agura <ag...@gridgain.com>
Authored: Tue May 19 21:32:29 2015 +0300
Committer: agura <ag...@gridgain.com>
Committed: Tue May 19 21:32:29 2015 +0300
----------------------------------------------------------------------
.../cache/eviction/fifo/FifoEvictionPolicy.java | 21 +-
.../eviction/fifo/FifoEvictionPolicyMBean.java | 22 +
.../cache/eviction/lru/LruEvictionPolicy.java | 106 ++++-
.../eviction/lru/LruEvictionPolicyMBean.java | 38 ++
.../eviction/random/RandomEvictionPolicy.java | 2 +-
.../eviction/sorted/SortedEvictionPolicy.java | 118 ++++--
.../sorted/SortedEvictionPolicyMBean.java | 22 +
.../cache/CacheEvictableEntryImpl.java | 20 +-
.../GridCacheEmptyEntriesAbstractSelfTest.java | 2 +-
.../eviction/GridCacheEvictionAbstractTest.java | 145 +++++--
...ridCacheFifoBatchEvictionPolicySelfTest.java | 84 ++--
.../GridCacheFifoEvictionPolicySelfTest.java | 89 ++--
...idCacheFifoMemoryEvictionPolicySelfTest.java | 49 ++-
.../lru/GridCacheLruEvictionPolicySelfTest.java | 82 ++--
.../GridCacheRandomEvictionPolicySelfTest.java | 2 +-
...dCacheSortedBatchEvictionPolicySelfTest.java | 120 +++---
...acheSortedEvictionPolicyPerformanceTest.java | 4 -
.../GridCacheSortedEvictionPolicySelfTest.java | 91 ++--
...CacheSortedMemoryEvictionPolicySelfTest.java | 410 +++++++++++++++++++
.../IgniteCacheEvictionSelfTestSuite.java | 4 +
20 files changed, 1097 insertions(+), 334 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/FifoEvictionPolicy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/FifoEvictionPolicy.java b/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/FifoEvictionPolicy.java
index 06f67a2..b69d899 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/FifoEvictionPolicy.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/FifoEvictionPolicy.java
@@ -131,22 +131,25 @@ public class FifoEvictionPolicy<K, V> implements EvictionPolicy<K, V>, FifoEvict
this.batchSize = batchSize;
}
- public long getMaxMemSize() {
+ /** {@inheritDoc} */
+ @Override public int getCurrentSize() {
+ return queue.size();
+ }
+
+ /** {@inheritDoc} */
+ @Override public long getMaxMemSize() {
return maxMemSize;
}
- public void setMaxMemSize(long maxMemSize) {
+ /** {@inheritDoc} */
+ @Override public void setMaxMemSize(long maxMemSize) {
A.ensure(maxMemSize > 0, "maxMemSize > 0");
this.maxMemSize = maxMemSize;
}
/** {@inheritDoc} */
- @Override public int getCurrentSize() {
- return queue.size();
- }
-
- public long getCurrentMemSize() {
+ @Override public long getCurrentMemSize() {
return memSize.longValue();
}
@@ -249,12 +252,10 @@ public class FifoEvictionPolicy<K, V> implements EvictionPolicy<K, V>, FifoEvict
int max = this.max;
if (max > 0) {
- int batchSize = this.batchSize;
-
int startSize = queue.sizex();
// Shrink only if queue is full.
- if (startSize >= max + batchSize)
+ if (startSize >= max + (maxMem > 0 ? 1 : this.batchSize))
for (int i = max; i < startSize && queue.sizex() > max; i++)
if (shrink0() == -1)
break;
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/FifoEvictionPolicyMBean.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/FifoEvictionPolicyMBean.java b/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/FifoEvictionPolicyMBean.java
index 63a413e..c9a09ec 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/FifoEvictionPolicyMBean.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/fifo/FifoEvictionPolicyMBean.java
@@ -63,4 +63,26 @@ public interface FifoEvictionPolicyMBean {
*/
@MXBeanDescription("Current FIFO queue size.")
public int getCurrentSize();
+
+ /**
+ * Gets maximum allowed cache size in bytes.
+ *
+ * @return maximum allowed cache size in bytes.
+ */
+ @MXBeanDescription("Maximum allowed cache size in bytes.")
+ public long getMaxMemSize();
+
+ /**
+ * Sets maximum allowed cache size in bytes.
+ */
+ @MXBeanDescription("Set maximum allowed cache size in bytes.")
+ public void setMaxMemSize(long maxMemSize);
+
+ /**
+ * Gets current queue size in bytes.
+ *
+ * @return current queue size in bytes.
+ */
+ @MXBeanDescription("Current FIFO queue size in bytes.")
+ public long getCurrentMemSize();
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/LruEvictionPolicy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/LruEvictionPolicy.java b/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/LruEvictionPolicy.java
index 309d577..bf4051d 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/LruEvictionPolicy.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/LruEvictionPolicy.java
@@ -39,6 +39,15 @@ public class LruEvictionPolicy<K, V> implements EvictionPolicy<K, V>, LruEvictio
/** Maximum size. */
private volatile int max = CacheConfiguration.DFLT_CACHE_SIZE;
+ /** Batch size. */
+ private volatile int batchSize = 1;
+
+ /** Max memory size. */
+ private volatile long maxMemSize;
+
+ /** Memory size. */
+ private final LongAdder8 memSize = new LongAdder8();
+
/** Queue. */
private final ConcurrentLinkedDeque8<EvictableEntry<K, V>> queue =
new ConcurrentLinkedDeque8<>();
@@ -82,10 +91,39 @@ public class LruEvictionPolicy<K, V> implements EvictionPolicy<K, V>, LruEvictio
}
/** {@inheritDoc} */
+ @Override public int getBatchSize() {
+ return batchSize;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void setBatchSize(int batchSize) {
+ A.ensure(batchSize > 0, "batchSize > 0");
+
+ this.batchSize = batchSize;
+ }
+
+ /** {@inheritDoc} */
@Override public int getCurrentSize() {
return queue.size();
}
+ /** {@inheritDoc} */
+ @Override public long getMaxMemSize() {
+ return maxMemSize;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void setMaxMemSize(long maxMemSize) {
+ A.ensure(maxMemSize > 0, "maxMemSize > 0");
+
+ this.maxMemSize = maxMemSize;
+ }
+
+ /** {@inheritDoc} */
+ @Override public long getCurrentMemSize() {
+ return memSize.longValue();
+ }
+
/**
* Gets read-only view on internal {@code FIFO} queue in proper order.
*
@@ -107,8 +145,11 @@ public class LruEvictionPolicy<K, V> implements EvictionPolicy<K, V>, LruEvictio
else {
Node<EvictableEntry<K, V>> node = entry.removeMeta();
- if (node != null)
+ if (node != null) {
queue.unlinkx(node);
+
+ memSize.add(-entry.size());
+ }
}
}
@@ -139,11 +180,18 @@ public class LruEvictionPolicy<K, V> implements EvictionPolicy<K, V>, LruEvictio
return false;
}
+ memSize.add(entry.size());
+
return true;
}
// If node was unlinked by concurrent shrink() call, we must repeat the whole cycle.
else if (!entry.removeMeta(node))
return false;
+ else {
+ memSize.add(-entry.size());
+
+ return true;
+ }
}
}
else if (queue.unlinkx(node)) {
@@ -163,31 +211,73 @@ public class LruEvictionPolicy<K, V> implements EvictionPolicy<K, V>, LruEvictio
* Shrinks queue to maximum allowed size.
*/
private void shrink() {
+ long maxMem = this.maxMemSize;
+
+ if (maxMem > 0) {
+ long startMemSize = memSize.longValue();
+
+ if (startMemSize >= maxMem)
+ for (long i = maxMem; i < startMemSize && memSize.longValue() > maxMem;) {
+ int size = shrink0();
+
+ if (size == -1)
+ break;
+
+ i += size;
+ }
+ }
+
int max = this.max;
- int startSize = queue.sizex();
+ if (max > 0) {
+ int startSize = queue.sizex();
- for (int i = 0; i < startSize && queue.sizex() > max; i++) {
- EvictableEntry<K, V> entry = queue.poll();
+ if (startSize >= max + (maxMem > 0 ? 1 : this.batchSize))
+ for (int i = max; i < startSize && queue.sizex() > max; i++)
+ if (shrink0() == -1)
+ break;
+ }
+ }
+
+ /**
+ * Tries to remove one item from queue.
+ *
+ * @return number of bytes that was free. {@code -1} if queue is empty.
+ */
+ private int shrink0() {
+ EvictableEntry<K, V> entry = queue.poll();
+
+ if (entry == null)
+ return -1;
+
+ int size = 0;
- if (entry == null)
- break;
+ Node<EvictableEntry<K, V>> meta = entry.removeMeta();
- Node<EvictableEntry<K, V>> meta = entry.removeMeta();
+ if (meta != null) {
+ size = entry.size();
- if (meta != null && !entry.evict())
+ memSize.add(-size);
+
+ if (!entry.evict())
touch(entry);
}
+
+ return size;
}
/** {@inheritDoc} */
@Override public void writeExternal(ObjectOutput out) throws IOException {
out.writeInt(max);
+ out.writeInt(batchSize);
+ out.writeLong(maxMemSize);
}
/** {@inheritDoc} */
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
max = in.readInt();
+ batchSize = in.readInt();
+ maxMemSize = in.readLong();
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/LruEvictionPolicyMBean.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/LruEvictionPolicyMBean.java b/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/LruEvictionPolicyMBean.java
index c243374..69347ee 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/LruEvictionPolicyMBean.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/lru/LruEvictionPolicyMBean.java
@@ -41,10 +41,48 @@ public interface LruEvictionPolicyMBean {
public void setMaxSize(int max);
/**
+ * Gets batch size.
+ *
+ * @return batch size.
+ */
+ @MXBeanDescription("Batch size.")
+ public int getBatchSize();
+
+ /**
+ * Sets batch size.
+ *
+ * @param batchSize Batch size.
+ */
+ @MXBeanDescription("Set batch size.")
+ public void setBatchSize(int batchSize);
+
+ /**
* Gets current queue size.
*
* @return Current queue size.
*/
@MXBeanDescription("Current queue size.")
public int getCurrentSize();
+
+ /**
+ * Gets maximum allowed cache size in bytes.
+ *
+ * @return maximum allowed cache size in bytes.
+ */
+ @MXBeanDescription("Maximum allowed cache size in bytes.")
+ public long getMaxMemSize();
+
+ /**
+ * Sets maximum allowed cache size in bytes.
+ */
+ @MXBeanDescription("Set maximum allowed cache size in bytes.")
+ public void setMaxMemSize(long maxMemSize);
+
+ /**
+ * Gets current queue size in bytes.
+ *
+ * @return current queue size in bytes.
+ */
+ @MXBeanDescription("Current queue size in bytes.")
+ public long getCurrentMemSize();
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/RandomEvictionPolicy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/RandomEvictionPolicy.java b/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/RandomEvictionPolicy.java
index c88b31d..9c968dc 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/RandomEvictionPolicy.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/random/RandomEvictionPolicy.java
@@ -31,7 +31,7 @@ import java.io.*;
* extremely light weight, lock-free, and does not create any data structures to maintain
* any order for eviction.
* <p>
- * Random eviction will provide the best performance over any key set in which every
+ * Random eviction will provide the best performance over any key queue in which every
* key has the same probability of being accessed.
*/
public class RandomEvictionPolicy<K, V> implements EvictionPolicy<K, V>, RandomEvictionPolicyMBean, Externalizable {
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/main/java/org/apache/ignite/cache/eviction/sorted/SortedEvictionPolicy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/sorted/SortedEvictionPolicy.java b/modules/core/src/main/java/org/apache/ignite/cache/eviction/sorted/SortedEvictionPolicy.java
index 7965c97..ee3e857 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/sorted/SortedEvictionPolicy.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/sorted/SortedEvictionPolicy.java
@@ -18,6 +18,7 @@
package org.apache.ignite.cache.eviction.sorted;
import org.apache.ignite.cache.eviction.*;
+import org.apache.ignite.configuration.*;
import org.apache.ignite.internal.util.*;
import org.apache.ignite.internal.util.typedef.internal.*;
@@ -48,18 +49,24 @@ public class SortedEvictionPolicy<K, V> implements EvictionPolicy<K, V>, SortedE
private static final long serialVersionUID = 0L;
/** Maximum size. */
- private volatile int max;
+ private volatile int max = CacheConfiguration.DFLT_CACHE_SIZE;
/** Batch size. */
private volatile int batchSize = 1;
+ /** Max memory size. */
+ private volatile long maxMemSize;
+
+ /** Memory size. */
+ private final LongAdder8 memSize = new LongAdder8();
+
/** Comparator. */
private Comparator<Holder<K, V>> comp;
/** Order. */
private final AtomicLong orderCnt = new AtomicLong();
- /** Backed sorted set. */
+ /** Backed sorted queue. */
private final GridConcurrentSkipListSetEx<K, V> set;
/**
@@ -142,12 +149,29 @@ public class SortedEvictionPolicy<K, V> implements EvictionPolicy<K, V>, SortedE
return set.sizex();
}
+ /** {@inheritDoc} */
+ @Override public long getMaxMemSize() {
+ return maxMemSize;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void setMaxMemSize(long maxMemSize) {
+ A.ensure(maxMemSize > 0, "maxMemSize > 0");
+
+ this.maxMemSize = maxMemSize;
+ }
+
+ /** {@inheritDoc} */
+ @Override public long getCurrentMemSize() {
+ return memSize.longValue();
+ }
+
/**
- * Gets read-only view of backed set in proper order.
+ * Gets read-only view of backed queue in proper order.
*
- * @return Read-only view of backed set.
+ * @return Read-only view of backed queue.
*/
- public Collection<EvictableEntry<K, V>> set() {
+ public Collection<EvictableEntry<K, V>> queue() {
Set<EvictableEntry<K, V>> cp = new LinkedHashSet<>();
for (Holder<K, V> holder : set)
@@ -168,19 +192,22 @@ public class SortedEvictionPolicy<K, V> implements EvictionPolicy<K, V>, SortedE
else {
Holder<K, V> holder = entry.removeMeta();
- if (holder != null)
+ if (holder != null) {
removeHolder(holder);
+
+ memSize.add(-entry.size());
+ }
}
}
/**
* @param entry Entry to touch.
- * @return {@code True} if backed set has been changed by this call.
+ * @return {@code True} if backed queue has been changed by this call.
*/
private boolean touch(EvictableEntry<K, V> entry) {
Holder<K, V> holder = entry.meta();
- // Entry has not been add yet to backed set..
+ // Entry has not been add yet to backed queue..
if (holder == null) {
while (true) {
holder = new Holder<>(entry, orderCnt.incrementAndGet());
@@ -188,7 +215,7 @@ public class SortedEvictionPolicy<K, V> implements EvictionPolicy<K, V>, SortedE
set.add(holder);
if (entry.putMetaIfAbsent(holder) != null) {
- // Was concurrently added, need to remove it from set.
+ // Was concurrently added, need to remove it from queue.
removeHolder(holder);
// Set has not been changed.
@@ -196,17 +223,24 @@ public class SortedEvictionPolicy<K, V> implements EvictionPolicy<K, V>, SortedE
}
else if (holder.order > 0) {
if (!entry.isCached()) {
- // Was concurrently evicted, need to remove it from set.
+ // Was concurrently evicted, need to remove it from queue.
removeHolder(holder);
return false;
}
+ memSize.add(entry.size());
+
return true;
}
// If holder was removed by concurrent shrink() call, we must repeat the whole cycle.
else if (!entry.removeMeta(holder))
return false;
+ else {
+ memSize.add(-entry.size());
+
+ return true;
+ }
}
}
@@ -215,34 +249,71 @@ public class SortedEvictionPolicy<K, V> implements EvictionPolicy<K, V>, SortedE
}
/**
- * Shrinks backed set to maximum allowed size.
+ * Shrinks backed queue to maximum allowed size.
*/
private void shrink() {
- int max = this.max;
+ long maxMem = this.maxMemSize;
- int batchSize = this.batchSize;
+ if (maxMem > 0) {
+ long startMemSize = memSize.longValue();
- int startSize = set.sizex();
+ if (startMemSize >= maxMem)
+ for (long i = maxMem; i < startMemSize && memSize.longValue() > maxMem;) {
+ int size = shrink0();
- if (startSize >= max + batchSize) {
- for (int i = max; i < startSize && set.sizex() > max; i++) {
- Holder<K, V> h = set.pollFirst();
+ if (size == -1)
+ break;
- if (h == null)
- break;
+ i += size;
+ }
+ }
- EvictableEntry<K, V> entry = h.entry;
+ int max = this.max;
- if (h.order > 0 && entry.removeMeta(h) && !entry.evict())
- touch(entry);
+ if (max > 0) {
+ int startSize = set.sizex();
+
+ if (startSize >= max + (maxMem > 0 ? 1 : this.batchSize)) {
+ for (int i = max; i < startSize && set.sizex() > max; i++) {
+ if (shrink0() == -1)
+ break;
+ }
}
}
}
+ /**
+ * Tries to remove one item from queue.
+ *
+ * @return number of bytes that was free. {@code -1} if queue is empty.
+ */
+ private int shrink0() {
+ Holder<K, V> h = set.pollFirst();
+
+ if (h == null)
+ return -1;
+
+ int size = 0;
+
+ EvictableEntry<K, V> entry = h.entry;
+
+ if (h.order > 0 && entry.removeMeta(h)) {
+ size = entry.size();
+
+ memSize.add(-size);
+
+ if (!entry.evict())
+ touch(entry);
+ }
+
+ return size;
+ }
+
/** {@inheritDoc} */
@Override public void writeExternal(ObjectOutput out) throws IOException {
out.writeInt(max);
out.writeInt(batchSize);
+ out.writeLong(maxMemSize);
out.writeObject(comp);
}
@@ -251,11 +322,12 @@ public class SortedEvictionPolicy<K, V> implements EvictionPolicy<K, V>, SortedE
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
max = in.readInt();
batchSize = in.readInt();
+ maxMemSize = in.readLong();
comp = (Comparator<Holder<K, V>>)in.readObject();
}
/**
- * Removes holder from backed set and marks holder as removed.
+ * Removes holder from backed queue and marks holder as removed.
*
* @param holder Holder.
*/
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/main/java/org/apache/ignite/cache/eviction/sorted/SortedEvictionPolicyMBean.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/eviction/sorted/SortedEvictionPolicyMBean.java b/modules/core/src/main/java/org/apache/ignite/cache/eviction/sorted/SortedEvictionPolicyMBean.java
index bc696ff..aada1ce 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/eviction/sorted/SortedEvictionPolicyMBean.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/eviction/sorted/SortedEvictionPolicyMBean.java
@@ -63,4 +63,26 @@ public interface SortedEvictionPolicyMBean {
*/
@MXBeanDescription("Current sorted key set size.")
public int getCurrentSize();
+
+ /**
+ * Gets maximum allowed cache size in bytes.
+ *
+ * @return maximum allowed cache size in bytes.
+ */
+ @MXBeanDescription("Maximum allowed cache size in bytes.")
+ public long getMaxMemSize();
+
+ /**
+ * Sets maximum allowed cache size in bytes.
+ */
+ @MXBeanDescription("Set maximum allowed cache size in bytes.")
+ public void setMaxMemSize(long maxMemSize);
+
+ /**
+ * Gets current sorted entries queue size in bytes.
+ *
+ * @return current sorted entries queue size in bytes.
+ */
+ @MXBeanDescription("Current sorted entries set size in bytes.")
+ public long getCurrentMemSize();
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictableEntryImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictableEntryImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictableEntryImpl.java
index 8b2aad8..7a3fbee 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictableEntryImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEvictableEntryImpl.java
@@ -23,6 +23,7 @@ import org.apache.ignite.internal.processors.cache.transactions.*;
import org.apache.ignite.internal.util.lang.*;
import org.apache.ignite.internal.util.tostring.*;
import org.apache.ignite.internal.util.typedef.internal.*;
+
import org.jetbrains.annotations.*;
import java.util.*;
@@ -93,11 +94,24 @@ public class CacheEvictableEntryImpl<K, V> implements EvictableEntry<K, V> {
/** {@inheritDoc} */
public int size() {
try {
- int keySize = cached.key().valueBytes(cached.context().cacheObjectContext()).length;
+ GridCacheContext<Object, Object> cctx = cached.context();
- CacheObject val = cached.peek(true, false, false, null);
+ KeyCacheObject key = cached.key();
+
+ byte[] keyBytes = key.valueBytes(cctx.cacheObjectContext());
+
+ byte[] valBytes = null;
+
+ if (cctx.useOffheapEntry())
+ valBytes = cctx.offheap().get(cctx.swap().spaceName(), cached.partition(), key, keyBytes);
+ else {
+ CacheObject cacheObj = cached.valueBytes();
+
+ if (cacheObj != null)
+ valBytes = cacheObj.valueBytes(cctx.cacheObjectContext());
+ }
- return val == null ? keySize : keySize + val.valueBytes(cached.context().cacheObjectContext()).length;
+ return valBytes == null ? keyBytes.length : keyBytes.length + valBytes.length;
}
catch (GridCacheEntryRemovedException e) {
return 0;
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEmptyEntriesAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEmptyEntriesAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEmptyEntriesAbstractSelfTest.java
index 768bced..9239274 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEmptyEntriesAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEmptyEntriesAbstractSelfTest.java
@@ -127,7 +127,7 @@ public abstract class GridCacheEmptyEntriesAbstractSelfTest extends GridCommonAb
}
/**
- * Checks policy with and without store set.
+ * Checks policy with and without store queue.
*
* @throws Exception If failed.
*/
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictionAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictionAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictionAbstractTest.java
index bc17f14..f62c5c3 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictionAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/GridCacheEvictionAbstractTest.java
@@ -22,6 +22,7 @@ import org.apache.ignite.cache.*;
import org.apache.ignite.cache.eviction.*;
import org.apache.ignite.configuration.*;
import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.processors.cache.distributed.dht.colocated.*;
import org.apache.ignite.internal.util.typedef.*;
import org.apache.ignite.internal.util.typedef.internal.*;
import org.apache.ignite.spi.discovery.tcp.*;
@@ -29,9 +30,11 @@ import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
import org.apache.ignite.testframework.junits.common.*;
import org.apache.ignite.transactions.*;
+
import org.jetbrains.annotations.*;
import javax.cache.*;
+import java.lang.reflect.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
@@ -40,6 +43,7 @@ import static org.apache.ignite.cache.CacheAtomicityMode.*;
import static org.apache.ignite.cache.CacheMode.*;
import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*;
import static org.apache.ignite.events.EventType.*;
+import static org.apache.ignite.internal.processors.cache.eviction.GridCacheEvictionAbstractTest.EvictionPolicyProxy.*;
import static org.apache.ignite.transactions.TransactionConcurrency.*;
import static org.apache.ignite.transactions.TransactionIsolation.*;
@@ -63,15 +67,15 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
/** Evict near sync. */
protected boolean evictNearSync = true;
+ /** Policy max. */
+ protected int plcMax = 10;
+
/** Policy batch size. */
protected int plcBatchSize = 0;
/** Policy max memory size. */
protected long plcMaxMemSize = 0;
- /** Policy max. */
- protected int plcMax = 10;
-
/** Near policy max. */
protected int nearMax = 3;
@@ -167,10 +171,23 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
* @param c1 Policy collection.
* @param c2 Expected list.
*/
- protected void check(Collection<EvictableEntry<String, String>> c1, MockEntry... c2) {
+ protected static void check(Collection<EvictableEntry<String, String>> c1, MockEntry... c2) {
check(c1, F.asList(c2));
}
+ protected void check(int expSize, int entrySize) {
+ EvictionPolicyProxy proxy = proxy(policy());
+
+ assertEquals(expSize, proxy.getCurrentSize());
+ assertEquals(expSize * entrySize, proxy.getCurrentMemSize());
+ }
+
+ protected void check(int entrySize, Collection<EvictableEntry<String, String>> c1, MockEntry... c2) {
+ check(c2.length, entrySize);
+
+ check(c1, c2);
+ }
+
/** @return Policy. */
@SuppressWarnings({"unchecked"})
protected T policy() {
@@ -203,7 +220,7 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
* @param c1 Policy collection.
* @param c2 Expected list.
*/
- protected void check(Collection<EvictableEntry<String, String>> c1, List<MockEntry> c2) {
+ protected static void check(Collection<EvictableEntry<String, String>> c1, List<MockEntry> c2) {
assert c1.size() == c2.size() : "Mismatch [actual=" + string(c1) + ", expected=" + string(c2) + ']';
assert c1.containsAll(c2) : "Mismatch [actual=" + string(c1) + ", expected=" + string(c2) + ']';
@@ -220,7 +237,7 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
* @return String.
*/
@SuppressWarnings("unchecked")
- protected String string(Iterable<? extends Cache.Entry> c) {
+ protected static String string(Iterable<? extends Cache.Entry> c) {
return "[" +
F.fold(
c,
@@ -242,7 +259,7 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
gridCnt = 2;
- checkPartitioned(plcMax, plcMax, false);
+ checkPartitioned();
}
/** @throws Exception If failed. */
@@ -256,7 +273,7 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
gridCnt = 2;
- checkPartitioned(0, 0, true); // Near size is 0 because of backups present.
+ checkPartitioned(); // Near size is 0 because of backups present.
}
/** @throws Exception If failed. */
@@ -268,7 +285,7 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
gridCnt = 2;
- checkPartitionedMultiThreaded(gridCnt);
+ checkPartitionedMultiThreaded();
}
/** @throws Exception If failed. */
@@ -280,7 +297,7 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
gridCnt = 2;
- checkPartitionedMultiThreaded(gridCnt);
+ checkPartitionedMultiThreaded();
}
/** @throws Exception If failed. */
@@ -292,7 +309,7 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
gridCnt = 2;
- checkPartitionedMultiThreaded(gridCnt);
+ checkPartitionedMultiThreaded();
}
/** @throws Exception If failed. */
@@ -304,15 +321,18 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
gridCnt = 2;
- checkPartitionedMultiThreaded(gridCnt);
+ checkPartitionedMultiThreaded();
}
/**
- * @param endSize Final near size.
- * @param endPlcSize Final near policy size.
* @throws Exception If failed.
*/
- private void checkPartitioned(int endSize, int endPlcSize, boolean near) throws Exception {
+ protected void checkPartitioned() throws Exception {
+
+ int endSize = nearEnabled ? 0 : plcMax;
+
+ int endPlcSize = nearEnabled ? 0 : plcMax;
+
startGridsMultiThreaded(gridCnt);
try {
@@ -332,7 +352,7 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
info("Stored cache object for key [key=" + key + ", idx=" + i + ']');
}
- if (near) {
+ if (nearEnabled) {
for (int i = 0; i < gridCnt; i++)
assertEquals(endSize, near(i).nearSize());
@@ -340,14 +360,31 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
checkNearPolicies(endPlcSize);
}
else {
- for (int i = 0; i < gridCnt; i++) {
- int actual = colocated(i).size();
+ if (plcMaxMemSize > 0) {
+ for (int i = 0; i < gridCnt; i++) {
+ GridDhtColocatedCache<Object, Object> cache = colocated(i);
+
+ int memSize = 0;
+
+ for (Cache.Entry<Object, Object> entry : cache.entrySet())
+ memSize += entry.unwrap(EvictableEntry.class).size();
+
+ EvictionPolicyProxy plc = proxy(policy(i));
+
+ assertTrue(plc.getCurrentMemSize() <= memSize);
+ }
+ }
- assertTrue("Cache size is greater then policy size [expected=" + endSize + ", actual=" + actual + ']',
- actual <= endSize + plcBatchSize);
+ if (plcMax > 0) {
+ for (int i = 0; i < gridCnt; i++) {
+ int actual = colocated(i).size();
+
+ assertTrue("Cache size is greater then policy size [expected=" + endSize + ", actual=" + actual + ']',
+ actual <= endSize + (plcMaxMemSize > 0 ? 1 : plcBatchSize));
+ }
}
- checkPolicies(endPlcSize);
+ checkPolicies();
}
}
finally {
@@ -356,10 +393,9 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
}
/**
- * @param gridCnt Grid count.
* @throws Exception If failed.
*/
- protected void checkPartitionedMultiThreaded(int gridCnt) throws Exception {
+ protected void checkPartitionedMultiThreaded() throws Exception {
try {
startGridsMultiThreaded(gridCnt);
@@ -424,10 +460,8 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
/**
* Performs after-test policy check.
- *
- * @param plcMax Maximum allowed size of ploicy.
*/
- protected abstract void checkPolicies(int plcMax);
+ protected abstract void checkPolicies();
/**
*
@@ -498,4 +532,63 @@ public abstract class GridCacheEvictionAbstractTest<T extends EvictionPolicy<?,
return S.toString(MockEntry.class, this, super.toString());
}
}
+
+ /**
+ * Rvicition policy proxy.
+ */
+ protected static class EvictionPolicyProxy<K, V> {
+ private final EvictionPolicy<K, V> plc;
+
+ /**
+ * @param plc Policy.
+ */
+ private EvictionPolicyProxy(EvictionPolicy<K, V> plc) {
+ this.plc = plc;
+ }
+
+ /**
+ * @param plc Policy.
+ */
+ public static EvictionPolicyProxy proxy(EvictionPolicy<?, ?> plc) {
+ return new EvictionPolicyProxy(plc);
+ }
+
+ /**
+ * Get current size.
+ */
+ public int getCurrentSize() {
+ try {
+ return (Integer)plc.getClass().getDeclaredMethod("getCurrentSize").invoke(plc);
+ }
+ catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Current memory size.
+ */
+ public long getCurrentMemSize() {
+ try {
+ return (Long)plc.getClass().getDeclaredMethod("getCurrentMemSize").invoke(plc);
+ }
+ catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+ /**
+ * Current queue.
+ */
+ public Collection<EvictableEntry<K, V>> queue() {
+ try {
+ return (Collection<EvictableEntry<K, V>>)plc.getClass().getDeclaredMethod("queue").invoke(plc);
+ }
+ catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoBatchEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoBatchEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoBatchEvictionPolicySelfTest.java
index d2dd3d2..d1cc2fa 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoBatchEvictionPolicySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoBatchEvictionPolicySelfTest.java
@@ -53,38 +53,29 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
p.onEntryAccessed(false, e1);
- check(p.queue(), e1);
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1);
p.onEntryAccessed(false, e2);
- check(p.queue(), e1, e2);
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1, e2);
p.onEntryAccessed(false, e3);
- check(p.queue(), e1, e2, e3);
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1, e2, e3);
p.onEntryAccessed(false, e4);
- check(p.queue(), e1, e2, e3, e4);
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1, e2, e3, e4);
assertFalse(e1.isEvicted());
assertFalse(e2.isEvicted());
assertFalse(e3.isEvicted());
assertFalse(e4.isEvicted());
- assertEquals(4, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
-
p.onEntryAccessed(false, e5);
// Batch evicted.
- check(p.queue(), e3, e4, e5);
-
- assertEquals(3, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5);
assertTrue(e1.isEvicted());
assertTrue(e2.isEvicted());
@@ -94,10 +85,7 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
p.onEntryAccessed(false, e1 = new MockEntry("1", "1"));
- check(p.queue(), e3, e4, e5, e1);
-
- assertEquals(4, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5, e1);
assertFalse(e3.isEvicted());
assertFalse(e4.isEvicted());
@@ -106,9 +94,7 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
p.onEntryAccessed(false, e5);
- check(p.queue(), e3, e4, e5, e1);
-
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5, e1);
assertFalse(e3.isEvicted());
assertFalse(e4.isEvicted());
@@ -117,10 +103,7 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
p.onEntryAccessed(false, e1);
- check(p.queue(), e3, e4, e5, e1);
-
- assertEquals(4, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5, e1);
assertFalse(e3.isEvicted());
assertFalse(e4.isEvicted());
@@ -129,8 +112,7 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
p.onEntryAccessed(true, e1);
- assertEquals(3, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5);
assertFalse(e3.isEvicted());
assertFalse(e4.isEvicted());
@@ -138,23 +120,20 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
p.onEntryAccessed(true, e4);
- assertEquals(2, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e3, e5);
assertFalse(e3.isEvicted());
assertFalse(e5.isEvicted());
p.onEntryAccessed(true, e5);
- assertEquals(1, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e3);
assertFalse(e3.isEvicted());
p.onEntryAccessed(true, e3);
- assertEquals(0, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue());
assertFalse(e3.isEvicted());
@@ -188,8 +167,7 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
info(p);
- assertEquals(cnt - batchSize, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(cnt - batchSize, MockEntry.ENTRY_SIZE);
}
finally {
stopAllGrids();
@@ -241,10 +219,8 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
int curSize = p.getCurrentSize();
- assert curSize < max + batchSize :
- "curSize < max + batchSize [curSize=" + curSize + ", max=" + max + ", batchSize=" + batchSize + ']';
-
- assertEquals(p.queue().size() * MockEntry.KEY_SIZE, p.getCurrentMemSize());
+ assertTrue(curSize < max + batchSize);
+ assertEquals(curSize * MockEntry.KEY_SIZE, p.getCurrentMemSize());
}
finally {
stopAllGrids();
@@ -272,21 +248,21 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
assertFalse(e1.isEvicted());
- assertEquals(p.queue().size() * MockEntry.KEY_SIZE, p.getCurrentMemSize());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
p.onEntryAccessed(false, e2);
assertFalse(e1.isEvicted());
assertFalse(e2.isEvicted());
- assertEquals(p.queue().size() * MockEntry.KEY_SIZE, p.getCurrentMemSize());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
p.onEntryAccessed(false, e3);
assertFalse(e1.isEvicted());
assertFalse(e3.isEvicted());
- assertEquals(p.queue().size() * MockEntry.KEY_SIZE, p.getCurrentMemSize());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
p.onEntryAccessed(false, e4);
@@ -294,7 +270,7 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
assertFalse(e3.isEvicted());
assertFalse(e4.isEvicted());
- assertEquals(p.queue().size() * MockEntry.KEY_SIZE, p.getCurrentMemSize());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
p.onEntryAccessed(false, e5);
@@ -302,7 +278,7 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
assertFalse(e3.isEvicted());
assertFalse(e5.isEvicted());
- assertEquals(p.queue().size() * MockEntry.KEY_SIZE, p.getCurrentMemSize());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
}
finally {
stopAllGrids();
@@ -324,16 +300,13 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
GridCacheContext cctx = ((IgniteCacheProxy)cache).context();
- FifoEvictionPolicy plc =
- (FifoEvictionPolicy)cctx.config().getEvictionPolicy();
-
int cnt = 500;
int min = Integer.MAX_VALUE;
int minIdx = 0;
- int memSize = 0;
+ int entrySize = 0;
for (int i = 0; i < cnt; i++) {
cache.put(i, i);
@@ -345,17 +318,15 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
minIdx = i;
}
- if (i >= cnt - plcMax) {
- memSize += cctx.toCacheKeyObject(i).valueBytes(cctx.cacheObjectContext()).length;
- memSize += cctx.toCacheObject(i).valueBytes(cctx.cacheObjectContext()).length;
- }
+ if (entrySize == 0)
+ entrySize = cctx.toCacheKeyObject(i).valueBytes(cctx.cacheObjectContext()).length +
+ cctx.toCacheObject(i).valueBytes(cctx.cacheObjectContext()).length;
}
// Batch evicted.
assert min >= plcMax : "Min cache size is too small: " + min;
- assertEquals(plcMax, plc.getCurrentSize());
- assertEquals(memSize, plc.getCurrentMemSize());
+ check(plcMax, entrySize);
info("Min cache size [min=" + min + ", idx=" + minIdx + ']');
info("Current cache size " + cache.size());
@@ -385,8 +356,7 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
// Batch evicted.
assert min >= plcMax : "Min cache size is too small: " + min;
- assertEquals(plcMax, plc.getCurrentSize());
- assertEquals(memSize, plc.getCurrentMemSize());
+ check(plcMax, entrySize);
}
finally {
stopAllGrids();
@@ -418,7 +388,7 @@ public class GridCacheFifoBatchEvictionPolicySelfTest extends
}
/** {@inheritDoc} */
- @Override protected void checkPolicies(int plcMax) {
+ @Override protected void checkPolicies() {
for (int i = 0; i < gridCnt; i++) {
assert policy(i).queue().size() <= plcMax + policy(i).getBatchSize();
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoEvictionPolicySelfTest.java
index 14b536b..e636174 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoEvictionPolicySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoEvictionPolicySelfTest.java
@@ -52,31 +52,23 @@ public class GridCacheFifoEvictionPolicySelfTest extends
p.onEntryAccessed(false, e1);
- check(p.queue(), e1);
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1);
p.onEntryAccessed(false, e2);
- check(p.queue(), e1, e2);
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1, e2);
p.onEntryAccessed(false, e3);
- check(p.queue(), e1, e2, e3);
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1, e2, e3);
assert !e1.isEvicted();
assert !e2.isEvicted();
assert !e3.isEvicted();
- assertEquals(3, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
-
p.onEntryAccessed(false, e4);
- check(p.queue(), e2, e3, e4);
- assertEquals(3, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e2, e3, e4);
assert e1.isEvicted();
assert !e2.isEvicted();
@@ -85,9 +77,7 @@ public class GridCacheFifoEvictionPolicySelfTest extends
p.onEntryAccessed(false, e5);
- check(p.queue(), e3, e4, e5);
- assertEquals(3, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5);
assert e2.isEvicted();
assert !e3.isEvicted();
@@ -96,9 +86,7 @@ public class GridCacheFifoEvictionPolicySelfTest extends
p.onEntryAccessed(false, e1 = new MockEntry("1", "1"));
- check(p.queue(), e4, e5, e1);
- assertEquals(3, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e4, e5, e1);
assert e3.isEvicted();
assert !e1.isEvicted();
@@ -107,8 +95,7 @@ public class GridCacheFifoEvictionPolicySelfTest extends
p.onEntryAccessed(false, e5);
- check(p.queue(), e4, e5, e1);
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e4, e5, e1);
assert !e1.isEvicted();
assert !e4.isEvicted();
@@ -116,9 +103,7 @@ public class GridCacheFifoEvictionPolicySelfTest extends
p.onEntryAccessed(false, e1);
- check(p.queue(), e4, e5, e1);
- assertEquals(3, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e4, e5, e1);
assert !e1.isEvicted();
assert !e4.isEvicted();
@@ -126,9 +111,7 @@ public class GridCacheFifoEvictionPolicySelfTest extends
p.onEntryAccessed(false, e5);
- check(p.queue(), e4, e5, e1);
- assertEquals(3, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e4, e5, e1);
assert !e1.isEvicted();
assert !e4.isEvicted();
@@ -136,8 +119,7 @@ public class GridCacheFifoEvictionPolicySelfTest extends
p.onEntryAccessed(true, e1);
- assertEquals(2, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e4, e5);
assert !e1.isEvicted();
assert !e4.isEvicted();
@@ -145,16 +127,14 @@ public class GridCacheFifoEvictionPolicySelfTest extends
p.onEntryAccessed(true, e4);
- assertEquals(1, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e5);
assert !e4.isEvicted();
assert !e5.isEvicted();
p.onEntryAccessed(true, e5);
- assertEquals(0, p.getCurrentSize());
- assertEquals(p.queue().size() * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(MockEntry.ENTRY_SIZE, p.queue());
assert !e5.isEvicted();
@@ -185,8 +165,7 @@ public class GridCacheFifoEvictionPolicySelfTest extends
info(p);
- assertEquals(max, p.getCurrentSize());
- assertEquals(max * MockEntry.ENTRY_SIZE, p.getCurrentMemSize());
+ check(max, MockEntry.ENTRY_SIZE);
}
finally {
stopAllGrids();
@@ -232,12 +211,8 @@ public class GridCacheFifoEvictionPolicySelfTest extends
info(p);
- int curSize = p.getCurrentSize();
- long curMemSize = p.getCurrentMemSize();
-
- assert curSize <= max : "curSize <= max [curSize=" + curSize + ", max=" + max + ']';
- assert curMemSize <= max * MockEntry.ENTRY_SIZE : "curMemSize <= maxMemSize [curMemSize=" + curMemSize +
- ", maxMemSize =" + max * MockEntry.ENTRY_SIZE + ']';
+ assertTrue(p.getCurrentSize() <= max);
+ assertTrue(p.getCurrentMemSize() <= max * MockEntry.ENTRY_SIZE);
}
finally {
stopAllGrids();
@@ -264,33 +239,33 @@ public class GridCacheFifoEvictionPolicySelfTest extends
p.onEntryAccessed(false, e1);
assertFalse(e1.isEvicted());
- assertEquals(p.queue().size() * MockEntry.KEY_SIZE, p.getCurrentMemSize());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
p.onEntryAccessed(false, e2);
assertFalse(e1.isEvicted());
assertFalse(e2.isEvicted());
- assertEquals(p.queue().size() * MockEntry.KEY_SIZE, p.getCurrentMemSize());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
p.onEntryAccessed(false, e3);
assertFalse(e1.isEvicted());
assertFalse(e3.isEvicted());
- assertEquals(p.queue().size() * MockEntry.KEY_SIZE, p.getCurrentMemSize());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
p.onEntryAccessed(false, e4);
assertFalse(e1.isEvicted());
assertFalse(e3.isEvicted());
assertFalse(e4.isEvicted());
- assertEquals(p.queue().size() * MockEntry.KEY_SIZE, p.getCurrentMemSize());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
p.onEntryAccessed(false, e5);
assertFalse(e1.isEvicted());
assertFalse(e3.isEvicted());
assertFalse(e5.isEvicted());
- assertEquals(p.queue().size() * MockEntry.KEY_SIZE, p.getCurrentMemSize());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
}
finally {
stopAllGrids();
@@ -312,16 +287,13 @@ public class GridCacheFifoEvictionPolicySelfTest extends
GridCacheContext cctx = ((IgniteCacheProxy)cache).context();
- FifoEvictionPolicy plc =
- (FifoEvictionPolicy)cctx.config().getEvictionPolicy();
-
int cnt = 500;
int min = Integer.MAX_VALUE;
int minIdx = 0;
- int memSize = 0;
+ int entrySize = 0;
for (int i = 0; i < cnt; i++) {
cache.put(i, i);
@@ -333,16 +305,14 @@ public class GridCacheFifoEvictionPolicySelfTest extends
minIdx = i;
}
- if (i >= cnt - plcMax) {
- memSize += cctx.toCacheKeyObject(i).valueBytes(cctx.cacheObjectContext()).length;
- memSize += cctx.toCacheObject(i).valueBytes(cctx.cacheObjectContext()).length;
- }
+ if (entrySize == 0)
+ entrySize = cctx.toCacheKeyObject(i).valueBytes(cctx.cacheObjectContext()).length +
+ cctx.toCacheObject(i).valueBytes(cctx.cacheObjectContext()).length;
}
- assert min >= plcMax : "Min cache size is too small: " + min;
+ assertTrue("Min cache size is too small: " + min, min >= plcMax);
- assertEquals(plcMax, plc.getCurrentSize());
- assertEquals(memSize, plc.getCurrentMemSize());
+ check(plcMax, entrySize);
info("Min cache size [min=" + min + ", idx=" + minIdx + ']');
info("Current cache size " + cache.size());
@@ -369,10 +339,7 @@ public class GridCacheFifoEvictionPolicySelfTest extends
info("Current cache size " + cache.size());
info("Current cache key size " + cache.size());
- assert min >= plcMax : "Min cache size is too small: " + min;
-
- assertEquals(plcMax, plc.getCurrentSize());
- assertEquals(memSize, plc.getCurrentMemSize());
+ check(plcMax, entrySize);
}
finally {
stopAllGrids();
@@ -397,7 +364,7 @@ public class GridCacheFifoEvictionPolicySelfTest extends
}
/** {@inheritDoc} */
- @Override protected void checkPolicies(int plcMax) {
+ @Override protected void checkPolicies() {
for (int i = 0; i < gridCnt; i++) {
assert policy(i).queue().size() <= plcMax;
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoMemoryEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoMemoryEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoMemoryEvictionPolicySelfTest.java
index 610db1d..1e6e0be 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoMemoryEvictionPolicySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/fifo/GridCacheFifoMemoryEvictionPolicySelfTest.java
@@ -312,16 +312,13 @@ public class GridCacheFifoMemoryEvictionPolicySelfTest extends
GridCacheContext cctx = ((IgniteCacheProxy)cache).context();
- FifoEvictionPolicy plc =
- (FifoEvictionPolicy)cctx.config().getEvictionPolicy();
-
int cnt = 500;
int min = Integer.MAX_VALUE;
int minIdx = 0;
- int memSize = 0;
+ int entrySize = 0;
for (int i = 0; i < cnt; i++) {
cache.put(i, i);
@@ -333,16 +330,14 @@ public class GridCacheFifoMemoryEvictionPolicySelfTest extends
minIdx = i;
}
- if (i >= cnt - max) {
- memSize += cctx.toCacheKeyObject(i).valueBytes(cctx.cacheObjectContext()).length;
- memSize += cctx.toCacheObject(i).valueBytes(cctx.cacheObjectContext()).length;
- }
+ if (entrySize == 0)
+ entrySize = cctx.toCacheKeyObject(i).valueBytes(cctx.cacheObjectContext()).length +
+ cctx.toCacheObject(i).valueBytes(cctx.cacheObjectContext()).length;
}
-// assert min >= max : "Min cache size is too small: " + min;
+ assert min >= max : "Min cache size is too small: " + min;
- assertEquals(max, plc.getCurrentSize());
- assertEquals(memSize, plc.getCurrentMemSize());
+ check(max, entrySize);
info("Min cache size [min=" + min + ", idx=" + minIdx + ']');
info("Current cache size " + cache.size());
@@ -371,14 +366,26 @@ public class GridCacheFifoMemoryEvictionPolicySelfTest extends
assert min >= max : "Min cache size is too small: " + min;
- assertEquals(max, plc.getCurrentSize());
- assertEquals(memSize, plc.getCurrentMemSize());
+ check(max, entrySize);
}
finally {
stopAllGrids();
}
}
+ /** @throws Exception If failed. */
+ public void testPartitionedNearDisabled() throws Exception {
+ mode = PARTITIONED;
+ nearEnabled = false;
+ plcMax = 0;
+ plcMaxMemSize = 100;
+ syncCommit = true;
+
+ gridCnt = 2;
+
+ checkPartitioned();
+ }
+
/** {@inheritDoc} */
@Override protected FifoEvictionPolicy<String, String> createPolicy(int plcMax) {
return new FifoEvictionPolicy<>(1000L);
@@ -397,16 +404,18 @@ public class GridCacheFifoMemoryEvictionPolicySelfTest extends
}
/** {@inheritDoc} */
- @Override protected void checkPolicies(int plcMax) {
+ @Override protected void checkPolicies() {
for (int i = 0; i < gridCnt; i++) {
- assert policy(i).queue().size() <= plcMax;
+ if (plcMaxMemSize > 0) {
+ int size = 0;
- int size = 0;
+ for (EvictableEntry<String, String> entry : policy(i).queue())
+ size += ((CacheEvictableEntryImpl)entry).size();
- for (EvictableEntry<String, String> entry : policy(i).queue())
- size += ((CacheEvictableEntryImpl)entry).size();
-
- assertEquals(size, ((FifoEvictionPolicy)policy(i)).getCurrentMemSize());
+ assertEquals(size, ((FifoEvictionPolicy)policy(i)).getCurrentMemSize());
+ }
+ else
+ assert policy(i).queue().size() <= plcMax;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheLruEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheLruEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheLruEvictionPolicySelfTest.java
index c623b38..7194373 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheLruEvictionPolicySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/lru/GridCacheLruEvictionPolicySelfTest.java
@@ -21,6 +21,7 @@ import org.apache.ignite.*;
import org.apache.ignite.cache.*;
import org.apache.ignite.cache.eviction.*;
import org.apache.ignite.cache.eviction.lru.*;
+import org.apache.ignite.internal.processors.cache.*;
import org.apache.ignite.internal.processors.cache.eviction.*;
import java.util.*;
@@ -50,27 +51,24 @@ public class GridCacheLruEvictionPolicySelfTest extends
p.onEntryAccessed(false, e1);
- check(p.queue(), e1);
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1);
p.onEntryAccessed(false, e2);
- check(p.queue(), e1, e2);
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1, e2);
p.onEntryAccessed(false, e3);
- check(p.queue(), e1, e2, e3);
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1, e2, e3);
assert !e1.isEvicted();
assert !e2.isEvicted();
assert !e3.isEvicted();
- assertEquals(3, p.getCurrentSize());
-
p.onEntryAccessed(false, e4);
check(p.queue(), e2, e3, e4);
-
- assertEquals(3, p.getCurrentSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e2, e3, e4);
assert e1.isEvicted();
assert !e2.isEvicted();
@@ -79,9 +77,7 @@ public class GridCacheLruEvictionPolicySelfTest extends
p.onEntryAccessed(false, e5);
- check(p.queue(), e3, e4, e5);
-
- assertEquals(3, p.getCurrentSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5);
assert e2.isEvicted();
assert !e3.isEvicted();
@@ -90,9 +86,7 @@ public class GridCacheLruEvictionPolicySelfTest extends
p.onEntryAccessed(false, e1 = new MockEntry("1", "1"));
- check(p.queue(), e4, e5, e1);
-
- assertEquals(3, p.getCurrentSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e4, e5, e1);
assert e3.isEvicted();
assert !e1.isEvicted();
@@ -103,7 +97,7 @@ public class GridCacheLruEvictionPolicySelfTest extends
assertEquals(3, p.getCurrentSize());
- check(p.queue(), e4, e1, e5);
+ check(MockEntry.ENTRY_SIZE, p.queue(), e4, e1, e5);
assert !e1.isEvicted();
assert !e4.isEvicted();
@@ -111,9 +105,7 @@ public class GridCacheLruEvictionPolicySelfTest extends
p.onEntryAccessed(false, e1);
- assertEquals(3, p.getCurrentSize());
-
- check(p.queue(), e4, e5, e1);
+ check(MockEntry.ENTRY_SIZE, p.queue(), e4, e5, e1);
assert !e1.isEvicted();
assert !e4.isEvicted();
@@ -123,7 +115,7 @@ public class GridCacheLruEvictionPolicySelfTest extends
assertEquals(3, p.getCurrentSize());
- check(p.queue(), e4, e1, e5);
+ check(MockEntry.ENTRY_SIZE, p.queue(), e4, e1, e5);
assert !e1.isEvicted();
assert !e4.isEvicted();
@@ -131,7 +123,7 @@ public class GridCacheLruEvictionPolicySelfTest extends
p.onEntryAccessed(true, e1);
- assertEquals(2, p.getCurrentSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e4, e5);
assert !e1.isEvicted();
assert !e4.isEvicted();
@@ -139,14 +131,14 @@ public class GridCacheLruEvictionPolicySelfTest extends
p.onEntryAccessed(true, e4);
- assertEquals(1, p.getCurrentSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e5);
assert !e4.isEvicted();
assert !e5.isEvicted();
p.onEntryAccessed(true, e5);
- assertEquals(0, p.getCurrentSize());
+ check(MockEntry.ENTRY_SIZE, p.queue());
assert !e5.isEvicted();
@@ -177,7 +169,7 @@ public class GridCacheLruEvictionPolicySelfTest extends
info(p);
- assertEquals(max, p.getCurrentSize());
+ check(max, MockEntry.ENTRY_SIZE);
}
finally {
stopGrid();
@@ -226,7 +218,7 @@ public class GridCacheLruEvictionPolicySelfTest extends
info(p);
- assertEquals(max, p.getCurrentSize());
+ check(max, MockEntry.ENTRY_SIZE);
}
finally {
stopGrid();
@@ -272,7 +264,8 @@ public class GridCacheLruEvictionPolicySelfTest extends
info(p);
- assert p.getCurrentSize() <= max;
+ assertTrue(p.getCurrentSize() <= max);
+ assertTrue(p.getCurrentMemSize() <= max * MockEntry.ENTRY_SIZE);
}
finally {
stopGrid();
@@ -287,13 +280,9 @@ public class GridCacheLruEvictionPolicySelfTest extends
startGrid();
MockEntry e1 = new MockEntry("1");
-
MockEntry e2 = new MockEntry("2");
-
MockEntry e3 = new MockEntry("3");
-
MockEntry e4 = new MockEntry("4");
-
MockEntry e5 = new MockEntry("5");
LruEvictionPolicy<String, String> p = policy();
@@ -304,27 +293,37 @@ public class GridCacheLruEvictionPolicySelfTest extends
assertFalse(e1.isEvicted());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
+
p.onEntryAccessed(false, e2);
assertFalse(e1.isEvicted());
assertFalse(e2.isEvicted());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
+
p.onEntryAccessed(false, e3);
assertFalse(e1.isEvicted());
assertFalse(e3.isEvicted());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
+
p.onEntryAccessed(false, e4);
assertFalse(e1.isEvicted());
assertFalse(e3.isEvicted());
assertFalse(e4.isEvicted());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
+
p.onEntryAccessed(false, e5);
assertFalse(e1.isEvicted());
assertFalse(e3.isEvicted());
assertFalse(e5.isEvicted());
+
+ check(p.queue().size(), MockEntry.KEY_SIZE);
}
finally {
stopAllGrids();
@@ -344,12 +343,16 @@ public class GridCacheLruEvictionPolicySelfTest extends
try {
IgniteCache<Integer, Integer> cache = ignite.cache(null);
+ GridCacheContext cctx = ((IgniteCacheProxy)cache).context();
+
int cnt = 500;
int min = Integer.MAX_VALUE;
int minIdx = 0;
+ int entrySize = 0;
+
for (int i = 0; i < cnt; i++) {
cache.put(i, i);
@@ -359,9 +362,15 @@ public class GridCacheLruEvictionPolicySelfTest extends
min = cacheSize;
minIdx = i;
}
+
+ if (entrySize == 0)
+ entrySize = cctx.toCacheKeyObject(i).valueBytes(cctx.cacheObjectContext()).length +
+ cctx.toCacheObject(i).valueBytes(cctx.cacheObjectContext()).length;
}
- assert min >= plcMax : "Min cache size is too small: " + min;
+ assertTrue("Min cache size is too small: " + min, min >= plcMax);
+
+ check(plcMax, entrySize);
info("Min cache size [min=" + min + ", idx=" + minIdx + ']');
info("Current cache size " + cache.size());
@@ -386,7 +395,7 @@ public class GridCacheLruEvictionPolicySelfTest extends
info("Min cache size [min=" + min + ", idx=" + minIdx + ']');
info("Current cache size " + cache.size());
- assert min >= plcMax : "Min cache size is too small: " + min;
+ check(plcMax, entrySize);
}
finally {
stopAllGrids();
@@ -398,6 +407,7 @@ public class GridCacheLruEvictionPolicySelfTest extends
return new LruEvictionPolicy<>(plcMax);
}
+ /** {@inheritDoc} */
@Override protected LruEvictionPolicy<String, String> createNearPolicy(int nearMax) {
return new LruEvictionPolicy<>(nearMax);
}
@@ -410,8 +420,16 @@ public class GridCacheLruEvictionPolicySelfTest extends
}
/** {@inheritDoc} */
- @Override protected void checkPolicies(int plcMax) {
- for (int i = 0; i < gridCnt; i++)
+ @Override protected void checkPolicies() {
+ for (int i = 0; i < gridCnt; i++) {
assert policy(i).queue().size() <= plcMax;
+
+ int size = 0;
+
+ for (EvictableEntry<String, String> entry : policy(i).queue())
+ size += ((CacheEvictableEntryImpl)entry).size();
+
+ assertEquals(size, ((LruEvictionPolicy)policy(i)).getCurrentMemSize());
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/GridCacheRandomEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/GridCacheRandomEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/GridCacheRandomEvictionPolicySelfTest.java
index 7088714..7ce7ee4 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/GridCacheRandomEvictionPolicySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/random/GridCacheRandomEvictionPolicySelfTest.java
@@ -252,7 +252,7 @@ public class GridCacheRandomEvictionPolicySelfTest extends
}
/** {@inheritDoc} */
- @Override protected void checkPolicies(int plcMax) {
+ @Override protected void checkPolicies() {
// No-op.
}
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedBatchEvictionPolicySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedBatchEvictionPolicySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedBatchEvictionPolicySelfTest.java
index 3cec217..b7cfeb2 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedBatchEvictionPolicySelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedBatchEvictionPolicySelfTest.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.processors.cache.eviction.sorted;
import org.apache.ignite.*;
import org.apache.ignite.cache.eviction.*;
import org.apache.ignite.cache.eviction.sorted.*;
+import org.apache.ignite.internal.processors.cache.*;
import org.apache.ignite.internal.processors.cache.eviction.*;
import java.util.*;
@@ -38,11 +39,11 @@ public class GridCacheSortedBatchEvictionPolicySelfTest extends
try {
startGrid();
- GridCacheEvictionAbstractTest.MockEntry e1 = new GridCacheEvictionAbstractTest.MockEntry("1", "1");
- GridCacheEvictionAbstractTest.MockEntry e2 = new GridCacheEvictionAbstractTest.MockEntry("2", "2");
- GridCacheEvictionAbstractTest.MockEntry e3 = new GridCacheEvictionAbstractTest.MockEntry("3", "3");
- GridCacheEvictionAbstractTest.MockEntry e4 = new GridCacheEvictionAbstractTest.MockEntry("4", "4");
- GridCacheEvictionAbstractTest.MockEntry e5 = new GridCacheEvictionAbstractTest.MockEntry("5", "5");
+ MockEntry e1 = new MockEntry("1", "1");
+ MockEntry e2 = new MockEntry("2", "2");
+ MockEntry e3 = new MockEntry("3", "3");
+ MockEntry e4 = new MockEntry("4", "4");
+ MockEntry e5 = new MockEntry("5", "5");
SortedEvictionPolicy<String, String> p = policy();
@@ -52,33 +53,29 @@ public class GridCacheSortedBatchEvictionPolicySelfTest extends
p.onEntryAccessed(false, e1);
- check(p.set(), e1);
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1);
p.onEntryAccessed(false, e2);
- check(p.set(), e1, e2);
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1, e2);
p.onEntryAccessed(false, e3);
- check(p.set(), e1, e2, e3);
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1, e2, e3);
p.onEntryAccessed(false, e4);
- check(p.set(), e1, e2, e3, e4);
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1, e2, e3, e4);
assertFalse(e1.isEvicted());
assertFalse(e2.isEvicted());
assertFalse(e3.isEvicted());
assertFalse(e4.isEvicted());
- assertEquals(4, p.getCurrentSize());
-
p.onEntryAccessed(false, e5);
// Batch evicted.
- check(p.set(), e3, e4, e5);
-
- assertEquals(3, p.getCurrentSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5);
assertTrue(e1.isEvicted());
assertTrue(e2.isEvicted());
@@ -86,11 +83,9 @@ public class GridCacheSortedBatchEvictionPolicySelfTest extends
assertFalse(e4.isEvicted());
assertFalse(e5.isEvicted());
- p.onEntryAccessed(false, e1 = new GridCacheEvictionAbstractTest.MockEntry("1", "1"));
-
- check(p.set(), e1, e3, e4, e5);
+ p.onEntryAccessed(false, e1 = new MockEntry("1", "1"));
- assertEquals(4, p.getCurrentSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1, e3, e4, e5);
assertFalse(e1.isEvicted());
assertFalse(e3.isEvicted());
@@ -99,7 +94,7 @@ public class GridCacheSortedBatchEvictionPolicySelfTest extends
p.onEntryAccessed(false, e5);
- check(p.set(), e1, e3, e4, e5);
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1, e3, e4, e5);
assertFalse(e1.isEvicted());
assertFalse(e3.isEvicted());
@@ -108,9 +103,7 @@ public class GridCacheSortedBatchEvictionPolicySelfTest extends
p.onEntryAccessed(false, e1);
- assertEquals(4, p.getCurrentSize());
-
- check(p.set(), e1, e3, e4, e5);
+ check(MockEntry.ENTRY_SIZE, p.queue(), e1, e3, e4, e5);
assertFalse(e1.isEvicted());
assertFalse(e3.isEvicted());
@@ -119,7 +112,7 @@ public class GridCacheSortedBatchEvictionPolicySelfTest extends
p.onEntryAccessed(true, e1);
- assertEquals(3, p.getCurrentSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e3, e4, e5);
assertFalse(e3.isEvicted());
assertFalse(e4.isEvicted());
@@ -127,20 +120,20 @@ public class GridCacheSortedBatchEvictionPolicySelfTest extends
p.onEntryAccessed(true, e4);
- assertEquals(2, p.getCurrentSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e3, e5);
assertFalse(e3.isEvicted());
assertFalse(e5.isEvicted());
p.onEntryAccessed(true, e5);
- assertEquals(1, p.getCurrentSize());
+ check(MockEntry.ENTRY_SIZE, p.queue(), e3);
assertFalse(e3.isEvicted());
p.onEntryAccessed(true, e3);
- assertEquals(0, p.getCurrentSize());
+ check(MockEntry.ENTRY_SIZE, p.queue());
assertFalse(e3.isEvicted());
@@ -170,11 +163,11 @@ public class GridCacheSortedBatchEvictionPolicySelfTest extends
int cnt = max + batchSize;
for (int i = 0; i < cnt; i++)
- p.onEntryAccessed(false, new GridCacheEvictionAbstractTest.MockEntry(Integer.toString(i), Integer.toString(i)));
+ p.onEntryAccessed(false, new MockEntry(Integer.toString(i), Integer.toString(i)));
info(p);
- assertEquals(cnt - batchSize, p.getCurrentSize());
+ check(cnt - batchSize, MockEntry.ENTRY_SIZE);
}
finally {
stopAllGrids();
@@ -202,22 +195,22 @@ public class GridCacheSortedBatchEvictionPolicySelfTest extends
int keys = 31;
- GridCacheEvictionAbstractTest.MockEntry[] fifos = new GridCacheEvictionAbstractTest.MockEntry[keys];
+ MockEntry[] entries = new MockEntry[keys];
- for (int i = 0; i < fifos.length; i++)
- fifos[i] = new GridCacheEvictionAbstractTest.MockEntry(Integer.toString(i));
+ for (int i = 0; i < entries.length; i++)
+ entries[i] = new MockEntry(Integer.toString(i));
int runs = 5000000;
for (int i = 0; i < runs; i++) {
boolean rmv = rand.nextBoolean();
- int j = rand.nextInt(fifos.length);
+ int j = rand.nextInt(entries.length);
- GridCacheEvictionAbstractTest.MockEntry e = entry(fifos, j);
+ MockEntry e = entry(entries, j);
if (rmv)
- fifos[j] = new GridCacheEvictionAbstractTest.MockEntry(Integer.toString(j));
+ entries[j] = new MockEntry(Integer.toString(j));
p.onEntryAccessed(rmv, e);
}
@@ -226,8 +219,8 @@ public class GridCacheSortedBatchEvictionPolicySelfTest extends
int curSize = p.getCurrentSize();
- assert curSize < max + batchSize :
- "curSize < max + batchSize [curSize=" + curSize + ", max=" + max + ", batchSize=" + batchSize + ']';
+ assertTrue(curSize < max + batchSize);
+ assertEquals(curSize * MockEntry.KEY_SIZE, p.getCurrentMemSize());
}
finally {
stopAllGrids();
@@ -241,15 +234,11 @@ public class GridCacheSortedBatchEvictionPolicySelfTest extends
try {
startGrid();
- GridCacheEvictionAbstractTest.MockEntry e1 = new GridCacheEvictionAbstractTest.MockEntry("1");
-
- GridCacheEvictionAbstractTest.MockEntry e2 = new GridCacheEvictionAbstractTest.MockEntry("2");
-
- GridCacheEvictionAbstractTest.MockEntry e3 = new GridCacheEvictionAbstractTest.MockEntry("3");
-
- GridCacheEvictionAbstractTest.MockEntry e4 = new GridCacheEvictionAbstractTest.MockEntry("4");
-
- GridCacheEvictionAbstractTest.MockEntry e5 = new GridCacheEvictionAbstractTest.MockEntry("5");
+ MockEntry e1 = new MockEntry("1");
+ MockEntry e2 = new MockEntry("2");
+ MockEntry e3 = new MockEntry("3");
+ MockEntry e4 = new MockEntry("4");
+ MockEntry e5 = new MockEntry("5");
SortedEvictionPolicy<String, String> p = policy();
@@ -259,27 +248,37 @@ public class GridCacheSortedBatchEvictionPolicySelfTest extends
assertFalse(e1.isEvicted());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
+
p.onEntryAccessed(false, e2);
assertFalse(e1.isEvicted());
assertFalse(e2.isEvicted());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
+
p.onEntryAccessed(false, e3);
assertFalse(e1.isEvicted());
assertFalse(e3.isEvicted());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
+
p.onEntryAccessed(false, e4);
assertFalse(e1.isEvicted());
assertFalse(e3.isEvicted());
assertFalse(e4.isEvicted());
+ check(p.queue().size(), MockEntry.KEY_SIZE);
+
p.onEntryAccessed(false, e5);
assertFalse(e1.isEvicted());
assertFalse(e3.isEvicted());
assertFalse(e5.isEvicted());
+
+ check(p.queue().size(), MockEntry.KEY_SIZE);
}
finally {
stopAllGrids();
@@ -299,12 +298,16 @@ public class GridCacheSortedBatchEvictionPolicySelfTest extends
try {
IgniteCache<Object, Object> cache = ignite.cache(null);
+ GridCacheContext cctx = ((IgniteCacheProxy)cache).context();
+
int cnt = 500;
int min = Integer.MAX_VALUE;
int minIdx = 0;
+ int entrySize = 0;
+
for (int i = 0; i < cnt; i++) {
cache.put(i, i);
@@ -314,11 +317,17 @@ public class GridCacheSortedBatchEvictionPolicySelfTest extends
min = cacheSize;
minIdx = i;
}
+
+ if (entrySize == 0)
+ entrySize = cctx.toCacheKeyObject(i).valueBytes(cctx.cacheObjectContext()).length +
+ cctx.toCacheObject(i).valueBytes(cctx.cacheObjectContext()).length;
}
// Batch evicted.
assert min >= plcMax : "Min cache size is too small: " + min;
+ check(plcMax, entrySize);
+
info("Min cache size [min=" + min + ", idx=" + minIdx + ']');
info("Current cache size " + cache.size());
info("Current cache key size " + cache.size());
@@ -346,6 +355,8 @@ public class GridCacheSortedBatchEvictionPolicySelfTest extends
// Batch evicted.
assert min >= plcMax : "Min cache size is too small: " + min;
+
+ check(plcMax, entrySize);
}
finally {
stopAllGrids();
@@ -372,14 +383,23 @@ public class GridCacheSortedBatchEvictionPolicySelfTest extends
/** {@inheritDoc} */
@Override protected void checkNearPolicies(int endNearPlcSize) {
for (int i = 0; i < gridCnt; i++)
- for (EvictableEntry<String, String> e : nearPolicy(i).set())
- assert !e.isCached() : "Invalid near policy size: " + nearPolicy(i).set();
+ for (EvictableEntry<String, String> e : nearPolicy(i).queue())
+ assert !e.isCached() : "Invalid near policy size: " + nearPolicy(i).queue();
}
/** {@inheritDoc} */
- @Override protected void checkPolicies(int plcMax) {
- for (int i = 0; i < gridCnt; i++)
- assert policy(i).set().size() <= plcMax + policy(i).getBatchSize();
+ @Override protected void checkPolicies() {
+ for (int i = 0; i < gridCnt; i++) {
+ assert policy(i).queue().size() <= plcMax + policy(i).getBatchSize();
+
+ int size = 0;
+
+ for (EvictableEntry<String, String> entry : policy(i).queue())
+ size += ((CacheEvictableEntryImpl)entry).size();
+
+ assertEquals(size, ((SortedEvictionPolicy)policy(i)).getCurrentMemSize());
+ }
+
}
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ed8b82/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicyPerformanceTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicyPerformanceTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicyPerformanceTest.java
index 8d97a1e..449467a 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicyPerformanceTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/sorted/GridCacheSortedEvictionPolicyPerformanceTest.java
@@ -19,7 +19,6 @@ package org.apache.ignite.internal.processors.cache.eviction.sorted;
import org.apache.ignite.*;
import org.apache.ignite.cache.*;
-import org.apache.ignite.cache.eviction.fifo.*;
import org.apache.ignite.cache.eviction.sorted.*;
import org.apache.ignite.configuration.*;
import org.apache.ignite.internal.util.typedef.internal.*;
@@ -49,9 +48,6 @@ public class GridCacheSortedEvictionPolicyPerformanceTest extends GridCommonAbst
/** Get probability. */
private static final int P_GET = 30;
- /** Measurement count. */
- private static final int MEASUREMENT_CNT = 100;
-
/** Rnd. */
private static final ThreadLocalRandom8 RND = ThreadLocalRandom8.current();