Hystrix command does not run in Hystrix environment - aop

I am having an issue with my Hystrix commands. If the call to hystrix wrapped method comes from within the class, the hystrix-wrapped method does not run in Hystrix enviroment
In that case I see logs as
05-02-2018 22:51:25.809 [http-nio-auto-1-exec-3] INFO c.i.q.v.e.ConnectorImpl.populateFIDSchema -
populating FID Schema
But, if I make call to the same method from outside the class, I see it running it in Hystrix enviroment
05-02-2018 22:54:53.735 [hystrix-ConnectorImpl-1] INFO c.i.q.v.e.ConnectorImpl.populateFIDSchema -
populating FID Schema
I am wrapping my method with HystrixCommand like this
#HystrixCommand(commandKey = "getSchemaCommand", fallbackMethod = "getSchemaCommandFallback")
Any ideas?

Contrary to #pvpkiran's answer, this is not a limitation of AspectJ, but a limitation Spring AOP. Spring AOP is a solution that tries to implement a subset of AspectJ through proxies, and the proxy based approach is what causing the advices not being called when the calls are not made through the proxy.
See Spring AOP capabilities and goals and AOP Proxies in the Spring Framework Reference for more details.
AspectJ on the other hand directly modifies the bytecode of the advised class, involves no proxies at all, and doesn't suffer from the limitation of the proxy based Spring AOP.
AspectJ is superior in pretty much all aspects to Spring AOP so I would advise you to switch over from Spring AOP to AspectJ (you don't need to ditch Spring for this as Spring and AspectJ can work together very well).

This is a limitation of Spring AOP (Hystrix-Javanica is based on AOP).
When you call a method locally, it doesn't go through a proxy and hence it doesn't really run in Hystrix environment, instead it runs as if it's another method.
But when you make a call from outside the class, it goes through proxy and hence it works.
This is true of many other functionalities. Another example is #Cacheable
When you call from outside the class, Hystrix (Spring AOP) intercepts the call and wraps it around its own environment. But when you do a call locally, it cannot intercept the call.

Related

Why Does Ignite Use Spring framework?

I had used Spring framework in my apps and while it is nice conceptually, it is not suitable for real-time apps due to its run-time overhead. For instance, http://apache-ignite-users.70518.x6.nabble.com/Failed-to-map-keys-for-cache-all-partition-nodes-left-the-grid-td23510.html shows the actual run-time Spring stack.
The Spring features that Ignite uses for loading application-defined beans are just many layers wrapped around simple Java reflection features. So Why Ignite uses Spring instead of straight Java'reflection ?
To make Ignite more performant, is there plan with Ignite to switch from Spring framework to Java reflection features ?
Similarly, if Ignite uses Spring Boot to handle port requests, why does it not use a light-weight framework such as www.sparkjava.com ?
Ignite uses Spring only to convert XML configuration files into configuration beans during startup. This way Ignite provides a convenient well-known way of configuring instead of introducing a custom one. In the runtime, after node is started, Spring is not used for anything.
In the thread you provided it's actually other way around - Spring invokes Ignite. Apparently, that's a Spring application with an embedded Ignite node.

Does javamelody work with spring webflux?

can anyone point me to a resource, how I can get spring-webflux and javamelody to work together?
Seems, that a servletcontext is neccessary for startup, which I don't have/need.
I'm aware of the coll metrics stuff, that comes with spring-boot 2.x, but I don't have anything to display the metrics with, and am locked to a company environment, where just installing something isn't a valid option.
Thanks,
Henning
javamelody is mainly based on monitoring of memory, cpu, http requests, sql requests and spring components among other things. See javamelody-spring-boot-starter for example.
But as far as I know, Spring webflux does not use the servlet api. So what do you want to monitor?
If you just want to have graphs in a browser, then start a http server for javamelody reports like in standalone. And if you also want to monitor sql requests and spring components, then add in your application all methods from this example, except monitoringSessionListener and monitoringFilter.
A new spring-boot-starter for javamelody in webflux could be created if it makes sense.

AspectJ Spring AOP pointcut hibernate entity functions

How do i pointcut the execution of functions defined in the Hibernate Entities, Which is not created or loaded as spring beans. Couldnt find any help over internet to how to do this.
Is there a way to use spring to point cut hibernate entities.
This is what I found, but no solution
With Spring AOP, you cannot do it. Spring AOP is a limited AOP solution that is only similar to AspectJ. Spring AOP is less capable than AspectJ in a number of ways:
Spring AOP supports only a limited subset of the AspectJ pointcuts (only execution type of pointcuts)
Spring AOP has different semantics compared AspectJ, because it uses dynamic proxies instead of direct bytecode manipulation. With the proxy based solution the Spring AOP uses, advices are not executed when the control flow doesn't leave the proxied object, as when invoking another method in the same object, like this.someOtherMethod()
Spring AOP only works for Spring managed beans. Hibernate entities are not Spring managed beans, so Spring AOP doesn't apply to them.
I encourage you to switch over to native AspectJ to be able to advise Hibernate entites or any other non spring managed beans. Spring supports AspectJ nicely and you should be able to change your configuration to use native AspectJ instead of Spring AOP.

Spring boot websocket test

I have a spring boot project with websocket and I want to test the project sending multiple request to the socket from different users. I want to use threads to imitate the users that send data from the web app but I don't know exactly how to make the test. Can anyone help me, and show one simple test for an websocket using threads?
You can use JMeter for testing your websocket project.
For further reading:
https://www.blazemeter.com/blog/websocket-testing-apache-jmeter
http://www.baeldung.com/websockets-spring
Good example:
https://github.com/Fyro-Ing/JMeter-WebSocket-StompSampler
When writing a Spring Boot application using STOMP on websockets, I struggled a lot to find out how to configure a test client.
I ended up writing a little library called Jackstomp to make it easier to create type-safe tests for STOMP WS applications using JSON as message body.
I haven't used it with multiple threads, but you should be able to easily use it within each thread to create independent clients for each user and perform basic operations. (Please note that a different client should be used in each thread).
The point is that you can really express a synchronous flow for each client, including actively querying for received events.
Even if you don't use this library, you can look at the code to get a grasp of the different things to setup.

RestAssured testing without running Tomcat

I have REST web service which needs to be tested. I am using Mockito for mocking DAO classes and RestAssured for testing REST methods through URI. Is there any way to test REST service without running it separately with Tomcat? Or how to run application on Tomcat with mocked classes before test cases?
There is a tutorial that shows you how to use maven to start an embedded instance of tomcat and run tests against your service using RestAssured:
http://www.hascode.com/2011/09/rest-assured-vs-jersey-test-framework-testing-your-restful-web-services/
You start tomcat in one shell and run your tests in another.
However, I strongly recommend using the jersey test framework which transparently spins up an embedded container. In this case you wouldn't use RestAssured at all, but the jersey test client. Your tests will run more quickly and with less fuss. It's well documented here: https://jersey.github.io/documentation/latest/test-framework.html. The tutorial also demonstrates this approach, though it doesn't seem to me that the client is correctly constructed.
In the past I've also tested REST resources by calling the implementing class methods directly. Though this doesn't test the correct mapping of the http query parameters/body to java method parameters, it was often sufficient (especially when I'm also coding the client side code).