Skip to content

Commit

Permalink
Reformat and correct unit test for ReadOnlyReplicationHelperCLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Xu Ha committed Dec 18, 2014
1 parent 43495a8 commit 35414b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
28 changes: 9 additions & 19 deletions src/java/voldemort/tools/ReadOnlyReplicationHelperCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,9 @@ public static List<String> 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<String> fileNames = adminClient.readonlyOps.getROStorageFileList(sourceNode.getId(),
Expand All @@ -233,11 +222,12 @@ public static List<String> 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
Expand Down Expand Up @@ -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<String> infoList = getReadOnlyReplicationInfo(adminClient, nodeId);
for(String info: infoList) {
Expand Down
22 changes: 16 additions & 6 deletions test/unit/voldemort/tools/ReadOnlyReplicationHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ private List<String> getSourceFileList(List<String> infoList,
Integer srcNodeId) {
List<String> 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;
Expand All @@ -100,9 +105,14 @@ private List<String> getSourceFileList(List<String> infoList,
private List<String> getDestFileList(List<String> infoList, String storeName, Integer srcNodeId) {
List<String> 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;
Expand Down

0 comments on commit 35414b4

Please sign in to comment.