本文整理汇总了Java中org.netbeans.junit.NbTestCase.assertGC方法的典型用法代码示例。如果您正苦于以下问题:Java NbTestCase.assertGC方法的具体用法?Java NbTestCase.assertGC怎么用?Java NbTestCase.assertGC使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.junit.NbTestCase
的用法示例。
在下文中一共展示了NbTestCase.assertGC方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAllSessionsClosed
import org.netbeans.junit.NbTestCase; //导入方法依赖的package包/类
public void testAllSessionsClosed() {
//open source
Node beanNode = new Node(new SourcePackagesNode(Utilities.testProjectName), "examples.advanced|MemoryView.java"); //NOI18N
new OpenAction().perform(beanNode); // NOI18N
EditorOperator eo = new EditorOperator("MemoryView.java");
try {
eo.clickMouse(50,50,1);
} catch (Throwable t) {
System.err.println(t.getMessage());
}
new EventTool().waitNoEvent(1000);
//place breakpoint
Utilities.toggleBreakpoint(eo, 104);
//start debugging
new DebugJavaFileAction().perform(beanNode);
//wait for breakpoint
Utilities.waitStatusText("Thread main stopped at MemoryView.java:104");
List<? extends JPDADebugger> list = DebuggerManager
.getDebuggerManager()
.getCurrentSession()
.lookup(null, JPDADebugger.class);
JPDADebugger debugger = list.get(0);
WeakReference<? extends JPDADebugger> debuggerRef = new WeakReference(debugger);
//finish debugging
Utilities.endAllSessions();
//close sources
eo.close();
//nulling all temporary variables which could hold some references to debugger
list = null;
debugger = null;
System.gc();
try {
NbTestCase.assertGC("All the debugging sessions were not correctly closed", debuggerRef);
} catch (OutOfMemoryError u) {
System.out.println(u.getMessage());
}
}
示例2: assertGC
import org.netbeans.junit.NbTestCase; //导入方法依赖的package包/类
/**
* Asserts that the object can be garbage collected.
* It suspends event queue thread to assure that OutOfMemoryError is not
* thrown in it instead of the current thread.
* @param text the text to show when test fails.
* @param ref the referent to object that should be GCed
* @see NbTestCase#assertGC(java.lang.String, java.lang.ref.Reference)
*/
static void assertGC(String text, Reference<?> ref) {
final Object LOCK = new Object();
blockEQ(LOCK);
try {
NbTestCase.assertGC(text, ref);
} finally {
// Resume EQ:
synchronized (LOCK) {
LOCK.notifyAll();
}
}
}
示例3: assertGC
import org.netbeans.junit.NbTestCase; //导入方法依赖的package包/类
public static void assertGC(String msg, String... names) {
AssertionFailedError t = null;
List<Reference> refs = new ArrayList<Reference>();
List<String> txts = new ArrayList<String>();
int count = 0;
Set<String> nameSet = names == null || names.length == 0 ? null : new HashSet<String>(Arrays.asList(names));
synchronized (instances) {
for (Iterator<Map.Entry<Object, String>> it = instances.entrySet().iterator(); it.hasNext();) {
Entry<Object, String> entry = it.next();
if (nameSet != null && !nameSet.contains(entry.getValue())) {
continue;
}
refs.add(new WeakReference<Object>(entry.getKey()));
txts.add(entry.getValue());
it.remove();
count++;
}
}
if (count == 0) {
Assert.fail("No instance of this type reported");
}
int cannotBeCollected = 0;
for (int i = 0; i < count; i++) {
Reference<?> r = refs.get(i);
try {
NbTestCase.assertGC(msg + " " + txts.get(i), r);
} catch (AssertionFailedError ex) {
cannotBeCollected++;
if (t == null) {
t = ex;
} else {
Throwable last = t;
while (last.getCause() != null) {
last = last.getCause();
}
last.initCause(ex);
}
}
}
if (t != null && cannotBeCollected > treshhold) {
throw t;
}
}