From 6b52660c8a42346e790f2a81515d4e4b0cf043c8 Mon Sep 17 00:00:00 2001 From: Britt Park Date: Wed, 24 May 2006 21:45:41 +0000 Subject: [PATCH] A handful of tests of more arcane scenarios. Fixed issues as found. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@2975 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../java/org/alfresco/repo/avm/AVMNode.java | 26 ++ .../org/alfresco/repo/avm/AVMServiceTest.java | 433 +++++++++++++++++- .../repo/avm/LayeredDirectoryNode.java | 4 +- .../alfresco/repo/avm/hibernate/AVM.hbm.xml | 4 +- .../repo/avm/impl/RepositoryImpl.java | 2 +- .../repo/avm/impl/SuperRepositoryImpl.java | 33 +- 6 files changed, 470 insertions(+), 32 deletions(-) diff --git a/source/java/org/alfresco/repo/avm/AVMNode.java b/source/java/org/alfresco/repo/avm/AVMNode.java index 6ff09df37e..855f80fd82 100644 --- a/source/java/org/alfresco/repo/avm/AVMNode.java +++ b/source/java/org/alfresco/repo/avm/AVMNode.java @@ -240,4 +240,30 @@ public abstract class AVMNode * @param lPath The Lookup. */ public abstract String toString(Lookup lPath); + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (!(obj instanceof AVMNode)) + { + return false; + } + return getDataBean().equals(((AVMNode)obj).getDataBean()); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() + { + return getDataBean().hashCode(); + } } diff --git a/source/java/org/alfresco/repo/avm/AVMServiceTest.java b/source/java/org/alfresco/repo/avm/AVMServiceTest.java index 3c2b972d9c..5040249347 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceTest.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceTest.java @@ -56,7 +56,7 @@ public class AVMServiceTest extends TestCase protected void setUp() throws Exception { Configuration cfg = HibernateHelper.GetConfiguration(); - HibernateHelper.GetSessionFactory().getStatistics().setStatisticsEnabled(true); +// HibernateHelper.GetSessionFactory().getStatistics().setStatisticsEnabled(true); SchemaExport se = new SchemaExport(cfg); se.drop(false, true); AVMServiceImpl service = new AVMServiceImpl(); @@ -74,11 +74,374 @@ public class AVMServiceTest extends TestCase { long now = System.currentTimeMillis(); System.out.println("Timing: " + (now - fStartTime) + "ms"); - Statistics stats = HibernateHelper.GetSessionFactory().getStatistics(); - stats.logSummary(); - stats.clear(); +// Statistics stats = HibernateHelper.GetSessionFactory().getStatistics(); +// stats.logSummary(); +// stats.clear(); HibernateHelper.Reset(); } + + /** + * Another test of renaming in a layer. + */ + public void testRenameLayer2() + { + try + { + TreeMap history = new TreeMap(); + // Set up a basic hierarchy. + fService.createDirectory("main:/", "a"); + fService.createDirectory("main:/a", "b"); + fService.createDirectory("main:/a", "c"); + fService.createFile("main:/a/b", "foo"); + fService.createFile("main:/a/c", "bar"); + fService.createSnapshot("main"); + // History is unchanged. + checkHistory(history, "main"); + // Make a layer to a. + fService.createLayeredDirectory("main:/a", "main:/", "layer"); + fService.createSnapshot("main"); + // History is unchanged. + checkHistory(history, "main"); + // /a and /layer should have identical contents. + assertEquals(recursiveContents("main:/a", -1), recursiveContents("main:/layer", -1)); + // Now rename /layer/c/bar to /layer/b/bar + fService.rename("main:/layer/c", "bar", "main:/layer/b", "bar"); + fService.createSnapshot("main"); + // History is unchanged. + checkHistory(history, "main"); + // /layer/c should be empty. + List listing = fService.getDirectoryListing(-1, "main:/layer/c"); + assertEquals(0, listing.size()); + // /layer/b should contain fao and bar + listing = fService.getDirectoryListing(-1, "main:/layer/b"); + assertEquals(2, listing.size()); + assertEquals("bar", listing.get(0).getName()); + assertEquals("foo", listing.get(1).getName()); + // /a/b should contain foo. + listing = fService.getDirectoryListing(-1, "main:/a/b"); + assertEquals(1, listing.size()); + assertEquals("foo", listing.get(0).getName()); + // /a/c should contain bar. + listing = fService.getDirectoryListing(-1, "main:/a/c"); + assertEquals(1, listing.size()); + assertEquals("bar", listing.get(0).getName()); + // Now make a file in /a/b + fService.createFile("main:/a/b", "baz"); + fService.createSnapshot("main"); + // History is unchanged. + checkHistory(history, "main"); + // /a/b should contain baz and foo. + listing = fService.getDirectoryListing(-1, "main:/a/b"); + assertEquals(2, listing.size()); + assertEquals("baz", listing.get(0).getName()); + assertEquals("foo", listing.get(1).getName()); + // /layer/b should contain foo, bar, and baz. + listing = fService.getDirectoryListing(-1, "main:/layer/b"); + assertEquals(3, listing.size()); + assertEquals("bar", listing.get(0).getName()); + assertEquals("baz", listing.get(1).getName()); + assertEquals("foo", listing.get(2).getName()); + // Remove baz from /layer/b + fService.removeNode("main:/layer/b", "baz"); + fService.createSnapshot("main"); + // History is unchanged. + checkHistory(history, "main"); + // /layer/b should have bar and foo. + listing = fService.getDirectoryListing(-1, "main:/layer/b"); + assertEquals(2, listing.size()); + assertEquals("bar", listing.get(0).getName()); + assertEquals("foo", listing.get(1).getName()); + // /a/b should contain baz and foo as before. + listing = fService.getDirectoryListing(-1, "main:/a/b"); + assertEquals(2, listing.size()); + assertEquals("baz", listing.get(0).getName()); + assertEquals("foo", listing.get(1).getName()); + } + catch (Exception e) + { + e.printStackTrace(System.err); + fail(); + } + } + + /** + * Yet another test around rename in layers. + */ + public void testRenameLayer3() + { + try + { + TreeMap history = new TreeMap(); + // Set up a handy hierarchy. + fService.createDirectory("main:/", "a"); + fService.createDirectory("main:/a", "b"); + fService.createFile("main:/a/b", "foo"); + fService.createFile("main:/a/b", "bar"); + fService.createDirectory("main:/", "c"); + fService.createDirectory("main:/c", "d"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // Make a layer over /a + fService.createLayeredDirectory("main:/a", "main:/", "layer"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // Move /c/d to /layer + fService.rename("main:/c", "d", "main:/layer", "d"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // Now make a file in /layer/d + fService.createFile("main:/layer/d", "baz"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // Make /a/d/figs and see the wackiness. + fService.createDirectory("main:/a", "d"); + fService.createFile("main:/a/d", "figs"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // /layer/d should no contain baz and figs. + List listing = fService.getDirectoryListing(-1, "main:/layer/d"); + assertEquals(2, listing.size()); + assertEquals("baz", listing.get(0).getName()); + assertEquals("figs", listing.get(1).getName()); + for (String val : history.values()) + { + System.out.println(val); + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + fail(); + } + } + + /** + * Test the slide operation. + */ + public void testSlide() + { + try + { + TreeMap history = new TreeMap(); + // Set up a handy hierarchy. + fService.createDirectory("main:/", "a"); + fService.createDirectory("main:/a/", "b"); + fService.createFile("main:/a/b", "foo"); + fService.createFile("main:/a/b", "bar"); + fService.createDirectory("main:/", "c"); + fService.createDirectory("main:/c", "d"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // Make a layer over /a + fService.createLayeredDirectory("main:/a", "main:/", "layer"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // Move /c/d to /layer + fService.rename("main:/c", "d", "main:/layer", "d"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // Make a file in /layer/d + fService.createFile("main:/layer/d", "baz"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // Make /a/d/figs and see the wackiness. + fService.createDirectory("main:/a", "d"); + fService.createFile("main:/a/d", "figs"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // /layer/d should now contain baz and figs. + List listing = fService.getDirectoryListing(-1, "main:/layer/d"); + assertEquals(2, listing.size()); + assertEquals("baz", listing.get(0).getName()); + assertEquals("figs", listing.get(1).getName()); + // Slide /layer/d to /layer/e + fService.slide("main:/layer", "d", "main:/layer", "e"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // /layer/d contains figs. + listing = fService.getDirectoryListing(-1, "main:/layer/d"); + assertEquals(1, listing.size()); + assertEquals("figs", listing.get(0).getName()); + // /layer/e contains baz. + listing = fService.getDirectoryListing(-1, "main:/layer/e"); + assertEquals(1, listing.size()); + assertEquals("baz", listing.get(0).getName()); + for (String val : history.values()) + { + System.out.println(val); + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + fail(); + } + } + + /** + * Another test of renaming in a layer. + */ + public void testRenameLayer4() + { + try + { + TreeMap history = new TreeMap(); + // Set up a handy hierarchy. + fService.createDirectory("main:/", "a"); + fService.createDirectory("main:/a", "b"); + fService.createFile("main:/a/b", "foo"); + fService.createFile("main:/a/b", "bar"); + fService.createDirectory("main:/", "c"); + fService.createDirectory("main:/c", "d"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // Make a layer over /a + fService.createLayeredDirectory("main:/a", "main:/", "layer"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // Move /layer/b to /b + fService.rename("main:/layer", "b", "main:/", "b"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // Add something to /a/b and it should show up in /b. + fService.createFile("main:/a/b", "baz"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // /b should have foo and bar and baz. + List listing = fService.getDirectoryListing(-1, "main:/b"); + assertEquals(3, listing.size()); + assertEquals("bar", listing.get(0).getName()); + assertEquals("baz", listing.get(1).getName()); + assertEquals("foo", listing.get(2).getName()); + // Add something to /a and it will show up in /layer. + fService.createFile("main:/a", "figs"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // /layer should have figs in it. + listing = fService.getDirectoryListing(-1, "main:/layer"); + assertEquals(1, listing.size()); + assertEquals("figs", listing.get(0).getName()); + for (String val : history.values()) + { + System.out.println(val); + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + fail(); + } + } + + /** + * Test branching within branches. + */ + public void testBranchesInBranches() + { + try + { + TreeMap history = new TreeMap(); + // Set up a hierarchy. + setupBasicTree(); + // History unchanged. + checkHistory(history, "main"); + // Make a branch from /a + fService.createBranch(-1, "main:/a", "main:/", "abranch"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // Make a branch in something that has been branched. + fService.createBranch(-1, "main:/a/b", "main:/a", "bbranch"); + fService.createSnapshot("main"); + // History unchanged + checkHistory(history, "main"); + // Everything under /abranch should be identical in this version + // and the previous. + int version = fService.getLatestVersionID("main"); + assertEquals(recursiveContents("main:/abranch", version - 1), + recursiveContents("main:/abranch", version - 2)); + // Make a branch within a branch. + fService.createBranch(-1, "main:/abranch/b/c", "main:/abranch/b", "cbranch"); + fService.createSnapshot("main"); + // History unchanged + checkHistory(history, "main"); + // Everything under /a should be unchanged between this version and the last. + version = fService.getLatestVersionID("main"); + assertEquals(recursiveContents("main:/a", version - 1), + recursiveContents("main:/a", version - 2)); + // Make a branch to something outside of a branch inside a branch. + fService.createBranch(-1, "main:/d", "main:/abranch", "dbranch"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // Make something ind /abranch/dbranch. + fService.createFile("main:/abranch/dbranch/e/f", "baz"); + fService.createSnapshot("main"); + // History unchanged. + checkHistory(history, "main"); + // d should not have changed since the previous version. + version = fService.getLatestVersionID("main"); + assertEquals(recursiveContents("main:/d", version - 1), + recursiveContents("main:/d", version - 2)); + for (String val : history.values()) + { + System.out.println(val); + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + fail(); + } + } + + /** + * Test adding 100 files to each directory. + */ + public void testAdd100() + { + try + { + String [] dirs = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }; + for (String dir : dirs) + { + fService.createDirectory("main:/", dir); + dir = "main:/" + dir; + for (int i = 0; i < 50; i++) + { + fService.createFile(dir, "file" + i); + System.out.println(dir + "/file" + i); + PrintStream out = + new PrintStream(fService.getFileOutputStream(dir + "/file" + i)); + out.println("I am " + dir + "/file" + i); + out.close(); + } + } + fService.createSnapshot("main"); + System.out.println(recursiveList("main", -1)); + } + catch (Exception e) + { + e.printStackTrace(System.err); + fail(); + } + } /** * Test Nothing. Just make sure set up works. @@ -599,29 +962,41 @@ public class AVMServiceTest extends TestCase } /** - * Test adding 100 files to each directory. + * Test rename within a layer. */ - public void testAdd100() + public void testRenameInLayer() { try { - String [] dirs = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }; - for (String dir : dirs) - { - fService.createDirectory("main:/", dir); - dir = "main:/" + dir; - for (int i = 0; i < 50; i++) - { - fService.createFile(dir, "file" + i); - System.out.println(dir + "/file" + i); - PrintStream out = - new PrintStream(fService.getFileOutputStream(dir + "/file" + i)); - out.println("I am " + dir + "/file" + i); - out.close(); - } - } + // Setup a base hierarchy. + fService.createDirectory("main:/", "a"); + fService.createDirectory("main:/a", "b"); + fService.createDirectory("main:/a/b", "c"); + fService.createDirectory("main:/a", "d"); fService.createSnapshot("main"); - System.out.println(recursiveList("main", -1)); + // Now make a layer to a. + fService.createLayeredDirectory("main:/a", "main:/", "layer"); + fService.createSnapshot("main"); + // /layer should have the same contents as /a at this point. + String original = recursiveContents("main:/a", -1); + String layer = recursiveContents("main:/layer", -1); + assertEquals(original, layer); + // Now we will rename /layer/d to /layer/moved + fService.rename("main:/layer", "d", "main:/layer", "moved"); + fService.createSnapshot("main"); + // /layer should contain b and moved + List listing = fService.getDirectoryListing(-1, "main:/layer"); + assertEquals(2, listing.size()); + assertEquals("b", listing.get(0).getName()); + assertEquals("moved", listing.get(1).getName()); + // Now rename moved back to d. + fService.rename("main:/layer", "moved", "main:/layer", "d"); + fService.createSnapshot("main"); + // /layer should contain b and d. + listing = fService.getDirectoryListing(-1, "main:/layer"); + assertEquals(2, listing.size()); + assertEquals("b", listing.get(0).getName()); + assertEquals("d", listing.get(1).getName()); } catch (Exception e) { @@ -630,6 +1005,20 @@ public class AVMServiceTest extends TestCase } } + + /** + * Get the recursive contents of the given path and version. + * @param path + * @param version + * @return + */ + private String recursiveContents(String path, int version) + { + String val = recursiveList(path, version, 0); + return val.substring(val.indexOf('\n')); + } + + /** * Helper to write a recursive listing of a repository at a given version. * @param repoName The name of the repository. diff --git a/source/java/org/alfresco/repo/avm/LayeredDirectoryNode.java b/source/java/org/alfresco/repo/avm/LayeredDirectoryNode.java index 104fe5a52c..fdbd1e4c84 100644 --- a/source/java/org/alfresco/repo/avm/LayeredDirectoryNode.java +++ b/source/java/org/alfresco/repo/avm/LayeredDirectoryNode.java @@ -353,7 +353,9 @@ public class LayeredDirectoryNode extends DirectoryNode implements Layered */ public boolean directlyContains(AVMNode node) { - return fData.getAdded().containsValue(node.getDataBean()); + DirectoryEntry entry = new DirectoryEntry(node.getType(), + node.getDataBean()); + return fData.getAdded().containsValue(entry); } /* (non-Javadoc) diff --git a/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml b/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml index 4a70ece457..84f8497c57 100644 --- a/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml +++ b/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml @@ -74,7 +74,7 @@ - + @@ -109,7 +109,7 @@ - + diff --git a/source/java/org/alfresco/repo/avm/impl/RepositoryImpl.java b/source/java/org/alfresco/repo/avm/impl/RepositoryImpl.java index cec9953ee0..5384860738 100644 --- a/source/java/org/alfresco/repo/avm/impl/RepositoryImpl.java +++ b/source/java/org/alfresco/repo/avm/impl/RepositoryImpl.java @@ -346,7 +346,7 @@ public class RepositoryImpl implements Repository throw new AlfrescoRuntimeException("Not in this layer: " + srcName); } Lookup dPath = lookupDirectory(-1, dstPath); - if (!dPath.isLayered() || dPath.getTopLayer() != sPath.getTopLayer()) + if (!dPath.isLayered() || !dPath.getTopLayer().equals(sPath.getTopLayer())) { throw new AlfrescoRuntimeException("Destination must be in same layer: " + dstPath); } diff --git a/source/java/org/alfresco/repo/avm/impl/SuperRepositoryImpl.java b/source/java/org/alfresco/repo/avm/impl/SuperRepositoryImpl.java index e2ba9898db..b506102b4e 100644 --- a/source/java/org/alfresco/repo/avm/impl/SuperRepositoryImpl.java +++ b/source/java/org/alfresco/repo/avm/impl/SuperRepositoryImpl.java @@ -88,10 +88,10 @@ public class SuperRepositoryImpl implements SuperRepository { fSession = session; fStorage = storage; - fNodeIssuer = (Issuer)fSession.get(Issuer.class, "node"); - fContentIssuer = (Issuer)fSession.get(Issuer.class, "content"); - fBranchIssuer = (Issuer)fSession.get(Issuer.class, "branch"); - fLayerIssuer = (Issuer)fSession.get(Issuer.class, "layer"); + fNodeIssuer = null; + fContentIssuer = null; + fBranchIssuer = null; + fLayerIssuer = null; } /* (non-Javadoc) @@ -186,7 +186,7 @@ public class SuperRepositoryImpl implements SuperRepository dstNode.setVersion(dstRepo.getLatestVersion() + 1); dstRepo.setNew(dstNode); dstNode.setAncestor(srcNode); - dstNode.setBranchID(fBranchIssuer.issue()); + dstNode.setBranchID(issueBranchID()); dirNode.addChild(name, dstNode, dPath); } @@ -270,7 +270,7 @@ public class SuperRepositoryImpl implements SuperRepository // we need to compute the indirection path for this layer after the rename. dstNode = new LayeredDirectoryNode((DirectoryNode)srcNode, dstRepo, sPath, srcName); - ((LayeredDirectoryNode)dstNode).setLayerID(fLayerIssuer.issue()); + ((LayeredDirectoryNode)dstNode).setLayerID(issueLayerID()); } } else if (srcNode instanceof LayeredFileNode) @@ -415,6 +415,10 @@ public class SuperRepositoryImpl implements SuperRepository */ public long issueID() { + if (fNodeIssuer == null) + { + fNodeIssuer = (Issuer)fSession.get(Issuer.class, "node"); + } return fNodeIssuer.issue(); } @@ -423,6 +427,10 @@ public class SuperRepositoryImpl implements SuperRepository */ public long issueContentID() { + if (fContentIssuer == null) + { + fContentIssuer = (Issuer)fSession.get(Issuer.class, "content"); + } return fContentIssuer.issue(); } @@ -431,8 +439,21 @@ public class SuperRepositoryImpl implements SuperRepository */ public long issueLayerID() { + if (fLayerIssuer == null) + { + fLayerIssuer = (Issuer)fSession.get(Issuer.class, "layer"); + } return fLayerIssuer.issue(); } + + private long issueBranchID() + { + if (fBranchIssuer == null) + { + fBranchIssuer = (Issuer)fSession.get(Issuer.class, "branch"); + } + return fBranchIssuer.issue(); + } /* (non-Javadoc) * @see org.alfresco.repo.avm.SuperRepository#getSession()