@Test public void testMoveFile() { long reqId = 4; String from = "/a/need_to_be_moved"; String to = "/a/moved_file"; ms.putFile(from, file1); BinaryRawWriterEx message = createMessage(reqId, ModelStorateThinClientProcessor.PROCESSOR_ID, ModelStorateThinClientProcessor.Method.MOVE); message.writeString(from); message.writeString(to); ClientCustomQueryRequest req = new ClientCustomQueryRequest(toReader(message)); ClientResponse resp = req.process(connCtx); assertEquals(ClientStatus.SUCCESS, resp.status()); assertFalse(ms.exists(from)); assertTrue(ms.exists(to)); }
private ClientResponse moveFile(long reqId, BinaryRawReader reader) { String from = reader.readString(); String to = reader.readString(); String[] pathsToLock = new String[] {from, to}; Arrays.sort(pathsToLock, (s1, s2) -> { if (s1.length() == s2.length()) return s1.compareTo(s2); else return Integer.compare(s1.length(), s2.length()); }); return modelStorage.lockPaths(() -> { if (!modelStorage.exists(from)) return error(reqId, "File not found [path=" + from + "]"); if (modelStorage.exists(to)) return error(reqId, "File already exists [path=" + to + "]"); if (!modelStorage.isFile(from)) return error(reqId, "File is not regular file [path=" + from + "]"); byte[] file = modelStorage.getFile(from); modelStorage.remove(from); modelStorage.putFile(to, file); return new ClientResponse(reqId); }, pathsToLock); }
ModelStorateThinClientProcessor implements CustomQueryProcessor { private ClientResponse moveFile(long reqId, BinaryRawReader reader) { String from = reader.readString(); String to = reader.readString(); String[] pathsToLock = new String[] {from, to}; Arrays.sort(pathsToLock, (s1, s2) -> { if (s1.length() == s2.length()) return s1.compareTo(s2); else return Integer.compare(s1.length(), s2.length()); }); return modelStorage.lockPaths(() -> { if (!modelStorage.exists(from)) return error(reqId, "File not found [path=" + from + "]"); if (modelStorage.exists(to)) return error(reqId, "File already exists [path=" + to + "]"); if (!modelStorage.isFile(from)) return error(reqId, "File is not regular file [path=" + from + "]"); byte[] file = modelStorage.getFile(from); modelStorage.remove(from); modelStorage.putFile(to, file); return new ClientResponse(reqId); }, pathsToLock); } }
ModelStorateThinClientProcessor implements CustomQueryProcessor { private ClientResponse moveFile(long reqId, BinaryRawReader reader) { String from = reader.readString(); String to = reader.readString(); String[] pathsToLock = new String[] {from, to}; Arrays.sort(pathsToLock, (s1, s2) -> { if (s1.length() == s2.length()) return s1.compareTo(s2); else return Integer.compare(s1.length(), s2.length()); }); return modelStorage.lockPaths(() -> { if (!modelStorage.exists(from)) return error(reqId, "File not found [path=" + from + "]"); if (modelStorage.exists(to)) return error(reqId, "File already exists [path=" + to + "]"); if (!modelStorage.isFile(from)) return error(reqId, "File is not regular file [path=" + from + "]"); byte[] file = modelStorage.getFile(from); modelStorage.remove(from); modelStorage.putFile(to, file); return new ClientResponse(reqId); }, pathsToLock); } ModelStorateThinClientProcessor(ModelStorage modelStorage); }
ModelStorateThinClientProcessor implements CustomQueryProcessor { private ClientResponse moveFile(long reqId, BinaryRawReader reader) { String from = reader.readString(); String to = reader.readString(); String[] pathsToLock = new String[] {from, to}; Arrays.sort(pathsToLock, (s1, s2) -> { if (s1.length() == s2.length()) return s1.compareTo(s2); else return Integer.compare(s1.length(), s2.length()); }); return modelStorage.lockPaths(() -> { if (!modelStorage.exists(from)) return error(reqId, "File not found [path=" + from + "]"); if (modelStorage.exists(to)) return error(reqId, "File already exists [path=" + to + "]"); if (!modelStorage.isFile(from)) return error(reqId, "File is not regular file [path=" + from + "]"); byte[] file = modelStorage.getFile(from); modelStorage.remove(from); modelStorage.putFile(to, file); return new ClientResponse(reqId); }, pathsToLock); } ModelStorateThinClientProcessor(ModelStorage modelStorage); @Override ClientResponse call(long requestId, byte methodId, BinaryRawReader reader); @Override String id(); }
ModelStorateThinClientProcessor implements CustomQueryProcessor { private ClientResponse moveFile(long reqId, BinaryRawReader reader) { String from = reader.readString(); String to = reader.readString(); String[] pathsToLock = new String[] {from, to}; Arrays.sort(pathsToLock, (s1, s2) -> { if (s1.length() == s2.length()) return s1.compareTo(s2); else return Integer.compare(s1.length(), s2.length()); }); return modelStorage.lockPaths(() -> { if (!modelStorage.exists(from)) return error(reqId, "File not found [path=" + from + "]"); if (modelStorage.exists(to)) return error(reqId, "File already exists [path=" + to + "]"); if (!modelStorage.isFile(from)) return error(reqId, "File is not regular file [path=" + from + "]"); byte[] file = modelStorage.getFile(from); modelStorage.remove(from); modelStorage.putFile(to, file); return new ClientResponse(reqId); }, pathsToLock); } ModelStorateThinClientProcessor(ModelStorage modelStorage); @Override ClientResponse call(long requestId, byte methodId, BinaryRawReader reader); @Override String id(); static final String PROCESSOR_ID; }