You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Phil Steitz (JIRA)" <ji...@apache.org> on 2019/07/21 23:32:00 UTC

[jira] [Comment Edited] (POOL-361) setTestOnCreate does not test on create

    [ https://issues.apache.org/jira/browse/POOL-361?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16889836#comment-16889836 ] 

Phil Steitz edited comment on POOL-361 at 7/21/19 11:31 PM:
------------------------------------------------------------

The analysis above is correct.  Newly created instances are not validated until borrowObject is called. [https://github.com/apache/commons-pool/pull/23] is an attempt at fixing this.


was (Author: psteitz):
The analysis above is correct.  Newly created instances are not validated until borrowObject is called.  This [[PR]https://github.com/apache/commonspool/pull/23] is an attempt at fixing this.  

> 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
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> 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.14#76016)