Search in sources :

Example 6 with CachingSessionFactory

use of org.springframework.integration.file.remote.session.CachingSessionFactory in project spring-integration by spring-projects.

the class FtpTestSupport method sessionFactory.

public static SessionFactory<FTPFile> sessionFactory() {
    DefaultFtpSessionFactory sf = new DefaultFtpSessionFactory();
    sf.setHost("localhost");
    sf.setPort(port);
    sf.setUsername("foo");
    sf.setPassword("foo");
    sf.setClientMode(FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE);
    return new CachingSessionFactory<FTPFile>(sf);
}
Also used : CachingSessionFactory(org.springframework.integration.file.remote.session.CachingSessionFactory) DefaultFtpSessionFactory(org.springframework.integration.ftp.session.DefaultFtpSessionFactory)

Example 7 with CachingSessionFactory

use of org.springframework.integration.file.remote.session.CachingSessionFactory in project spring-integration by spring-projects.

the class SessionFactoryTests method testSessionWaitExpire.

// timeout expire
@Test(expected = MessagingException.class)
public void testSessionWaitExpire() throws Exception {
    SessionFactory sessionFactory = Mockito.mock(SessionFactory.class);
    Session session = Mockito.mock(Session.class);
    Mockito.when(sessionFactory.getSession()).thenReturn(session);
    CachingSessionFactory cachingFactory = new CachingSessionFactory(sessionFactory, 2);
    cachingFactory.setSessionWaitTimeout(3000);
    cachingFactory.getSession();
    cachingFactory.getSession();
    cachingFactory.getSession();
}
Also used : SessionFactory(org.springframework.integration.file.remote.session.SessionFactory) CachingSessionFactory(org.springframework.integration.file.remote.session.CachingSessionFactory) CachingSessionFactory(org.springframework.integration.file.remote.session.CachingSessionFactory) Session(org.springframework.integration.file.remote.session.Session) Test(org.junit.Test)

Example 8 with CachingSessionFactory

use of org.springframework.integration.file.remote.session.CachingSessionFactory in project spring-integration by spring-projects.

the class SessionFactoryTests method testStaleConnection.

@Test
public void testStaleConnection() throws Exception {
    SessionFactory sessionFactory = Mockito.mock(SessionFactory.class);
    Session sessionA = Mockito.mock(Session.class);
    Session sessionB = Mockito.mock(Session.class);
    Mockito.when(sessionA.isOpen()).thenReturn(true);
    Mockito.when(sessionB.isOpen()).thenReturn(false);
    Mockito.when(sessionFactory.getSession()).thenReturn(sessionA);
    Mockito.when(sessionFactory.getSession()).thenReturn(sessionB);
    CachingSessionFactory cachingFactory = new CachingSessionFactory(sessionFactory, 2);
    Session firstSession = cachingFactory.getSession();
    Session secondSession = cachingFactory.getSession();
    secondSession.close();
    Session nonStaleSession = cachingFactory.getSession();
    assertEquals(TestUtils.getPropertyValue(firstSession, "targetSession"), TestUtils.getPropertyValue(nonStaleSession, "targetSession"));
}
Also used : SessionFactory(org.springframework.integration.file.remote.session.SessionFactory) CachingSessionFactory(org.springframework.integration.file.remote.session.CachingSessionFactory) CachingSessionFactory(org.springframework.integration.file.remote.session.CachingSessionFactory) Session(org.springframework.integration.file.remote.session.Session) Test(org.junit.Test)

Example 9 with CachingSessionFactory

use of org.springframework.integration.file.remote.session.CachingSessionFactory in project spring-integration by spring-projects.

the class SessionFactoryTests method testSameSessionFromThePool.

@Test
public void testSameSessionFromThePool() throws Exception {
    SessionFactory sessionFactory = Mockito.mock(SessionFactory.class);
    Session session = Mockito.mock(Session.class);
    Mockito.when(sessionFactory.getSession()).thenReturn(session);
    CachingSessionFactory cachingFactory = new CachingSessionFactory(sessionFactory, 2);
    Session s1 = cachingFactory.getSession();
    s1.close();
    Session s2 = cachingFactory.getSession();
    s2.close();
    assertEquals(TestUtils.getPropertyValue(s1, "targetSession"), TestUtils.getPropertyValue(s2, "targetSession"));
    Mockito.verify(sessionFactory, Mockito.times(2)).getSession();
}
Also used : SessionFactory(org.springframework.integration.file.remote.session.SessionFactory) CachingSessionFactory(org.springframework.integration.file.remote.session.CachingSessionFactory) CachingSessionFactory(org.springframework.integration.file.remote.session.CachingSessionFactory) Session(org.springframework.integration.file.remote.session.Session) Test(org.junit.Test)

Aggregations

CachingSessionFactory (org.springframework.integration.file.remote.session.CachingSessionFactory)9 Test (org.junit.Test)6 Session (org.springframework.integration.file.remote.session.Session)5 SessionFactory (org.springframework.integration.file.remote.session.SessionFactory)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DefaultSftpSessionFactory (org.springframework.integration.sftp.session.DefaultSftpSessionFactory)2 MessagingException (org.springframework.messaging.MessagingException)2 ChannelSftp (com.jcraft.jsch.ChannelSftp)1 LsEntry (com.jcraft.jsch.ChannelSftp.LsEntry)1 JSch (com.jcraft.jsch.JSch)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 Random (java.util.Random)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Ignore (org.junit.Ignore)1 BeansException (org.springframework.beans.BeansException)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 SimplePatternFileListFilter (org.springframework.integration.file.filters.SimplePatternFileListFilter)1