Java Code Examples for org.apache.jmeter.samplers.SampleResult#setBytes()

The following examples show how to use org.apache.jmeter.samplers.SampleResult#setBytes() . 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: BlurSamplerClient.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: BytesThroughputOverTimeGuiTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * Test of add method, of class BytesThroughputOverTimeGui.
 */
@Test
public void testAdd()
{
    System.out.println("add");
    SampleResult res = new SampleResult();
    res.setAllThreads(1);
    res.setThreadName("test 1-2");
    res.setBytes(1234);
    BytesThroughputOverTimeGui instance = new BytesThroughputOverTimeGui();
    instance.add(res);
    res.sampleStart();
    try
    {
        Thread.sleep(10);
    } catch (InterruptedException ex)
    {
    }
    res.sampleEnd();
    instance.add(res);
}
 
Example 3
Source File: UDPSampler.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
private ByteArrayOutputStream readResponse(SampleResult res) throws IOException {
    ByteArrayOutputStream response = new ByteArrayOutputStream();
    int cnt;
    ByteBuffer recvBuf = getRecvBuf();
    recvBuf.clear();
    if ((cnt = channel.read(recvBuf)) != -1) {
        res.latencyEnd();
        //log.debug("Read " + recvBuf.toString());
        recvBuf.flip();
        byte[] bytes = new byte[cnt];
        recvBuf.get(bytes);
        response.write(bytes);
        recvBuf.clear();
    }
    res.latencyEnd();
    res.sampleEnd();
    res.setBytes(response.size());
    return response;
}
 
Example 4
Source File: SubSampler.java    From mqtt-jmeter with Apache License 2.0 5 votes vote down vote up
private SampleResult fillOKResult(SampleResult result, int size, String message, String contents) {
	result.setResponseCode("200");
	result.setSuccessful(true);
	result.setResponseMessage(message);
	result.setBodySize(size);
	result.setBytes(size);
	result.setResponseData(contents.getBytes());
	result.sampleEnd();
	return result;
}
 
Example 5
Source File: FortressCreateSession.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * 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 6
Source File: AccelCreateSession.java    From directory-fortress-core with Apache License 2.0 5 votes vote down vote up
/**
 * 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 7
Source File: HonoReceiver.java    From hono with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Takes a sample.
 *
 * @param result The result to set the sampler's current statistics on.
 */
public void sample(final SampleResult result) {
    synchronized (lock) {
        long elapsed = 0;
        result.setResponseCodeOK();
        result.setSuccessful(errorCount == 0 && !senderClockNotInSync);
        result.setSampleCount(messageCount);
        result.setErrorCount(errorCount); // NOTE: This method does nothing in JMeter 3.3/4.0
        result.setBytes(bytesReceived);
        if (messageCount > 0) {
            if (sampler.isUseSenderTime() && sampleStart != 0 && errorCount == 0) {
                // errorCount has to be 0 here - otherwise totalSampleDeliveryTime doesn't have a correct value
                elapsed = senderClockNotInSync ? -1 : totalSampleDeliveryTime / messageCount;
                result.setStampAndTime(sampleStart, elapsed);
            } else if (sampleStart != 0) {
                elapsed = System.currentTimeMillis() - sampleStart;
                result.setStampAndTime(sampleStart, elapsed);
                result.setIdleTime(elapsed);
            } else {
                LOGGER.warn("sampleStart hasn't been set - setting elapsed time to 0");
                result.setStampAndTime(System.currentTimeMillis(), 0);
                result.setIdleTime(0);
            }
        } else {
            // empty sample
            result.setStampAndTime(System.currentTimeMillis(), 0);
            result.setIdleTime(0);
        }
        String responseMessage = "";
        if (errorCount == 0) {
            final String formatString = sampler.isUseSenderTime() ? "{}: received batch of {} messages; average delivery time: {}ms"
                    : "{}: received batch of {} messages in {}ms";
            LOGGER.info(formatString, sampler.getThreadName(), messageCount, elapsed);
        } else {
            LOGGER.info("{}: received batch of {} messages with {} errors in {}ms", sampler.getThreadName(), messageCount, errorCount, elapsed);
            responseMessage = "got " + errorCount + " invalid messages";
        }
        if (senderClockNotInSync) {
            responseMessage = (responseMessage.isEmpty() ? "" : responseMessage + "; ") + "sender clock not in sync";
            LOGGER.error("The sender time extracted from at least one of the received messages is newer than the receiver time" +
                    " - sender and receiver clocks are not in sync. Consider deactivating usage of the sender time.");
        }
        result.setResponseMessage(responseMessage);

        // reset all fields
        totalSampleDeliveryTime = 0;
        senderClockNotInSync = false;
        bytesReceived = 0;
        messageCount = 0;
        errorCount = 0;
        sampleStart = 0;
    }
}
 
