当前位置: 首页>>代码示例>>Java>>正文


Java JavaSamplerContext类代码示例

本文整理汇总了Java中org.apache.jmeter.protocol.java.sampler.JavaSamplerContext的典型用法代码示例。如果您正苦于以下问题:Java JavaSamplerContext类的具体用法?Java JavaSamplerContext怎么用?Java JavaSamplerContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JavaSamplerContext类属于org.apache.jmeter.protocol.java.sampler包,在下文中一共展示了JavaSamplerContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupTest

import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入依赖的package包/类
/**
 * Do any initialization required by this client. In this case,
 * initialization consists of getting the value of the AWS region
 * and credentials parameters.
 *
 * @param context
 *            the context to run with. This provides access to
 *            initialization parameters.
 */
@Override
public void setupTest(JavaSamplerContext context) {
  apigatewayBaseUrl = context.getParameter("APIGATEWAY_BASE_URL");
  accessKeyId = context.getParameter("ACCESS_KEY_ID");
  secretKey = context.getParameter("SECRET_KEY");
  sessionToken = context.getParameter("SESSION_TOKEN");

  AWSCredentials awsCredentials = new BasicSessionCredentials(accessKeyId, secretKey,
      sessionToken);
  AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider(
      awsCredentials);

  String region = context.getParameter("REGION");
  client = Squash.builder().iamRegion(region)
      .iamCredentials((AWSCredentialsProvider) awsStaticCredentialsProvider).build();
  samplerName = context.getParameter(TestElement.NAME);
  bookingName = context.getParameter("BOOKING_NAME");
  court = context.getParameter("COURT");
  courtSpan = context.getParameter("COURTSPAN");
  slot = context.getParameter("SLOT");
  slotSpan = context.getParameter("SLOTSPAN");
  date = context.getParameter("DATE");
  putOrDelete = context.getParameter("PUT_OR_DELETE");
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:34,代码来源:SquashBookingApiCustomSampler.java

示例2: runTest

import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入依赖的package包/类
/**
 * For each sample request this method is invoked and will return success/failure result
 *
 * @param context
 * @return
 */
@Override
public SampleResult runTest(JavaSamplerContext context) {

    SampleResult sampleResult = new SampleResult();
    sampleResult.sampleStart();
    Object message = JMeterContextService.getContext().getVariables().getObject(placeHolder);

    try {

        ProducerRecord<String, Object> producerRecord = new ProducerRecord<String, Object>(topic, message);
        producer.send(producerRecord);
        sampleResult.setResponseData(message.toString(), StandardCharsets.UTF_8.name());
        sampleResult.setSuccessful(true);
        sampleResult.sampleEnd();

    } catch (Exception e) {
        log.error("Failed to send message", e);
        sampleResult.setResponseData(e.getMessage(), StandardCharsets.UTF_8.name());
        sampleResult.setSuccessful(false);
        sampleResult.sampleEnd();

    }

    return sampleResult;
}
 
开发者ID:GSLabDev,项目名称:pepper-box,代码行数:32,代码来源:PepperBoxKafkaSampler.java

示例3: setupTest

import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入依赖的package包/类
/**
 * This is executed once per instantiation of this class. Nothing specific to an
 * individual test run should appear in this method.
 *
 * @param context ignored
 */
@Override
public void setupTest(JavaSamplerContext context) {
	try {
		assertNotInterrupted();
		executing = true;
		super.setupTest(context);

		JMeterContext jmeterContext = JMeterContextService.getContext();
		AbstractThreadGroup threadGroup = jmeterContext.getThreadGroup();
		threadGroupName = threadGroup.getName();

		JMeterThread thread = jmeterContext.getThread();
		threadName = thread.getThreadName();

		String parameter = context.getParameter(PARAMETER, PARAMETER_DEFAULT).trim();
		boolean generatingJson = Boolean.valueOf(parameter);

		assertNotInterrupted();
		if (generatingJson) {
			marshaller = SpringPreProcessor.getBean(MartiniResultMarshaller.class);
		}
		eventManager = SpringPreProcessor.getBean(EventManager.class);
		suiteIdentifier = SpringPreProcessor.getBean(SuiteIdentifier.class);
	}
	finally {
		executing = false;
	}
}
 
开发者ID:qas-guru,项目名称:martini-jmeter-extension,代码行数:35,代码来源:MartiniSamplerClient.java

示例4: getLeakySpankContext

import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入依赖的package包/类
private LeakySpankContext getLeakySpankContext(JavaSamplerContext arg0) {
	LeakySpankContext leakySpankContext = threadLocal.get();		
	if (leakySpankContext==null) {
		long pid = arg0.getLongParameter(P_PID);
		int intervalInSeconds = arg0.getIntParameter(P_INTERVAL_IN_SECONDS, 15);
		int intervalCountPerWindow = arg0.getIntParameter(P_INTERVAL_COUNT_PER_WINDOW, 4);
		int topNSuspectsPerWindow = arg0.getIntParameter(P_TOP_N_SUSPECTS_PER_WINDOW, 2);
		leakySpankContext = new LeakySpankContext(
				pid,
				intervalInSeconds,
				intervalCountPerWindow,
				topNSuspectsPerWindow);
		
		threadLocal.set(leakySpankContext);
	}
		
	return leakySpankContext;
}
 
开发者ID:eostermueller,项目名称:heapSpank,代码行数:19,代码来源:LeakySpankSampler.java

示例5: setupTest

import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入依赖的package包/类
/**
 * Description of the Method
 *
 * @param samplerContext Description of the Parameter
 */
public void setupTest( JavaSamplerContext samplerContext )
{
    ctr = 0;
    if( StringUtils.isEmpty( userId ))
    {
        // Load userids are format:  loadtestuserN - where N is a number between 0 and 99.
        // i.e. loadtestuser0,  loadtestuser1,  ... loadtestuser99
        // N is threadid mod 100.
        key = getKey();
        userId = "loadtestuser" + key % 100;
    }
    String message = "FT SETUP CreateSession TID: " + getThreadId() + " UID: " + userId;
    LOG.info( message );
    System.out.println( message );
    try
    {
        accessMgr = AccessMgrFactory.createInstance( TestUtils.getContext() );
    }
    catch ( SecurityException se )
    {
        System.out.println( "ThreadId:" + getThreadId() + "FT SETUP Error: " + se );
        se.printStackTrace();
    }
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:30,代码来源:FortressCreateSession.java

示例6: teardownTest

import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入依赖的package包/类
@Override
public final void teardownTest(JavaSamplerContext context) {
	// we only need one teardown invocation
	if (teardownDone || os == null)
		return;
	teardownDone = true;

	log.debug("cleaning resources");

	try {
		// this method is executed from the JMeter main thread, this means we need to re-wire a token to instantiate
		// a lightweight client without re-authentication
		Access access = os.getAccess();
		os = OSFactory.clientFromAccess(access);

		// call the actual teardown
		teardown(context);
	} catch (Exception e) {
		log.error(e.getMessage(), e);
	}
}
 
开发者ID:savoirfairelinux,项目名称:jmeter-openstack,代码行数:22,代码来源:AbstractOpenstackSampler.java

示例7: setupTest

import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入依赖的package包/类
/**
 * Description of the Method
 *
 * @param samplerContext Description of the Parameter
 */
public void setupTest( JavaSamplerContext samplerContext )
{
    ctr = 0;
    if( StringUtils.isEmpty( userId ))
    {
        // Load userids are format:  loadtestuserN - where N is a number between 0 and 99.
        // i.e. loadtestuser0,  loadtestuser1,  ... loadtestuser99
        // N is threadid mod 100.
        key = getKey();
        userId = "loadtestuser" + key % 100;
    }
    String message = "AC SETUP CreateSession TID: " + getThreadId() + " UID: " + userId;
    LOG.info( message );
    System.out.println( message );
    try
    {
        accelMgr = AccelMgrFactory.createInstance( TestUtils.getContext() );
    }
    catch ( SecurityException se )
    {
        System.out.println( "ThreadId:" + getThreadId() + "FT SETUP Error: " + se );
        se.printStackTrace();
    }
}
 
开发者ID:apache,项目名称:directory-fortress-core,代码行数:30,代码来源:AccelCreateSession.java

示例8: runTest

import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入依赖的package包/类
@Override
public SampleResult runTest(JavaSamplerContext ctx)
{
   final SampleResult sampleResult = new SampleResult();
   sampleResult.sampleStart();

   try {
      performIteration(ep);
      sampleResult.setSuccessful(true);
   } catch (Exception e) {
      sampleResult.setSuccessful(false);
      sampleResult.setResponseMessage("Exception: " + e);
      StringWriter stringWriter = new StringWriter();
      e.printStackTrace(new PrintWriter(stringWriter));
      sampleResult.setResponseData(stringWriter.toString(), "UTF-8");
      sampleResult.setDataType(SampleResult.TEXT);
   } finally {
      sampleResult.sampleEnd();
   }

   return sampleResult;
}
 
开发者ID:jbossws,项目名称:jbossws-cxf,代码行数:23,代码来源:JAXWSBenchmark.java

示例9: runTest

import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入依赖的package包/类
public SampleResult runTest(JavaSamplerContext ctx) {
   	
       SampleResult result = new SampleResult();
       result.sampleStart(); // start stopwatch    	
       StringBuilder sb = new StringBuilder();
       try {
		performXslt(this.repos, sb);
		result.setResponseData(sb.toString(), "UTF-8");
		result.setSuccessful(true);
		result.setResponseCodeOK();
		result.sampleEnd();//time for all transformations
	} catch (TransformerException e) {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		e.printStackTrace(pw);
		result.setResponseData(sw.toString(), "UTF-8");
		result.setSuccessful(false);
	}
	return result;
}
 
开发者ID:eostermueller,项目名称:crazyFastXml,代码行数:21,代码来源:XsltSampler01.java

示例10: runTest

import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入依赖的package包/类
public SampleResult runTest(JavaSamplerContext ctx) {
 	
       SampleResult result = new SampleResult();
       result.sampleStart(); // start stopwatch    	
	String textResults = null;
       try {
		textResults = getXPathResults();
		result.setResponseData(textResults, "UTF-8");
		result.setSuccessful(true);
		result.setResponseCodeOK();
		result.sampleEnd();//time for all transformations
	} catch (Exception e) {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		e.printStackTrace(pw);
		result.setResponseData(sw.toString(), "UTF-8");
		result.setSuccessful(false);
	}
	return result;
}
 
开发者ID:eostermueller,项目名称:crazyFastXml,代码行数:21,代码来源:XPathSampler01.java

示例11: runTest

import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入依赖的package包/类
public SampleResult runTest(JavaSamplerContext ctx) {
   	
       SampleResult result = new SampleResult();
       result.sampleStart(); // start stopwatch    	
       try {
		parseXml(xml);
		result.setResponseData(formatResults(), "UTF-8");
		result.setSuccessful(true);
		result.setResponseCodeOK();
		result.sampleEnd();//time for all transformations
	} catch (Exception e) {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		e.printStackTrace(pw);
		result.setResponseData(sw.toString(), "UTF-8");
		result.setSuccessful(false);
	}
	return result;
}
 
开发者ID:eostermueller,项目名称:crazyFastXml,代码行数:20,代码来源:XmlParseSampler01.java

示例12: runTest

import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入依赖的package包/类
@Override
public SampleResult runTest(JavaSamplerContext context) {
    final SampleResult result = new SampleResult();
    result.sampleStart();
    try {
        writeDocumentIntoCacheWithNewData(extractParameters(context));
        result.sampleEnd();
        result.setSuccessful(true);
        result.setResponseOK();
    } catch (Exception e) {
        result.setResponseMessage(e.toString());
        result.sampleEnd();
        result.setSuccessful(false);
        getLogger().error("Error running test", e);
        result.setResponseMessage(e.toString());
    }

    return result;
}
 
开发者ID:Excelian,项目名称:Mache,代码行数:20,代码来源:WriteToCache.java

示例13: runTest

import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入依赖的package包/类
@Override
public SampleResult runTest(JavaSamplerContext context) {
    final SampleResult result = new SampleResult();
    result.sampleStart();

    try {
        readFromCache(extractParameters(context));
        result.sampleEnd();
        result.setSuccessful(true);
    } catch (Exception e) {
        result.sampleEnd();
        result.setSuccessful(false);
        getLogger().error("Error running test", e);
        result.setResponseMessage(e.toString());
    }

    return result;
}
 
开发者ID:Excelian,项目名称:Mache,代码行数:19,代码来源:ReadFromCache.java

示例14: setupTest

import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入依赖的package包/类
@Override
public void setupTest(JavaSamplerContext context) {
    getLogger().info(getClass().getName() + ".setupTest");

    final Map<String, String> mapParams = extractParameters(context);

    try {
        MongoDBProvisioner<String, MongoTestEntity> provisioner = mongodb()
                .withSeeds(new ServerAddress(mapParams.get("mongo.server.ip.address"), 27017))
                .withDatabase(mapParams.get("keyspace.name"))
                .withSchemaOptions(SchemaOptions.CREATE_SCHEMA_IF_NEEDED)
                .build();//
        db = provisioner.getCacheLoader(String.class, MongoTestEntity.class);
        db.create();// ensure we are connected and schema exists

    } catch (Exception e) {
        getLogger().error("Error connecting to mongo", e);
    }
}
 
开发者ID:Excelian,项目名称:Mache,代码行数:20,代码来源:WriteToDB.java

示例15: runTest

import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入依赖的package包/类
@Override
public SampleResult runTest(JavaSamplerContext context) {
    final SampleResult result = new SampleResult();
    result.sampleStart();
    try {
        writeDocumentToDbWithNewData(extractParameters(context));
        result.sampleEnd();
        result.setSuccessful(true);
    } catch (Exception e) {
        result.sampleEnd();
        result.setSuccessful(false);
        getLogger().error("Error running test", e);
        result.setResponseMessage(e.toString());
    }

    return result;
}
 
开发者ID:Excelian,项目名称:Mache,代码行数:18,代码来源:WriteToDB.java


注:本文中的org.apache.jmeter.protocol.java.sampler.JavaSamplerContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。