Example usage for org.apache.commons.pool2.impl SoftReferenceObjectPool borrowObject

List of usage examples for org.apache.commons.pool2.impl SoftReferenceObjectPool borrowObject

Introduction

In this page you can find the example usage for org.apache.commons.pool2.impl SoftReferenceObjectPool borrowObject.

Prototype

@SuppressWarnings("null") 
@Override
public synchronized T borrowObject() throws Exception 

Source Link

Document

Borrow an object from the pool.

Usage

From source file:com.lambdaworks.redis.support.ConnectionPoolSupportTest.java

@Test
public void softRefPoolShouldWorkWithWrappedConnections() throws Exception {

    SoftReferenceObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport
            .createSoftReferenceObjectPool(() -> client.connect());

    StatefulRedisConnection<String, String> connection = pool.borrowObject();
    RedisCommands<String, String> sync = connection.sync();
    sync.ping();//from   w ww .  ja v  a 2s.  co  m
    sync.close();

    pool.close();
}

From source file:com.lambdaworks.redis.support.ConnectionPoolSupportTest.java

@Test
public void softReferencePoolShouldWorkWithPlainConnections() throws Exception {

    SoftReferenceObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport
            .createSoftReferenceObjectPool(() -> client.connect(), false);

    borrowAndReturn(pool);//from  w w  w  . ja  v  a2  s  .  com

    StatefulRedisConnection<String, String> connection = pool.borrowObject();
    assertThat(Proxy.isProxyClass(connection.getClass())).isFalse();
    pool.returnObject(connection);

    pool.close();
}

From source file:io.lettuce.core.support.ConnectionPoolSupportTest.java

@Test
public void softRefPoolShouldWorkWithWrappedConnections() throws Exception {

    SoftReferenceObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport
            .createSoftReferenceObjectPool(() -> client.connect());

    StatefulRedisConnection<String, String> connection = pool.borrowObject();

    assertThat(channels).hasSize(1);/* w  ww .jav a 2 s. c  o m*/

    RedisCommands<String, String> sync = connection.sync();
    sync.ping();

    connection.close();
    pool.close();

    Wait.untilTrue(channels::isEmpty).waitOrTimeout();

    assertThat(channels).isEmpty();
}

From source file:com.lambdaworks.redis.support.ConnectionPoolSupportTest.java

@Test
public void tryWithResourcesReturnsSoftRefConnectionToPool() throws Exception {

    SoftReferenceObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport
            .createSoftReferenceObjectPool(() -> client.connect());

    StatefulRedisConnection<String, String> usedConnection = null;
    try (StatefulRedisConnection<String, String> connection = pool.borrowObject()) {

        RedisCommands<String, String> sync = connection.sync();
        sync.ping();// ww  w . j  a  va 2 s  . c o m

        usedConnection = connection;
    }

    try {
        usedConnection.isMulti();
        fail("Missing RedisException");
    } catch (RedisException e) {
        assertThat(e).hasMessageContaining("deallocated");
    }

    pool.close();
}

From source file:io.lettuce.core.support.ConnectionPoolSupportTest.java

@Test
public void softReferencePoolShouldWorkWithPlainConnections() throws Exception {

    SoftReferenceObjectPool<StatefulRedisConnection<String, String>> pool = ConnectionPoolSupport
            .createSoftReferenceObjectPool(() -> client.connect(), false);

    borrowAndReturn(pool);//w  ww . ja v a 2s  .c o  m

    StatefulRedisConnection<String, String> connection = pool.borrowObject();
    assertThat(Proxy.isProxyClass(connection.getClass())).isFalse();
    pool.returnObject(connection);

    connection.close();
    pool.close();
}