Java Code Examples for org.apache.jmeter.protocol.java.sampler.JavaSamplerContext#getParameter()

The following examples show how to use org.apache.jmeter.protocol.java.sampler.JavaSamplerContext#getParameter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WeEventConsumer.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
@Override
public void setupTest(JavaSamplerContext context) {
    super.setupTest(context);
    getNewLogger().info("this is consumer setupTest");
    super.setupTest(context);
    try {
        this.defaultUrl = context.getParameter("url") == null ? this.defaultUrl : context.getParameter("url");

        this.topic = context.getParameter("topic") == null ? this.topic : context.getParameter("topic");
        this.groupId = context.getParameter("groupId") == null ? WeEvent.DEFAULT_GROUP_ID : context.getParameter("groupId");
        this.weEventClient = IWeEventClient.builder().brokerUrl(defaultUrl).groupId(this.groupId).build();
        getNewLogger().info("weEventClient:{}", this.weEventClient);
        boolean result = this.weEventClient.open(this.topic);
        getNewLogger().info("open topic result: {}", result);
    } catch (BrokerException e) {
        getNewLogger().error("open ClientException", e);
    }
}
 
Example 2
Source File: KafkaProducerSampler.java    From kafkameter with Apache License 2.0 6 votes vote down vote up
@Override
public SampleResult runTest(JavaSamplerContext context) {
  SampleResult result = newSampleResult();
  String topic = context.getParameter(PARAMETER_KAFKA_TOPIC);
  String key = context.getParameter(PARAMETER_KAFKA_KEY);
  String message = context.getParameter(PARAMETER_KAFKA_MESSAGE);
  sampleResultStart(result, message);

  final ProducerRecord<String, String> producerRecord;
  String partitionString = context.getParameter(PARAMETER_KAFKA_PARTITION);
  if (Strings.isNullOrEmpty(partitionString)) {
    producerRecord = new ProducerRecord<String, String>(topic, key, message);
  } else {
    final int partitionNumber = Integer.parseInt(partitionString);
    producerRecord = new ProducerRecord<String, String>(topic, partitionNumber, key, message);
  }

  try {
    producer.send(producerRecord);
    sampleResultSuccess(result, null);
  } catch (Exception e) {
    sampleResultFailed(result, "500", e);
  }
  return result;
}
 
Example 3
Source File: KafkaProducerSampler.java    From kafkameter with Apache License 2.0 6 votes vote down vote up
@Override
public void setupTest(JavaSamplerContext context) {
  Properties props = new Properties();

  props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, context.getParameter(PARAMETER_KAFKA_BROKERS));
  props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, context.getParameter(PARAMETER_KAFKA_KEY_SERIALIZER));
  props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, context.getParameter(PARAMETER_KAFKA_MESSAGE_SERIALIZER));
  props.put(ProducerConfig.ACKS_CONFIG, "1");

  // check if kafka security protocol is SSL or PLAINTEXT (default)
  if(context.getParameter(PARAMETER_KAFKA_USE_SSL).equals("true")){
    log.info("Setting up SSL properties...");
    props.put("security.protocol", "SSL");
    props.put("ssl.keystore.location", context.getParameter(PARAMETER_KAFKA_SSL_KEYSTORE));
    props.put("ssl.keystore.password", context.getParameter(PARAMETER_KAFKA_SSL_KEYSTORE_PASSWORD));
    props.put("ssl.truststore.location", context.getParameter(PARAMETER_KAFKA_SSL_TRUSTSTORE));
    props.put("ssl.truststore.password", context.getParameter(PARAMETER_KAFKA_SSL_TRUSTSTORE_PASSWORD));
  }

  String compressionType = context.getParameter(PARAMETER_KAFKA_COMPRESSION_TYPE);
  if (!Strings.isNullOrEmpty(compressionType)) {
    props.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, compressionType);
  }

  producer = new KafkaProducer<String, String>(props);
}
 
