Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Test a complete failure of the JVM

DZone's Guide to

Test a complete failure of the JVM

· Java Zone
Free Resource

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

Say you want to test that your application behaves correctly on restart even after the application crashes. One approach is to trigger a crash in test code and check that data is in a correctable state on restart.

Unsafe unsafe = getUnsafe(); // use reflection
unsafe.setMemory(0, 1, (byte) 0);
This triggers a SIGSEGV
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00000032b967ae09, pid=17870, tid=1082034496
#
# JRE version: 7.0_01-b08
# Java VM: Java HotSpot(TM) 64-Bit Server VM (21.1-b02 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libc.so.6+0x7ae09]  memset+0x9
#
If your tests still pass, you can be reasonably confident it is recoverable even on a complete failure of the JVM.

 

From http://vanillajava.blogspot.com/2011/12/test-complete-failure-of-jvm.html

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}