// Path: examples/simple-client/src/test/java/info/developerblog/examples/thirft/simpleclient/configuration/CountingAspect.java
// @Aspect
// public class CountingAspect {
//     public AtomicInteger counter = new AtomicInteger(0);
// 
//     @Pointcut("execution(* org.springframework.cloud.client.loadbalancer.LoadBalancerClient.choose(..))")
//     private void loadBalancerServerChoice() {}
// 
//     @Before("loadBalancerServerChoice()")
//     public void before(){
//         counter.incrementAndGet();
//     }
// }
// 
// Path: examples/simple-client/src/test/java/info/developerblog/examples/thirft/simpleclient/configuration/TestAspectConfiguration.java
// @TestConfiguration
// @EnableAspectJAutoProxy
// public class TestAspectConfiguration {
// 
//     @Bean
//     public CountingAspect countingAspect(){
//         return new CountingAspect();
//     }
// 
// }
// 
// Path: examples/simple-client/src/main/java/info/developerblog/examples/thirft/simpleclient/TGreetingServiceController.java
// public static final String TIMEOUTEMULATOR = "timeoutemulator";


import info.developerblog.examples.thirft.simpleclient.configuration.CountingAspect;
import info.developerblog.examples.thirft.simpleclient.configuration.TestAspectConfiguration;
import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
import org.apache.thrift.transport.TTransportException;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.context.WebApplicationContext;
import static info.developerblog.examples.thirft.simpleclient.TGreetingServiceController.TIMEOUTEMULATOR;
import static org.junit.Assert.assertEquals;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
    GenericKeyedObjectPool clientPool;

    @Autowired
    CountingAspect countingAspect;

    @Value("${thrift.client.max.threads}")
    private int maxThreads;

    @Value("${thrift.client.max.idle.threads:8}")
    private int maxIdleThreads;

    @Value("${thrift.client.max.total.threads:8}")
    private int maxTotalThreads;

    @Test
    public void testSimpleCall() throws Exception {
        assertEquals("Hello John Smith", greetingService.getGreeting("Smith", "John"));
    }

    @Test(expected = TTransportException.class)
    public void testCallWithTimeout() throws Exception {
        greetingService.getGreetingWithTimeout(TIMEOUTEMULATOR, "John");
    }

    @Test
    public void testMappedClient() throws Exception {
        greetingService.getGreetingForKey("key1", "Doe", "John");
    }

    @Test(expected = TTransportException.class)
// Path: examples/simple-client/src/test/java/info/developerblog/examples/thirft/simpleclient/configuration/CountingAspect.java
// @Aspect
// public class CountingAspect {
//     public AtomicInteger counter = new AtomicInteger(0);
// 
//     @Pointcut("execution(* org.springframework.cloud.client.loadbalancer.LoadBalancerClient.choose(..))")
//     private void loadBalancerServerChoice() {}
// 
//     @Before("loadBalancerServerChoice()")
//     public void before(){
//         counter.incrementAndGet();
//     }
// }
// 
// Path: examples/simple-client/src/test/java/info/developerblog/examples/thirft/simpleclient/configuration/TestAspectConfiguration.java
// @TestConfiguration
// @EnableAspectJAutoProxy
// public class TestAspectConfiguration {
// 
//     @Bean
//     public CountingAspect countingAspect(){
//         return new CountingAspect();
//     }
// 
// }
// 
// Path: examples/simple-client/src/main/java/info/developerblog/examples/thirft/simpleclient/TGreetingServiceController.java
// public static final String TIMEOUTEMULATOR = "timeoutemulator";


// Path: examples/simple-client/src/test/java/info/developerblog/examples/thirft/simpleclient/TGreetingServiceHandlerTests.java
import info.developerblog.examples.thirft.simpleclient.configuration.CountingAspect;
import info.developerblog.examples.thirft.simpleclient.configuration.TestAspectConfiguration;
import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
import org.apache.thrift.transport.TTransportException;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.context.WebApplicationContext;
import static info.developerblog.examples.thirft.simpleclient.TGreetingServiceController.TIMEOUTEMULATOR;
import static org.junit.Assert.assertEquals;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

    GenericKeyedObjectPool clientPool;

    @Autowired
    CountingAspect countingAspect;

    @Value("${thrift.client.max.threads}")
    private int maxThreads;

    @Value("${thrift.client.max.idle.threads:8}")
    private int maxIdleThreads;

    @Value("${thrift.client.max.total.threads:8}")
    private int maxTotalThreads;

    @Test
    public void testSimpleCall() throws Exception {
        assertEquals("Hello John Smith", greetingService.getGreeting("Smith", "John"));
    }

    @Test(expected = TTransportException.class)
    public void testCallWithTimeout() throws Exception {
        greetingService.getGreetingWithTimeout(TIMEOUTEMULATOR, "John");
    }

    @Test
    public void testMappedClient() throws Exception {
        greetingService.getGreetingForKey("key1", "Doe", "John");
    }

    @Test(expected = TTransportException.class)
    public void testMappedClientWithTimeout() throws Exception {