use of org.glassfish.jersey.internal.inject.ForeignDescriptor in project jersey by jersey.
the class RequestScopeTest method testScopeWithTwoInternalTasks.
@Test
public void testScopeWithTwoInternalTasks() throws Exception {
final RequestScope requestScope = new RequestScope();
assertNull(requestScope.suspendCurrent());
ForeignDescriptor inhab = ForeignDescriptor.wrap(new TestProvider("a"));
final Instance instance = requestScope.runInScope(new Callable<Instance>() {
@Override
public Instance call() throws Exception {
final Instance internalInstance = requestScope.suspendCurrent();
final Instance anotherInstance = requestScope.runInScope(new Callable<Instance>() {
@Override
public Instance call() throws Exception {
final Instance currentInstance = requestScope.suspendCurrent();
assertTrue(!currentInstance.equals(internalInstance));
currentInstance.put(inhab, "1");
return currentInstance;
}
});
assertTrue(!anotherInstance.equals(internalInstance));
assertEquals("1", anotherInstance.get(inhab));
anotherInstance.release();
assertNull(anotherInstance.get(inhab));
return internalInstance;
}
});
instance.release();
assertNull(instance.get(inhab));
}
use of org.glassfish.jersey.internal.inject.ForeignDescriptor in project jersey by jersey.
the class RequestScopeTest method testScopeWithImplicitInstance.
@Test
public void testScopeWithImplicitInstance() throws Exception {
final RequestScope requestScope = new RequestScope();
assertNull(requestScope.suspendCurrent());
ForeignDescriptor inhab = ForeignDescriptor.wrap(new TestProvider("a"));
final Instance instance = requestScope.runInScope(new Callable<Instance>() {
@Override
public Instance call() throws Exception {
final Instance internalInstance = requestScope.suspendCurrent();
assertNull(internalInstance.get(inhab));
internalInstance.put(inhab, "1");
assertEquals("1", internalInstance.get(inhab));
return internalInstance;
}
});
assertEquals("1", instance.get(inhab));
instance.release();
assertNull(instance.get(inhab));
}
Aggregations