java

How to invoke CompletableFuture callback while propagating result or error?

时光毁灭记忆、已成空白 提交于 2021-02-20 15:38:04
问题 I was trying .exceptionally and .handle but those don't seem to work. In scala, you can call a method on the future with a closure that is just like a finally block(it runs on exception AND on success) AND it propogates the exception or success up the chain as-is. I tried this... CompletableFuture<Object> future = newFuture.handle((r, e) -> { if(r != null) return r; else if(e != null) return e; else return new RuntimeException("Asdf"); }); Assert.assertTrue(future.isCompletedExceptionally());

How to invoke CompletableFuture callback while propagating result or error?

北慕城南 提交于 2021-02-20 15:34:11
问题 I was trying .exceptionally and .handle but those don't seem to work. In scala, you can call a method on the future with a closure that is just like a finally block(it runs on exception AND on success) AND it propogates the exception or success up the chain as-is. I tried this... CompletableFuture<Object> future = newFuture.handle((r, e) -> { if(r != null) return r; else if(e != null) return e; else return new RuntimeException("Asdf"); }); Assert.assertTrue(future.isCompletedExceptionally());

How to invoke CompletableFuture callback while propagating result or error?

拈花ヽ惹草 提交于 2021-02-20 15:34:08
问题 I was trying .exceptionally and .handle but those don't seem to work. In scala, you can call a method on the future with a closure that is just like a finally block(it runs on exception AND on success) AND it propogates the exception or success up the chain as-is. I tried this... CompletableFuture<Object> future = newFuture.handle((r, e) -> { if(r != null) return r; else if(e != null) return e; else return new RuntimeException("Asdf"); }); Assert.assertTrue(future.isCompletedExceptionally());

How to invoke CompletableFuture callback while propagating result or error?

妖精的绣舞 提交于 2021-02-20 15:32:10
问题 I was trying .exceptionally and .handle but those don't seem to work. In scala, you can call a method on the future with a closure that is just like a finally block(it runs on exception AND on success) AND it propogates the exception or success up the chain as-is. I tried this... CompletableFuture<Object> future = newFuture.handle((r, e) -> { if(r != null) return r; else if(e != null) return e; else return new RuntimeException("Asdf"); }); Assert.assertTrue(future.isCompletedExceptionally());

Spring shutdown event that fires immediately before ApplicationContext is destroyed?

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-20 14:14:34
问题 I am looking for an interceptor or a trigger to know that, all the context beans are destroyed and the applicationcontext instance is about to destroy itself. So I can do one process at the end of the application lifetime. There is this event type ContextClosedEvent, which is close to the thing that I wanna do but, it throws the event after destruction of beans. I thing it comes with the close() method of the applicationcontext. So it doesn't fit to my need Any ideas? Regards Ali 回答1: You can

Spring shutdown event that fires immediately before ApplicationContext is destroyed?

故事扮演 提交于 2021-02-20 14:12:38
问题 I am looking for an interceptor or a trigger to know that, all the context beans are destroyed and the applicationcontext instance is about to destroy itself. So I can do one process at the end of the application lifetime. There is this event type ContextClosedEvent, which is close to the thing that I wanna do but, it throws the event after destruction of beans. I thing it comes with the close() method of the applicationcontext. So it doesn't fit to my need Any ideas? Regards Ali 回答1: You can

Spring shutdown event that fires immediately before ApplicationContext is destroyed?

不想你离开。 提交于 2021-02-20 14:03:33
问题 I am looking for an interceptor or a trigger to know that, all the context beans are destroyed and the applicationcontext instance is about to destroy itself. So I can do one process at the end of the application lifetime. There is this event type ContextClosedEvent, which is close to the thing that I wanna do but, it throws the event after destruction of beans. I thing it comes with the close() method of the applicationcontext. So it doesn't fit to my need Any ideas? Regards Ali 回答1: You can

Can we create a mocked instance of java.lang.Class with PowerMock?

若如初见. 提交于 2021-02-20 13:53:37
问题 I need to write a test that mocks a instance of the java.lang.Class class. Is this possible via PowerMock? I tried to do following: PowerMock.createMock(Class.class); And the result is: java.lang.IllegalAccessError: java.lang.Class at sun.reflect.GeneratedSerializationConstructorAccessor12.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator

Can we create a mocked instance of java.lang.Class with PowerMock?

空扰寡人 提交于 2021-02-20 13:53:26
问题 I need to write a test that mocks a instance of the java.lang.Class class. Is this possible via PowerMock? I tried to do following: PowerMock.createMock(Class.class); And the result is: java.lang.IllegalAccessError: java.lang.Class at sun.reflect.GeneratedSerializationConstructorAccessor12.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator

Can we create a mocked instance of java.lang.Class with PowerMock?

不想你离开。 提交于 2021-02-20 13:53:11
问题 I need to write a test that mocks a instance of the java.lang.Class class. Is this possible via PowerMock? I tried to do following: PowerMock.createMock(Class.class); And the result is: java.lang.IllegalAccessError: java.lang.Class at sun.reflect.GeneratedSerializationConstructorAccessor12.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator