Search in sources :

Example 31 with SessionFactory

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

SessionFactory (org.springframework.integration.file.remote.session.SessionFactory)31 Test (org.junit.Test)30 MessageBuilder (org.springframework.integration.support.MessageBuilder)19 GenericMessage (org.springframework.messaging.support.GenericMessage)19 Matchers.containsString (org.hamcrest.Matchers.containsString)17 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)17 Session (org.springframework.integration.file.remote.session.Session)15 ArrayList (java.util.ArrayList)14 List (java.util.List)14 File (java.io.File)9 FileOutputStream (java.io.FileOutputStream)9 IOException (java.io.IOException)9 OutputStream (java.io.OutputStream)8 CachingSessionFactory (org.springframework.integration.file.remote.session.CachingSessionFactory)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 RunWith (org.junit.runner.RunWith)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2