Search in sources :

Example 21 with Session

use of org.springframework.integration.file.remote.session.Session 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 22 with Session

use of org.springframework.integration.file.remote.session.Session 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 23 with Session

use of org.springframework.integration.file.remote.session.Session 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

Session (org.springframework.integration.file.remote.session.Session)23 Test (org.junit.Test)22 SessionFactory (org.springframework.integration.file.remote.session.SessionFactory)16 List (java.util.List)13 GenericMessage (org.springframework.messaging.support.GenericMessage)13 ArrayList (java.util.ArrayList)12 MessageBuilder (org.springframework.integration.support.MessageBuilder)12 Matchers.containsString (org.hamcrest.Matchers.containsString)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 CachingSessionFactory (org.springframework.integration.file.remote.session.CachingSessionFactory)5 ChannelSftp (com.jcraft.jsch.ChannelSftp)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)4 LsEntry (com.jcraft.jsch.ChannelSftp.LsEntry)3 JSch (com.jcraft.jsch.JSch)3 File (java.io.File)3 IOException (java.io.IOException)2 DefaultSftpSessionFactory (org.springframework.integration.sftp.session.DefaultSftpSessionFactory)2 SftpSession (org.springframework.integration.sftp.session.SftpSession)2 MessagingException (org.springframework.messaging.MessagingException)2