// Path: src/test/java/jresp/JRESPTest.java
// public class JRESPTest {
//     protected static final Responses NULL_RESPONSES = response -> {
//         // nothing
//     };
// 
//     protected Client client;
//     protected CountDownLatch latch;
// 
//     protected void setup() throws Exception {
//         client = new Client("localhost", 6379);
//         client.setDb(2);
//     }
// 
//     protected void teardown() throws Exception {
//         client.shutdown();
//     }
// 
//     protected static Ary command(String name, RespType... options) {
//         List<RespType> elements = new ArrayList<>(options.length + 1);
//         elements.add(new BulkStr(name));
//         elements.addAll(Arrays.asList(options));
// 
//         return new Ary(elements);
//     }
// 
//     protected static RespType ping() {
//         return command("PING");
//     }
// 
//     protected static RespType flushDB() {
//         return command("FLUSHDB");
//     }
// 
//     protected static RespType get(String key) {
//         return command("GET", new BulkStr(key));
//     }
// 
//     protected static RespType set(String key, String value) {
//         return command("SET", new BulkStr(key), new BulkStr(value));
//     }
// 
//     protected static RespType sadd(String key, String value) {
//         return command("SADD", new BulkStr(key), new BulkStr(value));
//     }
// 
//     protected static RespType smembers(String key) {
//         return command("SMEMBERS", new BulkStr(key));
//     }
// 
//     protected static RespType hgetall(String key) {
//         return command("HGETALL", new BulkStr(key));
//     }
// 
//     protected static RespType blpop(String key, int timeout) {
//         return command("BLPOP", new BulkStr(key), new BulkStr(Integer.toString(timeout)));
//     }
// 
//     protected static RespType rpush(String key, String value) {
//         return command("RPUSH", new BulkStr(key), new BulkStr(value));
//     }
// 
//     protected static RespType publish(String channel, String payload) {
//         return command("PUBLISH", new BulkStr(channel), new BulkStr(payload));
//     }
// 
//     protected void await() {
//         try {
//             boolean success = latch.await(5, TimeUnit.SECONDS);
//             if (!success) {
//                 throw new AssertionError("Timed out waiting");
//             }
//         } catch (InterruptedException e) {
//             throw new IllegalStateException(e);
//         }
//     }
// }
// 
// Path: src/main/java/jresp/protocol/RespType.java
// public interface RespType {
//     /**
//      * Write the RESP form to the ByteBuf
//      */
//     void writeBytes(Deque<ByteBuffer> out);
// 
//     /**
//      * Return the high-level Java equivalent.
//      */
//     Object unwrap();
// }


import jresp.JRESPTest;
import jresp.protocol.RespType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.stream.IntStream;
import static org.junit.Assert.*;
    @After
    public void teardown() throws Exception {
        super.teardown();
    }

    @Test
    public void testGetSet() throws Exception {
        latch = new CountDownLatch(1);
        String[] value = new String[1];

        sharedConnection.write(set("KEY-1", "VALUE-1"), NULL_RESPONSES);
        sharedConnection.write(get("KEY-1"), resp -> {
            value[0] = (String)resp.unwrap();
            latch.countDown();
        });

        await();

        assertEquals("VALUE-1", value[0]);
    }

    @Test
    public void thousandPingTest() throws Exception {
        int numPings = 1000;
        int runs = 1;

        for (int n = 0; n < runs; n++) {
            long start = System.nanoTime();
            latch = new CountDownLatch(numPings);

// Path: src/test/java/jresp/JRESPTest.java
// public class JRESPTest {
//     protected static final Responses NULL_RESPONSES = response -> {
//         // nothing
//     };
// 
//     protected Client client;
//     protected CountDownLatch latch;
// 
//     protected void setup() throws Exception {
//         client = new Client("localhost", 6379);
//         client.setDb(2);
//     }
// 
//     protected void teardown() throws Exception {
//         client.shutdown();
//     }
// 
//     protected static Ary command(String name, RespType... options) {
//         List<RespType> elements = new ArrayList<>(options.length + 1);
//         elements.add(new BulkStr(name));
//         elements.addAll(Arrays.asList(options));
// 
//         return new Ary(elements);
//     }
// 
//     protected static RespType ping() {
//         return command("PING");
//     }
// 
//     protected static RespType flushDB() {
//         return command("FLUSHDB");
//     }
// 
//     protected static RespType get(String key) {
//         return command("GET", new BulkStr(key));
//     }
// 
//     protected static RespType set(String key, String value) {
//         return command("SET", new BulkStr(key), new BulkStr(value));
//     }
// 
//     protected static RespType sadd(String key, String value) {
//         return command("SADD", new BulkStr(key), new BulkStr(value));
//     }
// 
//     protected static RespType smembers(String key) {
//         return command("SMEMBERS", new BulkStr(key));
//     }
// 
//     protected static RespType hgetall(String key) {
//         return command("HGETALL", new BulkStr(key));
//     }
// 
//     protected static RespType blpop(String key, int timeout) {
//         return command("BLPOP", new BulkStr(key), new BulkStr(Integer.toString(timeout)));
//     }
// 
//     protected static RespType rpush(String key, String value) {
//         return command("RPUSH", new BulkStr(key), new BulkStr(value));
//     }
// 
//     protected static RespType publish(String channel, String payload) {
//         return command("PUBLISH", new BulkStr(channel), new BulkStr(payload));
//     }
// 
//     protected void await() {
//         try {
//             boolean success = latch.await(5, TimeUnit.SECONDS);
//             if (!success) {
//                 throw new AssertionError("Timed out waiting");
//             }
//         } catch (InterruptedException e) {
//             throw new IllegalStateException(e);
//         }
//     }
// }
// 
// Path: src/main/java/jresp/protocol/RespType.java
// public interface RespType {
//     /**
//      * Write the RESP form to the ByteBuf
//      */
//     void writeBytes(Deque<ByteBuffer> out);
// 
//     /**
//      * Return the high-level Java equivalent.
//      */
//     Object unwrap();
// }


// Path: src/test/java/jresp/pool/SharedConnectionTest.java
import jresp.JRESPTest;
import jresp.protocol.RespType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.stream.IntStream;
import static org.junit.Assert.*;

    @After
    public void teardown() throws Exception {
        super.teardown();
    }

    @Test
    public void testGetSet() throws Exception {
        latch = new CountDownLatch(1);
        String[] value = new String[1];

        sharedConnection.write(set("KEY-1", "VALUE-1"), NULL_RESPONSES);
        sharedConnection.write(get("KEY-1"), resp -> {
            value[0] = (String)resp.unwrap();
            latch.countDown();
        });

        await();

        assertEquals("VALUE-1", value[0]);
    }

    @Test
    public void thousandPingTest() throws Exception {
        int numPings = 1000;
        int runs = 1;

        for (int n = 0; n < runs; n++) {
            long start = System.nanoTime();
            latch = new CountDownLatch(numPings);

            List<RespType> results = new ArrayList<>(numPings);