Commit Graph

396 Commits

Author SHA1 Message Date
gzhao9
7974f9c5b6 Refactor to Eliminate Repetitive Mock Object Creation in some tests 2024-07-02 13:00:46 -04:00
gzhao9
7a371d637b GH-9271: Refactor Repetitive Mocks in TcpMessageMapperTests
Fixes: #9271

* Update `TcpMessageMapperTests`

* Update formatting and style details
2024-06-27 11:04:48 -04:00
Artem Bilan
c155d5d418 Add EmptyLineSeparator Checkstyle rule
* Support "blank lines around" via `spring-framework.xml` IDEA config
* Fix all the Checkstyle violations
2024-03-27 16:54:25 -04:00
Artem Bilan
39c99c0719 Fix phase for TaskScheduler instances in tests
Related to: #8856

Many tests create their own `ThreadPoolTaskScheduler` beans.
Therefore, its default phase might affect the memory and performance.

* Use `phase = SmartLifecycle.DEFAULT_PHASE / 2` for manual
 `ThreadPoolTaskScheduler` beans
* Migrate affected tests classes to JUnit 5
* Make some other configuration adjustments for better performance

**Cherry-pick to `6.2.x`**
2024-01-16 11:26:51 -05:00
Artem Bilan
0b60dfc9d1 GH-8852: Fix TcpNetServerConnectionFactory.run loop
Fixes: #8852

The `while (true) {` causes the thread to be blocked forever.
The `stop()` waits on the `if (!executorService.awaitTermination(10, TimeUnit.SECONDS)) {` the whole time

* Fix with the `while (isActive()) {`
* Remove the `ConnectionFactoryTests.testEarlyCloseNet()` since we cannot reach expectations because of
race condition between `start()` and `stop()`

