Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

JUnit for Memory footprint?

Thread view: 
nibblix@gmail.com - 17 Apr 2006 19:52 GMT
Hello,
Does anyone know of any extensions to JUnit or any other testing
framework that would allow me to put checks on the memory footprint of
my java app? I'd like to ensure that major refactoring etc doesn't blow
out memory bounds.

thanks,
n
TheOne - 18 Apr 2006 01:44 GMT
How about using jmap/jhat?
nibblix - 18 Apr 2006 19:27 GMT
I'm not looking for a tool to do memory analysis but more for a testing
framework where I can set memory bounds. For example, I should be able
to set a limit on the amount of java heap the module I'm testing uses.
If it crosses that threshold the test should fail.

thanks,
n
Andrew McDonagh - 18 Apr 2006 20:58 GMT
> I'm not looking for a tool to do memory analysis but more for a testing
> framework where I can set memory bounds. For example, I should be able
[quoted text clipped - 3 lines]
> thanks,
> n

These types of tests are not Unit tests, they are more Acceptance tests.

As in...

The application can handle 100 concurrent clients using no more than
256mb of heap space.

To automate a test against this requirement, I'd used something like FIT
or FitNesse.

They use HTML tables to describe the Acceptance Test, and then actually
launch the application.

Take a look at

http://fitnesse.org/FitNesse.TwoMinuteExample
James McGill - 18 Apr 2006 21:05 GMT
> To automate a test against this requirement, I'd used something like
> FIT
> or FitNesse.

Fit/Fitnesse looks so interesting, but it's SO hard to understand what
to do with it from their documentation.  Maybe it makes more sense to
others, but I can't get my brain around it.  I understand some *depth*
of it mind you, but that's not helpful until the *basics* are explained,
and the Fit/Fitnesse sites, pretty as they are, do a poor job of
explaining to a potential user, what the product is good for, and how to
begin using it.  
Andrew McDonagh - 18 Apr 2006 21:06 GMT
>> I'm not looking for a tool to do memory analysis but more for a testing
>> framework where I can set memory bounds. For example, I should be able
[quoted text clipped - 20 lines]
>
> http://fitnesse.org/FitNesse.TwoMinuteExample

When writing the FitNesse testcase, you can specify how much heap the
JVM should use....

Tools like Fit & FitNesse are preferred for Acceptance Testing, as they
allow non-programmers to read & write testcases.  They use the 'Domain
Specific Language' idea, which basically allows people who will use the
application, to know what the tests are doing, cause they are writtern
using the kind of words they would understand. Where as xUnit unit tests
are written in a programming language - which only programmers would
understand or be able to write new ones.

If you really want to use JUnit, then you can change the JVM parameters
of the JUnit session from within Eclipse's Run TestCase dialog. No doubt
other IDEs will allow the same.

Andrew
Andrew McDonagh - 18 Apr 2006 23:36 GMT
>> I'm not looking for a tool to do memory analysis but more for a testing
>> framework where I can set memory bounds. For example, I should be able
[quoted text clipped - 20 lines]
>
> http://fitnesse.org/FitNesse.TwoMinuteExample

Link to FIT

http://fit.c2.com/wiki.cgi?IntroductionToFit

Fit is the actual Framework for Integrated Tests, FitNesse is a simple
Wiki around Fit, that allows remote users to browser to the FIT server
and Run, create, edit, delete tests - amongst other cool things.

Andrew
nibblix - 20 Apr 2006 23:49 GMT
Consider the case where I have foo( ) having a peak heap usage of 150M.
I'd like to write a unit test case that ensures that future
refactoring/changes of foo() does not cause the heap to grow beyond
150M.

One way would be to set the Xmx to 150M but I'm looking for a way to do
this without causing the JVM to error out.

thanks,
n
Andrew McDonagh - 21 Apr 2006 01:13 GMT
> Consider the case where I have foo( ) having a peak heap usage of 150M.
> I'd like to write a unit test case that ensures that future
[quoted text clipped - 6 lines]
> thanks,
> n

There's no Unit Test reliable means of doing this.

The best you can do is use the Runtime memory methods to check that
current usage after running foo() is less than 150M. The problem with
this is that other factors may make the test pass or fail intermittently
- eg GC previous testcases mount up memory usage before GC can reclaimm etc.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html

e.g.

public void testMemoryConsumptionIsBelowMaximumHeapSize() {

  Runtime rt = Runtime.getRuntime();

  assertTrue("Sanity test - starting memory is already beyond heap size
target", rt.totalMemory() < 150);

  ClassUnderTest.foo();

  assertTrue("Heap size target exceeded", rt.totalMemory() < 150);
}

It would also be a stress test of Foo() which is only being tested
within the single threaded nature of JUnit.  It wouldn't be testing
Foo() in the nature of how it would be used in the application, where
other processing would be happening which might take memory consumption
over the limit.
nibblix - 24 Apr 2006 03:32 GMT
Very True.

Thanks for your input.

- n


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.