Example 4
Source File: LicenseActivateCheckDeactivate.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SampleResult runTest(JavaSamplerContext context) {
	results = new SampleResult();
	results.sampleStart();

	licenseID = context.getParameter("LicenseID");
	hardwareCode = context.getParameter("HardwareCode");
	installCode = context.getParameter("InstallCode");
	waitTimeMillis = Integer.valueOf(context.getParameter("WaitSeconds")) * 1000;
	intervalTimeMillis = Integer.valueOf(context
			.getParameter("IntervalSeconds")) * 1000;
	strResult = licenseID + ":\n";
	startTime = System.currentTimeMillis();

	// 检查许可证状态,应为未激活,然后激活
	check(NextAction.ACTIVATE, "不通过");

	// 等待两次测试之间的间隔时间
	wait(intervalTimeMillis);

	pastTime = System.currentTimeMillis() - startTime - waitTimeMillis
			* waitCount - intervalTimeMillis;

	results.setResponseMessage(strResult + "\n实际耗时(毫秒):" + pastTime);
	results.sampleEnd();
	return results;
}
 
Example 5
Source File: LicenseActivateCheckDeactivate.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SampleResult runTest(JavaSamplerContext context) {
	results = new SampleResult();
	results.sampleStart();

	licenseID = context.getParameter("LicenseID");
	hardwareCode = context.getParameter("HardwareCode");
	installCode = context.getParameter("InstallCode");
	waitTimeMillis = Integer.valueOf(context.getParameter("WaitSeconds")) * 1000;
	intervalTimeMillis = Integer.valueOf(context
			.getParameter("IntervalSeconds")) * 1000;
	strResult = licenseID + ":\n";
	startTime = System.currentTimeMillis();

	// 检查许可证状态,应为未激活,然后激活
	check(NextAction.ACTIVATE, "不通过");

	// 等待两次测试之间的间隔时间
	wait(intervalTimeMillis);

	pastTime = System.currentTimeMillis() - startTime - waitTimeMillis
			* waitCount - intervalTimeMillis;

	results.setResponseMessage(strResult + "\n实际耗时(毫秒):" + pastTime);
	results.sampleEnd();
	return results;
}
 
Example 6
Source File: JMeterTest.java    From learning-hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void setupTest(JavaSamplerContext context) {
	super.setupTest(context);
	if (table == null) {
		String tableName = context.getParameter("tableName");
		byte[] tableNamebyte = tableName.getBytes();
		boolean autoFlush = Boolean.valueOf(context.getParameter("autoFlush"));
		long  writeBufferSize = Long.valueOf(context.getParameter("writeBufferSize"));
		int poolSize = Integer.parseInt(context.getParameter("poolSize"));
		try {
			table = JMeterHTablePool.getinstancePool(conf,poolSize,tableNamebyte,autoFlush,writeBufferSize).tablePool.getTable(tableName);
		} catch (Exception e) {
			System.out.println("htable pool error");
		}
	}
	if( methedType == null ){
		methedType = context.getParameter("putOrget");
	}
	if( keyNumLength == 0){
		keyNumLength = Integer.parseInt(context.getParameter("keyNumLength"));
	}
	if(cfs == null){
		String cf = context.getParameter("cf");
		cfs = cf.split(",");
	}
	if( qualifiers == null ){
		String qualifier = context.getParameter("qualifier");
		qualifiers = qualifier.split(",");
	}		
	if( values == null ){
		String valueLength = context.getParameter("valueLength");
		values = Strings.repeat('v', Integer.parseInt(valueLength));
	}
	if( writeToWAL == true ){
		writeToWAL = Boolean.valueOf(context.getParameter("writeToWAL"));
	}
}
 
Example 7
Source File: WeEventProducer.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
@Override
public void setupTest(JavaSamplerContext context) {
    getNewLogger().info("this is producer setupTest");
    super.setupTest(context);
    try {
        this.defaultUrl = context.getParameter("url") == null ? this.defaultUrl : context.getParameter("url");
        this.size = context.getIntParameter("size") <= 0 ? this.size : context.getIntParameter("size");
        this.topic = context.getParameter("topic") == null ? this.topic : context.getParameter("topic");
        this.format = context.getParameter("format") == null ? this.format : context.getParameter("format");
        this.groupId = context.getParameter("groupId") == null ? WeEvent.DEFAULT_GROUP_ID : context.getParameter("groupId");
        extensions.put(WeEvent.WeEvent_FORMAT, format);
        this.weEventClient = IWeEventClient.builder().brokerUrl(defaultUrl).groupId(this.groupId).build();
        getNewLogger().info("weEventClient:{}", this.weEventClient);

        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < size; i++) {
            buffer.append("a");
        }

        weEvent = new WeEvent(this.topic, buffer.toString().getBytes(), this.extensions);
        getNewLogger().info("weEvent:{}", weEvent);

        boolean result = this.weEventClient.open(this.topic);
        getNewLogger().info("open topic result: {}", result);
    } catch (BrokerException e) {
        getNewLogger().error("open ClientException", e);
    }
}
 
