55 Commits

Author SHA1 Message Date
Spring Builds
3518224082 Update Copyright to -present instead of current year
* Remove unnecessary anymore Gradle `updateCopyrights`
2025-06-16 16:01:37 -04:00
Artem Bilan
2aaa8db7d0 Migrate imports order to other Spring projects style 2025-01-28 15:44:03 -05:00
Artem Bilan
db59442ea2 Add @DirtiesContext to tests to clean up app ctx cache
And attempt to mitigate out of memory error on CI/CD
2024-12-12 11:22:46 -05:00
Tran Ngoc Nhan
d7058bbac6 Apply Java pattern matching 2024-09-04 12:20:44 -04:00
Artem Bilan
37d96412a1 SMLC: defer counter release until fetched messages are processed
Currently, the `SimpleMessageListenerContainer` is stopped immediately
when `cancelOK` is received.

The expectation do not stop an application context until all the fetched
messages are processed.
Therefore, move `this.activeObjectCounter.release(this);` to the `BlockingQueueConsumer.nextMessage()`
if the internal queue is empty and `cancelled` has been requested.

* Adjust all the SMLC tests for a shorter `receiveTimeout` to not have blocking for nothing
* Fix `EnableRabbitIntegrationTests.exec1` bean for `setAcceptTasksAfterContextClose(true)`.
Looks like an `Executor` can be stopped by the application context before listener container
is able to schedule its shutdown
* Also add `System.setProperty("spring.amqp.deserialization.trust.all", "true");` to be
able to run tests from IDE

**Cherry-pick to `3.0.x`**
2024-02-05 12:49:44 -05:00
Artem Bilan
243ae93668 GH-2577: No synchronized in spring-rabbit-test
Fixes: #2577

* Use `ConcurrentHashMap.newKeySet()` for `exceptions` property in `Answer` impls
2023-12-16 10:21:27 -05:00
Christian Tzolov
c5489e2912 GH-2481: Replace trivial synchronized with locks
Fixes: #2481
2023-12-11 17:22:27 -05:00
Gary Russell
d4e0f5c366 GH-1485: Remove Deprecations
Resolves https://github.com/spring-projects/spring-amqp/issues/1485
2022-09-06 15:55:47 -04:00
Gary Russell
ab3eb36a47 GH-1494: Fix Test Harness with @Repeatable
Resolves https://github.com/spring-projects/spring-amqp/issues/1494

Capture mode failed to capture arguments/result/exception if multiple
`@RabbitListener` annotations present.

**cherry-pick to 2.4.x**
2022-08-29 11:53:19 -04:00
Gary Russell
bb06e92a81 Upgrade checkstyle; fix violations
- a checkstyle bug prevented detection of javadoc tag ordering
- `allowMissingJavadoc` is no longer available on `JavadocMethod`
  (replaced by `MissingJavadocMethod`)
2021-09-27 15:58:27 -04:00
Gary Russell
8981c90f89 Fix new Sonar Issues 2020-08-28 12:29:04 -04:00
Gary Russell
c413fdd259 Fix Sonar Issue 2020-07-23 09:51:19 -04:00
Gary Russell
e6ae6ccb32 Resolve Sonar Issues 2020-07-22 09:32:07 -04:00
Gary Russell
73fdff5a3f Consistent Use of BDDMockito
Mixture of plain and BDD Mockito, sometimes in the same class.

Enforce with checkstyle.
2020-07-21 17:57:31 -04:00
Gary Russell
c40b2b53bc GH-1226: Fix Test Harness
Resolves https://github.com/spring-projects/spring-amqp/issues/1226

https://github.com/spring-projects/spring-amqp/issues/1157 changed the way we spy
listeners - to support CGLIB proxies (e.g. `@Transactional`).

Instead of spying the listener, it mocks the listener and sets a default answer
to call the real method on the delegate.

This broke when users used other answers, such as those provided by the framework.

Change the provided answers to subclass `ForwardsInvocation`.

Also fix `ConcurrentModificationException` in `getExceptions()`.

