ModelStorateThinClientProcessor implements CustomQueryProcessor { private ClientResponse readFile(long reqId, BinaryRawReader reader) { String path = reader.readString(); return modelStorage.lockPaths(() -> { if (!modelStorage.exists(path)) return error(reqId, "File not found [path=" + path + "]"); if (!modelStorage.isFile(path)) return error(reqId, "File is not regular file [path" + path + "]"); return new FileRespose(reqId, modelStorage.getFile(path)); }, path); } ModelStorateThinClientProcessor(ModelStorage modelStorage); @Override ClientResponse call(long requestId, byte methodId, BinaryRawReader reader); @Override String id(); static final String PROCESSOR_ID; }
@Test public void testReadFile() { long reqId = 1; BinaryRawWriterEx message = createMessage(reqId, ModelStorateThinClientProcessor.PROCESSOR_ID, ModelStorateThinClientProcessor.Method.READ_FILE); message.writeString(pathToFile1); ClientCustomQueryRequest req = new ClientCustomQueryRequest(toReader(message)); ClientResponse resp = req.process(connCtx); assertArrayEquals(file1, ((FileRespose)resp).getData()); BinaryRawWriterEx out = createWriter(); resp.encode(connCtx, out); byte[] result = out.out().arrayCopy(); BinaryRawWriterEx expectedOut = getExpectedMessageHeader(reqId); expectedOut.writeByteArray(file1); byte[] expected = expectedOut.out().arrayCopy(); assertArrayEquals(expected, result); }