mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -27,10 +27,13 @@ package org.alfresco.repo.deploy;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.alfresco.repo.avm.AVMServiceTestBase;
|
import org.alfresco.repo.avm.AVMServiceTestBase;
|
||||||
import org.alfresco.repo.avm.util.BulkLoader;
|
import org.alfresco.repo.avm.util.BulkLoader;
|
||||||
|
import org.alfresco.service.cmr.avm.AVMException;
|
||||||
import org.alfresco.service.cmr.avm.deploy.DeploymentCallback;
|
import org.alfresco.service.cmr.avm.deploy.DeploymentCallback;
|
||||||
import org.alfresco.service.cmr.avm.deploy.DeploymentEvent;
|
import org.alfresco.service.cmr.avm.deploy.DeploymentEvent;
|
||||||
import org.alfresco.service.cmr.avm.deploy.DeploymentReport;
|
import org.alfresco.service.cmr.avm.deploy.DeploymentReport;
|
||||||
@@ -41,38 +44,128 @@ import org.alfresco.util.NameMatcher;
|
|||||||
import org.springframework.context.support.FileSystemXmlApplicationContext;
|
import org.springframework.context.support.FileSystemXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of to filesystem deployment.
|
* End to end test of filesystem deployment.
|
||||||
* @author britt
|
* @author britt
|
||||||
*/
|
*/
|
||||||
public class FSDeploymentTest extends AVMServiceTestBase
|
public class FSDeploymentTest extends AVMServiceTestBase
|
||||||
{
|
{
|
||||||
|
private File log = null;
|
||||||
|
private File metadata = null;
|
||||||
|
private File data = null;
|
||||||
|
private File target = null;
|
||||||
|
|
||||||
|
DeploymentService service = null;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
log = new File("deplog");
|
||||||
|
log.mkdir();
|
||||||
|
metadata = new File("depmetadata");
|
||||||
|
metadata.mkdir();
|
||||||
|
data = new File("depdata");
|
||||||
|
data.mkdir();
|
||||||
|
target = new File("target");
|
||||||
|
target.mkdir();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the FSR
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
FileSystemXmlApplicationContext receiverContext =
|
||||||
|
new FileSystemXmlApplicationContext("../deployment/config/application-context.xml");
|
||||||
|
|
||||||
|
service = (DeploymentService)fContext.getBean("DeploymentService");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void tearDown() throws Exception
|
||||||
|
{
|
||||||
|
super.tearDown();
|
||||||
|
|
||||||
|
if(log != null)
|
||||||
|
{
|
||||||
|
Deleter.Delete(log);
|
||||||
|
}
|
||||||
|
if(data != null)
|
||||||
|
{
|
||||||
|
Deleter.Delete(data);
|
||||||
|
}
|
||||||
|
if(metadata != null)
|
||||||
|
{
|
||||||
|
Deleter.Delete(metadata);
|
||||||
|
}
|
||||||
|
if(target != null)
|
||||||
|
{
|
||||||
|
Deleter.Delete(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
File dot = new File(".");
|
||||||
|
String[] listing = dot.list();
|
||||||
|
for (String name : listing)
|
||||||
|
{
|
||||||
|
if (name.startsWith("dep-record-"))
|
||||||
|
{
|
||||||
|
File file = new File(name);
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testBasic()
|
public void testBasic()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
File log = new File("deplog");
|
|
||||||
log.mkdir();
|
|
||||||
File metadata = new File("depmetadata");
|
|
||||||
metadata.mkdir();
|
|
||||||
File data = new File("depdata");
|
|
||||||
data.mkdir();
|
|
||||||
File target = new File("target");
|
|
||||||
target.mkdir();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
FileSystemXmlApplicationContext receiverContext =
|
|
||||||
new FileSystemXmlApplicationContext("../deployment/config/application-context.xml");
|
|
||||||
DeploymentService service = (DeploymentService)fContext.getBean("DeploymentService");
|
|
||||||
NameMatcher matcher = (NameMatcher)fContext.getBean("globalPathExcluder");
|
NameMatcher matcher = (NameMatcher)fContext.getBean("globalPathExcluder");
|
||||||
setupBasicTree();
|
setupBasicTree();
|
||||||
|
|
||||||
|
/*
|
||||||
|
BasicTree has the following format
|
||||||
|
"main:/", "a"
|
||||||
|
"main:/a", "b"
|
||||||
|
"main:/a/b", "c"
|
||||||
|
"main:/", "d"
|
||||||
|
"main:/d", "e"
|
||||||
|
"main:/d/e", "f"
|
||||||
|
"main:/a/b/c", "foo").close()
|
||||||
|
"main:/a/b/c", "bar").close()
|
||||||
|
"main:/a/b", "fudge.bak").close()
|
||||||
|
*/
|
||||||
|
|
||||||
fService.createFile("main:/a/b", "fudge.bak").close();
|
fService.createFile("main:/a/b", "fudge.bak").close();
|
||||||
DeploymentReport report = new DeploymentReport();
|
DeploymentReport report = new DeploymentReport();
|
||||||
List<DeploymentCallback> callbacks = new ArrayList<DeploymentCallback>();
|
List<DeploymentCallback> callbacks = new ArrayList<DeploymentCallback>();
|
||||||
callbacks.add(new DeploymentReportCallback(report));
|
callbacks.add(new DeploymentReportCallback(report));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* do our first deployment - should deploy the basic tree defined above
|
* Do our first deployment - should deploy the basic tree defined above
|
||||||
|
* fudge.bak should be excluded due to the matcher.
|
||||||
*/
|
*/
|
||||||
|
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", matcher, false, false, false, callbacks);
|
||||||
|
Set<DeploymentEvent> firstDeployment = new HashSet<DeploymentEvent>();
|
||||||
|
firstDeployment.addAll(report.getEvents());
|
||||||
|
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")));
|
||||||
|
assertTrue("first deployment wrong size", firstDeployment.size() == 10);
|
||||||
|
assertTrue("Update missing: /a", firstDeployment.contains(new DeploymentEvent(DeploymentEvent.Type.COPIED, null, "/a")));
|
||||||
|
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")));
|
||||||
|
assertTrue("Update missing: /d/e", firstDeployment.contains(new DeploymentEvent(DeploymentEvent.Type.COPIED, null, "/d/e")));
|
||||||
|
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")));
|
||||||
|
|
||||||
|
for (DeploymentEvent event : report)
|
||||||
|
{
|
||||||
|
System.out.println(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Now do the same deployment again - should just get start and end events.
|
||||||
|
*/
|
||||||
|
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);
|
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Watcher", "sampleTarget", matcher, false, false, false, callbacks);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (DeploymentEvent event : report)
|
for (DeploymentEvent event : report)
|
||||||
@@ -80,11 +173,12 @@ public class FSDeploymentTest extends AVMServiceTestBase
|
|||||||
System.out.println(event);
|
System.out.println(event);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
assertEquals(10, count);
|
assertEquals(2, count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Now do the same deployment again - should just get start and end events.
|
* now remove a single file in a deployment
|
||||||
*/
|
*/
|
||||||
|
fService.removeNode("main:/a/b/c", "bar");
|
||||||
report = new DeploymentReport();
|
report = new DeploymentReport();
|
||||||
callbacks = new ArrayList<DeploymentCallback>();
|
callbacks = new ArrayList<DeploymentCallback>();
|
||||||
callbacks.add(new DeploymentReportCallback(report));
|
callbacks.add(new DeploymentReportCallback(report));
|
||||||
@@ -95,10 +189,10 @@ public class FSDeploymentTest extends AVMServiceTestBase
|
|||||||
System.out.println(event);
|
System.out.println(event);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
assertEquals(2, count);
|
assertEquals(3, count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Now create a new dir and file and remove
|
* Now create a new dir and file and remove a node in a single deployment
|
||||||
*/
|
*/
|
||||||
fService.createFile("main:/d", "jonathan").close();
|
fService.createFile("main:/d", "jonathan").close();
|
||||||
fService.removeNode("main:/a/b");
|
fService.removeNode("main:/a/b");
|
||||||
@@ -118,7 +212,7 @@ public class FSDeploymentTest extends AVMServiceTestBase
|
|||||||
assertEquals(4, count);
|
assertEquals(4, count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a single file
|
* Replace a single directory with a file
|
||||||
*/
|
*/
|
||||||
fService.removeNode("main:/d/e");
|
fService.removeNode("main:/d/e");
|
||||||
fService.createFile("main:/d", "e").close();
|
fService.createFile("main:/d", "e").close();
|
||||||
@@ -157,51 +251,110 @@ public class FSDeploymentTest extends AVMServiceTestBase
|
|||||||
assertEquals(5, count);
|
assertEquals(5, count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Now load a large number of files.
|
* Negative tests
|
||||||
* Do a deployment - should load successfully
|
* Wrong password
|
||||||
*
|
|
||||||
* Remove a node
|
|
||||||
* Do a deployment - should only see start and end events.
|
|
||||||
*/
|
*/
|
||||||
BulkLoader loader = new BulkLoader();
|
try {
|
||||||
loader.setAvmService(fService);
|
service.deployDifferenceFS(-1, "main:/", "default", "localhost", 44100, "Giles", "Wrong!", "sampleTarget", matcher, false, false, false, callbacks);
|
||||||
loader.recursiveLoad("source/java/org/alfresco/repo/avm", "main:/");
|
fail("Wrong password should throw exception");
|
||||||
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);
|
|
||||||
|
|
||||||
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", matcher, false, false, false, callbacks);
|
|
||||||
count = 0;
|
|
||||||
for (DeploymentEvent event : report)
|
|
||||||
{
|
|
||||||
System.out.println(event);
|
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
assertEquals(4, count);
|
catch (AVMException de)
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Deleter.Delete(log);
|
|
||||||
Deleter.Delete(data);
|
|
||||||
Deleter.Delete(metadata);
|
|
||||||
Deleter.Delete(target);
|
|
||||||
File dot = new File(".");
|
|
||||||
String[] listing = dot.list();
|
|
||||||
for (String name : listing)
|
|
||||||
{
|
{
|
||||||
if (name.startsWith("dep-record-"))
|
// pass
|
||||||
{
|
de.printStackTrace();
|
||||||
File file = new File(name);
|
|
||||||
file.delete();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* 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")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -75,4 +75,10 @@ public class DeploymentReport implements Serializable, Iterable<DeploymentEvent>
|
|||||||
{
|
{
|
||||||
return fEvents.iterator();
|
return fEvents.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<DeploymentEvent> getEvents()
|
||||||
|
{
|
||||||
|
return fEvents;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user