**cherry-pick to 2.2.x, 2.1.x**
2020-07-21 13:49:17 -04:00
Gary Russell
0674a3b491 Fix test for previous commit 2020-07-13 13:49:53 -04:00
Tim Malich
4063b7743c Enhance mocking in TestRabbitTemplateTests
Fix exception in log

fix travis

Polishing
2020-07-13 13:19:28 -04:00
Wander Costa
c7897ed977 GH-891 Introduced MultiRabbit to handle multiple brokers (#1111)
* GH-891 Introduced MultiRabbit for handle multiple brokers

* GH-891 Fixed formatting and conventions

* GH-891 Avoid premature load of factory beans and some minor refactoring

* GH-891 Introduced tests for SpringMultirabbit

* GH-891 Modified BPP to return list of Declarables created

* GH-891 Minor refactoring

* GH-891 Updated copyright year

* GH-891 Introduced default setAdminsThatShouldDeclare() into Declarable

* GH-891 Avoiding premature instantiation of RabbitAdmin by providing the bean name instead

* GH-891 Changed to non-default

* GH-891 Removed MultiRabbitBootstrapConfiguration and its test
2020-06-24 17:01:32 -04:00
Miguel Gross Valle
d3af209577 GH-1157: Defer spy stubs to original bean
Resolves https://github.com/spring-projects/spring-amqp/issues/1157

CGLib proxies due to e.g. declarative transactional semantics couldn't
be spied upon due to being final. Replacing the spy, which tries to hold
the state itself, with a mock that delegates execution fixes this.
2020-05-14 17:27:16 -04:00
Gary Russell
cc7270c190 GH-1190: Remove reference to Junit4 Assume
Resolves https://github.com/spring-projects/spring-amqp/issues/1190

- Remove reference to `Assume` in `BrokerRunningSupport`
- Move example test cases to a new package so they can be easily copied/pasted
- Remove `assumeOnline` field - it looks like it was intended to support running
  tests only if RabbitMQ is NOT running; but there was never any way to set it
  to false

**cherry-pick to 2.2.x**
2020-05-05 13:34:00 -04:00
Gary Russell
f85a3849fc GH-1175: Add @SpringRabbitTest
Resolves https://github.com/spring-projects/spring-amqp/issues/1175

- provision boilerplate infrastructure

* Fix test name in doc

* Remove `@ContextConfiguration` from doc.
2020-03-13 11:15:24 -04:00
Gary Russell
3fccb5a176 Resolve Sonar issue 2020-03-09 09:57:30 -04:00
Gary Russell
0695d05042 Remove super() 2019-12-27 13:03:20 -05:00
Gary Russell
2874cd24c8 Mockito Answers: Capture any exceptions 2019-12-09 12:44:34 -05:00
Gary Russell
868979d9a4 Convert remaining spring-rabbit tests to JUnit 5
* Fix possible race in testConsumerBatching

* Convert all spring-amqp tests to JUnit 5

* Convert remaining tests to JUnit 5; remove JUnit 4 test dependency

* Remove JUnit vintage engine dependency
2019-08-22 16:31:58 -04:00
Artem Bilan
73029315d7 Remove @Config from RabbitListenerTestBootstrap
The `RabbitListenerTestBootstrap` is an `ImportBeanDefinitionRegistrar`
so, a `@Configuration` annotation is redundant for this class
2019-07-22 14:18:32 -04:00
Gary Russell
4ef8e963a9 Use assertThatThrownBy() Vs. ExpectedException
Also avoid `access()` method in `RabbitTemplatePublisherCallbacksIntegrationTests3`.
2019-04-16 20:30:20 -04:00
Gary Russell
c1ec3e0d3f More AssertJ Conversion
- `hasSize()`
- more tests that the plugin missed first time around
2019-04-16 18:16:12 -04:00
Gary Russell
7472f1b0b6 Convert tests to AssertJ
- initial automated conversion + polishing

- TODO: `...size()).isEqualTo(...` to `).hasSize(...` etc
2019-04-16 13:16:32 -04:00
Artem Bilan
25888693ab Fix new Sonar smells 2019-04-11 09:00:31 -04:00
Artem Bilan
24e8048e70 GH-973: Higher order for RabbitListTestBootstrap (#976)
* GH-973: Higher order for RabbitListTestBootstrap

Fixes https://github.com/spring-projects/spring-amqp/issues/973

When we use `@EnableRabbit` and `@RabbitListenerTest` in the same
configuration set, e.g. mixing real `@Configuration` and test one for
`@RabbitListenerTest`, we may end up with the case when `@EnableRabbit`
is processed before `@RabbitListenerTest`, so, `RabbitListenerTestHarness`
bean is not going to appear in the application context.

* Implement a `DeferredImportSelector` with an `@Order` for the
`@EnableRabbit` as well as `RabbitListenerTest` giving higher order to
the `RabbitListenerTestSelector`, so `RabbitListenerTestBootstrap` is
processed and register its `RabbitListenerTestHarness` earlier, than it
is done by the `RabbitBootstrapConfiguration`

**Cherry-pick to 2.1.x**

* * Fix Checkstyle
* Add JavaDocs to new classes
2019-04-10 15:09:26 -04:00
Artem Bilan
ff49223c94 GH-973: Higher order for RabbitListenerTestHarness
Fixes https://github.com/spring-projects/spring-amqp/issues/973

When we use `@EnableRabbit` and `@RabbitListenerTest` in the same
configuration set, e.g. mixing real `@Configuration` and test one for
`@RabbitListenerTest`, we may end up with the case when `@EnableRabbit`
is processed before `@RabbitListenerTest`, so, `RabbitListenerTestHarness`
bean is not going to appear in the application context.

* Override `getOrder()` for the `RabbitListenerTestHarness` to give it
higher priority than regular `RabbitListenerAnnotationBeanPostProcessor`,
so it is registered first and then the last one won't override existing
bean

**Cherry-pick to 2.1.x**
2019-04-10 12:36:19 -04:00
Artem Bilan
1614a4b053 URL Cleanup
This commit updates URLs to prefer the https protocol.
Redirects are not followed to avoid accidentally expanding intentionally
shortened URLs (i.e. if using a URL shortener).

# Fixed URLs

## Fixed Success
These URLs were switched to an https URL with a 2xx status.
While the status was successful, your review is still recommended.

* [ ] http://www.apache.org/licenses/ with 1 occurrences migrated to:
  https://www.apache.org/licenses/ ([https](https://www.apache.org/licenses/) result 200).
* [ ] http://www.apache.org/licenses/LICENSE-2.0 with 433 occurrences migrated to:
  https://www.apache.org/licenses/LICENSE-2.0 ([https](https://www.apache.org/licenses/LICENSE-2.0) result 200).
2019-03-22 17:28:13 -04:00
Spring Operator
cd8db5305c URL Cleanup
This commit updates URLs to prefer the https protocol.
Redirects are not followed to avoid accidentally expanding intentionally
shortened URLs (i.e. if using a URL shortener).

# Fixed URLs

## Fixed But Review Recommended
These URLs were fixed, but the https status was not OK.
However, the https status was the same as the http request or http
redirected to an https URL, so they were migrated. Your review is recommended.

* http://www.puppycrawl.com/dtds/configuration_1_2.dtd (404) with 1 occurrences migrated to:
  https://www.puppycrawl.com/dtds/configuration_1_2.dtd ([https](https://www.puppycrawl.com/dtds/configuration_1_2.dtd) result 404).
* http://www.puppycrawl.com/dtds/suppressions_1_1.dtd (404) with 1 occurrences migrated to:
  https://www.puppycrawl.com/dtds/suppressions_1_1.dtd ([https](https://www.puppycrawl.com/dtds/suppressions_1_1.dtd) result 404).

## Fixed Success
These URLs were switched to an https URL with a 2xx status.
While the status was successful, your review is still recommended.

* http://www.springframework.org/schema/beans/spring-beans.xsd with 34 occurrences migrated to:
  https://www.springframework.org/schema/beans/spring-beans.xsd ([https](https://www.springframework.org/schema/beans/spring-beans.xsd) result 200).
* http://www.springframework.org/schema/context/spring-context.xsd with 1 occurrences migrated to:
  https://www.springframework.org/schema/context/spring-context.xsd ([https](https://www.springframework.org/schema/context/spring-context.xsd) result 200).
* http://www.springframework.org/schema/rabbit/spring-rabbit.xsd with 32 occurrences migrated to:
  https://www.springframework.org/schema/rabbit/spring-rabbit.xsd ([https](https://www.springframework.org/schema/rabbit/spring-rabbit.xsd) result 200).
* http://www.springframework.org/schema/task/spring-task.xsd with 2 occurrences migrated to:
  https://www.springframework.org/schema/task/spring-task.xsd ([https](https://www.springframework.org/schema/task/spring-task.xsd) result 200).
* http://www.springframework.org/schema/util/spring-util.xsd with 5 occurrences migrated to:
  https://www.springframework.org/schema/util/spring-util.xsd ([https](https://www.springframework.org/schema/util/spring-util.xsd) result 200).

# Ignored
These URLs were intentionally ignored.

* http://www.springframework.org/schema/beans with 77 occurrences
* http://www.springframework.org/schema/context with 2 occurrences
* http://www.springframework.org/schema/rabbit with 71 occurrences
* http://www.springframework.org/schema/task with 4 occurrences
* http://www.springframework.org/schema/util with 10 occurrences
* http://www.w3.org/2001/XMLSchema-instance with 34 occurrences

* Fix Checkstyle configs for the latest DTD and their HTTPS variants
2019-03-20 10:18:53 -04:00
Artem Bilan
89446a2926 GH-914: Honor AllowBeanDefOverriding = false (#915)
* GH-914: Honor AllowBeanDefOverriding = false

Fixes https://github.com/spring-projects/spring-amqp/issues/914

* Rework `RabbitBootstrapConfiguration` into the `ImportBeanDefinitionRegistrar`
and check for bean definitions presence it is going to register.
This way an override from the `RabbitListenerTestBootstrap` is going to
have a precedence and its `RabbitListenerTestHarness` won't allow a
regular `RabbitListenerAnnotationBeanPostProcessor` to be registered
* Rework `TestRabbitTemplate` to gather all the listener container
from the `ContextRefreshedEvent` instead of the `SmartInitializingSingleton`.
Looks like Spring doesn't care about their order, therefore we need to
be sure that `RabbitListenerAnnotationBeanPostProcessor` has populated
its `registry` with containers before.
* Demonstrate that `allowBeanDefinitionOverriding = false` works well
now in the `ExampleRabbitListenerCaptureTest`
* Optimize `checkTestConfigs` and `updateCopyrights` Gradle tasks for
their `inputs` and `outputs` for better `UP-TO-DATE` handling

**Cherry-pick to 2.1.x without `build.gradle` changes**

* * Fix typo in the `ExampleRabbitListenerCaptureTest`
2019-02-22 16:03:17 -05:00
Gary Russell
77e1216559 GH-905: Configurable executor on @RabbitListener
Resolves https://github.com/spring-projects/spring-amqp/issues/905
2019-02-17 18:21:16 -05:00
Gary Russell
b2802b5d0d 2.2 General Code and API Cleanup
- remove redundant `implements`
- remove redundant `throws`
- narrow thrown exceptions
- other 2.2. TODOs
2019-02-15 15:36:35 -05:00
Gary Russell
6ba27ee97d Sonar Fixes
- all minors

* Remaining issues - mostly imports for Javadocs only.

* Final final

* Polising - bogus chars in comment

* Polishing idle time.
2018-12-23 12:27:04 -05:00
Gary Russell
24521d8937 Sonar Fixes
- remaining majors
2018-12-21 12:55:50 -05:00
Gary Russell
91f79aa547 Fix Package Tangle
The introduction of `ClosingRecoveryListener` introduced a tangle between
`connection` and `support`.

Move all channel-related classes from `support` to `connection`.
2018-09-11 14:19:36 -04:00
Gary Russell
4464d4d8a5 AMQP-798: Master to 2.1.x; Fix Tangles
JIRA: https://jira.spring.io/browse/AMQP-798

Also update amqp-client to 5.2.0

Don't use `MessageConverter` in `Message.toString()` (cycle)

Fix cycle between template and admin (via containers)

Fix outbound reference from support to connection

Fix cycle between connection and listener via RabbitUtils

Fix cycle between listener and core via ChannelAwareMessageListener and admin

Fix cycle between listener.adapter and listener via RabbitListenerErrorHandler
Fix cycle between amqp.support and amqp.core via Correlation

Fix cycle between listener and transaction via ListenerFailedRuleBasedTransactionAttribute

Fix Tests

Polishing - PR Comments; rename schema

Test polishing - travis failures

Polishing according PR comments

* Update Copyright for all affected classes
* Optimize `DirectMessageListenerContainer.checkMissingQueues()` to
cache `amqpAdmin` from the locally created
* `RabbitUtils.DEFAULT_PORT` as not-used and deprecated in `2.0.x`
* Remove commented test in the `LogAppenderUtils`
* Deprecate `AbstractAdaptableMessageListener#setRabbitAdmin()` in favor
of newly introduced `setAmqpAdmin()`
2018-03-16 12:06:17 -04:00
Gary Russell
308c869044 AMQP-670: Broker-less @RabbitListener Testing
JIRA: https://jira.spring.io/browse/AMQP-670

Initial PoC.

`TestRabbitTemplate` invokes the listener on the calling test thread.

Polishing - support other listener containers, and broadcast (fanout simulation).

Docs and remove reference to fanout since broadcasting does not simulate fanout.

Remove broadcast flag.

Polishing

More Polishing
2017-04-04 10:11:49 -04:00
Gary Russell
25ee8bc859 AMQP-694: Upgrade to Mockito 2.5.4
JIRA: https://jira.spring.io/browse/AMQP-694

- `anyXXX()` no longer matches null
- change `Matchers` to `ArgumentMatchers`
2017-01-09 16:17:26 -05:00
dreis2211
ff06da68a2 AMQP-685: Use Supplier variants of Spring-Framework's core Assert utility 2016-12-08 15:49:13 -05:00
Gary Russell
4fded3dde1 AMQP-678: Move BrokerRunning @Rule to junit Jar
JIRA: https://jira.spring.io/browse/AMQP-678

Convert `BrokerRunning` to use the amqp-client directly to avoid circular reference.

Also `LongRunningIntegrationTest`.

Polishing - PR Comments
2016-12-02 15:05:09 -05:00
Gary Russell
87e2fd4041 Avoid Synthetic ctors
Private inner classes with a private ctor (real or implied) cause the compiler
to generate synthetic package-visibility ctors, with a synthetic class parameter if needed.

Also a few more lambdas.

Avoid empty CTORs to avoid Sonar complaints.
2016-11-01 16:32:49 -04:00
Artem Bilan
6d1d59277b AMQP-630: Migrate to Log4J2, Part II
JIRA: https://jira.spring.io/browse/AMQP-630

The previous fix wasn't full: we still need to adjust logger configs for Log4J2
2016-08-11 10:20:46 -04:00
Gary Russell
b89756eec7 checkstyle FinalClass
checkstyle Import Rules

checkstyle HideUtilityCtor

checkstyle InnerTypeLast

checkstyle Annotation Rules

checkstyle Block Rules

checkstyle InnerAssignment

checkstyle Boolean Rules

checkstyle Remaining Code Rules

checkstyle ImportOrder

checkstyle Misc Rules and Trailing Whitespace

checkstyle GenericWhitespace

checkstyle ParenPad

checkstyle WhiteSpaceAfter Script

checkstyle WhiteSpaceAfter

checkstyle WhiteSpaceAround Script

checkstyle WhiteSpaceAround
2016-04-05 13:16:55 -04:00
Artem Bilan
a084f6cdf6 Add fixHeaders.gradle and apply the fix 2016-03-07 15:51:16 -05:00
Ry Lowry
85556c2f1b Make getSpy method visible to other packages. 2016-02-24 18:11:03 -05:00