// Path: src/main/java/com/flipkart/ranger/ServiceFinderBuilders.java
// public class ServiceFinderBuilders {
//     
//     private ServiceFinderBuilders() {
//         throw new InstantiationError("Must not instantiate this class");
//     }
//     
//     public static <T> SimpleShardedServiceFinderBuilder<T> shardedFinderBuilder() {
//         return new SimpleShardedServiceFinderBuilder<>();
//     }
// 
//     public static UnshardedFinderBuilder unshardedFinderBuilder() {
//         return new UnshardedFinderBuilder();
//     }
// }
// 
// Path: src/main/java/com/flipkart/ranger/finder/RoundRobinServiceNodeSelector.java
// public class RoundRobinServiceNodeSelector<T> implements ServiceNodeSelector<T> {
//     private static final ThreadLocal<Integer> index = ThreadLocal.withInitial(() -> 0);
// 
//     @Override
//     public ServiceNode<T> select(List<ServiceNode<T>> serviceNodes) {
//         index.set((index.get() + 1) % serviceNodes.size());
//         return serviceNodes.get(index.get());
//     }
// }


import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.flipkart.ranger.ServiceFinderBuilders;
import com.flipkart.ranger.finder.RoundRobinServiceNodeSelector;
import com.flipkart.ranger.finder.sharded.SimpleShardedServiceFinder;
import org.apache.curator.test.TestingCluster;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;

    @Test
    public void testBasicDiscovery() throws Exception {
        SimpleShardedServiceFinder<TestShardInfo> serviceFinder = ServiceFinderBuilders.<TestShardInfo>shardedFinderBuilder()
                .withConnectionString(testingCluster.getConnectString())
                .withNamespace("test")
                .withServiceName("test-service")
                .withDeserializer(new Deserializer<TestShardInfo>() {
                    @Override
                    public ServiceNode<TestShardInfo> deserialize(byte[] data) {
                        try {
                            return objectMapper.readValue(data,
                                    new TypeReference<ServiceNode<TestShardInfo>>() {
                                    });
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        return null;
                    }
                })
                .build();
        serviceFinder.start();
        ServiceNode<TestShardInfo> node = serviceFinder.get(new TestShardInfo(1));
        Assert.assertNull(node);
        serviceFinder.stop();

    }

    @Test
    public void testBasicDiscoveryRR() throws Exception {
// Path: src/main/java/com/flipkart/ranger/ServiceFinderBuilders.java
// public class ServiceFinderBuilders {
//     
//     private ServiceFinderBuilders() {
//         throw new InstantiationError("Must not instantiate this class");
//     }
//     
//     public static <T> SimpleShardedServiceFinderBuilder<T> shardedFinderBuilder() {
//         return new SimpleShardedServiceFinderBuilder<>();
//     }
// 
//     public static UnshardedFinderBuilder unshardedFinderBuilder() {
//         return new UnshardedFinderBuilder();
//     }
// }
// 
// Path: src/main/java/com/flipkart/ranger/finder/RoundRobinServiceNodeSelector.java
// public class RoundRobinServiceNodeSelector<T> implements ServiceNodeSelector<T> {
//     private static final ThreadLocal<Integer> index = ThreadLocal.withInitial(() -> 0);
// 
//     @Override
//     public ServiceNode<T> select(List<ServiceNode<T>> serviceNodes) {
//         index.set((index.get() + 1) % serviceNodes.size());
//         return serviceNodes.get(index.get());
//     }
// }


// Path: src/test/java/com/flipkart/ranger/model/ServiceNoProviderTest.java
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.flipkart.ranger.ServiceFinderBuilders;
import com.flipkart.ranger.finder.RoundRobinServiceNodeSelector;
import com.flipkart.ranger.finder.sharded.SimpleShardedServiceFinder;
import org.apache.curator.test.TestingCluster;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;


    @Test
    public void testBasicDiscovery() throws Exception {
        SimpleShardedServiceFinder<TestShardInfo> serviceFinder = ServiceFinderBuilders.<TestShardInfo>shardedFinderBuilder()
                .withConnectionString(testingCluster.getConnectString())
                .withNamespace("test")
                .withServiceName("test-service")
                .withDeserializer(new Deserializer<TestShardInfo>() {
                    @Override
                    public ServiceNode<TestShardInfo> deserialize(byte[] data) {
                        try {
                            return objectMapper.readValue(data,
                                    new TypeReference<ServiceNode<TestShardInfo>>() {
                                    });
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        return null;
                    }
                })
                .build();
        serviceFinder.start();
        ServiceNode<TestShardInfo> node = serviceFinder.get(new TestShardInfo(1));
        Assert.assertNull(node);
        serviceFinder.stop();

    }

    @Test
    public void testBasicDiscoveryRR() throws Exception {
        SimpleShardedServiceFinder<TestShardInfo> serviceFinder = ServiceFinderBuilders.<TestShardInfo>shardedFinderBuilder()