Example 8
Source File: TopicMessageGeneratorClient.java    From hedera-mirror-node with Apache License 2.0 5 votes vote down vote up
/**
 * Setup test by instantiating client using user defined test properties
 */
@Override
public void setupTest(JavaSamplerContext context) {
    host = context.getParameter("host", "localhost");
    port = context.getIntParameter("port", 5432);
    dbName = context.getParameter("dbName", "mirror_node");
    dbUser = context.getParameter("dbUser", "mirror_node");
    dbPassword = context.getParameter("dbPassword", "mirror_node_pass");

    super.setupTest(context);
}
 
Example 9
Source File: CheckAccess.java    From directory-fortress-core with Apache License 2.0 4 votes vote down vote up
/**
     * Description of the Method
     *
     * @param samplerContext Description of the Parameter
     */
    public void setupTest( JavaSamplerContext samplerContext )
    {
        ctr = 0;
        int numberOfUsers = 100;
        String szNumber = samplerContext.getParameter( "number" );
        if(StringUtils.isNotEmpty( szNumber ))
        {
            numberOfUsers = new Integer( szNumber );
        }

        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 % numberOfUsers;
        }
        try
        {
            String val = samplerContext.getParameter( "type" );
            System.out.println("PARAMETER VALUE = " + val);
            if(session == null)
            {
                String message;
                User user = new User(userId);
                // positive test case:
                user.setPassword( "secret" );
                if( StringUtils.isNotEmpty( val ) && val.equals( "1" ))
                {
                    message = "AC SETUP CreateSession, User: " + user.getUserId() + ", key: " + key + ", TID: " + getThreadId();
                    isFortress = false;

                    LOG.info( message );
                    System.out.println( message );

                    message = "ThreadId:" + getThreadId() + ", createSession user: " + user.getUserId();
                    LOG.info( message );
                    System.out.println( message );

                    accelMgr = AccelMgrFactory.createInstance( TestUtils.getContext() );
                    session = accelMgr.createSession( user, false );
                }
                else
                {
                    message = "FT SETUP CreateSession, User: " + user.getUserId() + ", key: " + key + ", TID: " + getThreadId();
                    isFortress = true;

                    LOG.info( message );
                    System.out.println( message );
                    message = "ThreadId:" + getThreadId() + ", createSession user: " + user.getUserId();
                    LOG.info( message );
                    System.out.println( message );

                    accessMgr = AccessMgrFactory.createInstance( TestUtils.getContext() );
                    session = accessMgr.createSession( user, false );
                }
/*
                if( StringUtils.isNotEmpty( val ) && val.equals( "1" ))
                {
                    message = "FT SETUP CreateSession, User: " + user.getUserId() + ", key: " + key + ", TID: " + getThreadId();
                    isFortress = true;
                    accessMgr = AccessMgrFactory.createInstance( TestUtils.getContext() );
                    session = accessMgr.createSession( user, false );
                }
                else
                {
                    message = "AC SETUP CreateSession, User: " + user.getUserId() + ", key: " + key + ", TID: " + getThreadId();
                    isFortress = false;
                    accelMgr = AccelMgrFactory.createInstance( TestUtils.getContext() );
                    session = accelMgr.createSession( user, false );
                }
*/
/*
                LOG.info( message );
                System.out.println( message );
*/
            }

            assertNotNull( session );
            assertTrue( session.isAuthenticated() );
        }
        catch ( SecurityException se )
        {
            String error = "ThreadId:" + getThreadId() + " Error starting test: " + se;
            System.out.println( error );
            LOG.error( error );
            se.printStackTrace();
            fail(error);
        }
    }
 
