MCPcopy Create free account
hub / github.com/grpc/grpc-java / testWrapCallable

Method testWrapCallable

api/src/test/java/io/grpc/ContextTest.java:516–554  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

514 }
515
516 @Test
517 public void testWrapCallable() throws Exception {
518 Context base = Context.current().withValue(PET, "cat");
519 Context current = Context.current().withValue(PET, "fish");
520 current.attach();
521
522 final Object ret = new Object();
523 Callable<Object> callable = new Callable<Object>() {
524 @Override
525 public Object call() {
526 runner.run();
527 return ret;
528 }
529 };
530
531 assertSame(ret, base.wrap(callable).call());
532 assertSame(base, observed);
533 assertSame(current, Context.current());
534
535 assertSame(ret, current.wrap(callable).call());
536 assertSame(current, observed);
537 assertSame(current, Context.current());
538
539 final TestError err = new TestError();
540 try {
541 base.wrap(new Callable<Object>() {
542 @Override
543 public Object call() {
544 throw err;
545 }
546 }).call();
547 fail("Excepted exception");
548 } catch (TestError ex) {
549 assertSame(err, ex);
550 }
551 assertSame(current, Context.current());
552
553 current.detach(Context.ROOT);
554 }
555
556 @Test
557 public void currentContextExecutor() {

Callers

nothing calls this directly

Calls 7

currentMethod · 0.95
attachMethod · 0.95
wrapMethod · 0.95
detachMethod · 0.95
withValueMethod · 0.80
callMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected