Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2c509dfb9631760076a2958e2f00270e785313ff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.tests.ccvs.ui.benchmark;

import java.io.*;

import junit.framework.Test;

import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
import org.eclipse.team.tests.ccvs.core.subscriber.SyncInfoSource;
import org.eclipse.team.tests.ccvs.ui.ModelParticipantSyncInfoSource;
import org.eclipse.team.tests.ccvs.ui.SubscriberParticipantSyncInfoSource;

/**
 * The test performed by this class is used to compare the performance of the old-style synchronization
 * and the model-based synchronization. It also performs an update to use as a baseline. 
 * <p>
 * The data used for the test is from bug 152581. The data used is the client/server
 * communication trace. This data is used to create and share a similar file structure.
 */
public class Bug152581Test extends BenchmarkTest {

	private static final String OLD_SYNCHRONIZE_GROUP_SUFFIX = "OldSynchronize";
	private static final String NEW_SYNCHRONIZE_GROUP_SUFFIX = "NewSynchronize";
	private static final String UPDATE_GROUP_SUFFIX = "Update";
	private static final String OLD_SYNCHRONIZE_GROUP_SUFFIX2 = "OldSynchronize2";
	private static final String NEW_SYNCHRONIZE_GROUP_SUFFIX2 = "NewSynchronize2";
	private static final String UPDATE_GROUP_SUFFIX2 = "Update2";
    private static final String[] PERFORMANCE_GROUPS = new String[] {OLD_SYNCHRONIZE_GROUP_SUFFIX, NEW_SYNCHRONIZE_GROUP_SUFFIX, UPDATE_GROUP_SUFFIX, OLD_SYNCHRONIZE_GROUP_SUFFIX2, NEW_SYNCHRONIZE_GROUP_SUFFIX2, UPDATE_GROUP_SUFFIX2};
    
	public Bug152581Test() {
		super();
	}

	public Bug152581Test(String name) {
		super(name);
	}

	public static Test suite() {
		return suite(Bug152581Test.class);
	}
	
	private void populateProject(BufferedReader reader, IProject project) throws IOException {
		String line;
		IContainer currentDir = null;
		while((line = reader.readLine()) != null) {
			if (line.startsWith("Directory")) {
				String path = line.substring(9).trim();
				currentDir = ensureFolderExists(project, path);
			} else if (line.startsWith("Unchanged")) {
				String filename = line.substring(9).trim();
				ensureFileExists(currentDir, filename);
			}
		}
	}
	
	private void ensureFileExists(IContainer currentDir, String filename) {
		if (filename.equals(".project") && currentDir.getType() == IResource.PROJECT)
			return;
		ensureExistsInWorkspace(currentDir.getFile(new Path(null,filename)), true);
	}

	public void ensureExistsInWorkspace(final IResource resource, final boolean local) {
		IWorkspaceRunnable body = new IWorkspaceRunnable() {
			public void run(IProgressMonitor monitor) throws CoreException {
				create(resource, local);
			}
		};
		try {
			getWorkspace().run(body, null);
		} catch (CoreException e) {
			if (!resource.exists())
				fail("#ensureExistsInWorkspace(IResource): " + resource.getFullPath(), e);
		}
	}
	
	private IContainer ensureFolderExists(IProject project, String path) {
		if (path.equals("."))
			return project;
		IFolder folder = project.getFolder(path);
		ensureExistsInWorkspace(folder,true);
		return folder;
	}

	private IProject createProject(String filename) throws IOException, CoreException {
		File file = BenchmarkTestSetup.getTestFile(filename + ".txt");
		InputStream content = getContents(file, "Could not read seed file " + filename + ".txt");
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(content));
			IProject project = getUniqueTestProject(filename);
			populateProject(reader, project);
			shareProject(project);
			// Perform an update to prune any empty directories
			updateProject(project, null, false);
			return project;
		} finally {
			content.close();
		}
	}
	
	public void testCase1() throws IOException, CoreException {
		openEmptyPerspective();
		IProject project = createProject("bug152581case1");
		IProject project2 = createProject("bug152581case2");
		setupGroups(PERFORMANCE_GROUPS, "Sync Tests", false);
		System.out.println("Here we go");
		for (int i = 0; i < 100; i++) {
			SyncInfoSource source = new SubscriberParticipantSyncInfoSource();
			startGroup(OLD_SYNCHRONIZE_GROUP_SUFFIX);
			syncResources(source, source.createWorkspaceSubscriber(), new IResource[] { project });
			endGroup();
			startGroup(OLD_SYNCHRONIZE_GROUP_SUFFIX2);
			syncResources(source, source.createWorkspaceSubscriber(), new IResource[] { project2 });
			endGroup();
			source = new ModelParticipantSyncInfoSource();
			startGroup(NEW_SYNCHRONIZE_GROUP_SUFFIX);
			syncResources(source, source.createWorkspaceSubscriber(), new IResource[] { project });
			endGroup();
			startGroup(NEW_SYNCHRONIZE_GROUP_SUFFIX2);
			syncResources(source, source.createWorkspaceSubscriber(), new IResource[] { project2 });
			endGroup();
			startGroup(UPDATE_GROUP_SUFFIX);
			updateResources(new IResource[] { project }, false);
			endGroup();
			startGroup(UPDATE_GROUP_SUFFIX2);
			updateResources(new IResource[] { project2 }, false);
			endGroup();
			System.out.println(i + 1);
		}
		commitGroups(false);
	}
}

Back to the top