Example 10
Source File: SessionPermissions.java    From directory-fortress-core with Apache License 2.0 4 votes vote down vote up
/**
     * 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;
        }
        try
        {
            String val = samplerContext.getParameter( "type" );
            System.out.println("PARAMETER VALUE = " + val);
            if(session == null)
            {
                String message;
                User user = new User(userId);
                // positive test case:
                user.setPassword( "secret" );
                if( StringUtils.isNotEmpty( val ) && val.equals( "1" ))
                {
                    message = "AC SETUP CreateSession, User: " + user.getUserId() + ", key: " + key + ", TID: " + getThreadId();
                    isFortress = false;

                    LOG.info( message );
                    System.out.println( message );

                    message = "ThreadId:" + getThreadId() + ", createSession user: " + user.getUserId();
                    LOG.info( message );
                    System.out.println( message );

                    accelMgr = AccelMgrFactory.createInstance( TestUtils.getContext() );
                    session = accelMgr.createSession( user, false );
                }
                else
                {
                    message = "FT SETUP CreateSession, User: " + user.getUserId() + ", key: " + key + ", TID: " + getThreadId();
                    isFortress = true;

                    LOG.info( message );
                    System.out.println( message );
                    message = "ThreadId:" + getThreadId() + ", createSession user: " + user.getUserId();
                    LOG.info( message );
                    System.out.println( message );

                    accessMgr = AccessMgrFactory.createInstance( TestUtils.getContext() );
                    session = accessMgr.createSession( user, false );
                }
/*
                if( StringUtils.isNotEmpty( val ) && val.equals( "1" ))
                {
                    message = "FT SETUP CreateSession, User: " + user.getUserId() + ", key: " + key + ", TID: " + getThreadId();
                    isFortress = true;
                    accessMgr = AccessMgrFactory.createInstance( TestUtils.getContext() );
                    session = accessMgr.createSession( user, false );
                }
                else
                {
                    message = "AC SETUP CreateSession, User: " + user.getUserId() + ", key: " + key + ", TID: " + getThreadId();
                    isFortress = false;
                    accelMgr = AccelMgrFactory.createInstance( TestUtils.getContext() );
                    session = accelMgr.createSession( user, false );
                }
*/
/*
                LOG.info( message );
                System.out.println( message );
*/
            }

            assertNotNull( session );
            assertTrue( session.isAuthenticated() );
        }
        catch ( SecurityException se )
        {
            String error = "ThreadId:" + getThreadId() + " Error starting test: " + se;
            System.out.println( error );
            LOG.error( error );
            se.printStackTrace();
            fail(error);
        }
    }
 
Example 11
Source File: LicenseCheck.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public SampleResult runTest(JavaSamplerContext context) {
	SampleResult results = new SampleResult();
	results.sampleStart();

	String licenseID = context.getParameter("LicenseID");
	String hardwareCode = context.getParameter("HardwareCode");
	String installCode = context.getParameter("InstallCode");
	int intervalTime = Integer.valueOf(context
			.getParameter("IntervalSeconds")) * 1000;
	String strResult = licenseID + ":\n";
	long startTime = System.currentTimeMillis();

	// 验证许可证的激活状态
	try {
		String result = ServiceUtilTest.check(licenseID, hardwareCode,
				installCode);
		if (result.equals("Check Success")) {
			results.setSuccessful(true);
			results.setResponseCodeOK();
			strResult += "验证通过!\n";
		} else {
			results.setSuccessful(true);
			results.setResponseCodeOK();
			strResult += "验证未通过,返回结果为:" + result + "\n";
		}
	} catch (Exception e) {
		results.setSuccessful(false);
		strResult += "验证失败,异常信息:\n" + e.getMessage() + "\n";
	}

	// 等待两次测试之间的间隔
	if (intervalTime != 0) {
		try {
			Thread.sleep(intervalTime);
		} catch (InterruptedException e1) {
			e1.printStackTrace();
		}
	}

	long pastTime = System.currentTimeMillis() - startTime - intervalTime;

	results.setResponseMessage(strResult + "\n实际耗时(毫秒):" + pastTime);
	results.sampleEnd();
	return results;
}
 
