GH-8745: Add RFT.shouldMarkSessionAsDirty() (#8759)

* GH-8745: Add RFT.shouldMarkSessionAsDirty()

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

Not all errors caught in the `RemoteFileTemplate.execute()`
are fatal to mark session as dirty and physically close the target session
in the cache

* Introduce a `RemoteFileTemplate.shouldMarkSessionAsDirty()`
to consult with an exception if it is really a fatal error to close
the session in the end.
* Override `shouldMarkSessionAsDirty()` in the `RemoteFileTemplate`
implementations to check statuses of respective protocol errors

**Cherry-pick to `6.1.x` & `6.0.x`**

* * Fix tests for pool interaction

* * Fix language in Javadocs
* Add more `not dirty` statuses to `SftpRemoteFileTemplate` & `SmbRemoteFileTemplate`
This commit is contained in:
Artem Bilan
2023-10-11 10:52:48 -04:00
committed by GitHub
parent b8228531d5
commit 44433ed8a1
7 changed files with 239 additions and 44 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,9 +21,14 @@ import java.io.IOException;
import jcifs.smb.SmbFile;
import org.junit.jupiter.api.Test;
import org.springframework.integration.file.remote.session.CachingSessionFactory;
import org.springframework.integration.file.remote.session.Session;
import org.springframework.integration.smb.SmbTestSupport;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.MessagingException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
*
@@ -85,4 +90,24 @@ public class SmbSessionTests extends SmbTestSupport {
}
}
@Test
public void sessionIsNotDirtyOnNoSuchFileError() {
CachingSessionFactory<SmbFile> cachingSessionFactory = new CachingSessionFactory<>(smbSessionFactory);
Session<SmbFile> session = cachingSessionFactory.getSession();
session.close();
SmbRemoteFileTemplate template = new SmbRemoteFileTemplate(cachingSessionFactory);
assertThatExceptionOfType(MessagingException.class)
.isThrownBy(() -> template.rename("No_such_file1", "No_such_file2"))
.withRootCauseInstanceOf(IOException.class)
.withStackTraceContaining("The system cannot find the file specified");
Session<SmbFile> newSession = cachingSessionFactory.getSession();
assertThat(TestUtils.getPropertyValue(newSession, "targetSession"))
.isSameAs(TestUtils.getPropertyValue(session, "targetSession"));
newSession.close();
}
}