aboutsummaryrefslogtreecommitdiff
path: root/0.20.0/tests/threads_explicit_detach.rs
blob: 3010ca3518542360c1ae4235d423bc01a203bf8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#![cfg(feature = "invocation")]

mod util;
use util::{attach_current_thread, call_java_abs, detach_current_thread, jvm};

#[test]
pub fn explicit_detach_detaches_thread_attached_locally() {
    assert_eq!(jvm().threads_attached(), 0);
    let guard = attach_current_thread();
    let val = call_java_abs(&guard, -1);
    assert_eq!(val, 1);
    assert_eq!(jvm().threads_attached(), 1);

    detach_current_thread();
    assert_eq!(jvm().threads_attached(), 0);
    assert!(jvm().get_env().is_err());
}