Example 8
Source File: SubscriberSampler.java    From mqtt-jmeter with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public SampleResult sample(Entry entry) {
    SampleResult result = new SampleResult();
    result.setSampleLabel(getNameLabel());
    result.sampleStart();

    if (null != exceptionOccurred) {
        result.setSuccessful(false);
        result.setResponseMessage("Client is not connected." + lineSeparator + exceptionOccurred.toString());
        result.setResponseData(exceptionOccurred.toString().getBytes());
        result.sampleEnd();
        result.setResponseCode("FAILED");
        return result;
    }

    Message receivedMessage;
    while (!interrupted && null != client.getReceivedMessages() && null != client.getReceivedMessageCounter()) {
        receivedMessage = client.getReceivedMessages().poll();
        if (receivedMessage != null) {
            client.getReceivedMessageCounter().incrementAndGet();
            result.sampleEnd();
            result.setSuccessful(true);
            result.setResponseMessage(lineSeparator + "Received " + client.getReceivedMessageCounter().get() + " " +
                                      "messages." +
                                      lineSeparator + "Current message QOS : " + receivedMessage.getQos() +
                                      lineSeparator + "Is current message a duplicate : " + receivedMessage.isDup()
                                      + lineSeparator + "Received timestamp of current message : " +
                                      receivedMessage.getCurrentTimestamp() + lineSeparator + "Is current message" +
                                      " a retained message : " + receivedMessage.isRetained());
            result.setBytes(receivedMessage.getPayload().length);
            result.setResponseData(receivedMessage.getPayload());
            result.setResponseCodeOK();
            return result;
        }
    }

    result.setSuccessful(false);
    result.setResponseMessage("Client has been stopped or an error occurred while receiving messages. Received "  + " valid messages.");
    result.sampleEnd();
    result.setResponseCode("FAILED");
    return result;
}
 
Example 9
Source File: SessionPermissions.java    From directory-fortress-core with Apache License 2.0 4 votes vote down vote up
/**224
     * 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;
            if(isFortress)
            {
                message = "FT ";
            }
            else
            {
                message = "AC ";
            }

            message += "SessionPermissions isFortress: " + isFortress + ", userId: " + userId;
/*
            LOG.info( message );
            System.out.println( message );
*/
            assertNotNull( session );
            assertTrue( session.isAuthenticated() );
            List<Permission> result;
            if(isFortress)
            {
                assertNotNull( accessMgr );
                result = accessMgr.sessionPermissions( session );
            }
            else
            {
                assertNotNull( accelMgr );
                result = accelMgr.sessionPermissions( session );
            }

            // positive test case:
            assertNotNull( message, result );
            assertTrue( message, result.size() > 0 );
            sampleResult.sampleEnd();
            sampleResult.setBytes(1);
            sampleResult.setResponseMessage("test sessionPermissions completed, message=" + message);
            sampleResult.setSuccessful(true);
        }
        catch ( org.apache.directory.fortress.core.SecurityException se )
        {
            String error = "ThreadId:" + getThreadId() + "Error running test: " + se;
            LOG.error( error );
            System.out.println( error );
            se.printStackTrace();
            fail( error );
            sampleResult.setSuccessful( false );
        }

        return sampleResult;
    }
 
Example 10
Source File: CheckAccess.java    From directory-fortress-core with Apache License 2.0 4 votes vote down vote up
/**224
     * 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
        {
            int opCount = ++ctr % 10;
            if( opCount == 0 )
                opCount = 10;

            int objCount = (ctr / 10) + 1;
            if(objCount > 10)
            {
                objCount = objCount % 10;
            }
            if(objCount == 0)
            {
                objCount = 1;
            }

            //int objCount = ((ctr / 10) + 1) % 10;
            String opName = "oper" + opCount;
            String objName = "loadtestobject" + objCount;
            sampleResult.sampleStart();
            String message;
            if(isFortress)
            {
                message = "FT ";
            }
            else
            {
                message = "AC ";
            }

            message += "CheckAccess isFortress: " + isFortress + ", userId: " + userId + ", objName:" + objName + ", opName: " + opName;
/*
            LOG.info( message );
            System.out.println( message );
*/
            assertNotNull( session );
            assertTrue( session.isAuthenticated() );
            Permission perm = new Permission();
            perm.setObjName( objName );
            perm.setOpName( opName );
            boolean result;
            if(isFortress)
            {
                assertNotNull( accessMgr );
                result = accessMgr.checkAccess( session, perm );
            }
            else
            {
                assertNotNull( accelMgr );
                result = accelMgr.checkAccess( session, perm );
            }

            // positive test case:
            assertTrue( message, result );
            sampleResult.sampleEnd();
            sampleResult.setBytes(1);
            sampleResult.setResponseMessage("test checkAccess completed");
            sampleResult.setSuccessful(true);
        }
        catch ( org.apache.directory.fortress.core.SecurityException se )
        {
            String error = "ThreadId:" + getThreadId() + "Error running test: " + se;
            LOG.error( error );
            System.out.println( error );
            se.printStackTrace();
            fail( error );
            sampleResult.setSuccessful( false );
        }

        return sampleResult;
    }
 
Example 11
Source File: HTTPRawSampler.java    From jmeter-plugins with Apache License 2.0 4 votes vote down vote up
protected byte[] readResponse(SocketChannel channel, SampleResult res) throws IOException {
    ByteArrayOutputStream response = new ByteArrayOutputStream();
    
    ByteBuffer recvBuf = getRecvBuf();
    recvBuf.clear();
    
    boolean firstPack = true;
    int cnt;
    int responseSize = 0;
    
    if (log.isDebugEnabled()) {
        log.debug("Start reading response");
    }
    
    try {
        while ((cnt = channel.read(recvBuf)) != -1) {
            responseSize += cnt;
            if (firstPack) {
                res.latencyEnd();
                firstPack = false;
            }
            recvBuf.flip();
            if (response.size() <= recvDataLimit) {
                byte[] bytes = new byte[cnt];
                recvBuf.get(bytes);
                response.write(bytes);
            }
            
            recvBuf.clear();
        }
        
        if (response.size() < 1) {
            log.warn("Read no bytes from socket, seems it was closed. Let it be so.");
            channel.close();
        }
    } catch (IOException ex) {
        channel.close();
        throw ex;
    }
    
    if (log.isDebugEnabled()) {
        log.debug("Done reading response");
    }
    
    res.sampleEnd();
    if (!isUseKeepAlive()) {
        channel.close();
    }
    
    res.setBytes(responseSize);
    return response.toByteArray();
}