package com.vladmihalcea.flexypool;

import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.sql.Connection;
import java.util.List;

import static org.junit.Assert.assertEquals;

/**
 * C3P0IntegrationTest - BasicDataSource Integration Test
 *
 * @author Vlad Mihalcea
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring/applicationContext-test.xml")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class C3P0IntegrationTest extends AbstractPoolAdapterIntegrationTest {

    @Override
    protected void verifyLeasedConnections(List<Connection> leasedConnections) {
        //ComboPooledDataSource#setMaxPoolSize calls resetPoolManager( false );
        //This will end up recreating teh data source, so the old connections are not managed anymore
        //Because we have 2 overflows (from 3 to 4 and from 4 to 5) we will end up with
        //12 connections = 3(initial max) + 4(initial max + 1 over flow) + 5(initial max + 2 over flow)
        assertEquals(12, leasedConnections.size());
    }
}

@@ -356,22 +356,20 @@
 t.assert
-Equals
+True
 ;%0D%0A%0D%0A/**
@@ -957,10 +957,10 @@
 ng t
-e
 h
+e
  dat
@@ -1211,24 +1211,26 @@
  flow)%0D%0A
+%0D%0A
         
 assertEq
@@ -1225,49 +1225,563 @@
     
-assertEquals(12, leasedConnections.size()
+//ComboPooledDataSource doesn't initializes eagerly, so we can get a timeout right from teh first call, because%0D%0A        //the first connection request might have to wait for the pool to be initialised%0D%0A        //This will end up recreating the data source from the first call.%0D%0A        //Because we have 2 overflows (from 3 to 4 and from 4 to 5) we will end up with%0D%0A        //9 connections = 0(initial call) + 4(initial max + 1 over flow) + 5(initial max + 2 over flow)%0D%0A        assertTrue(leasedConnections.size() == 12 %7C%7C leasedConnections.size() == 9
 );%0D%0A

Fix C3P0 test that fails spuriously #15