下面列出了org.testng.collections.Lists#newArrayList ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Apply the method interceptor (if applicable) to the list of methods.
*/
private ITestNGMethod[] intercept(ITestNGMethod[] methods) {
List<IMethodInstance> methodInstances = methodsToMethodInstances(Arrays.asList(methods));
// add built-in interceptor (PreserveOrderMethodInterceptor or InstanceOrderingMethodInterceptor at the end of the list
m_methodInterceptors.add(builtinInterceptor);
for (IMethodInterceptor m_methodInterceptor : m_methodInterceptors) {
methodInstances = m_methodInterceptor.intercept(methodInstances, this);
}
List<ITestNGMethod> result = Lists.newArrayList();
for (IMethodInstance imi : methodInstances) {
result.add(imi.getMethod());
}
//Since an interceptor is involved, we would need to ensure that the ClassMethodMap object is in sync with the
//output of the interceptor, else @AfterClass doesn't get executed at all when interceptors are involved.
//so let's update the current classMethodMap object with the list of methods obtained from the interceptor.
this.m_classMethodMap = new ClassMethodMap(result, null);
return result.toArray(new ITestNGMethod[result.size()]);
}
private static List<ITestNGMethod> sortMethods(boolean forTests,
List<ITestNGMethod> allMethods, IAnnotationFinder finder) {
List<ITestNGMethod> sl = Lists.newArrayList();
List<ITestNGMethod> pl = Lists.newArrayList();
ITestNGMethod[] allMethodsArray = allMethods.toArray(new ITestNGMethod[allMethods.size()]);
// Fix the method inheritance if these are @Configuration methods to make
// sure base classes are invoked before child classes if 'before' and the
// other way around if they are 'after'
if (!forTests && allMethodsArray.length > 0) {
ITestNGMethod m = allMethodsArray[0];
boolean before = m.isBeforeClassConfiguration()
|| m.isBeforeMethodConfiguration() || m.isBeforeSuiteConfiguration()
|| m.isBeforeTestConfiguration();
MethodInheritance.fixMethodInheritance(allMethodsArray, before);
}
topologicalSort(allMethodsArray, sl, pl);
List<ITestNGMethod> result = Lists.newArrayList();
result.addAll(sl);
result.addAll(pl);
return result;
}
private List<List<IMethodInstance>> createInstances(List<IMethodInstance> methodInstances) {
Map<Object, List<IMethodInstance>> map = Maps.newHashMap();
// MapList<IMethodInstance[], Object> map = new MapList<IMethodInstance[], Object>();
for (IMethodInstance imi : methodInstances) {
for (Object o : imi.getInstances()) {
System.out.println(o);
List<IMethodInstance> l = map.get(o);
if (l == null) {
l = Lists.newArrayList();
map.put(o, l);
}
l.add(imi);
}
// for (Object instance : imi.getInstances()) {
// map.put(imi, instance);
// }
}
// return map.getKeys();
// System.out.println(map);
return new ArrayList<List<IMethodInstance>>(map.values());
}
@Query
public Iterable<Sample> getSampleIds(long start, long end, boolean increment) {
List<Sample> samples = Lists.newArrayList();
if (increment) {
samples.add(new Sample(start + 1, end + 1));
} else {
samples.add(new Sample(start, end));
}
return samples;
}
@DataProvider
static Object[][] testCasesAll() {
List<Object[]> result = Lists.newArrayList();
result.addAll(Arrays.asList(testClasses()));
result.addAll(Arrays.asList(testInterfaces()));
return result.toArray(new Object[result.size()][]);
}
@DataProvider
static Object[][] testCasesAll() {
List<Object[]> result = Lists.newArrayList();
result.addAll(Arrays.asList(testClasses()));
result.addAll(Arrays.asList(testInterfaces()));
return result.toArray(new Object[result.size()][]);
}
@Test
public void testReplicationClient() throws Exception {
log.info("--- Starting ReplicatorTlsTest::testReplicationClient ---");
for (BrokerService ns : Lists.newArrayList(ns1, ns2, ns3)) {
ns.getReplicationClients().forEach((cluster, client) -> {
assertTrue(((PulsarClientImpl) client).getConfiguration().isUseTls());
assertEquals(((PulsarClientImpl) client).getConfiguration().getTlsTrustCertsFilePath(),
TLS_SERVER_CERT_FILE_PATH);
});
}
}
public boolean runMethodParallel() {
TestNG testNG = new TestNG();
List<String> suites = Lists.newArrayList();
suites.add(getProperty("user.dir") + PARALLEL_XML_LOCATION);
testNG.setTestSuites(suites);
testNG.run();
return testNG.hasFailure();
}
@DataProvider
static Object[][] testCasesAll() {
List<Object[]> result = Lists.newArrayList();
result.addAll(Arrays.asList(testClasses()));
result.addAll(Arrays.asList(testInterfaces()));
return result.toArray(new Object[result.size()][]);
}
@DataProvider
static Object[][] testCasesAll() {
List<Object[]> result = Lists.newArrayList();
result.addAll(Arrays.asList(testClasses()));
result.addAll(Arrays.asList(testInterfaces()));
return result.toArray(new Object[result.size()][]);
}
@DataProvider
static Object[][] testCasesAll() {
List<Object[]> result = Lists.newArrayList();
result.addAll(Arrays.asList(testClasses()));
result.addAll(Arrays.asList(testInterfaces()));
return result.toArray(new Object[result.size()][]);
}
@Test
@SuppressWarnings("unchecked")
public void testEncryptionOfArray()
throws SchemaConversionException, DataConversionException, IOException {
AvroStringFieldEncryptorConverter converter = new AvroStringFieldEncryptorConverter();
WorkUnitState wuState = new WorkUnitState();
wuState.getJobState().setProp("converter.fieldsToEncrypt", "favorite_quotes");
wuState.getJobState().setProp("converter.encrypt.algorithm", "insecure_shift");
converter.init(wuState);
GenericRecord inputRecord =
getRecordFromFile(getClass().getClassLoader().getResource("fieldPickInput_arrays.avro").getPath());
GenericArray origValues = (GenericArray) inputRecord.get("favorite_quotes");
for (int i = 0; i < origValues.size(); i++) {
origValues.set(i, origValues.get(i).toString());
}
Schema inputSchema = inputRecord.getSchema();
Schema outputSchema = converter.convertSchema(inputSchema, wuState);
Iterable<GenericRecord> recordIt = converter.convertRecord(outputSchema, inputRecord, wuState);
GenericRecord encryptedRecord = recordIt.iterator().next();
Assert.assertEquals(outputSchema, inputSchema);
GenericArray<String> encryptedVals = (GenericArray<String>) encryptedRecord.get("favorite_quotes");
List<String> decryptedValues = Lists.newArrayList();
for (String encryptedValue: encryptedVals) {
InsecureShiftCodec codec = new InsecureShiftCodec(Maps.<String, Object>newHashMap());
InputStream in =
codec.decodeInputStream(new ByteArrayInputStream(encryptedValue.getBytes(StandardCharsets.UTF_8)));
byte[] decryptedValue = new byte[in.available()];
in.read(decryptedValue);
decryptedValues.add(new String(decryptedValue, StandardCharsets.UTF_8));
}
Assert.assertEquals(decryptedValues, origValues);
}
@DataProvider
static Object[][] testCasesAll() {
List<Object[]> result = Lists.newArrayList();
result.addAll(Arrays.asList(testClasses()));
result.addAll(Arrays.asList(testInterfaces()));
return result.toArray(new Object[result.size()][]);
}
@Override
public Collection<Config> getWorkerConfigs() {
Config rawConfig = super.getWorkerConfigs().iterator().next();
Config workerConfig = ConfigFactory.parseMap(ImmutableMap.of(GobblinClusterConfigurationKeys.TASK_RUNNER_SUITE_BUILDER, "TestJobFactorySuiteBuilder"))
.withFallback(rawConfig);
return Lists.newArrayList(workerConfig);
}
/**
* Extracts the unique list of <code>ITestNGMethod</code>s.
*/
public static List<ITestNGMethod> uniqueMethodList(Collection<List<ITestNGMethod>> methods) {
Set<ITestNGMethod> resultSet = Sets.newHashSet();
for (List<ITestNGMethod> l : methods) {
resultSet.addAll(l);
}
return Lists.newArrayList(resultSet);
}
@DataProvider
static Object[][] testCasesAll() {
List<Object[]> result = Lists.newArrayList();
result.addAll(Arrays.asList(testClasses()));
result.addAll(Arrays.asList(testInterfaces()));
return result.toArray(new Object[result.size()][]);
}
@Override
public ZkHelixPropertyStore<ZNRecord> getHelixPropertyStore() {
// TODO Auto-generated method stub
return new ZkHelixPropertyStore<>(
(ZkBaseDataAccessor<ZNRecord>) _accessor.getBaseDataAccessor(), TaskConstants.REBALANCER_CONTEXT_ROOT, Lists.<String>newArrayList());
}
/**
* Finds TestNG methods that the specified TestNG method depends upon
* @param m TestNG method
* @param methods list of methods to search for depended upon methods
* @return list of methods that match the criteria
*/
protected static ITestNGMethod[] findDependedUponMethods(ITestNGMethod m,
ITestNGMethod[] methods)
{
String canonicalMethodName = calculateMethodCanonicalName(m);
List<ITestNGMethod> vResult = Lists.newArrayList();
String regexp = null;
for (String fullyQualifiedRegexp : m.getMethodsDependedUpon()) {
boolean foundAtLeastAMethod = false;
if (null != fullyQualifiedRegexp) {
// Escapes $ in regexps as it is not meant for end - line matching, but inner class matches.
regexp = fullyQualifiedRegexp.replace("$", "\\$");
boolean usePackage = regexp.indexOf('.') != -1;
Pattern pattern = Pattern.compile(regexp);
for (ITestNGMethod method : methods) {
ConstructorOrMethod thisMethod = method.getConstructorOrMethod();
String thisMethodName = thisMethod.getName();
String methodName = usePackage ?
calculateMethodCanonicalName(method)
: thisMethodName;
Pair<String, String> cacheKey = Pair.create(regexp, methodName);
Boolean match = MATCH_CACHE.get(cacheKey);
if (match == null) {
match = pattern.matcher(methodName).matches();
MATCH_CACHE.put(cacheKey, match);
}
if (match) {
vResult.add(method);
foundAtLeastAMethod = true;
}
}
}
if (!foundAtLeastAMethod) {
if (m.ignoreMissingDependencies()) {
continue;
}
if (m.isAlwaysRun()) {
continue;
}
Method maybeReferringTo = findMethodByName(m, regexp);
if (maybeReferringTo != null) {
throw new TestNGException(canonicalMethodName + "() is depending on method "
+ maybeReferringTo + ", which is not annotated with @Test or not included.");
}
throw new TestNGException(canonicalMethodName
+ "() depends on nonexistent method " + regexp);
}
}//end for
return vResult.toArray(new ITestNGMethod[vResult.size()]);
}
@Test
public void testSimulation() throws Exception
{
final int threadQty = 20;
final int executionQty = 50;
final AtomicInteger optimisticTries = new AtomicInteger();
final AtomicInteger promotedLockTries = new AtomicInteger();
final AtomicInteger failures = new AtomicInteger();
final AtomicInteger errors = new AtomicInteger();
final SummaryStatistics timingStats = new SynchronizedSummaryStatistics();
List<Future<Void>> procs = Lists.newArrayList();
ExecutorService executorService = Executors.newFixedThreadPool(threadQty);
for ( int i = 0; i < threadQty; ++i )
{
Callable<Void> proc = new Callable<Void>()
{
@Override
public Void call() throws Exception
{
doSimulation(executionQty, timingStats, optimisticTries, promotedLockTries, failures, errors);
return null;
}
};
procs.add(executorService.submit(proc));
}
for ( Future<Void> f : procs )
{
f.get();
}
System.out.println("OptimisticTries: " + optimisticTries.get());
System.out.println("PromotedLockTries: " + promotedLockTries.get());
System.out.println("Failures: " + failures.get());
System.out.println("Errors: " + errors.get());
System.out.println();
System.out.println("Avg time: " + timingStats.getMean());
System.out.println("Max time: " + timingStats.getMax());
System.out.println("Min time: " + timingStats.getMin());
System.out.println("Qty: " + timingStats.getN());
Assert.assertEquals(errors.get(), 0);
Assert.assertTrue(optimisticTries.get() > 0);
Assert.assertTrue(promotedLockTries.get() > 0);
}
@Query
public Iterable<Sample> getSampleIds(Long start, Long end) {
List<Sample> samples = Lists.newArrayList();
samples.add(new Sample(start, end));
return samples;
}