From 35414b4fad03fed9109fb6787acd235537c557eb Mon Sep 17 00:00:00 2001 From: Xu Ha Date: Wed, 17 Dec 2014 18:30:07 -0800 Subject: [PATCH] Reformat and correct unit test for ReadOnlyReplicationHelperCLI --- .../tools/ReadOnlyReplicationHelperCLI.java | 28 ++++++------------- .../tools/ReadOnlyReplicationHelperTest.java | 22 +++++++++++---- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/java/voldemort/tools/ReadOnlyReplicationHelperCLI.java b/src/java/voldemort/tools/ReadOnlyReplicationHelperCLI.java index a7fdb4d5a5..1a956e26b8 100644 --- a/src/java/voldemort/tools/ReadOnlyReplicationHelperCLI.java +++ b/src/java/voldemort/tools/ReadOnlyReplicationHelperCLI.java @@ -194,20 +194,9 @@ public static List getReadOnlyReplicationInfo(AdminClient adminClient, I // Now find out which node hosts one of these replicas Node sourceNode = cluster.getNodeForPartitionId(naryPartitionIds.get(0)); Integer sourceNodeId = sourceNode.getId(); - Long sourceVersion = adminClient.readonlyOps.getROCurrentVersion(sourceNodeId, - Arrays.asList(storeName)) - .get(storeName); - String sourcePath = adminClient.readonlyOps.getROCurrentVersionDir(sourceNodeId, - Arrays.asList(storeName)) - .get(storeName); - Long destVersion = adminClient.readonlyOps.getROCurrentVersion(nodeId, - Arrays.asList(storeName)) - .get(storeName); - String destPath = adminClient.readonlyOps.getROCurrentVersionDir(nodeId, - Arrays.asList(storeName)) - .get(storeName); - - // TODO FROM HERE + Long version = adminClient.readonlyOps.getROCurrentVersion(sourceNodeId, + Arrays.asList(storeName)) + .get(storeName); // Now get all the file names from this node. List fileNames = adminClient.readonlyOps.getROStorageFileList(sourceNode.getId(), @@ -233,11 +222,12 @@ public static List getReadOnlyReplicationInfo(AdminClient adminClient, I .concat(replicaId) .concat(SPLIT_LITERAL) .concat(chunkId); + String sourceRelPath = storeName + "/version-" + version + "/" + + sourceFileName; + String destRelPath = storeName + "/version-" + version + "/" + destFileName; - infoList.add(storeName + "," + sourceNode.getHost() + "," - + sourceNode.getId() + "," + sourceVersion + "," + sourcePath - + "," + sourceFileName + "," + destVersion + "," + destPath - + "," + destFileName); + infoList.add(sourceNode.getHost() + "," + sourceNode.getId() + "," + + sourceRelPath + "," + destRelPath); } } else { logger.warn("Cannot find file for partition " + masterPartitionId @@ -265,7 +255,7 @@ public static void main(String[] args) throws Exception { AdminClient adminClient = new AdminClient(url, new AdminClientConfig(), new ClientConfig()); - outputStream.println("store_name,src_host_name,src_node_id,src_version,src_file_path,src_file_name,dest_version,dest_file_path,dest_file_name"); + outputStream.println("src_host_name,src_node_id,src_rel_path,dest_rel_path"); List infoList = getReadOnlyReplicationInfo(adminClient, nodeId); for(String info: infoList) { diff --git a/test/unit/voldemort/tools/ReadOnlyReplicationHelperTest.java b/test/unit/voldemort/tools/ReadOnlyReplicationHelperTest.java index 5a50882391..47cc318500 100644 --- a/test/unit/voldemort/tools/ReadOnlyReplicationHelperTest.java +++ b/test/unit/voldemort/tools/ReadOnlyReplicationHelperTest.java @@ -89,9 +89,14 @@ private List getSourceFileList(List infoList, Integer srcNodeId) { List fileList = Lists.newArrayList(); for(String info: infoList) { - String[] split = info.split(","); - if(storeName.equals(split[0]) && srcNodeId.equals(Integer.parseInt(split[1]))) { - fileList.add(split[2]); + String[] infoSplit = info.split(","); + String nodeId = infoSplit[1]; + String relPath = infoSplit[2]; + String[] pathSplit = relPath.split("/"); + String parsedStoreName = pathSplit[0]; + String parserFileName = pathSplit[2]; + if(storeName.equals(parsedStoreName) && srcNodeId.equals(Integer.parseInt(nodeId))) { + fileList.add(parserFileName); } } return fileList; @@ -100,9 +105,14 @@ private List getSourceFileList(List infoList, private List getDestFileList(List infoList, String storeName, Integer srcNodeId) { List fileList = Lists.newArrayList(); for(String info: infoList) { - String[] split = info.split(","); - if(storeName.equals(split[0]) && srcNodeId.equals(Integer.parseInt(split[1]))) { - fileList.add(split[3]); + String[] infoSplit = info.split(","); + String nodeId = infoSplit[1]; + String relPath = infoSplit[3]; + String[] pathSplit = relPath.split("/"); + String parsedStoreName = pathSplit[0]; + String parserFileName = pathSplit[2]; + if(storeName.equals(parsedStoreName) && srcNodeId.equals(Integer.parseInt(nodeId))) { + fileList.add(parserFileName); } } return fileList;