Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/cmdLineTests/shareClassTests/URLHelperTests/PartitioningTests/URLPartitioningStoreFindTest.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2005, 2020 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
package PartitioningTests;
23
24
import java.io.BufferedReader;
25
import java.io.FileInputStream;
26
import java.io.InputStreamReader;
27
import java.net.URL;
28
import java.util.Properties;
29
30
import CustomCLs.CustomPartitioningURLLoader;
31
import Utilities.StringManipulator;
32
import Utilities.URLClassPathCreator;
33
34
/**
35
* @author Matthew Kilner
36
*/
37
public class URLPartitioningStoreFindTest {
38
39
StringManipulator manipulator = new StringManipulator();
40
41
public static void main(String[] args) {
42
43
if(args.length != 2){
44
System.out.println("\n Incorrect usage");
45
System.out.println("\n Please specifiy -testfile <filename>");
46
}
47
48
URLPartitioningStoreFindTest test = new URLPartitioningStoreFindTest();
49
50
String testFile = args[1];
51
52
test.run(testFile);
53
}
54
55
private void run(String testFile){
56
57
Properties props = new Properties();
58
try{
59
FileInputStream PropertiesFile = new FileInputStream(testFile);
60
props.load(PropertiesFile);
61
62
PropertiesFile.close();
63
} catch (Exception e){
64
e.printStackTrace();
65
}
66
67
String numberOfUrlsString = props.getProperty("NumberOfUrls");
68
Integer tempNumberOfUrls = Integer.valueOf(numberOfUrlsString);
69
int numberOfUrls = tempNumberOfUrls.intValue();
70
71
int maxClassesToLoad = 0;
72
int maxClassesToFind = 0;
73
String[] urls = new String[numberOfUrls];
74
String [] partitionStrings = new String[numberOfUrls];
75
for(int index = 0; index < numberOfUrls; index++){
76
urls[index] = props.getProperty("Url"+index);
77
partitionStrings[index] = props.getProperty("Partition"+index);
78
String ctl = props.getProperty("NumberOfClassesToLoad"+index);
79
Integer intctl = Integer.valueOf(ctl);
80
maxClassesToLoad = ((intctl.intValue() > maxClassesToLoad) ? intctl.intValue() : maxClassesToLoad);
81
String ctf = props.getProperty("NumberOfClassesToFind"+index);
82
Integer intctf = Integer.valueOf(ctl);
83
maxClassesToFind = ((intctl.intValue() > maxClassesToFind) ? intctl.intValue() : maxClassesToFind);
84
}
85
86
String[][] classesToLoad = new String[numberOfUrls][maxClassesToLoad];
87
String[][] classesToFind = new String[numberOfUrls][maxClassesToFind];
88
String[][] results = new String[numberOfUrls][maxClassesToFind];
89
90
for(int urlIndex = 0; urlIndex < numberOfUrls; urlIndex++){
91
String loadClasses = props.getProperty("LoadClasses"+urlIndex);
92
String findClasses = props.getProperty("FindClasses"+urlIndex);
93
String result = props.getProperty("Results"+urlIndex);
94
String ctl = props.getProperty("NumberOfClassesToLoad"+urlIndex);
95
Integer intctl = Integer.valueOf(ctl);
96
int numberOfClassesToLoad = intctl.intValue();
97
String ctf = props.getProperty("NumberOfClassesToFind"+urlIndex);
98
Integer intctf = Integer.valueOf(ctl);
99
int numberOfClassesToFind = intctf.intValue();
100
for(int classToLoadIndex = 0; classToLoadIndex < numberOfClassesToLoad; classToLoadIndex++){
101
classesToLoad[urlIndex][classToLoadIndex] = manipulator.getStringElement(classToLoadIndex, loadClasses);
102
}
103
for(int classToFindIndex = 0; classToFindIndex < numberOfClassesToFind; classToFindIndex++){
104
classesToFind[urlIndex][classToFindIndex] = manipulator.getStringElement(classToFindIndex, findClasses);
105
results[urlIndex][classToFindIndex] = manipulator.getStringElement(classToFindIndex, result);
106
}
107
}
108
109
String batchFile = props.getProperty("BatchFileToRun");
110
111
boolean passed = runTest(urls, partitionStrings, classesToLoad, classesToFind, results, batchFile);
112
113
if(passed){
114
System.out.println("\nTEST PASSED");
115
} else {
116
System.out.println("\nTEST FAILED");
117
}
118
}
119
120
private boolean runTest(String[] urls, String[] partitionStrings, String[][] classesToLoad, String[][] classesToFind, String[][] results, String batchFile){
121
122
String urlsString = urls[0];
123
for(int index = 1; index < urls.length; index++){
124
urlsString = new StringBuffer(urls[index].length() + 1).append(urlsString).append(urls[index]).toString();
125
}
126
System.out.println("\n** urlsString: "+urlsString);
127
URLClassPathCreator creator = new URLClassPathCreator(urlsString);
128
URL[] urlPath;
129
urlPath = creator.createURLClassPath();
130
CustomPartitioningURLLoader cl = new CustomPartitioningURLLoader(urlPath, this.getClass().getClassLoader());
131
132
for(int urlIndex = 0; urlIndex < urls.length; urlIndex++){
133
for(int classIndex = 0; classIndex < classesToLoad[urlIndex].length; classIndex++){
134
String classToLoad = classesToLoad[urlIndex][classIndex];
135
if(classToLoad != null){
136
cl.setPartition(partitionStrings[urlIndex]);
137
cl.loadClassFrom(classToLoad, urlIndex);
138
}
139
}
140
}
141
142
if(0 != batchFile.length()){
143
runBatchFile(batchFile);
144
}
145
146
boolean result = true;
147
148
for(int urlIndex = 0; urlIndex < urls.length; urlIndex++){
149
cl.setPartition(partitionStrings[urlIndex]);
150
for(int classIndex = 0; classIndex < classesToFind[urlIndex].length; classIndex++){
151
String classToFind = classesToFind[urlIndex][classIndex];
152
String expectedResult = results[urlIndex][classIndex];
153
if(classToFind != null){
154
String testResult = String.valueOf(cl.isClassInSharedCache(urlIndex, classToFind));
155
if(!(expectedResult.equals(testResult))){
156
System.out.println("\nFailure finding class: "+classToFind+" on path: "+urls[urlIndex]+" which is index: "+urlIndex+" result: "+testResult+" expecting: "+expectedResult);
157
result = false;
158
}
159
}
160
}
161
}
162
return result;
163
}
164
165
private void runBatchFile(String batch){
166
System.out.println("\n** makeStale: "+batch);
167
String s = null;
168
try{
169
Process p = Runtime.getRuntime().exec(batch);
170
171
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
172
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
173
174
System.out.println("Here is the standard output of the command:\n");
175
while ((s = stdInput.readLine()) != null) {
176
System.out.println(s);
177
}
178
179
System.out.println("Here is the standard error of the command (if any):\n");
180
while ((s = stdError.readLine()) != null) {
181
System.out.println(s);
182
}
183
184
} catch (Exception e){
185
e.printStackTrace();
186
}
187
}
188
}
189
190