Search in sources :

Example 21 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class HTTPRawSamplerTest method testSample.

@Test
public void testSample() throws MalformedURLException, IOException {
    System.out.println("sample");
    String req = "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n";
    String resp = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nTEST";
    instance.setRequestData(req);
    instance.setParseResult(true);
    instance.sockEmul.setBytesToRead(ByteBuffer.wrap(resp.getBytes()));
    SampleResult result = instance.sample(null);
    // System.err.println(result.getResponseDataAsString().length());
    assertEquals(ByteBuffer.wrap(req.getBytes()), instance.sockEmul.getWrittenBytes());
    assertTrue(result.isSuccessful());
    assertEquals("200", result.getResponseCode());
    assertEquals("TEST", result.getResponseDataAsString());
    assertTrue(!instance.sockEmul.isOpen());
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 22 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class HTTPRawSamplerTest method testSample_keepalive.

/**
 * Test of sample method, of class HTTPRawSampler.
 */
@Test
public void testSample_keepalive() throws MalformedURLException, IOException {
    System.out.println("sample");
    String req = "TEST";
    String resp = "TEST";
    instance.setRequestData(req);
    instance.setUseKeepAlive(true);
    instance.sockEmul.setBytesToRead(ByteBuffer.wrap(resp.getBytes()));
    SampleResult result = instance.sample(null);
    assertTrue(instance.sockEmul.isOpen());
    instance.setUseKeepAlive(false);
    instance.sockEmul.setBytesToRead(ByteBuffer.wrap(resp.getBytes()));
    instance.sample(null);
    assertFalse(instance.sockEmul.isOpen());
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 23 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class HTTPRawSamplerTest method testSample_hugeparse.

@Test
public void testSample_hugeparse() throws MalformedURLException, IOException {
    System.out.println("sample");
    final int testDataSize = 1000000;
    String req = "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n";
    String resp = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n" + TestJMeterUtils.getTestData(testDataSize);
    instance.setRequestData(req);
    instance.setParseResult(true);
    instance.sockEmul.setBytesToRead(ByteBuffer.wrap(resp.getBytes()));
    SampleResult result = instance.sample(null);
    // System.err.println(result.getResponseDataAsString().length());
    assertEquals(ByteBuffer.wrap(req.getBytes()), instance.sockEmul.getWrittenBytes());
    assertTrue(result.isSuccessful());
    assertEquals("200", result.getResponseCode());
    System.out.println("Len: " + result.getResponseDataAsString().length());
    assertEquals(testDataSize, result.getResponseDataAsString().length());
    assertTrue(!instance.sockEmul.isOpen());
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 24 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class HTTPRawSamplerTest method testReadResponse.

/**
 * Test of readResponse method, of class HTTPRawSampler.
 */
@Test
public void testReadResponse() throws Exception {
    System.out.println("readResponse");
    SocketChannelEmul sock = new SocketChannelEmul();
    sock.setBytesToRead(ByteBuffer.wrap("test".getBytes()));
    SampleResult res = new SampleResult();
    res.sampleStart();
    byte[] expResult = "test".getBytes();
    byte[] result = instance.readResponse(sock, res);
    assertEquals(expResult.length, result.length);
}
Also used : SocketChannelEmul(kg.apc.emulators.SocketChannelEmul) SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 25 with SampleResult

use of org.apache.jmeter.samplers.SampleResult in project jmeter-plugins by undera.

the class HTTPRawSamplerTest method testProcessIO_fileOnly.

/**
 * Test of processIO method, of class HTTPRawSampler.
 */
@Test
public void testProcessIO_fileOnly() throws Exception {
    System.out.println("processIO");
    SampleResult res = new SampleResult();
    res.sampleStart();
    instance.setPort("0");
    String file = this.getClass().getResource("/testSendFile.raw").getPath();
    instance.setFileToSend(file);
    instance.processIO(res);
    assertEquals(new File(file).length(), instance.sockEmul.getWrittenBytesCount());
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult) File(java.io.File)

Aggregations

SampleResult (org.apache.jmeter.samplers.SampleResult)381 Test (org.junit.Test)83 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)71 Test (org.junit.jupiter.api.Test)59 JMeterContext (org.apache.jmeter.threads.JMeterContext)47 BeforeEach (org.junit.jupiter.api.BeforeEach)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 SampleEvent (org.apache.jmeter.samplers.SampleEvent)30 Sampler (org.apache.jmeter.samplers.Sampler)30 AssertionResult (org.apache.jmeter.assertions.AssertionResult)27 ArrayList (java.util.ArrayList)26 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)20 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)20 IOException (java.io.IOException)17 Arguments (org.apache.jmeter.config.Arguments)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)13 CorrectedResultCollector (kg.apc.jmeter.vizualizers.CorrectedResultCollector)12 URL (java.net.URL)9 File (java.io.File)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7