Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-2478 Handle conversion exception in AsyncRabbitTemplate #2932

Merged
merged 3 commits into from
Dec 19, 2024

Conversation

BenEfrati
Copy link
Contributor

Previously, conversion errors in AsyncRabbitTemplate lead to AmqpReplyTimeoutException

Fixes #2478

#2478 (comment)

@pivotal-cla
Copy link

@BenEfrati Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-cla
Copy link

@BenEfrati Thank you for signing the Contributor License Agreement!

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, run ./gradlew check locally before pushing changes to PR.
Right now it even does not compile:

 /home/runner/work/spring-amqp/spring-amqp/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/AsyncRabbitTemplate.java:614: error: cannot find symbol
						} catch (MessageConversionException e) {
						         ^
  symbol:   class MessageConversionException
  location: class AsyncRabbitTemplate

@BenEfrati
Copy link
Contributor Author

Hi,
Sorry, at first I fork and created branch from old code, missed the import after sync with upstream.
BenEfrati@50452f8
Pushed the fixed code

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Please, add your name to the @author list of all the affected classes.

…late

Previously, conversion errors in AsyncRabbitTemplate lead to AmqpReplyTimeoutException
cdl.countDown();
});
assertThat(cdl.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(replyFuture).isCompletedExceptionally();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May we also verify what exactly exception we got here?

Comment on lines 411 to 418
final CountDownLatch cdl = new CountDownLatch(1);
final AtomicReference<Object> resultRef = new AtomicReference<>();
replyFuture.whenComplete((result, ex) -> {
resultRef.set(result);
cdl.countDown();
});
assertThat(cdl.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(replyFuture).isCompletedExceptionally();
Copy link
Contributor Author

@BenEfrati BenEfrati Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final CountDownLatch cdl = new CountDownLatch(1);
final AtomicReference<Object> resultRef = new AtomicReference<>();
replyFuture.whenComplete((result, ex) -> {
resultRef.set(result);
cdl.countDown();
});
assertThat(cdl.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(replyFuture).isCompletedExceptionally();
assertThat(replyFuture).failsWithin(Duration.ofSeconds(10))
.withThrowableThat()
.withCauseInstanceOf(MessageConversionException.class);

Something like this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!
But does not look like it would be a good candidate to commit such a suggestion: too many broken indents.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or never mind. I like it.
You have changed the logic, but at the same it is covered with that failsWithin() 😄
Committing and merging.
Thank you!

});
assertThat(cdl.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(replyFuture).isCompletedExceptionally();
assertThat(resultRef.get()).isNull();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this line has to be removed then 😄

Copy link
Contributor Author

@BenEfrati BenEfrati Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure :)

Do you want me to align other tests to use failsWithin

void testReturn() {
...
		assertThat(future)
				.as("Expected exception")
				.failsWithin(Duration.ofSeconds(10))
				.withThrowableThat()
				.withCauseInstanceOf(AmqpMessageReturnedException.class)
				.extracting("routingKey")
				.isEqualTo(this.requests.getName() + "x");

instead

try {
			future.get(10, TimeUnit.SECONDS);
			fail("Expected exception");
		}
		catch (ExecutionException e) {
			assertThat(e.getCause()).isInstanceOf(AmqpMessageReturnedException.class);
			assertThat(((AmqpMessageReturnedException) e.getCause()).getRoutingKey()).isEqualTo(this.requests.getName() + "x");
		}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would appreciate.
Thanks.
Those try..catch in tests is on my TODO list in favor of assertThat() when I touch these classes.
Although still would be with some code.
But now I have learned about failsWithin() which looks much cleaner. 😄

@artembilan artembilan merged commit 410b584 into spring-projects:main Dec 19, 2024
3 checks passed
@artembilan
Copy link
Member

@BenEfrati ,

thank you for contribution; looking forward for more!

@BenEfrati BenEfrati deleted the GH-2478 branch December 20, 2024 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants