MapGetAction implements Action { @Override public Reply handle() { String map = Actions.checkpointMapNameForRequest(request); String key = request.getSelector(); if (key == null || key.isEmpty()) { return Replies.createErrorReply("Key must be non-empty"); } Object mapValue = ctx.getMap(map).get(key); String replyValue; if (mapValue == null) { replyValue = null; } else { replyValue = mapValue.toString(); } return Replies.createOkReply(replyValue); } MapGetAction(CheckpointRequest request, ClusterContext ctx); @Override Reply handle();  }
@Test public void testMalformedSelectorNull() { CheckpointRequest request = new CheckpointRequest(CheckpointRequestType.GET, ""); fillIds(request); Action action = Actions.createAction(request, ctx); Reply reply = action.handle(); assertSame(ReplyType.ERROR, reply.getReplyType()); }
@Test public void testNonExistingKey() { CheckpointRequest request = new CheckpointRequest(CheckpointRequestType.GET, "nonExistingKey"); fillIds(request); Action action = Actions.createAction(request, ctx); Reply reply = action.handle(); assertSame(ReplyType.OK, reply.getReplyType()); assertSame(null, reply.getValue()); }
@Test public void testExistingKey() { ctx.getMap(MAP).put(KEY1, VALUE1); CheckpointRequest request = new CheckpointRequest(CheckpointRequestType.GET, KEY1); fillIds(request); Action action = Actions.createAction(request, ctx); Reply reply = action.handle(); assertSame(ReplyType.OK, reply.getReplyType()); assertEquals(VALUE1, reply.getValue()); }