Uploaded image for project: 'Commons Pool'
  1. Commons Pool
  2. POOL-361

setTestOnCreate does not test on create

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.6.1
    • 2.7.0
    • None

    Description

      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:

       

       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");
          }

       

       

      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?

       

       

       

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              pakman Pablo
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m