Author: manik.surtani(a)jboss.com
Date: 2008-09-30 10:49:46 -0400 (Tue, 30 Sep 2008)
New Revision: 6818
Added:
core/trunk/src/test/java/org/jboss/cache/profiling/MemConsumptionTest.java
Log:
Mem test
Added: core/trunk/src/test/java/org/jboss/cache/profiling/MemConsumptionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/MemConsumptionTest.java
(rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/MemConsumptionTest.java 2008-09-30
14:49:46 UTC (rev 6818)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.cache.profiling;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.util.TestingUtil;
+import org.testng.annotations.Test;
+
+import java.io.IOException;
+import java.text.NumberFormat;
+import java.util.Random;
+
+@Test(groups = "profiling")
+public class MemConsumptionTest
+{
+ // adjust the next 3 numbers
+ int numNodes = 1000000;
+ int payloadSize = 20; // bytes
+ int keySize = 10; // bytes
+
+ Random r = new Random();
+
+ public void testMemConsumption() throws IOException
+ {
+ int kBytesCached = (numNodes * (payloadSize + keySize)) / 1024;
+ System.out.println("Bytes to be cached: " +
NumberFormat.getIntegerInstance().format(kBytesCached) + " kb");
+
+ Cache<String, String> c = new DefaultCacheFactory<String,
String>().createCache(); // default LOCAL cache
+ for (int i = 0; i < numNodes; i++)
+ {
+ c.put(Fqn.fromString("/node" + i), generateRandomString(keySize),
generateRandomString(payloadSize));
+ }
+
+ System.out.println("Calling System.gc()");
+ System.gc(); // clear any unnecessary objects
+
+ TestingUtil.sleepThread(1000); // wait for gc
+
+ // wait for manual test exit
+ System.out.println("Cache populated; check mem usage using jconsole,
etc.!");
+ System.in.read();
+ }
+
+ private String generateRandomString(int stringSize)
+ {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < stringSize; i++)
+ {
+ sb.append(r.nextInt(9)); // single digit
+ }
+ assert sb.length() == stringSize;
+ return sb.toString();
+ }
+}