Pablo created POOL-361:
--------------------------

             Summary: setTestOnCreate does not test on create
                 Key: POOL-361
                 URL: https://issues.apache.org/jira/browse/POOL-361
             Project: Commons Pool
          Issue Type: Bug
    Affects Versions: 2.6.1
            Reporter: Pablo


When setting testOnCreate to true, I would expect for the validation to take 
place when an object is created, but apparently it does not.

It only seems to be tested on borrow and when idle.

This has a negative impact, because when new objects get created, since they 
are not tested they appear in the pool as idle.

I'm trying to determine if the pool's health, but even though the pool reports 
idle objects they are botched instances.

Also related to this issue, objects aren't actually created upfront. They seem 
to be created on first borrow or when timeBetweenEvictionRunMillis elapses.

Environment (unimportant I think): 1.8.0_191, Ubuntu 18.04

Test case:

 
{code:java}
 public static void main(String[] args) throws Exception {
        PooledObjectFactory<String> factory = new 
BasePooledObjectFactory<String>() {
            public String create() throws Exception {
                String s = "Hello";
                System.out.println("Creating " + s);
                return s;
            }

            public void destroyObject(PooledObject<String> p) throws Exception {
                System.out.println("Destroying " + p.getObject());
            }

            public boolean validateObject(PooledObject<String> p) {
                System.out.println("Validating " + p.getObject());
                return super.validateObject(p);
            }

            public PooledObject<String> wrap(String obj) {
                return new Wrapper<String>(obj);
            }
        };
        GenericObjectPoolConfig<String> socketPoolConfig = new 
GenericObjectPoolConfig<String>();
        socketPoolConfig.setTestOnCreate(true);
        socketPoolConfig.setTestWhileIdle(false);
        GenericObjectPool<String> objectPool = new 
GenericObjectPool<String>(factory, socketPoolConfig);

        System.out.println("Pool created");
        String f1 = objectPool.borrowObject();
        System.out.println("Borrowed" + f1);
        objectPool.returnObject(f1);
        objectPool.close();
        System.out.println("Done");
    }{code}
 

 

Expected result:

{{        Pool created}}
{{        Creating Hello}}
{{        *Validating Hello*}}
{{        Allocating Hello}}
{{        BorrowedHello}}
{{        DeallocatingHello}}
{{        Destroying Hello}}
{{        Done}}

 

Actual result:

{{        Pool created}}
{{        Creating Hello}}
{{        Allocating Hello}}
{{        *Validating Hello*}}
{{        BorrowedHello}}
{{        DeallocatingHello}}
{{        Destroying Hello}}
{{        Done}}

 

 Or am I misunderstanding something?

 

 

 

 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to