ClusterNodeMetricsSelfTest::testAllocatedMemory was fixed according to latest changes in memory management - Fixes
@@ -23,6 +23,8 @@ import java.util.concurrent.CountDownLatch;
import org.apache.ignite.GridTestTask;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.MemoryMetrics;
import org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy;
import org.apache.ignite.cluster.ClusterMetrics;
import org.apache.ignite.configuration.CacheConfiguration;
@@ -105,31 +107,36 @@ public class ClusterNodeMetricsSelfTest extends GridCommonAbstractTest {
* @throws Exception If failed.
*/
public void testAllocatedMemory() throws Exception {
- fail("https://issues.apache.org/jira/browse/IGNITE-4536");
-
- Ignite ignite = grid();
+ IgniteEx ignite = grid();
final IgniteCache cache = ignite.getOrCreateCache(CACHE_NAME);
- long prevTieredOffHeapSize = cache.metrics().getOffHeapAllocatedSize();
+ MemoryMetrics memMetrics = getDefaultMemoryPolicyMetrics(ignite);
- assertEquals(0, prevTieredOffHeapSize);
+ memMetrics.enableMetrics();
- long prevClusterNonHeapMemoryUsed = ignite.cluster().metrics().getNonHeapMemoryUsed();
+ int pageSize = getPageSize(ignite);
- fillCache(cache);
+ assertEquals(0, memMetrics.getTotalAllocatedPages());
- assertTrue(cache.metrics().getOffHeapAllocatedSize() > (MAX_VALS_AMOUNT - 5)
- * VAL_SIZE + prevTieredOffHeapSize);
+ fillCache(cache);
- assertTrue(prevClusterNonHeapMemoryUsed < ignite.cluster().metrics().getNonHeapMemoryUsed());
+ assertTrue(memMetrics.getTotalAllocatedPages() * pageSize > MAX_VALS_AMOUNT
+ * VAL_SIZE);
+ }
- prevClusterNonHeapMemoryUsed = ignite.cluster().metrics().getNonHeapMemoryUsed();
- prevTieredOffHeapSize = cache.metrics().getOffHeapAllocatedSize();
+ /**
+ * @param ignite Ignite instance.
+ */
+ private MemoryMetrics getDefaultMemoryPolicyMetrics(IgniteEx ignite) throws IgniteCheckedException {
+ return ignite.context().cache().context().database().memoryPolicy(null).memoryMetrics();
+ }
- assertEquals(prevTieredOffHeapSize, cache.metrics().getOffHeapAllocatedSize());
- assertTrue((MAX_VALS_AMOUNT - 5) * VAL_SIZE + prevClusterNonHeapMemoryUsed <
- ignite.cluster().metrics().getNonHeapMemoryUsed());
+ /**
+ * @param ignite Ignite instance.
+ */
+ private int getPageSize(IgniteEx ignite) {
+ return ignite.context().cache().context().database().pageSize();
}
/**
