// Path: examples/simple-client/src/main/java/info/developerblog/examples/thirft/simpleclient/SimpleClientApplication.java
// @EnableAsync
// @SpringBootApplication
// public class SimpleClientApplication {
// 
//     public static void main(String[] args) {
//         SpringApplication.run(SimpleClientApplication.class, args);
//     }
// 
//     @ThriftClient(serviceId = "greeting-service", path = "/api")
//     TGreetingService.Client client;
// }
// 
// Path: autoconfigure/src/main/java/info/developerblog/spring/thrift/client/pool/ThriftClientKey.java
// @Builder
// @EqualsAndHashCode
// public class ThriftClientKey {
//     private Class<? extends TServiceClient> clazz;
//     private String serviceName;
//     private String path;
// 
//     public String getServiceName() {
//         if (StringUtils.isEmpty(serviceName))
//             return WordUtils.uncapitalize(clazz.getEnclosingClass().getSimpleName());
//         return serviceName;
//     }
// 
//     public Class<? extends TServiceClient> getClazz() {
//         return clazz;
//     }
// 
//     public String getPath() {
//         return path;
//     }
// }
// 
// Path: autoconfigure/src/main/java/info/developerblog/spring/thrift/client/pool/ThriftClientPool.java
// public class ThriftClientPool extends GenericKeyedObjectPool<ThriftClientKey, TServiceClient> {
//     public ThriftClientPool(KeyedPooledObjectFactory<ThriftClientKey, TServiceClient> factory, GenericKeyedObjectPoolConfig config) {
//         super(factory, config);
//     }
// }


import example.TGreetingService;
import info.developerblog.examples.thirft.simpleclient.SimpleClientApplication;
import info.developerblog.spring.thrift.client.pool.ThriftClientKey;
import info.developerblog.spring.thrift.client.pool.ThriftClientPool;
import org.apache.commons.pool2.KeyedPooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.thrift.TServiceClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.PostConstruct;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
package info.developerblog.examples.thirft.poolfactory;




/**
 * @author Dmitry Zhikharev (jihor@ya.ru)
 *         Created on 13.09.2016
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = SimpleClientApplication.class, webEnvironment = RANDOM_PORT)
public class PoolFactoryTests {
    @Autowired
    private ThriftClientPool thriftClientsPool;

    private final ThriftClientKey thriftClientKey = ThriftClientKey.builder()
                                                                   .clazz(TGreetingService.Client.class)
                                                                   .serviceName("greeting-service")
                                                                   .path("/api")
                                                                   .build();

// Path: examples/simple-client/src/main/java/info/developerblog/examples/thirft/simpleclient/SimpleClientApplication.java
// @EnableAsync
// @SpringBootApplication
// public class SimpleClientApplication {
// 
//     public static void main(String[] args) {
//         SpringApplication.run(SimpleClientApplication.class, args);
//     }
// 
//     @ThriftClient(serviceId = "greeting-service", path = "/api")
//     TGreetingService.Client client;
// }
// 
// Path: autoconfigure/src/main/java/info/developerblog/spring/thrift/client/pool/ThriftClientKey.java
// @Builder
// @EqualsAndHashCode
// public class ThriftClientKey {
//     private Class<? extends TServiceClient> clazz;
//     private String serviceName;
//     private String path;
// 
//     public String getServiceName() {
//         if (StringUtils.isEmpty(serviceName))
//             return WordUtils.uncapitalize(clazz.getEnclosingClass().getSimpleName());
//         return serviceName;
//     }
// 
//     public Class<? extends TServiceClient> getClazz() {
//         return clazz;
//     }
// 
//     public String getPath() {
//         return path;
//     }
// }
// 
// Path: autoconfigure/src/main/java/info/developerblog/spring/thrift/client/pool/ThriftClientPool.java
// public class ThriftClientPool extends GenericKeyedObjectPool<ThriftClientKey, TServiceClient> {
//     public ThriftClientPool(KeyedPooledObjectFactory<ThriftClientKey, TServiceClient> factory, GenericKeyedObjectPoolConfig config) {
//         super(factory, config);
//     }
// }


// Path: examples/simple-client/src/test/java/info/developerblog/examples/thirft/poolfactory/PoolFactoryTests.java
import example.TGreetingService;
import info.developerblog.examples.thirft.simpleclient.SimpleClientApplication;
import info.developerblog.spring.thrift.client.pool.ThriftClientKey;
import info.developerblog.spring.thrift.client.pool.ThriftClientPool;
import org.apache.commons.pool2.KeyedPooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.thrift.TServiceClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.PostConstruct;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

package info.developerblog.examples.thirft.poolfactory;




/**
 * @author Dmitry Zhikharev (jihor@ya.ru)
 *         Created on 13.09.2016
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = SimpleClientApplication.class, webEnvironment = RANDOM_PORT)
public class PoolFactoryTests {
    @Autowired
    private ThriftClientPool thriftClientsPool;

    private final ThriftClientKey thriftClientKey = ThriftClientKey.builder()
                                                                   .clazz(TGreetingService.Client.class)
                                                                   .serviceName("greeting-service")
                                                                   .path("/api")
                                                                   .build();

    private KeyedPooledObjectFactory<ThriftClientKey, TServiceClient> factory;