org.apache.jmeter.protocol.java.sampler.JavaSamplerContext Java Examples
The following examples show how to use
org.apache.jmeter.protocol.java.sampler.JavaSamplerContext.
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: WeEventProducer.java From WeEvent with Apache License 2.0 | 6 votes |
@Override public SampleResult runTest(JavaSamplerContext context) { SampleResult result = new SampleResult(); result.setSampleLabel("producer"); try { result.sampleStart(); SendResult sendResult = this.weEventClient.publish(this.weEvent); result.sampleEnd(); result.setSuccessful(sendResult.getStatus() == SendResult.SendResultStatus.SUCCESS && sendResult.getEventId().length() > 0); result.setResponseMessage(sendResult.getEventId()); result.setResponseHeaders(sendResult.getStatus().toString()); result.setResponseData(sendResult.toString(), Charset.defaultCharset().name()); getNewLogger().info("sendResult:{}", sendResult); } catch (Exception e) { getNewLogger().error("publish exception", e); result.sampleEnd(); result.setSuccessful(false); result.setResponseMessage(e.getMessage()); } return result; }
Example #2
Source File: WeEventConsumer.java From WeEvent with Apache License 2.0 | 6 votes |
@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 #3
Source File: AccelCreateSession.java From directory-fortress-core with Apache License 2.0 | 6 votes |
/** * 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(); } }
Example #4
Source File: BlurSamplerClient.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@Override public SampleResult runTest(JavaSamplerContext context) { SampleResult sampleResult = new SampleResult(); BlurResults blurResults = null; try { BlurQuery blurQuery = getBlurQuery(); sampleResult.sampleStart(); blurResults = _client.query(_table, blurQuery); sampleResult.sampleEnd(); int size = getBytes(blurResults); sampleResult.setBytes(size); sampleResult.setSuccessful(true); sampleResult.setResponseOK(); } catch (Throwable t) { sampleResult.setResponseMessage("Exception " + t.getMessage()); sampleResult.setSuccessful(false); LOG.error("Unknown error.", t); } finally { processResults(blurResults); } return sampleResult; }
Example #5
Source File: KafkaProducerSampler.java From kafkameter with Apache License 2.0 | 6 votes |
@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 #6
Source File: KafkaProducerSampler.java From kafkameter with Apache License 2.0 | 6 votes |
@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 #7
Source File: FlowerSyncClient.java From flower with Apache License 2.0 | 6 votes |
@Override public SampleResult runTest(JavaSamplerContext arg0) { SampleResult result = new SampleResult(); result.sampleStart(); try { long begin = System.currentTimeMillis(); String ret = (String) flowRouter.syncCallService(message); long cost = (System.currentTimeMillis() - begin); logger.info("ret : {}, cost:[{}ms]", ret, cost); if (message.equals(ret)) { result.setSuccessful(true); } } catch (Exception e) { result.setSuccessful(false); logger.error("", e); } finally { result.sampleEnd(); } return result; }
Example #8
Source File: FortressCreateSession.java From directory-fortress-core with Apache License 2.0 | 6 votes |
/** * 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(); } }
Example #9
Source File: FortressCreateSession.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * Description of the Method * * @param samplerContext Description of the Parameter */ public void teardownTest( JavaSamplerContext samplerContext ) { String message = "FT SETUP CreateSession TID: " + getThreadId(); LOG.info( message ); System.out.println( message ); }
Example #10
Source File: JMeterTest.java From learning-hadoop with Apache License 2.0 | 5 votes |
public SampleResult runTest(JavaSamplerContext context) { SampleResult sampleResult = new SampleResult(); sampleResult.sampleStart(); String key = String.valueOf(String.valueOf(new Random().nextInt(keyNumLength)).hashCode()); try { if (methedType.equals("put")) { put = new Put(Bytes.toBytes(key)); put.setWriteToWAL(writeToWAL); for (int j = 0; j < cfs.length; j++) { for (int n = 0; n < qualifiers.length; n++) { put.add(Bytes.toBytes(cfs[j]), Bytes.toBytes(qualifiers[n]), Bytes.toBytes(values)); table.put(put); } } } else if (methedType.equals("get")) { get = new Get((key ).getBytes()); table.get(get); // Result rs = table.get(get); } sampleResult.setSuccessful(true); } catch (Throwable e) { sampleResult.setSuccessful(false); } finally { sampleResult.sampleEnd(); } // // 返回是否处理成功 return sampleResult; }
Example #11
Source File: JMeterTest.java From learning-hadoop with Apache License 2.0 | 5 votes |
@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 #12
Source File: HbaseJMeter.java From learning-hadoop with Apache License 2.0 | 5 votes |
@Override public void teardownTest(JavaSamplerContext context) { super.teardownTest(context); try { if (table != null) { table.flushCommits(); table.close(); table = null; } } catch (IOException e) { System.out.println("teardown error"); } }
Example #13
Source File: FortressCreateSession.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * Description of the Method * * @param samplerContext Description of the Parameter * @return Description of the Return Value */ public SampleResult runTest( JavaSamplerContext samplerContext ) { SampleResult sampleResult = new SampleResult(); try { sampleResult.sampleStart(); //String message = "FT CreateSession TID: " + getThreadId() + " UID:" + userId + " CTR:" + ctr++; //LOG.info( message ); //System.out.println( message ); assertNotNull( accessMgr ); Session session; User user = new User(); // positive test case: user.setUserId( userId ); user.setPassword( "secret" ); session = accessMgr.createSession( user, false ); assertNotNull( session ); assertTrue( session.isAuthenticated() ); sampleResult.sampleEnd(); sampleResult.setBytes(1); sampleResult.setResponseMessage("test completed TID: " + getThreadId() + " UID: " + userId); sampleResult.setSuccessful(true); } catch ( org.apache.directory.fortress.core.SecurityException se ) { System.out.println( "ThreadId:" + getThreadId() + "Error running test: " + se ); se.printStackTrace(); sampleResult.setSuccessful( false ); } return sampleResult; }
Example #14
Source File: LicenseActivateCheckDeactivate.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
@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 #15
Source File: HbaseJMeter.java From learning-hadoop with Apache License 2.0 | 5 votes |
public SampleResult runTest(JavaSamplerContext context) { SampleResult sampleResult = new SampleResult(); sampleResult.sampleStart(); String key = null; if (keyRondom) { key = String.valueOf(String.valueOf(new Random().nextInt(keyNumLength)).hashCode()); } else { key = SequenceKey.getsequenceKey(); } try { if (methedType.equals("put")) { put = new Put(Bytes.toBytes(key)); put.setWriteToWAL(writeToWAL); for (int j = 0; j < cfs.length; j++) { for (int n = 0; n < qualifiers.length; n++) { put.add(Bytes.toBytes(cfs[j]), Bytes.toBytes(qualifiers[n]), Bytes.toBytes(values)); } } table.put(put); } else if (methedType.equals("get")) { get = new Get((key).getBytes()); table.get(get); } sampleResult.setSuccessful(true); } catch (Throwable e) { sampleResult.setSuccessful(false); } finally { sampleResult.sampleEnd(); } return sampleResult; }
Example #16
Source File: WeEventProducer.java From WeEvent with Apache License 2.0 | 5 votes |
@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 #17
Source File: SessionPermissions.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * Description of the Method * * @param samplerContext Description of the Parameter */ public void teardownTest( JavaSamplerContext samplerContext ) { try { String message = "TEARDOWN UserId:" + userId + ", key: " + key + ", TID: " + getThreadId(); LOG.info( message ); System.out.println( message ); if(!isFortress) { assertNotNull( session ); accelMgr.deleteSession( session ); //Thread.sleep( 100 ); } session = null; } catch ( SecurityException se ) { String error = "teardownTest ThreadId:" + getThreadId() + " Error stopping test: " + se; LOG.error( error ); se.printStackTrace(); } /* catch ( InterruptedException ie ) { // ignore } */ }
Example #18
Source File: CheckAccess.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * Description of the Method * * @param samplerContext Description of the Parameter */ public void teardownTest( JavaSamplerContext samplerContext ) { try { String message = "TEARDOWN UserId:" + userId + ", key: " + key + ", TID: " + getThreadId(); LOG.info( message ); System.out.println( message ); if(!isFortress) { assertNotNull( session ); accelMgr.deleteSession( session ); //Thread.sleep( 100 ); } session = null; } catch ( SecurityException se ) { String error = "teardownTest ThreadId:" + getThreadId() + " Error stopping test: " + se; LOG.error( error ); se.printStackTrace(); } /* catch ( InterruptedException ie ) { // ignore } */ }
Example #19
Source File: AccelCreateSession.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * Description of the Method * * @param samplerContext Description of the Parameter * @return Description of the Return Value */ public SampleResult runTest( JavaSamplerContext samplerContext ) { SampleResult sampleResult = new SampleResult(); try { sampleResult.sampleStart(); //String message = "FT CreateSession TID: " + getThreadId() + " UID:" + userId + " CTR:" + ctr++; //LOG.info( message ); //System.out.println( message ); assertNotNull( accelMgr ); Session session; User user = new User(); // positive test case: user.setUserId( userId ); user.setPassword( "secret" ); session = accelMgr.createSession( user, false ); assertNotNull( session ); assertTrue( session.isAuthenticated() ); sampleResult.sampleEnd(); sampleResult.setBytes(1); sampleResult.setResponseMessage("AC test completed TID: " + getThreadId() + " UID: " + userId); sampleResult.setSuccessful(true); } catch ( org.apache.directory.fortress.core.SecurityException se ) { System.out.println( "ThreadId:" + getThreadId() + "Error running test: " + se ); se.printStackTrace(); sampleResult.setSuccessful( false ); } return sampleResult; }
Example #20
Source File: AccelCreateSession.java From directory-fortress-core with Apache License 2.0 | 5 votes |
/** * Description of the Method * * @param samplerContext Description of the Parameter */ public void teardownTest( JavaSamplerContext samplerContext ) { String message = "AC TEARDOWN CreateSession TID: " + getThreadId(); LOG.info( message ); System.out.println( message ); }
Example #21
Source File: JMeterTest.java From learning-hadoop with Apache License 2.0 | 5 votes |
@Override public void teardownTest(JavaSamplerContext context) { super.teardownTest(context); try { if (table != null) { table.flushCommits(); table.close(); table = null ; } } catch (IOException e) { System.out.println("teardown error"); } }
Example #22
Source File: PepperBoxKafkaSampler.java From pepper-box with Apache License 2.0 | 5 votes |
/** * 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_val = JMeterContextService.getContext().getVariables().getObject(msg_val_placeHolder); ProducerRecord<String, Object> producerRecord; try { if (key_message_flag) { Object message_key = JMeterContextService.getContext().getVariables().getObject(msg_key_placeHolder); producerRecord = new ProducerRecord<String, Object>(topic, message_key.toString(), message_val); } else { producerRecord = new ProducerRecord<String, Object>(topic, message_val); } producer.send(producerRecord); sampleResult.setResponseData(message_val.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; }
Example #23
Source File: JmsUtilTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
/** * Test of teardownTest method, of class JmsUtil. */ @Test public void testTeardownTest() { System.out.println("teardownTest"); JavaSamplerContext arg0 = null; JmsUtil instance = new JmsUtil(); instance.teardownTest(arg0); // TODO review the generated test code and remove the default call to fail. }
Example #24
Source File: LicenseActivateCheckDeactivate.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
@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 #25
Source File: JmsUtilTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
/** * Test of setupTest method, of class JmsUtil. */ @Test public void testSetupTest() { System.out.println("setupTest"); JavaSamplerContext arg0 = null; JmsUtil instance = new JmsUtil(); instance.setupTest(arg0); // TODO review the generated test code and remove the default call to fail. }
Example #26
Source File: JmsUtilTest.java From jmeter-plugins with Apache License 2.0 | 5 votes |
/** * Test of runTest method, of class JmsUtil. */ @Test public void testRunTest() { System.out.println("runTest"); JavaSamplerContext ctx = new JavaSamplerContext(new Arguments()); JmsUtil instance = new JmsUtil(); SampleResult expResult = null; SampleResult result = instance.runTest(ctx); }
Example #27
Source File: TopicMessageGeneratorClient.java From hedera-mirror-node with Apache License 2.0 | 5 votes |
/** * 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 #28
Source File: MultiTopicHCSClient.java From hedera-mirror-node with Apache License 2.0 | 5 votes |
@Override public void setupTest(JavaSamplerContext javaSamplerContext) { consensusServiceReactiveSamplers = new HashMap<>(); propHandler = new PropertiesHandler(javaSamplerContext); host = propHandler.getTestParam("host", "localhost"); port = propHandler.getIntTestParam("port", 5600); clientCount = propHandler.getIntTestParam("clientCount", 0); for (int i = 0; i < clientCount; i++) { TopicSubscription topicSubscription = TopicSubscription.builder() .topicId(propHandler.getLongClientTestParam("TopicId", i)) .startTime(propHandler.getLongClientTestParam("StartTime", i)) .endTime(propHandler.getLongClientTestParam("EndTime", i)) .limit(propHandler.getLongClientTestParam("Limit", i)) .historicMessagesCount(propHandler.getIntClientTestParam("HistoricMessagesCount", i)) .incomingMessageCount(propHandler.getIntClientTestParam("IncomingMessageCount", i)) .subscribeTimeoutSeconds(propHandler.getIntClientTestParam("SubscribeTimeoutSeconds", i)) .milliSecWaitBefore(propHandler.getLongClientTestParam("MilliSecWaitBefore", i)) .useMAPI(Boolean.valueOf(propHandler.getClientTestParam("UseMAPI", i))) .build(); log.debug("Created TopicSubscription : {}", topicSubscription); consensusServiceReactiveSamplers.put(topicSubscription, createSampler(topicSubscription)); } super.setupTest(javaSamplerContext); }
Example #29
Source File: TopicMessageGeneratorClient.java From hedera-mirror-node with Apache License 2.0 | 5 votes |
/** * Runs test by calling sampler to manage topic message table. Reports success based on successful db operations * * @return Sample result */ @Override public SampleResult runTest(JavaSamplerContext context) { SampleResult result = new SampleResult(); try { // establish db connection in test to ensure failures are reported connectionHandler = new ConnectionHandler(host, port, dbName, dbUser, dbPassword); sampler = new TopicMessageGeneratorSampler(connectionHandler); MessageGenerator messageGen = MessageGenerator.builder() .topicNum(context.getLongParameter("topicID", 0)) .historicMessagesCount(context.getIntParameter("historicMessagesCount", 0)) .futureMessagesCount(context.getIntParameter("newTopicsMessageCount", 0)) .topicMessageEmitCycles(context.getIntParameter("topicMessageEmitCycles", 0)) .newTopicsMessageDelay(context.getLongParameter("newTopicsMessageDelay", 0L)) .deleteFromSequence(context.getLongParameter("delSeqFrom", -1L)) .build(); result.sampleStart(); sampler.populateTopicMessages(messageGen); result.sampleEnd(); result.setResponseMessage("Successfully performed populateTopicMessages"); result.setResponseCodeOK(); result.setSuccessful(true); } catch (Exception ex) { log.error("Error populating topic messages", ex); StringWriter stringWriter = new StringWriter(); ex.printStackTrace(new PrintWriter(stringWriter)); result.sampleEnd(); result.setResponseMessage("Exception: " + ex); result.setResponseData(stringWriter.toString().getBytes()); result.setDataType(SampleResult.TEXT); result.setResponseCode("500"); } return result; }
Example #30
Source File: SessionPermissions.java From directory-fortress-core with Apache License 2.0 | 4 votes |
/** * 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); } }