Example 12
Source File: HbaseJMeter.java    From learning-hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public void setupTest(JavaSamplerContext context) {
  super.setupTest(context);
  String hbaseZK = context.getParameter("hbase.zookeeper.quorum");
  conf = HBaseConfiguration.create();
  conf.set("hbase.zookeeper.quorum", hbaseZK);
  conf.set("hbase.ipc.client.tcpnodelay", "true");
  conf.set("hbase.client.pause", "20");
  conf.set("ipc.ping.interval", "3000");
  conf.set("hbase.client.retries.number", "11");

  if (table == null) {
    String tableName = context.getParameter("tableName");
    byte[] tableNamebyte = tableName.getBytes();
    boolean autoFlush = Boolean.valueOf(context.getParameter("autoFlush"));
    long writeBufferSize = Long.valueOf(context.getParameter("writeBufferSize"));
    int poolSize = Integer.parseInt(context.getParameter("poolSize"));
    try {
      table =
          JMeterHTablePool.getinstancePool(conf, poolSize, tableNamebyte, autoFlush,
            writeBufferSize).tablePool.getTable(tableName);
    } catch (Exception e) {
      System.out.println("htable pool error");
    }
  }
  if (methedType == null) {
    methedType = context.getParameter("putOrget");
  }
  if (keyNumLength == 0) {
    keyNumLength = Integer.parseInt(context.getParameter("keyNumLength"));
  }
  if (cfs == null) {
    String cf = context.getParameter("cf");
    cfs = cf.split(",");
  }
  if (qualifiers == null) {
    String qualifier = context.getParameter("qualifier");
    qualifiers = qualifier.split(",");
  }
  if (values == null) {
    String valueLength = context.getParameter("valueLength");
    values = Strings.repeat('v', Integer.parseInt(valueLength));
  }
  if (writeToWAL == true) {
    writeToWAL = Boolean.valueOf(context.getParameter("writeToWAL"));
  }

  if (keyRondom == true) {
    keyRondom = Boolean.valueOf(context.getParameter("keyRondom"));
  }
}
 
Example 13
Source File: BlurSamplerClient.java    From incubator-retired-blur with Apache License 2.0 4 votes vote down vote up
@Override
public void setupTest(JavaSamplerContext context) {
  String zkConnectionString = context.getParameter("ZooKeeperConnection");
  _table = context.getParameter("Table");
  _client = BlurClient.getClientFromZooKeeperConnectionStr(zkConnectionString);
}
 
Example 14
Source File: PepperBoxKafkaSampler.java    From pepper-box with Apache License 2.0 4 votes vote down vote up
/**
 * Gets invoked exactly once  before thread starts
 *
 * @param context
 */
@Override
public void setupTest(JavaSamplerContext context) {

    Properties props = new Properties();

    props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, getBrokerServers(context));
    props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, context.getParameter(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG));
    props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, context.getParameter(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG));
    props.put(ProducerConfig.ACKS_CONFIG, context.getParameter(ProducerConfig.ACKS_CONFIG));
    props.put(ProducerConfig.SEND_BUFFER_CONFIG, context.getParameter(ProducerConfig.SEND_BUFFER_CONFIG));
    props.put(ProducerConfig.RECEIVE_BUFFER_CONFIG, context.getParameter(ProducerConfig.RECEIVE_BUFFER_CONFIG));
    props.put(ProducerConfig.BATCH_SIZE_CONFIG, context.getParameter(ProducerConfig.BATCH_SIZE_CONFIG));
    props.put(ProducerConfig.LINGER_MS_CONFIG, context.getParameter(ProducerConfig.LINGER_MS_CONFIG));
    props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, context.getParameter(ProducerConfig.BUFFER_MEMORY_CONFIG));
    props.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, context.getParameter(ProducerConfig.COMPRESSION_TYPE_CONFIG));
    props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, context.getParameter(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG));
    props.put(ProducerKeys.SASL_MECHANISM, context.getParameter(ProducerKeys.SASL_MECHANISM));

    Iterator<String> parameters = context.getParameterNamesIterator();
    parameters.forEachRemaining(parameter -> {
        if (parameter.startsWith("_")) {
            props.put(parameter.substring(1), context.getParameter(parameter));
        }
    });


    String sslEnabled = context.getParameter(ProducerKeys.SSL_ENABLED);

    if (sslEnabled != null && sslEnabled.equals(ProducerKeys.FLAG_YES)) {

        props.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, context.getParameter(SslConfigs.SSL_KEY_PASSWORD_CONFIG));
        props.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, context.getParameter(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG));
        props.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, context.getParameter(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG));
        props.put(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG,  context.getParameter(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG));
        props.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, context.getParameter(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG));
        props.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, context.getParameter(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG));
        props.put(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, context.getParameter(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG));
    }

    String kerberosEnabled = context.getParameter(ProducerKeys.KERBEROS_ENABLED);
    if (kerberosEnabled != null && kerberosEnabled.equals(ProducerKeys.FLAG_YES)) {
        System.setProperty(ProducerKeys.JAVA_SEC_AUTH_LOGIN_CONFIG, context.getParameter(ProducerKeys.JAVA_SEC_AUTH_LOGIN_CONFIG));
        System.setProperty(ProducerKeys.JAVA_SEC_KRB5_CONFIG, context.getParameter(ProducerKeys.JAVA_SEC_KRB5_CONFIG));
        props.put(ProducerKeys.SASL_KERBEROS_SERVICE_NAME, context.getParameter(ProducerKeys.SASL_KERBEROS_SERVICE_NAME));
    }

    if (context.getParameter(PropsKeys.KEYED_MESSAGE_KEY).equals("YES")) {
        key_message_flag= true;
        msg_key_placeHolder = context.getParameter(PropsKeys.MESSAGE_KEY_PLACEHOLDER_KEY);
    }
    msg_val_placeHolder = context.getParameter(PropsKeys.MESSAGE_VAL_PLACEHOLDER_KEY);
    topic = context.getParameter(ProducerKeys.KAFKA_TOPIC_CONFIG);
    producer = new KafkaProducer<String, Object>(props);

}
 