**Cherry-pick to `6.2.x` & `6.1.x`**
2024-01-05 15:53:37 -05:00
Artem Bilan
d85c5e3a0a GH-8704: Add global property for defaultTimeout (#8706)
* GH-8704: Add global property for `defaultTimeout`

Fixes https://github.com/spring-projects/spring-integration/issues/8704

The default timeout for requests and replies in the integration endpoints
is 30 seconds to avoid indefinite blocking in threads.
Sometime those 30 seconds is not enough.

* Introduce a `spring.integration.endpoints.defaultTimeout` global property
to allow overriding all the timeouts to desired value.
The negative number indicates an indefinite waiting time: similar to what
was there before introducing 30 seconds by default

* Fix language in docs

Co-authored-by: Gary Russell <grussell@vmware.com>

---------

Co-authored-by: Gary Russell <grussell@vmware.com>
2023-08-22 18:04:31 -04:00
EddieChoCho
ef5db3059d GH-8703: Fix MessagingAnnotationPP for AOT
Fixes https://github.com/spring-projects/spring-integration/issues/8703

* Instantiate a `MessagingAnnotationBeanPostProcessor` via factory method from `MessagingAnnotationPostProcessor`
avoiding extra code generation on an explicitly provided complex `Map` for bean definition property
* Fix test to react properly to a new logic of `MessagingAnnotationBeanPostProcessor` bean registration
2023-08-16 16:31:44 -04:00
Artem Bilan
c157b9b094 Upgrade some deps; fix deprecations 2023-08-12 10:27:48 -04:00
Kazuki Shimizu
9e7b20a059 GH-8609: Fix TcpConnectorInterceptor chain propagation
Fixes https://github.com/spring-projects/spring-integration/issues/8609

* Changed to passed the self instance to `addNewConnection()` instead of argument's connection
in a `TcpConnectionInterceptorSupport` to compose a chain of interceptors from top to down.
This way the target `Sender` get the last interceptor in a chain as its connection.

**Cherry-pick to `6.0.x` & `5.5.x`**
2023-05-05 09:32:55 -04:00
Artem Bilan
b99729544d GH-8586: Deprecate IntegrationComponentSpec.get() (#8594)
* GH-8586: Deprecate IntegrationComponentSpec.get()

Fixes https://github.com/spring-projects/spring-integration/issues/8586

The `IntegrationComponentSpec` is not a plain wrapper around single component.
Sometimes it comes with several components where all of them must be registered
as beans.
If `IntegrationComponentSpec.get()` is called from end-user code, we may lose
other related components, for example filters in the `FileInboundChannelAdapterSpec`.

* Deprecate `IntegrationComponentSpec.get()` with no-op for end-user,
rather encourage to leave it as is and let the framework take care about its lifecycle
and related components registration
* Fix `IntegrationComponentSpec` logic to deal as a simple `FactoryBean` instead of
extra overhead via `AbstractFactoryBean`
* Use `IntegrationComponentSpec.getObject()` in the framework code where `get()` was called
* Fix tests to expose `IntegrationComponentSpec` as beans instead of previously called `get()`
* Some other clean up and typos fixes in the affected classes
* Document the change

* * Revert `ObjectStringMapBuilder` in the `KafkaInboundGatewaySpec.getComponentsToRegister()`

* Fix language in docs

Co-authored-by: Gary Russell <grussell@vmware.com>

* * Remove trailing whitespace in the `ScriptMessageSourceSpec`

---------

Co-authored-by: Gary Russell <grussell@vmware.com>
2023-04-13 09:16:42 -04:00
abilan
e03d125fdb Improve some tests performance 2023-04-10 14:55:45 -04:00
Gary Russell
e8a9f95ca1 GH-4013: TCP DSL Improvements
Resolves https://github.com/spring-projects/spring-integration/issues/4013

Add Net/NIO specific Server/Client connection factory specs.

* Shorten DSL method names, as suggested.
2023-02-08 17:01:44 -05:00
Artem Bilan
ebba37497f GH-3993: Fix async race condition in TcpOutGateway (#3995)
* GH-3993: Fix async race condition in TcpOutGateway

Fixes https://github.com/spring-projects/spring-integration/issues/3993

When `TcpOutboundGateway` is in an `async` mode and `CCF` is configured
not for `singleUse` an `Semaphore` around an obtained `TcpConnection` is involved.
If we fail on `TcpConnection.send()`, resources are not clean up, including the
mentioned `Semaphore`: in async mode this happens only when we receive a reply.

* Catch an exception on the `TcpConnection.send()` and perform `cleanUp()` in async mode.
* Add `cleanUp()` into a scheduled task from the `TcpOutboundGateway.AsyncReply`
when no reply arrives in time.
* Optimize `TcpOutboundGateway.AsyncReply` behavior to cancel no-reply scheduled task
when reply arrives into a `CompletableFuture`

**Cherry-pick to `5.5.x`**

* * Call `cleanUp()` from no response scheduled task
only if `future.completeExceptionally()` is `true`
2023-01-23 11:07:19 -05:00
abilan
05659301df Fix race condition in TcpOutGateTests.testAsync
The `ChannelInterceptor.postSend()` may be called when
`MessageChannel.receive()` has already done its job polling from
the queue where message appears in the `MessageChannel.doSend()`

* Use `ChannelInterceptor.preSend()` contract instead to obtaine info about the current thread
2023-01-18 09:14:13 -05:00
abilan
52d43ea8ed Upgrade dependencies; prepare for release
Fix XML configs for new `Mockito.mock()` factory method
2022-12-20 16:25:06 -05:00
abilan
bfb2ca217f Upgrade dependencies including Gradle 2022-11-18 15:47:56 -05:00
abilan
7864658d01 GH-3686: Apply SF editor config
Fixes https://github.com/spring-projects/spring-integration/issues/3686

* Add `src/idea` with respective editor config for IntelliJ IDEA.
Must be imported into an IDE
* Add `src/eclipse` with respective editor config for Eclipse/STS
* Reformat imports in source code according a new editor config
2022-11-14 10:55:21 -05:00
Artem Bilan
e0f137905a Fix compatibility with the latest SF
* Mostly changes are related to the `TaskScheduler` and `Trigger` APIs
* Migrate to `micrometer-tracing` dependency
* Rework `SocketTestUtils` to use a `InetAddress.getLocalHost()`
for more stability and performance on Windows
* Fix docs for new `PeriodicTrigger` API
2022-07-08 17:36:15 -04:00
Artem Vozhdayenko
64aa4d5348 GH-3666: Revise TcpNioConnectionTests
Fixes: https://github.com/spring-projects/spring-integration/issues/3666

Seems like Windows socket connect to the loopback address fails sometimes because of a bug in the implementation of OpenJDK. 

* Changing loopback addr with the actual IP addr seems to help.
* Fix `TcpNioConnectionTests.testMultiAccept()` and `testNoMultiAccept()` to rely on the ` InetAddress.getLocalHost()` 
instead of `localhost` string which has to be resolved to the address yet in the testing loop
2022-07-08 11:26:50 -04:00
Artem Vozhdayenko
53dd050c5b GH-3623: Deprecarte an IntegrationFlows
Fixes https://github.com/spring-projects/spring-integration/issues/3623

* `IntegrationFlow` refactoring
* Apply several code style improvements and good practices
* Code style: no empty lines for methods javadocs
* make deprecated implementation reuse actual one instead of the copy-paste approach
* add whats-new comments
* Fix whats-new page according to standards
2022-07-05 15:47:30 -04:00
Artem Bilan
2022c40d55 Fix compatibility with the latest SF
* Upgrade Spring dependencies to the latest SNAPSHOTs
* Fix tests to verify against stack traces: the message
of the `NestedRuntimeException`  does not include the nested exception information.
Related to https://github.com/spring-projects/spring-framework/issues/25162
* Fix `JdbcMessageStore` and `DefaultLockRepository` to rely on the `DataIntegrityViolationException`
instead of only its `DuplicateKeyException` extension.
This is the current behavior of the SQL errors translation
* Disable `WebFluxDslTests.testValidation()` - doesn't subscribe to the reply somehow...
* Refine `SimplePool.PoolSemaphore.reducePermits()`
2022-06-27 20:30:14 -04:00
Artem Bilan
04c7a87bd9 Use lookupHost = false by default for TCP & UDP (#3825)
* Use `lookupHost = false` by default for TCP & UDP

The applications these days more and more are deployed and managed in the containers
where DNS is not configured by default.
Having `lookupHost = true` by default leads to a bad experience when some delays happen
for reverse host lookups.

* Use `lookupHost = false` by default for both TCP & UDP to have a reliable behavior
independently of the environment.
The `hostName` is used for `connectionId` and as a header in the message -
semantically it doesn't matter for the application logic what value is present over there.

* * Fix language in docs

Co-authored-by: Gary Russell <grussell@vmware.com>

Co-authored-by: Gary Russell <grussell@vmware.com>
2022-06-22 13:23:03 -04:00
Artem Bilan
ecb9ac3fc3 Fix flaky TcpNioConnectionTests.testCleanup() 2022-03-10 14:04:30 -05:00
Artem Bilan
c661d7925e Remove SocketUtils usage
* Remove usage of non-stable `org.springframework.util.SocketUtils`
* Replace it with `0` for those tests where it is possible to select OS port
* Remove the mentioning of the `SocketUtils` from the `testing.adoc`
* Use `TransportConstants.DEFAULT_STOMP_PORT` for `StompServerIntegrationTests`.
We may disable this test in the future for CI if it is not going to be stable
* Introduce `Supplier<String> connectUrl` variants for `ZeroMqMessageHandler`
to let it defer connection evaluation until subscription to the socket `Mono`
in the `ZeroMqMessageHandler`.
* Move connection logic in the `ZeroMqMessageHandler` to `Lifecycle.start()`

Related to https://github.com/spring-projects/spring-framework/issues/28054

**Cherry-pick to `5.4.x`**
2022-02-16 09:10:08 -05:00
Gary Russell
055eadc61f Add TCP Test Diagnostics 2022-02-07 11:25:34 -05:00
Gary Russell
64d5b25a7f GH-3713: Fix Race In Test 2022-02-03 09:22:33 -05:00
Gary Russell
a493c9c966 GH-3713: TCP: Fix Intercepted Sender List
Resolves https://github.com/spring-projects/spring-integration/issues/3713

https://github.com/spring-projects/spring-integration/issues/3326 added support
for multiple `TcpSenders`. However, when connections are intercepted, the sender
list was not properly chained through the interceptors.

- override `registerSenders` and properly capture the real senders in the last
  interceptor and intermediate interceptors
- this ensures that `addNewConnection` is called on each interceptor
- when removing dead connections, use the connection sender list insted of the
  factory's raw sender list; detect if the connection is an interceptor and
  call its remove method instead.

**cherry-pick to 5.5.x**
2022-02-02 12:10:56 -05:00
Artem Bilan
a80b22638d Start 6.0 version
* Upgrade to Java 17, SF-6.0, Gradle 7.2
* Upgrade to Jakarta dependencies and respective namespaces
* Fix some tests for Java 17 compatibility
* Fix wrong Javadocs
* Add some missed Javadocs
* Fix more `jakarta` namespace
* Fix WS & XML modules to use Jakarta EE
* `--add-opens` in some modules for their reflection-based tests
* Disable Kafka tests which does not work on Windows; see Apache Kafka `3.0.1`
* Upgrade to JUnit `5.8.1`
* Migrate JMS tests to Artemis
* Remove RMI module as it was deprecated before
* Fix `pr-build-workflow.yml` for Java 17
* Fix JavaDocs warnings using `Xdoclint:syntax` per module, not in the top-level `api` task
* Move docs for version `6.0`
2022-01-18 14:38:50 -05:00
Gary Russell
b47727765d GH-3701: Fix Possible TCP Memory Leak
Resolves https://github.com/spring-projects/spring-integration/issues/3701

Ensure `TcpSender.removeDeadConnection` is always called, for example when
intercepted and closed via `factory.closeConnectionId` or when closed
connections are harvested from the `connections` map.

**Cherry-pick to 5.4.x, 5.3.x**
2022-01-03 12:35:29 -05:00
Artem Bilan
726b216f07 Disable TcpNioConnectionTests.testCleanup()
The timeout is too short for CI server and there is
a high chance fo race condition with such a short `nioHarvestInterval`

* Use `@DisabledIfEnvironmentVariable(named = "bamboo_buildKey")`
to exclude the test from CI server, but still run it locally or in GH Actions
2021-09-20 11:36:23 -04:00
Mário Dias
415296a00f GH-3509: Fix regression in TcpNetServerConnectionFactory
Related to https://github.com/spring-projects/spring-integration/issues/3509

* Fix intercepted connection cleanup tests
* Add missing logic to call `setSenders()` on wrapped connection

**Cherry-pick to `5.4.x`**
2021-05-26 11:28:10 -04:00
Gary Russell
7abbe30c81 GH-3526: Fix Infinite Loop in FailoverCConnFactory
Resolves https://github.com/spring-projects/spring-integration/issues/3526

`FailoverClientConnectionFactory`

The logic to detect we had iterated over all factories and including
the one from which the previous connection was established was incorrect,
causing an infite loop until one of the factory connections was successful.

Change the logic to detect we have reset the iterator and the current failure
is from the same factory as the one from which the previous connection was
established.

**cherry-pick to 5.4.x, 5.3.x**

* Add diagnostics.

* Fix race in test.

* More race fixes and diagnostics.

* Remove diagnostics.
2021-03-25 17:46:54 -04:00
Gary Russell
7ee3db9ca5 GH-3523: TcpConnectionEvent Fixes
Resolves https://github.com/spring-projects/spring-integration/issues/3523

- `TcpNetConnection` - publish open event on reader thread to avoid race with first read.
- Intercepted connections - Ensure that the event source is always the outermost interceptor.
- Also reduce delays during NIO client connect.

**cherry-pick to 5.4.x, 5.3.x**

5.3.x will require cherry picking GH-3509 commits.
2021-03-23 13:16:51 -04:00
Gary Russell
90a2f4bff1 GH-3509: Fix if test in previous commit
Caused interceptor to be skipped.

**cherry-pick to 5.4.x**

* Fix race in new tests

* Remove overloaded conn id in test interceptor.
2021-03-17 18:33:34 -04:00
Gary Russell
482673a159 GH-3509: Fix Memory Leak with Intercepted TCP Conn
Resolves https://github.com/spring-projects/spring-integration/issues/3509

When a connection was intercepted, the `TcpSender.add...` was called with the
interceptor, but the `removeDead...` was called with the actual connection,
causing a memory leak.

Always call the `TcpSender` with the outer-most interceptor.

# Conflicts:
#	spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java
#	spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpSendingMessageHandlerTests.java
2021-03-17 17:54:15 -04:00
Artem Bilan
321f03620f Revert "GH-3509 Register TcpSenders on wrapped connection"
This reverts commit 78a0ae8a04.
2021-03-17 17:45:28 -04:00
Mário Dias
78a0ae8a04 GH-3509 Register TcpSenders on wrapped connection
Fixes https://github.com/spring-projects/spring-integration/issues/3509

Dead connections are not being removed on `TcpSender` when using a `TcpConnectionInterceptor`.
May cause a memory leak

* Fix `TcpConnectionInterceptorSupport` to override `registerSenders()`
 and delegate to the `this.theConnection`
* Introduce vararg-based `setInterceptor()` into `TcpConnectionInterceptorFactoryChain`
* Remove redundant `//NOSONAR` and properly return an `Arrays.copyOf()` in the `getInterceptorFactories()`

**Cherry-pick to `5.4.x`**
2021-03-12 15:44:32 -05:00
Gary Russell
ebb8a65f73 CachingClientConnectionFactoryTests Fix Timeout
- second "Response" log causes a timeout, producing log noise in
later tests.
2021-03-12 13:49:32 -05:00
Gary Russell
2522c79cb3 Catch async MessageTimeoutException in IP test
- fix async exec thread names
2021-03-12 13:40:08 -05:00
Gary Russell
84ea4422a2 Name executors in IP tests
- aid in debugging failing tests
2021-03-12 13:20:21 -05:00
Gary Russell
3edfb962d2 Fix missing @DirtiesContext on TCP tests
- also add bean name (if available) to the gateway timeout exception message.
2021-03-12 11:43:17 -05:00
Artem Bilan
a1a4341655 Add logging to CachingClientConnFactoryTests 2021-03-10 11:52:00 -05:00
Artem Bilan
207de60c0a Add logging diagnostics to UdpChannelAdapterTests 2021-03-10 11:16:18 -05:00
Artem Bilan
eef31d4b34 Fix new Sonar smells; optimize some tests 2021-02-24 11:34:29 -05:00
Artem Bilan
f200849eda Move deps back to SNAPSHOTs
* Increase a `remoteTimeout` for `IpIntegrationTests.testCloseStream()`
2021-02-23 14:06:57 -05:00
Artem Bilan
3bf4fd687d More GH Actions goodies (#3441)
* More GH Actions goodies

* Add RabbitMQ, MongoDB & Redis services into GH actions
* Remove Travis

* * Add `distributionSha256Sum` into `gradle-wrapper.properties`
* Try `TERM: dumb` to see difference for Gradle output in GH action
* Add `-S` to see the reason of test failure

* * Try MQTT plugin for RabbitMQ image

* * Try `-i` for test failure in Gradle on Actions

* * Use `eclipse-mosquitto` image for MQTT on actions
* Fix `FtpServerOutboundTests` for the proper FTP file list
* Output file list for the failed session in the `RotatingServersTests`

* * Adjust SOUT in the test for Checkstyle

* * Make some change to `RotatingServersTests`.
Looks like the order for `@BeforeAll` methods is not determined
and we may start to interaction with FTP server which is not
started yet

* Fix SSL Handshake Test

- we already made this change for the NIO test, but the NET test is failing the same
  way - the cert failure switched to the server so the expected exception was not
  thrown on the client side. Due to JVM changes.

* * Fix SFTP tests for wrong host and auto-startup state
* Remove `-i` for Gradle in the GH Actions

* * Try `--no-parallel` for Gradle in the GH Actions

* * Try GH actions without Mosquitto

* * Try `cyrilix/rabbitmq-mqtt` for GH Actions

Co-authored-by: Gary Russell <grussell@pivotal.io>
2020-12-09 10:26:13 -05:00
Gary Russell
a79be71ed2 GH-3410: Add UDP SocketCustomizer
Resolves https://github.com/spring-projects/spring-integration/issues/3410

**cherry-pick to 5.3.x**

* Doc polishing.
2020-10-22 13:32:56 -04:00
Artem Bilan
20348ae38f Fix compatibility with the latest Reactor
* Fix missed long-running tests according components under testing changes
2020-10-08 12:41:35 -04:00
Artem Bilan
c7ff99a4e8 Use LogAccessor from SF
* Change main classes to use a `LogAccessor` API to simplify code flow
* Fix tests according `LogAccessor` property
* Fix some Sonar smells
2020-10-06 13:56:50 -04:00
Gary Russell
e919428680 GH-3326: TCP: Support Unsolicited Server Messages
Resolves https://github.com/spring-projects/spring-integration/issues/3326

- OB Gateway - send unsolicited messages and late replies to a channel
- Support multiple `TcpSender` s

* Add channel variant to spec; code polishing
2020-07-06 15:05:57 -04:00