Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mattias Jiderhamn
committed
Mar 28, 2012
1 parent
fd8e57b
commit 57e441f
Showing
4 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/test/java/se/jiderhamn/classloader/leak/prevention/MBeanTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,43 @@ | |||
package se.jiderhamn.classloader.leak.prevention; | |||
|
|||
import java.lang.management.ManagementFactory; | |||
|
|||
import javax.management.*; | |||
|
|||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import se.jiderhamn.JUnitClassloaderRunner; | |||
import se.jiderhamn.LeakPreventor; | |||
|
|||
/** | |||
* Verify that custom MBean causes leak that can be prevented | |||
* @author Mattias Jiderhamn | |||
*/ | |||
@RunWith(JUnitClassloaderRunner.class) | |||
@LeakPreventor(MBeanTest.Prevent.class) | |||
public class MBeanTest { | |||
|
|||
@Test | |||
public void triggerMBeanLeak() throws Exception { | |||
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); | |||
mBeanServer.registerMBean(new Custom(), new ObjectName("se.jiderhamn:foo=bar")); | |||
} | |||
|
|||
public interface CustomMBean { | |||
} | |||
|
|||
public static class Custom implements CustomMBean { | |||
} | |||
|
|||
public static class Prevent implements Runnable { | |||
public void run() { | |||
new ClassLoaderLeakPreventor() { | |||
{ // Initializer / "Constructor" | |||
unregisterMBeans(); | |||
} | |||
}; | |||
} | |||
|
|||
} | |||
|
|||
} |