public void testExecuteMatrixProject() throws Exception {
//turn off run listener
RunListener listener = RunListener.all().get(DiskUsageBuildListener.class);
jenkins.getExtensionList(RunListener.class).remove(listener);
jenkins.setNumExecutors(0);
Slave slave1 = createSlave("slave1", new File(hudson.getRootDir(),"workspace1").getPath());
AxisList axes = new AxisList();
TextAxis axis1 = new TextAxis("axis","axis1 axis2 axis3");
axes.add(axis1);
MatrixProject project1 = createMatrixProject("project1");
project1.setAxes(axes);
project1.setAssignedNode(slave1);
buildAndAssertSuccess(project1);
MatrixProject project2 = createMatrixProject("project2");
AxisList axes2 = new AxisList();
TextAxis axis2 = new TextAxis("axis","axis1 axis2");
axes2.add(axis2);
project2.setAxes(axes2);
project2.setAssignedNode(slave1);
buildAndAssertSuccess(project2);
Slave slave2 = createSlave("slave2", new File(hudson.getRootDir(),"workspace2").getPath());
slave1.toComputer().setTemporarilyOffline(true, null);
project1.setAssignedNode(slave2);
buildAndAssertSuccess(project1);
WorkspaceDiskUsageCalculationThread thread = new WorkspaceDiskUsageCalculationThread();
if(thread.isExecuting()){
waitUntilThreadEnds(thread);
}
thread.execute(TaskListener.NULL);
waitUntilThreadEnds(thread);
slave1.toComputer().setTemporarilyOffline(false, null);
//project 1
File file = new File(slave1.getWorkspaceFor(project1).getRemote(), "fileList");
File fileAxis1 = new File(slave1.getWorkspaceFor(project1).getRemote()+"/axis/axis1", "fileList");
File fileAxis2 = new File(slave1.getWorkspaceFor(project1).getRemote()+"/axis/axis2", "fileList");
File fileAxis3 = new File(slave1.getWorkspaceFor(project1).getRemote()+"/axis/axis3", "fileList");
Long size = getSize(readFileList(file)) + slave1.getWorkspaceFor(project1).length();
Long sizeAxis1 = getSize(readFileList(fileAxis1)) + new File(slave1.getWorkspaceFor(project1).getRemote()+"/axis/axis1").length();
Long sizeAxis2 = getSize(readFileList(fileAxis2)) + new File(slave1.getWorkspaceFor(project1).getRemote()+"/axis/axis2").length();
Long sizeAxis3 = getSize(readFileList(fileAxis3)) + new File(slave1.getWorkspaceFor(project1).getRemote()+"/axis/axis3").length();
file = new File(slave2.getWorkspaceFor(project1).getRemote(), "fileList");
fileAxis1 = new File(slave2.getWorkspaceFor(project1).getRemote()+"/axis/axis1", "fileList");
fileAxis2 = new File(slave2.getWorkspaceFor(project1).getRemote()+"/axis/axis2", "fileList");
fileAxis3 = new File(slave2.getWorkspaceFor(project1).getRemote()+"/axis/axis3", "fileList");
size += getSize(readFileList(file)) + slave2.getWorkspaceFor(project1).length();
sizeAxis1 += getSize(readFileList(fileAxis1)) + new File(slave2.getWorkspaceFor(project1).getRemote()+"/axis/axis1").length();
sizeAxis2 += getSize(readFileList(fileAxis2)) + new File(slave2.getWorkspaceFor(project1).getRemote()+"/axis/axis2").length();
sizeAxis3 += getSize(readFileList(fileAxis3)) + new File(slave2.getWorkspaceFor(project1).getRemote()+"/axis/axis3").length();
Assert.assertEquals("Calculation of matrix job workspace disk usage does not return right size.", size, project1.getAction(ProjectDiskUsageAction.class).getDiskUsageWorkspace());
//configurations
Assert.assertEquals("Calculation of matrix configuration workspace disk usage does not return right size.", sizeAxis1, project1.getItem("axis=axis1").getAction(ProjectDiskUsageAction.class).getDiskUsageWorkspace());
Assert.assertEquals("Calculation of matrix configuration workspace disk usage does not return right size.", sizeAxis2, project1.getItem("axis=axis2").getAction(ProjectDiskUsageAction.class).getDiskUsageWorkspace());
Assert.assertEquals("Calculation of matrix configuration workspace disk usage does not return right size.", sizeAxis3, project1.getItem("axis=axis3").getAction(ProjectDiskUsageAction.class).getDiskUsageWorkspace());