We are implementing a retry mechanism (using Spring Retry) for http 409 Conflict responses, which we sometimes get on the production server.
But we wonder how to purposely get a server to respond with a 409 status code? In our cases, the error seems to happen whenever we try to load a lot of data in parallel; since the probability of it happening seems quite random, is there a method to get it consistently for testing purposes?
Well, There might be multiple possible ways to do so, You need to clarify where exactly you need 409 to be thrown ,
I assume (Its spring boot app) from one of your service (A) calls to another service/API(B) and you expect it to throw 409.
If that's the case, you can write #RunWith(SpringRunner.class)/#SpringBootTest test and mock the response from service/API B with 409 and test your retry mechanism.
Related
I'm trying to call a method on a remote EJB in a JUnit test that will run SQL against a DB and return results. Here's the message from the exception:
java.lang.IllegalArgumentException: No such EJB method org.jboss.ejb.client.EJBMethodLocator#3c2f505 found on SiViewDBFacadeEAR-0.0.1-SNAPSHOT/SiViewDBFacadeEJB-0.0.1-SNAPSHOT/SiViewMMDBAccessBean
First of all, this error seems to be intermittent. I have a couple different methods in the EJB that run different SQL and return results as a HashMap. In my JUnit test I was calling these methods back to back and I was noticing that the call to the second method was always failing even if I switched the order of the calls. Just recently I tried calling the exact same method twice and it comes back the first time but fails the second time.
Does this problem signature ring a bell with anyone. I'm somewhat new to working with EJBs but this problem seems strange in its inconsistent nature.
Thanks all.
most common reason for this this error to occur is the EJB is not initialized or not deployed at all to the server that hosts it. Look at the logs on both client and server side to make sure all necessary components are initialized and running.
I'm trying to configure the Spring WebClient to retry on a specific exception. Specifically PrematureCloseException but Im not really sure the exception matters.
I know how set a retry policy when calling a method on the client but I would like to do it globally for any request that goes through the client.
I fell like I should be able to do it with an ExchangeFilterFunction but I not really familiar with this and cannot figure it out.
I am using Spring Cloud Brixton.M3 and Spring Boot 1.3.0.RELEASE. I am sort of new in this (especially in Spring Cloud). I have created Registry Server (i.e. Eureka instance), Config server and Gateway.
As per my requirement I am intercepting each request hitting the gateway in one of my Filter to extract required information from Header and based upon that I am throwing exception or forwarding / verifying that request using Feign Client. Some time hystrix throw HystrixRuntimeException when it couldn't reach out to respective services or because of any other issues.
So What I want is:
Provide default fallback method for every forwarding request, so that I can read and process it accordingly.
Global Exception handling other than #ControllerAdvice since I am not providing any custom #HystrixCommand and Controller to call services (AOP based solution ?).
Is it possible to intercept every failed request and retry them for certain number of times ? Internally it might be happening but can I override this functionality and handle each failed request either because of TimedOutException or because of HttpConnectionPool exception ?
Update
Is it a good practice to provide own routing in Zuul gateway ? using #RestController and #HystrixCommand together ? (I think its a bad idea, because over the period of time we will end up with lots of controllers and hence actual use of intelligent routing wouldn't work as expected)
Currently there is an open issue for fallbacks with feign. There is also an open issue for fallbacks with zuul.
In our project we use Activemq (jms template) - to publish many events from one webapp to another.
we use logging aspect (spring aop) as well - mainly we log errors and entering\quitting methods.
Now, sometimes we face racing conditions on the flow of the systems. i.e. an entity is being created on one web app, an event is fired to notify another webapp, but the handling of the other webapp requires a different event to be handled first, so if such scenario happens, the handling fails (for example, an id is missing ) and immediately retried (jms re-delivery), on the 2nd time of the retry its usually works (never more then 3 retries are required).
So basically, we have exceptions as part of our day to day flow, but:
our log files are huge and messy because of the exceptions thrown by such scenarios, any idea how can we not log the first few retries exceptions and only on a later exception we will log? Maybe another approach you can recommend?
Thanks.
You can use JMSXDeliveryCount property of Message to get the redelivery count. See http://activemq.apache.org/activemq-message-properties.html
I am writing a Junit(4.x) test to test what happens when the web application is down.
When I hit the url in the browser, I get a message saying "Connection refused".
I am unsure about what to check for in the assert statements.
Do I check the header for this message? -- urlConnection.getResponseMessage() or
just say (expected = java.net.ConnectException) before the test case. I feel the latter is not specific enough.
EDIT: Right now, I'm using a combination of (expected = java.net.ConnectException) and assertEquals(502, urlConnection.getResponseCode). The test is passing.
Thanks,
Pratyusha.
First of all, your unit tests should not depend so much on external entities. What you describe is rather an integration test.
In a classic unit test, you could set up this scenario by using e.g. a mock HttpUrlConnection. This can be programmed to throw an exception from the desired method call. If you are not happy by simply acknowledging the type of exception thrown, you can always catch it within the test method, then assert the response message or whatever you are interested in.
However, from your post it is not clear to me what are you actually testing: a web client which depends on a server? A web app which calls another web app? Different tests may be adequate for different scenarios.
Integration tests in junit are fine. Many widely used open source projects use this approach. See CXF or Arquillian for examples of this approach.
For your question... you need to decide what the desired behaviour is and then test for this.
For example in this case you probably want to test the response code the server is returning. Or if "connection refused" really is desired behaviour then testing for (expected = java.net.ConnectException) should be sufficient.