Work on FSR deployment tests.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@11105 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2008-09-30 18:10:45 +00:00
parent 1ba9b17909
commit 07fbee8bf6
3 changed files with 388 additions and 207 deletions

View File

@@ -1,207 +1,360 @@
/* /*
* Copyright (C) 2005-2007 Alfresco Software Limited. * Copyright (C) 2005-2007 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of * As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing * http://www.alfresco.com/legal/licensing
*/ */
package org.alfresco.repo.deploy; package org.alfresco.repo.deploy;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.HashSet;
import java.util.List;
import org.alfresco.repo.avm.AVMServiceTestBase; import java.util.Set;
import org.alfresco.repo.avm.util.BulkLoader;
import org.alfresco.service.cmr.avm.deploy.DeploymentCallback; import org.alfresco.repo.avm.AVMServiceTestBase;
import org.alfresco.service.cmr.avm.deploy.DeploymentEvent; import org.alfresco.repo.avm.util.BulkLoader;
import org.alfresco.service.cmr.avm.deploy.DeploymentReport; import org.alfresco.service.cmr.avm.AVMException;
import org.alfresco.service.cmr.avm.deploy.DeploymentReportCallback; import org.alfresco.service.cmr.avm.deploy.DeploymentCallback;
import org.alfresco.service.cmr.avm.deploy.DeploymentService; import org.alfresco.service.cmr.avm.deploy.DeploymentEvent;
import org.alfresco.util.Deleter; import org.alfresco.service.cmr.avm.deploy.DeploymentReport;
import org.alfresco.util.NameMatcher; import org.alfresco.service.cmr.avm.deploy.DeploymentReportCallback;
import org.springframework.context.support.FileSystemXmlApplicationContext; import org.alfresco.service.cmr.avm.deploy.DeploymentService;
import org.alfresco.util.Deleter;
/** import org.alfresco.util.NameMatcher;
* Test of to filesystem deployment. import org.springframework.context.support.FileSystemXmlApplicationContext;
* @author britt
*/ /**
public class FSDeploymentTest extends AVMServiceTestBase * End to end test of filesystem deployment.
{ * @author britt
public void testBasic() */
throws Exception public class FSDeploymentTest extends AVMServiceTestBase
{ {
File log = new File("deplog"); private File log = null;
log.mkdir(); private File metadata = null;
File metadata = new File("depmetadata"); private File data = null;
metadata.mkdir(); private File target = null;
File data = new File("depdata");
data.mkdir(); DeploymentService service = null;
File target = new File("target");
target.mkdir();
try @Override
{ protected void setUp() throws Exception
@SuppressWarnings("unused") {
FileSystemXmlApplicationContext receiverContext = super.setUp();
new FileSystemXmlApplicationContext("../deployment/config/application-context.xml"); log = new File("deplog");
DeploymentService service = (DeploymentService)fContext.getBean("DeploymentService"); log.mkdir();
NameMatcher matcher = (NameMatcher)fContext.getBean("globalPathExcluder"); metadata = new File("depmetadata");
setupBasicTree(); metadata.mkdir();
fService.createFile("main:/a/b", "fudge.bak").close(); data = new File("depdata");
DeploymentReport report = new DeploymentReport(); data.mkdir();
List<DeploymentCallback> callbacks = new ArrayList<DeploymentCallback>(); target = new File("target");
callbacks.add(new DeploymentReportCallback(report)); target.mkdir();
/** /**
* do our first deployment - should deploy the basic tree defined above * Start the FSR
*/ */
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", matcher, false, false, false, callbacks); @SuppressWarnings("unused")
int count = 0; FileSystemXmlApplicationContext receiverContext =
for (DeploymentEvent event : report) new FileSystemXmlApplicationContext("../deployment/config/application-context.xml");
{
System.out.println(event); service = (DeploymentService)fContext.getBean("DeploymentService");
count++; }
}
assertEquals(10, count); protected void tearDown() throws Exception
{
/** super.tearDown();
* Now do the same deployment again - should just get start and end events.
*/ if(log != null)
report = new DeploymentReport(); {
callbacks = new ArrayList<DeploymentCallback>(); Deleter.Delete(log);
callbacks.add(new DeploymentReportCallback(report)); }
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", matcher, false, false, false, callbacks); if(data != null)
count = 0; {
for (DeploymentEvent event : report) Deleter.Delete(data);
{ }
System.out.println(event); if(metadata != null)
count++; {
} Deleter.Delete(metadata);
assertEquals(2, count); }
if(target != null)
/** {
* Now create a new dir and file and remove Deleter.Delete(target);
*/ }
fService.createFile("main:/d", "jonathan").close();
fService.removeNode("main:/a/b"); File dot = new File(".");
String[] listing = dot.list();
report = new DeploymentReport(); for (String name : listing)
callbacks = new ArrayList<DeploymentCallback>(); {
callbacks.add(new DeploymentReportCallback(report)); if (name.startsWith("dep-record-"))
{
File file = new File(name);
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", matcher, false, false, false, callbacks); file.delete();
count = 0; }
for (DeploymentEvent event : report) }
{ }
System.out.println(event);
count++; public void testBasic()
} throws Exception
assertEquals(4, count); {
/** NameMatcher matcher = (NameMatcher)fContext.getBean("globalPathExcluder");
* Create a single file setupBasicTree();
*/
fService.removeNode("main:/d/e"); /*
fService.createFile("main:/d", "e").close(); BasicTree has the following format
"main:/", "a"
report = new DeploymentReport(); "main:/a", "b"
callbacks = new ArrayList<DeploymentCallback>(); "main:/a/b", "c"
callbacks.add(new DeploymentReportCallback(report)); "main:/", "d"
"main:/d", "e"
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", matcher, false, false, false, callbacks); "main:/d/e", "f"
count = 0; "main:/a/b/c", "foo").close()
for (DeploymentEvent event : report) "main:/a/b/c", "bar").close()
{ "main:/a/b", "fudge.bak").close()
System.out.println(event); */
count++;
} fService.createFile("main:/a/b", "fudge.bak").close();
assertEquals(3, count); DeploymentReport report = new DeploymentReport();
List<DeploymentCallback> callbacks = new ArrayList<DeploymentCallback>();
/** callbacks.add(new DeploymentReportCallback(report));
* Create a few files
*/ /**
fService.removeNode("main:/d/e"); * Do our first deployment - should deploy the basic tree defined above
fService.createDirectory("main:/d", "e"); * fudge.bak should be excluded due to the matcher.
fService.createFile("main:/d/e", "Warren.txt").close(); */
fService.createFile("main:/d/e", "It's a silly name.txt").close(); service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", matcher, false, false, false, callbacks);
report = new DeploymentReport(); Set<DeploymentEvent> firstDeployment = new HashSet<DeploymentEvent>();
callbacks = new ArrayList<DeploymentCallback>(); firstDeployment.addAll(report.getEvents());
callbacks.add(new DeploymentReportCallback(report)); assertTrue("first deployment no start", firstDeployment.contains(new DeploymentEvent(DeploymentEvent.Type.START, null, "sampleTarget")));
assertTrue("first deployment no finish", firstDeployment.contains(new DeploymentEvent(DeploymentEvent.Type.END, null, "sampleTarget")));
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", matcher, false, false, false, callbacks); assertTrue("first deployment wrong size", firstDeployment.size() == 10);
count = 0; assertTrue("Update missing: /a", firstDeployment.contains(new DeploymentEvent(DeploymentEvent.Type.COPIED, null, "/a")));
for (DeploymentEvent event : report) assertTrue("Update missing: /a/b", firstDeployment.contains(new DeploymentEvent(DeploymentEvent.Type.COPIED, null, "/a/b")));
{ assertTrue("Update missing: /a/b/c", firstDeployment.contains(new DeploymentEvent(DeploymentEvent.Type.COPIED, null, "/a/b/c")));
System.out.println(event); assertTrue("Update missing: /d/e", firstDeployment.contains(new DeploymentEvent(DeploymentEvent.Type.COPIED, null, "/d/e")));
count++; assertTrue("Update missing: /a/b/c/foo", firstDeployment.contains(new DeploymentEvent(DeploymentEvent.Type.COPIED, null, "/a/b/c/foo")));
} assertTrue("Update missing: /a/b/c/bar", firstDeployment.contains(new DeploymentEvent(DeploymentEvent.Type.COPIED, null, "/a/b/c/bar")));
assertEquals(5, count);
for (DeploymentEvent event : report)
/** {
* Now load a large number of files. System.out.println(event);
* Do a deployment - should load successfully }
*
* Remove a node /**
* Do a deployment - should only see start and end events. * Now do the same deployment again - should just get start and end events.
*/ */
BulkLoader loader = new BulkLoader(); report = new DeploymentReport();
loader.setAvmService(fService); callbacks = new ArrayList<DeploymentCallback>();
loader.recursiveLoad("source/java/org/alfresco/repo/avm", "main:/"); callbacks.add(new DeploymentReportCallback(report));
report = new DeploymentReport(); service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", matcher, false, false, false, callbacks);
callbacks = new ArrayList<DeploymentCallback>(); int count = 0;
callbacks.add(new DeploymentReportCallback(report)); for (DeploymentEvent event : report)
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", matcher, false, false, false, callbacks); {
System.out.println(event);
fService.removeNode("main:/avm/hibernate"); count++;
fService.getFileOutputStream("main:/avm/AVMServiceTest.java").close(); }
report = new DeploymentReport(); assertEquals(2, count);
callbacks = new ArrayList<DeploymentCallback>();
callbacks.add(new DeploymentReportCallback(report)); /**
* now remove a single file in a deployment
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", matcher, false, false, false, callbacks); */
count = 0; fService.removeNode("main:/a/b/c", "bar");
for (DeploymentEvent event : report) report = new DeploymentReport();
{ callbacks = new ArrayList<DeploymentCallback>();
System.out.println(event); callbacks.add(new DeploymentReportCallback(report));
count++; service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", matcher, false, false, false, callbacks);
} count = 0;
assertEquals(4, count); for (DeploymentEvent event : report)
} {
finally System.out.println(event);
{ count++;
Deleter.Delete(log); }
Deleter.Delete(data); assertEquals(3, count);
Deleter.Delete(metadata);
Deleter.Delete(target); /**
File dot = new File("."); * Now create a new dir and file and remove a node in a single deployment
String[] listing = dot.list(); */
for (String name : listing) fService.createFile("main:/d", "jonathan").close();
{ fService.removeNode("main:/a/b");
if (name.startsWith("dep-record-"))
{ report = new DeploymentReport();
File file = new File(name); callbacks = new ArrayList<DeploymentCallback>();
file.delete(); callbacks.add(new DeploymentReportCallback(report));
}
}
} service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", matcher, false, false, false, callbacks);
} count = 0;
} for (DeploymentEvent event : report)
{
System.out.println(event);
count++;
}
assertEquals(4, count);
/**
* Replace a single directory with a file
*/
fService.removeNode("main:/d/e");
fService.createFile("main:/d", "e").close();
report = new DeploymentReport();
callbacks = new ArrayList<DeploymentCallback>();
callbacks.add(new DeploymentReportCallback(report));
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", matcher, false, false, false, callbacks);
count = 0;
for (DeploymentEvent event : report)
{
System.out.println(event);
count++;
}
assertEquals(3, count);
/**
* Create a few files
*/
fService.removeNode("main:/d/e");
fService.createDirectory("main:/d", "e");
fService.createFile("main:/d/e", "Warren.txt").close();
fService.createFile("main:/d/e", "It's a silly name.txt").close();
report = new DeploymentReport();
callbacks = new ArrayList<DeploymentCallback>();
callbacks.add(new DeploymentReportCallback(report));
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", matcher, false, false, false, callbacks);
count = 0;
for (DeploymentEvent event : report)
{
System.out.println(event);
count++;
}
assertEquals(5, count);
/**
* Negative tests
* Wrong password
*/
try {
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Wrong!", "sampleTarget", matcher, false, false, false, callbacks);
fail("Wrong password should throw exception");
}
catch (AVMException de)
{
// pass
de.printStackTrace();
}
/**
* Negative tests
* Wrong target
*/
try {
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "crapTarget", matcher, false, false, false, callbacks);
fail("Wrong target should have thrown an exception");
}
catch (AVMException de)
{
// pass
}
}
/**
* Now do the same deployment again - without the matcher - should deploy fudge.bak
*/
public void testNoExclusionFilter() throws Exception
{
DeploymentReport report = new DeploymentReport();
List<DeploymentCallback> callbacks = new ArrayList<DeploymentCallback>();
callbacks.add(new DeploymentReportCallback(report));
report = new DeploymentReport();
callbacks = new ArrayList<DeploymentCallback>();
callbacks.add(new DeploymentReportCallback(report));
fService.createDirectory("main:/", "a");
fService.createDirectory("main:/a", "b");
fService.createFile("main:/a/b", "fudge.bak").close();
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", null, false, false, false, callbacks);
Set<DeploymentEvent> smallUpdate = new HashSet<DeploymentEvent>();
smallUpdate.addAll(report.getEvents());
for (DeploymentEvent event : report)
{
System.out.println(event);
}
assertTrue("Update missing", smallUpdate.contains(new DeploymentEvent(DeploymentEvent.Type.COPIED, null, "/a/b/fudge.bak")));
assertEquals(5, smallUpdate.size());
}
/**
* Now load a large number of files.
* Do a deployment - should load successfully
*
* Remove a node and update a file
* Do a deployment - should only see start and end events and the two above.
*/
public void testBulkLoad() throws Exception
{
DeploymentReport report = new DeploymentReport();
List<DeploymentCallback> callbacks = new ArrayList<DeploymentCallback>();
callbacks.add(new DeploymentReportCallback(report));
BulkLoader loader = new BulkLoader();
loader.setAvmService(fService);
loader.recursiveLoad("source/java/org/alfresco/repo/avm", "main:/");
report = new DeploymentReport();
callbacks = new ArrayList<DeploymentCallback>();
callbacks.add(new DeploymentReportCallback(report));
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", null, false, false, false, callbacks);
Set<DeploymentEvent> bigUpdate = new HashSet<DeploymentEvent>();
bigUpdate.addAll(report.getEvents());
assertTrue("big update no start", bigUpdate.contains(new DeploymentEvent(DeploymentEvent.Type.START, null, "sampleTarget")));
assertTrue("big update no finish", bigUpdate.contains(new DeploymentEvent(DeploymentEvent.Type.END, null, "sampleTarget")));
assertTrue("big update too small", bigUpdate.size() > 100);
/**
* Now do a smaller update and check that just a few files update
*/
fService.removeNode("main:/avm/hibernate");
fService.getFileOutputStream("main:/avm/AVMServiceTest.java").close();
report = new DeploymentReport();
callbacks = new ArrayList<DeploymentCallback>();
callbacks.add(new DeploymentReportCallback(report));
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", null, false, false, false, callbacks);
Set<DeploymentEvent> smallUpdate = new HashSet<DeploymentEvent>();
smallUpdate.addAll(report.getEvents());
for (DeploymentEvent event : report)
{
System.out.println(event);
}
assertEquals(4, smallUpdate.size());
assertTrue("Start missing", smallUpdate.contains(new DeploymentEvent(DeploymentEvent.Type.START, null, "sampleTarget")));
assertTrue("End missing", smallUpdate.contains(new DeploymentEvent(DeploymentEvent.Type.DELETED, null, "/avm/hibernate")));
assertTrue("Update missing", smallUpdate.contains(new DeploymentEvent(DeploymentEvent.Type.UPDATED, null, "/avm/AVMServiceTest.java")));
assertTrue("Delete Missing", smallUpdate.contains(new DeploymentEvent(DeploymentEvent.Type.END, null, "sampleTarget")));
}
}

View File

@@ -123,4 +123,26 @@ public class DeploymentEvent implements Serializable
return str; return str;
} }
/**
*
*/
public int hashCode()
{
return (fType.toString() + fDestination).hashCode();
}
public boolean equals(Object obj)
{
if(obj instanceof DeploymentEvent)
{
DeploymentEvent other = (DeploymentEvent)obj;
if(this.getType() == other.getType() && this.getDestination().equals(other.getDestination()))
{
// objects are equal
return true;
}
}
return false;
}
} }

View File

@@ -75,4 +75,10 @@ public class DeploymentReport implements Serializable, Iterable<DeploymentEvent>
{ {
return fEvents.iterator(); return fEvents.iterator();
} }
public List<DeploymentEvent> getEvents()
{
return fEvents;
}
} }