Added rename to console. More in progress tweaks for concurrency.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3237 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-06-24 17:27:00 +00:00
parent 619f31b1bd
commit 64288d531d
4 changed files with 67 additions and 60 deletions

View File

@@ -210,6 +210,15 @@ public class AVMInteractiveConsole
} }
fService.createLayeredDirectory(command[1], command[2], command[3]); fService.createLayeredDirectory(command[1], command[2], command[3]);
} }
else if (command[0].equals("rename"))
{
if (command.length != 5)
{
System.err.println("Syntax error.");
continue;
}
fService.rename(command[1], command[2], command[3], command[4]);
}
else if (command[0].equals("retarget")) else if (command[0].equals("retarget"))
{ {
if (command.length != 3) if (command.length != 3)

View File

@@ -63,10 +63,7 @@ public class AVMStressTest extends AVMServiceTestBase
10000, // # ops 10000, // # ops
fService, fService,
"" + i); "" + i);
if (i == 0) tester.refresh();
{
tester.Refresh();
}
Thread thread = new Thread(tester); Thread thread = new Thread(tester);
testers.add(tester); testers.add(tester);
threads.add(thread); threads.add(thread);

View File

@@ -46,9 +46,9 @@ class AVMTester implements Runnable
private static final int READ_FILE = 7; private static final int READ_FILE = 7;
private static final int SNAPSHOT = 8; private static final int SNAPSHOT = 8;
private static List<String> fgAllPaths; private List<String> fAllPaths;
private static List<String> fgAllDirectories; private List<String> fAllDirectories;
private static List<String> fgAllFiles; private List<String> fAllFiles;
private static boolean fgFrozen = false; private static boolean fgFrozen = false;
@@ -240,7 +240,7 @@ class AVMTester implements Runnable
break; break;
} }
} }
System.out.println(fgAllPaths.size() + " fses in " + (System.currentTimeMillis() - startTime) + System.out.println(fAllPaths.size() + " fses in " + (System.currentTimeMillis() - startTime) +
"ms"); "ms");
} }
catch (Exception e) catch (Exception e)
@@ -254,14 +254,14 @@ class AVMTester implements Runnable
private void createFile() private void createFile()
{ {
String name = "PF" + fNames[fgRandom.nextInt(26 * 26)]; String name = "PF" + fNames[fgRandom.nextInt(26 * 26)];
String path = RandomDirectory(); String path = randomDirectory();
try try
{ {
System.out.println("create " + path + " " + name); System.out.println("create " + path + " " + name);
PrintStream out = new PrintStream(fService.createFile(path, name)); PrintStream out = new PrintStream(fService.createFile(path, name));
out.println(path + "/" + name); out.println(path + "/" + name);
out.close(); out.close();
AddFile(appendPath(path, name)); addFile(appendPath(path, name));
} }
catch (AVMException ae) catch (AVMException ae)
{ {
@@ -279,12 +279,12 @@ class AVMTester implements Runnable
private void createDirectory() private void createDirectory()
{ {
String name = "PD" + fNames[fgRandom.nextInt(26 * 26)]; String name = "PD" + fNames[fgRandom.nextInt(26 * 26)];
String path = RandomDirectory(); String path = randomDirectory();
try try
{ {
System.out.println("mkdir " + path + " " + name); System.out.println("mkdir " + path + " " + name);
fService.createDirectory(path, name); fService.createDirectory(path, name);
AddDirectory(appendPath(path, name)); addDirectory(appendPath(path, name));
} }
catch (AVMException ae) catch (AVMException ae)
{ {
@@ -302,7 +302,7 @@ class AVMTester implements Runnable
private void rename() private void rename()
{ {
String name = fNames[fgRandom.nextInt(26 * 26)]; String name = fNames[fgRandom.nextInt(26 * 26)];
String path = RandomPath(); String path = randomPath();
AVMNodeDescriptor desc = fService.lookup(-1, path); AVMNodeDescriptor desc = fService.lookup(-1, path);
if (path.equals("main:/")) if (path.equals("main:/"))
{ {
@@ -315,19 +315,19 @@ class AVMTester implements Runnable
srcPath = srcPath + "/"; srcPath = srcPath + "/";
} }
String srcName = path.substring(lastSlash + 1); String srcName = path.substring(lastSlash + 1);
String dstPath = RandomDirectory(); String dstPath = randomDirectory();
try try
{ {
System.out.println("rename " + srcPath + " " + srcName + " " + dstPath + " " + name); System.out.println("rename " + srcPath + " " + srcName + " " + dstPath + " " + name);
fService.rename(srcPath, srcName, dstPath, name); fService.rename(srcPath, srcName, dstPath, name);
RemovePath(path); removePath(path);
if (desc.isDirectory()) if (desc.isDirectory())
{ {
AddDirectory(appendPath(dstPath, name)); addDirectory(appendPath(dstPath, name));
} }
else else
{ {
AddFile(appendPath(dstPath, name)); addFile(appendPath(dstPath, name));
} }
} }
catch (AVMException ae) catch (AVMException ae)
@@ -346,13 +346,13 @@ class AVMTester implements Runnable
private void createLayeredDir() private void createLayeredDir()
{ {
String name = "LD" + fNames[fgRandom.nextInt(26 * 26)]; String name = "LD" + fNames[fgRandom.nextInt(26 * 26)];
String path = RandomDirectory(); String path = randomDirectory();
String target = RandomDirectory(); String target = randomDirectory();
try try
{ {
System.out.println("mklayereddir " + path + " " + name + " " + target); System.out.println("mklayereddir " + path + " " + name + " " + target);
fService.createLayeredDirectory(target, path, name); fService.createLayeredDirectory(target, path, name);
AddDirectory(appendPath(path, name)); addDirectory(appendPath(path, name));
} }
catch (AVMException ae) catch (AVMException ae)
{ {
@@ -370,13 +370,13 @@ class AVMTester implements Runnable
private void createLayeredFile() private void createLayeredFile()
{ {
String name = "LF" + fNames[fgRandom.nextInt(26 * 26)]; String name = "LF" + fNames[fgRandom.nextInt(26 * 26)];
String path = RandomDirectory(); String path = randomDirectory();
String target = RandomFile(); String target = randomFile();
try try
{ {
System.out.println("createlayered " + path + " " + name + " " + target); System.out.println("createlayered " + path + " " + name + " " + target);
fService.createLayeredFile(target, path, name); fService.createLayeredFile(target, path, name);
AddFile(appendPath(path, name)); addFile(appendPath(path, name));
} }
catch (AVMException ae) catch (AVMException ae)
{ {
@@ -393,7 +393,7 @@ class AVMTester implements Runnable
private void removeNode() private void removeNode()
{ {
String target = RandomPath(); String target = randomPath();
int lastSlash = target.lastIndexOf('/'); int lastSlash = target.lastIndexOf('/');
String path = target.substring(0, lastSlash); String path = target.substring(0, lastSlash);
if (path.equals("main:")) if (path.equals("main:"))
@@ -405,7 +405,7 @@ class AVMTester implements Runnable
{ {
System.out.println("remove " + target); System.out.println("remove " + target);
fService.removeNode(path, name); fService.removeNode(path, name);
RemovePath(target); removePath(target);
} }
catch (AVMException e) catch (AVMException e)
{ {
@@ -421,7 +421,7 @@ class AVMTester implements Runnable
private void modifyFile() private void modifyFile()
{ {
String path = RandomFile(); String path = randomFile();
try try
{ {
System.out.println("modify " + path); System.out.println("modify " + path);
@@ -444,7 +444,7 @@ class AVMTester implements Runnable
private void readFile() private void readFile()
{ {
String path = RandomFile(); String path = randomFile();
try try
{ {
System.out.println("read " + path); System.out.println("read " + path);
@@ -470,20 +470,20 @@ class AVMTester implements Runnable
} }
} }
public void Refresh() public void refresh()
{ {
System.out.println("refresh"); System.out.println("refresh");
fgAllPaths = new ArrayList<String>(); fAllPaths = new ArrayList<String>();
fgAllDirectories = new ArrayList<String>(); fAllDirectories = new ArrayList<String>();
fgAllFiles = new ArrayList<String>(); fAllFiles = new ArrayList<String>();
fgAllPaths.add("main:/"); fAllPaths.add("main:/");
fgAllDirectories.add("main:/"); fAllDirectories.add("main:/");
Set<Long> visited = new HashSet<Long>(); Set<Long> visited = new HashSet<Long>();
AVMNodeDescriptor root = fService.getRepositoryRoot(-1, "main"); AVMNodeDescriptor root = fService.getRepositoryRoot(-1, "main");
RecursiveRefresh(root, visited); recursiveRefresh(root, visited);
} }
private void RecursiveRefresh(AVMNodeDescriptor dir, Set<Long> visited) private void recursiveRefresh(AVMNodeDescriptor dir, Set<Long> visited)
{ {
try try
{ {
@@ -503,16 +503,16 @@ class AVMTester implements Runnable
continue; continue;
} }
visited.add(desc.getId()); visited.add(desc.getId());
fgAllPaths.add(path); fAllPaths.add(path);
fgAllDirectories.add(path); fAllDirectories.add(path);
RecursiveRefresh(desc, visited); recursiveRefresh(desc, visited);
break; break;
} }
case AVMNodeType.LAYERED_FILE : case AVMNodeType.LAYERED_FILE :
case AVMNodeType.PLAIN_FILE : case AVMNodeType.PLAIN_FILE :
{ {
fgAllPaths.add(path); fAllPaths.add(path);
fgAllFiles.add(path); fAllFiles.add(path);
break; break;
} }
} }
@@ -553,47 +553,47 @@ class AVMTester implements Runnable
fExit = true; fExit = true;
} }
private static synchronized void AddDirectory(String path) private void addDirectory(String path)
{ {
fgAllDirectories.add(path); fAllDirectories.add(path);
fgAllPaths.add(path); fAllPaths.add(path);
} }
private static synchronized void AddFile(String path) private void addFile(String path)
{ {
fgAllFiles.add(path); fAllFiles.add(path);
fgAllPaths.add(path); fAllPaths.add(path);
} }
private static synchronized void RemovePath(String path) private void removePath(String path)
{ {
List<String> allPaths = new ArrayList<String>(); List<String> allPaths = new ArrayList<String>();
List<String> allDirectories = new ArrayList<String>(); List<String> allDirectories = new ArrayList<String>();
List<String> allFiles = new ArrayList<String>(); List<String> allFiles = new ArrayList<String>();
for (String p : fgAllPaths) for (String p : fAllPaths)
{ {
if (p.indexOf(path) != 0) if (p.indexOf(path) != 0)
{ {
allPaths.add(p); allPaths.add(p);
} }
} }
for (String p : fgAllDirectories) for (String p : fAllDirectories)
{ {
if (p.indexOf(path) != 0) if (p.indexOf(path) != 0)
{ {
allDirectories.add(p); allDirectories.add(p);
} }
} }
for (String p : fgAllFiles) for (String p : fAllFiles)
{ {
if (p.indexOf(path) != 0) if (p.indexOf(path) != 0)
{ {
allFiles.add(p); allFiles.add(p);
} }
} }
fgAllPaths = allPaths; fAllPaths = allPaths;
fgAllDirectories = allDirectories; fAllDirectories = allDirectories;
fgAllFiles = allFiles; fAllFiles = allFiles;
} }
private String appendPath(String path, String name) private String appendPath(String path, String name)
@@ -601,18 +601,18 @@ class AVMTester implements Runnable
return path.endsWith("/") ? path + name : path + "/" + name; return path.endsWith("/") ? path + name : path + "/" + name;
} }
private static synchronized String RandomDirectory() private String randomDirectory()
{ {
return fgAllDirectories.get(fgRandom.nextInt(fgAllDirectories.size())); return fAllDirectories.get(fgRandom.nextInt(fAllDirectories.size()));
} }
private static synchronized String RandomFile() private String randomFile()
{ {
return fgAllFiles.get(fgRandom.nextInt(fgAllFiles.size())); return fAllFiles.get(fgRandom.nextInt(fAllFiles.size()));
} }
private static synchronized String RandomPath() private String randomPath()
{ {
return fgAllPaths.get(fgRandom.nextInt(fgAllPaths.size())); return fAllPaths.get(fgRandom.nextInt(fAllPaths.size()));
} }
} }

View File

@@ -185,7 +185,7 @@ class Lookup
{ {
// Inform the repository of a new root. // Inform the repository of a new root.
fRepository.setNewRoot((DirectoryNode)node); fRepository.setNewRoot((DirectoryNode)node);
// SuperRepository.GetInstance().getSession().flush(); SuperRepository.GetInstance().getSession().flush();
return; return;
} }
// Not the root. Check if we are the top layer and insert this into it's parent. // Not the root. Check if we are the top layer and insert this into it's parent.
@@ -194,6 +194,7 @@ class Lookup
fTopLayer = (LayeredDirectoryNode)node; fTopLayer = (LayeredDirectoryNode)node;
} }
((DirectoryNode)fComponents.get(fPosition - 1).getNode()).putChild(name, node); ((DirectoryNode)fComponents.get(fPosition - 1).getNode()).putChild(name, node);
SuperRepository.GetInstance().getSession().flush();
} }
} }