Example 15
Source File: PropertiesHandler.java    From hedera-mirror-node with Apache License 2.0 4 votes vote down vote up
public PropertiesHandler(JavaSamplerContext javaSamplerContext) {
    this.javaSamplerContext = javaSamplerContext;
    propertiesBase = javaSamplerContext.getParameter("propertiesBase", "hedera.mirror.test.performance");
}
 
Example 16
Source File: LicenseCheck.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public SampleResult runTest(JavaSamplerContext context) {
	SampleResult results = new SampleResult();
	results.sampleStart();

	String licenseID = context.getParameter("LicenseID");
	String hardwareCode = context.getParameter("HardwareCode");
	String installCode = context.getParameter("InstallCode");
	int intervalTime = Integer.valueOf(context
			.getParameter("IntervalSeconds")) * 1000;
	String strResult = licenseID + ":\n";
	long startTime = System.currentTimeMillis();

	// 验证许可证的激活状态
	try {
		String result = ServiceUtilTest.check(licenseID, hardwareCode,
				installCode);
		if (result.equals("Check Success")) {
			results.setSuccessful(true);
			results.setResponseCodeOK();
			strResult += "验证通过!\n";
		} else {
			results.setSuccessful(true);
			results.setResponseCodeOK();
			strResult += "验证未通过,返回结果为:" + result + "\n";
		}
	} catch (Exception e) {
		results.setSuccessful(false);
		strResult += "验证失败,异常信息:\n" + e.getMessage() + "\n";
	}

	// 等待两次测试之间的间隔
	if (intervalTime != 0) {
		try {
			Thread.sleep(intervalTime);
		} catch (InterruptedException e1) {
			e1.printStackTrace();
		}
	}

	long pastTime = System.currentTimeMillis() - startTime - intervalTime;

	results.setResponseMessage(strResult + "\n实际耗时(毫秒):" + pastTime);
	results.sampleEnd();
	return results;
}
 
Example 17
Source File: PepperBoxKafkaSampler.java    From pepper-box with Apache License 2.0 2 votes vote down vote up
private String getBrokerServers(JavaSamplerContext context) {

        StringBuilder kafkaBrokers = new StringBuilder();

        String zookeeperServers = context.getParameter(ProducerKeys.ZOOKEEPER_SERVERS);

        if (zookeeperServers != null && !zookeeperServers.equalsIgnoreCase(ProducerKeys.ZOOKEEPER_SERVERS_DEFAULT)) {

            try {

                ZooKeeper zk = new ZooKeeper(zookeeperServers, 10000, null);
                List<String> ids = zk.getChildren(PropsKeys.BROKER_IDS_ZK_PATH, false);

                for (String id : ids) {

                    String brokerInfo = new String(zk.getData(PropsKeys.BROKER_IDS_ZK_PATH + "/" + id, false, null));
                    JsonObject jsonObject = Json.parse(brokerInfo).asObject();

                    String brokerHost = jsonObject.getString(PropsKeys.HOST, "");
                    int brokerPort = jsonObject.getInt(PropsKeys.PORT, -1);

                    if (!brokerHost.isEmpty() && brokerPort != -1) {

                        kafkaBrokers.append(brokerHost);
                        kafkaBrokers.append(":");
                        kafkaBrokers.append(brokerPort);
                        kafkaBrokers.append(",");

                    }

                }
            } catch (IOException | KeeperException | InterruptedException e) {

                log.error("Failed to get broker information", e);

            }

        }

        if (kafkaBrokers.length() > 0) {

            kafkaBrokers.setLength(kafkaBrokers.length() - 1);

            return kafkaBrokers.toString();

        } else {

            return  context.getParameter(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG);

        }
    }