Skip to content

Conversation

artembilan
Copy link
Member

Fixes #3554

The remoteDirectoryExpression was introduced into an
AbstractInboundFileSynchronizer to let end-user to evaluate a remote directory
on each poll (essentially on each synchronizeToLocalDirectory() call).
The fix for the https://jira.spring.io/browse/INT-4491 introduced a regression
when such an expression was evaluated only once when we call a setRemoteDirectory().
So, an original purpose of this option was lost and we don't get an actual
remote dir on each poll

  • Remove evaluateRemoteDirectory() method and its usage since it doesn't
    reflect expectation of the remote dir expression property
  • Reinstate the remoteDirectoryExpression evaluation in the
    synchronizeToLocalDirectory()
  • Propagate the result of that expression into further methods for copying
    files
  • Remove setting of the remoteDirectory variable into a global EvaluationContext
    of the AbstractInboundFileSynchronizer instance since it is not thread-safe
  • Instead create an EvaluationContext locally for each synchronizeToLocalDirectory()
    call and set the remoteDirectory variable into this scoped instances
  • Generate a local file name from the localFilenameGeneratorExpression
    against locally created EvaluationContext with the mentioned remoteDirectory variable
  • Cover the expected functionality with a unit-test

Cherry-pick to 5.4.x & 5.3.x

Fixes spring-projects#3554

The `remoteDirectoryExpression` was introduced into an
`AbstractInboundFileSynchronizer` to let end-user to evaluate a remote directory
on each poll (essentially on each `synchronizeToLocalDirectory()` call).
The fix for the https://jira.spring.io/browse/INT-4491 introduced a regression
when such an expression was evaluated only once when we call a `setRemoteDirectory()`.
So, an original purpose of this option was lost and we don't get an actual
remote dir on each poll

* Remove `evaluateRemoteDirectory()` method and its usage since it doesn't
reflect expectation of the remote dir expression property
* Reinstate the `remoteDirectoryExpression` evaluation in the
`synchronizeToLocalDirectory()`
* Propagate the result of that expression into further methods for copying
files
* Remove setting of the `remoteDirectory` variable into a global `EvaluationContext`
of the `AbstractInboundFileSynchronizer` instance since it is not thread-safe
* Instead create an `EvaluationContext` locally for each `synchronizeToLocalDirectory()`
call and set the `remoteDirectory` variable into this scoped instances
* Generate a local file name from the `localFilenameGeneratorExpression`
against locally created `EvaluationContext` with the mentioned `remoteDirectory` variable
* Cover the expected functionality with a unit-test

**Cherry-pick to `5.4.x` & `5.3.x`**
Queue<String> remoteDirs = new LinkedList<>();
remoteDirs.add("dir1");
remoteDirs.add("dir2");
sync.setRemoteDirectoryExpression(new FunctionExpression<Message<?>>(s -> remoteDirs.poll()));
Copy link
Contributor

Choose a reason for hiding this comment

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

The function input is not a Message<?> (it actually doesn't have a root object, but I guess you have to specify something).

My concern is that reading this test might lead the reader to assume we have a Message<?> here. FunctionExpression<Void> ?

(filePath, fileAttr) -> fileAttr.isRegularFile())
.forEach(System.out::println);*/

assertThat(localDir.list()).containsAll(remoteDirs);
Copy link
Contributor

Choose a reason for hiding this comment

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

remoteDirs is empty by now, so this will always pass.

@garyrussell garyrussell merged commit 0d7bbea into spring-projects:main Apr 27, 2021
garyrussell pushed a commit that referenced this pull request Apr 27, 2021
* GH-3554: Eval remote dir on each synchToLocal

Fixes #3554

The `remoteDirectoryExpression` was introduced into an
`AbstractInboundFileSynchronizer` to let end-user to evaluate a remote directory
on each poll (essentially on each `synchronizeToLocalDirectory()` call).
The fix for the https://jira.spring.io/browse/INT-4491 introduced a regression
when such an expression was evaluated only once when we call a `setRemoteDirectory()`.
So, an original purpose of this option was lost and we don't get an actual
remote dir on each poll

* Remove `evaluateRemoteDirectory()` method and its usage since it doesn't
reflect expectation of the remote dir expression property
* Reinstate the `remoteDirectoryExpression` evaluation in the
`synchronizeToLocalDirectory()`
* Propagate the result of that expression into further methods for copying
files
* Remove setting of the `remoteDirectory` variable into a global `EvaluationContext`
of the `AbstractInboundFileSynchronizer` instance since it is not thread-safe
* Instead create an `EvaluationContext` locally for each `synchronizeToLocalDirectory()`
call and set the `remoteDirectory` variable into this scoped instances
* Generate a local file name from the `localFilenameGeneratorExpression`
against locally created `EvaluationContext` with the mentioned `remoteDirectory` variable
* Cover the expected functionality with a unit-test

**Cherry-pick to `5.4.x` & `5.3.x`**

* * Fix `testRemoteDirectoryRefreshedOnEachSynchronization` according PR review
garyrussell pushed a commit that referenced this pull request Apr 27, 2021
* GH-3554: Eval remote dir on each synchToLocal

Fixes #3554

The `remoteDirectoryExpression` was introduced into an
`AbstractInboundFileSynchronizer` to let end-user to evaluate a remote directory
on each poll (essentially on each `synchronizeToLocalDirectory()` call).
The fix for the https://jira.spring.io/browse/INT-4491 introduced a regression
when such an expression was evaluated only once when we call a `setRemoteDirectory()`.
So, an original purpose of this option was lost and we don't get an actual
remote dir on each poll

* Remove `evaluateRemoteDirectory()` method and its usage since it doesn't
reflect expectation of the remote dir expression property
* Reinstate the `remoteDirectoryExpression` evaluation in the
`synchronizeToLocalDirectory()`
* Propagate the result of that expression into further methods for copying
files
* Remove setting of the `remoteDirectory` variable into a global `EvaluationContext`
of the `AbstractInboundFileSynchronizer` instance since it is not thread-safe
* Instead create an `EvaluationContext` locally for each `synchronizeToLocalDirectory()`
call and set the `remoteDirectory` variable into this scoped instances
* Generate a local file name from the `localFilenameGeneratorExpression`
against locally created `EvaluationContext` with the mentioned `remoteDirectory` variable
* Cover the expected functionality with a unit-test

**Cherry-pick to `5.4.x` & `5.3.x`**

* * Fix `testRemoteDirectoryRefreshedOnEachSynchronization` according PR review
@garyrussell
Copy link
Contributor

... and cherry-picked to 5.4.x, 5.3.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SftpInboundAdapter - RemoteDirectoryExpression is not evaluated on each poll
2 participants