package com.netflix.dyno.jedis.utils;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class MockedResponseHandler extends SimpleChannelInboundHandler<String> {

    private static volatile int requestsReceived = 0;

    private final String response;

    public MockedResponseHandler(final String response) {
        this.response = response;
    }

    @Override
    protected void channelRead0(final ChannelHandlerContext ctx, final String msg) throws Exception {

        if (requestsReceived == 0) {
            ctx.writeAndFlush("$" + response.length() + "\r\n");
            ctx.writeAndFlush(response + "\r\n");
        } else {
            ctx.writeAndFlush("+OK\r\n");
        }

        requestsReceived++;
    }
}

@@ -219,63 +219,8 @@
  %7B%0A%0A
-    private static volatile int requestsReceived = 0;%0A%0A
     
@@ -250,16 +250,16 @@
 sponse;%0A
+
 %0A    pub
@@ -466,25 +466,24 @@
 ption %7B%0A
-%0A
         
 if (requ
@@ -478,41 +478,9 @@
     
-if (requestsReceived == 0) %7B%0A    
+%0A
     
@@ -536,36 +536,32 @@
 %5Cr%5Cn%22);%0A        
- 
-   
 ctx.writeAndFlus
@@ -586,106 +586,8 @@
 %22);%0A
-        %7D else %7B%0A            ctx.writeAndFlush(%22+OK%5Cr%5Cn%22);%0A        %7D%0A%0A        requestsReceived++;%0A
     

remove unused requestsReceived