ModelStorateThinClientProcessor implements CustomQueryProcessor { private ClientResponse mkdir(long reqId, BinaryRawReader reader) { String path = reader.readString(); boolean onlyIfNotExists = reader.readBoolean(); return modelStorage.lockPaths(() -> { if (onlyIfNotExists && modelStorage.exists(path)) return error(reqId, "Directory already exists [path=" + path + "]"); modelStorage.mkdir(path, onlyIfNotExists); return new ClientResponse(reqId); }, path); } ModelStorateThinClientProcessor(ModelStorage modelStorage); @Override ClientResponse call(long requestId, byte methodId, BinaryRawReader reader); @Override String id(); static final String PROCESSOR_ID; }
@Test public void testMkDir() { long reqId = 14; String path1 = "/a/b/test_mk_dir"; BinaryRawWriterEx message = createMessage(reqId, ModelStorateThinClientProcessor.PROCESSOR_ID, ModelStorateThinClientProcessor.Method.MKDIR); message.writeString(path1); message.writeBoolean(false); ClientCustomQueryRequest req = new ClientCustomQueryRequest(toReader(message)); ClientResponse resp = req.process(connCtx); BinaryRawWriterEx out = createWriter(); resp.encode(connCtx, out); byte[] result = out.out().arrayCopy(); assertTrue(ms.exists(path1)); assertArrayEquals(getExpectedMessageHeader(reqId).out().arrayCopy(), result); }