@Test public void test3() throws Exception { Map<String, String> map = new HashMap<>(); byte[][] args = new byte[2][]; args[0] = new byte[]{(byte) Command.GET.ordinal()}; args[1] = "no_key".getBytes(); GetCommand g = new GetCommand(map); ReplyMessage reply = g.run(2, args); assertEquals(reply.message(), BulkStringMessage.NoKeyFoundMessage.message()); }
@Override public ReplyMessage run(int argc, byte[][] argv) throws Exception { if (argc != 2) { return ErrorMessage.WrongArgcMessage; } String key = new String(argv[1], Protocol.KEYCAFE_CHARSET); String val = map.get(key); logger.info("get key: {} - result: {}", key, val); if (val != null) { return new BulkStringMessage(val); } else { return BulkStringMessage.NoKeyFoundMessage; } }
GetCommand implements CommandRunnable { @Override public ReplyMessage run(int argc, byte[][] argv) throws Exception { if (argc != 2) { return ErrorMessage.WrongArgcMessage; } String key = new String(argv[1], Protocol.KEYCAFE_CHARSET); String val = map.get(key); logger.info("get key: {} - result: {}", key, val); if (val != null) { return new BulkStringMessage(val); } else { return BulkStringMessage.NoKeyFoundMessage; } } }
GetCommand implements CommandRunnable { @Override public ReplyMessage run(int argc, byte[][] argv) throws Exception { if (argc != 2) { return ErrorMessage.WrongArgcMessage; } String key = new String(argv[1], Protocol.KEYCAFE_CHARSET); String val = map.get(key); logger.info("get key: {} - result: {}", key, val); if (val != null) { return new BulkStringMessage(val); } else { return BulkStringMessage.NoKeyFoundMessage; } } GetCommand(Map<String, String> map); }
GetCommand implements CommandRunnable { @Override public ReplyMessage run(int argc, byte[][] argv) throws Exception { if (argc != 2) { return ErrorMessage.WrongArgcMessage; } String key = new String(argv[1], Protocol.KEYCAFE_CHARSET); String val = map.get(key); logger.info("get key: {} - result: {}", key, val); if (val != null) { return new BulkStringMessage(val); } else { return BulkStringMessage.NoKeyFoundMessage; } } GetCommand(Map<String, String> map); @Override ReplyMessage run(int argc, byte[][] argv); @Override int keyIndex(); }
GetCommand implements CommandRunnable { @Override public ReplyMessage run(int argc, byte[][] argv) throws Exception { if (argc != 2) { return ErrorMessage.WrongArgcMessage; } String key = new String(argv[1], Protocol.KEYCAFE_CHARSET); String val = map.get(key); logger.info("get key: {} - result: {}", key, val); if (val != null) { return new BulkStringMessage(val); } else { return BulkStringMessage.NoKeyFoundMessage; } } GetCommand(Map<String, String> map); @Override ReplyMessage run(int argc, byte[][] argv); @Override int keyIndex();  }