outputStream.write(bos.toByteArray()); // Read the response ByteArrayOutputStream response = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int length = 0; while(( length = inputStream.read(buffer)) != -1) { response.write(buffer, 0, length); } response.close(); byte[] mirroredResponse = getMirroredResponse(response.toByteArray()); // Check that the request and response matches checkArraysHaveSameContent(bos.toByteArray(), mirroredResponse); // Close the connection clientSocket.close(); // Connect to the http server, and do a simple http get, with // a pause in the middle of transmitting the header clientSocket = new Socket("localhost", HTTP_SERVER_PORT); outputStream = clientSocket.getOutputStream(); inputStream = clientSocket.getInputStream(); // Write to the socket bos = new ByteArrayOutputStream(); // Headers bos.write("GET / HTTP 1.1".getBytes(ISO_8859_1)); bos.write(CRLF); // Write the start of the headers, and then sleep, so that the mirror // thread will have to block to wait for more data to appear bos.close();
outputStream.write(bos.toByteArray()); // Read the response ByteArrayOutputStream response = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int length = 0; while((length = inputStream.read(buffer)) != -1) { response.write(buffer, 0, length); } response.close(); byte[] mirroredResponse = getMirroredResponse(response.toByteArray()); // Check that the request and response matches checkArraysHaveSameContent(bos.toByteArray(), mirroredResponse); // Close the connection clientSocket.close(); // Connect to the http server, and do a simple http post, with // a pause after transmitting the headers clientSocket = new Socket("localhost", HTTP_SERVER_PORT); outputStream = clientSocket.getOutputStream(); inputStream = clientSocket.getInputStream(); // Write to the socket bos = new ByteArrayOutputStream(); // Headers bos.write("GET / HTTP 1.1".getBytes(ISO_8859_1)); bos.write(CRLF); bos.write("Host: localhost".getBytes(ISO_8859_1));
Clone fragments detected by clone detection tool
File path: /jakarta-jmeter-2.3.2/test/src/org/apache/jmeter/protocol/http/control/TestHTTPMirrorThread.java File path: /jakarta-jmeter-2.3.2/test/src/org/apache/jmeter/protocol/http/control/TestHTTPMirrorThread.java
Method name: void testGetRequest() Method name: void testPostRequest()
Number of AST nodes: 17 Number of AST nodes: 17
1
outputStream.write(bos.toByteArray());
1
outputStream.write(bos.toByteArray());
2
        
3
        // Read the response
2
        // Read the response
4
        ByteArrayOutputStream response = new ByteArrayOutputStream();        
3
        ByteArrayOutputStream response = new ByteArrayOutputStream();        
5
        byte[] buffer = new byte[1024];
4
        byte[] buffer = new byte[1024];
6
        int length = 0;
5
        int length = 0;
7
        while(( length = inputStream.read(buffer)) != -1) {
6
        while((length = inputStream.read(buffer)) != -1) {
8
        	response.write(buffer, 0, length);
7
        	response.write(buffer, 0, length);
9
        }
8
        }
10
        response.close();
9
        response.close();
11
        byte[] mirroredResponse = getMirroredResponse(response.toByteArray());   		
10
        byte[] mirroredResponse = getMirroredResponse(response.toByteArray());   		
12
        // Check that the request and response matches
11
        // Check that the request and response matches
13
        checkArraysHaveSameContent(bos.toByteArray(), mirroredResponse);
12
        checkArraysHaveSameContent(bos.toByteArray(), mirroredResponse);
14
        // Close the connection
13
        // Close the connection
15
        clientSocket.close();
14
        clientSocket.close();
16
        // Connect to the http server, and do a simple http get, with
15
        // Connect to the http server, and do a simple http post, with
17
        // a pause in the middle of transmitting the header
16
        // a pause after transmitting the headers
18
        clientSocket = new Socket("localhost", HTTP_SERVER_PORT);
17
        clientSocket = new Socket("localhost", HTTP_SERVER_PORT);
19
        outputStream = clientSocket.getOutputStream();
18
        outputStream = clientSocket.getOutputStream();
20
        inputStream = clientSocket.getInputStream();
19
        inputStream = clientSocket.getInputStream();
21
        
20
        
22
        // Write to the socket
21
        // Write to the socket
23
        bos = new ByteArrayOutputStream();
22
        bos = new ByteArrayOutputStream();
24
        // Headers
23
        // Headers
25
        bos.write("GET / HTTP 1.1".getBytes(ISO_8859_1));
24
        bos.write("GET / HTTP 1.1".getBytes(ISO_8859_1));
26
        bos.write(CRLF);
25
        bos.write(CRLF);
27
        // Write the start of the headers, and then sleep, so that the mirror
26
        
28
        // thread will have to block to wait for more data to appear
29
        bos.close();
27
bos.write("Host: localhost".getBytes(ISO_8859_1));
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)0.3
Clones locationClones are declared in the same class
Number of node comparisons202
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements17
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)13.3
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    11
    outputStream.write(bos.toByteArray());
    20
    outputStream.write(bos.toByteArray());
    12
    ByteArrayOutputStream response = new ByteArrayOutputStream();
    21
    ByteArrayOutputStream response = new ByteArrayOutputStream();
    13
    byte[] buffer = new byte[1024];
    22
    byte[] buffer = new byte[1024];
    14
    int length = 0;
    23
    int length = 0;
    15
    while ((length = inputStream.read(buffer)) != -1)
    24
    while ((length = inputStream.read(buffer)) != -1)
    16
    response.write(buffer, 0, length);
    25
    response.write(buffer, 0, length);
    17
    response.close();
    26
    response.close();
    18
    byte[] mirroredResponse = getMirroredResponse(response.toByteArray());
    27
    byte[] mirroredResponse = getMirroredResponse(response.toByteArray());
    19
    checkArraysHaveSameContent(bos.toByteArray(), mirroredResponse);
    28
    checkArraysHaveSameContent(bos.toByteArray(), mirroredResponse);
    20
    clientSocket.close();
    29
    clientSocket.close();
    21
    clientSocket = new Socket("localhost", HTTP_SERVER_PORT);
    30
    clientSocket = new Socket("localhost", HTTP_SERVER_PORT);
    22
    outputStream = clientSocket.getOutputStream();
    31
    outputStream = clientSocket.getOutputStream();
    23
    inputStream = clientSocket.getInputStream();
    32
    inputStream = clientSocket.getInputStream();
    24
    bos = new ByteArrayOutputStream();
    33
    bos = new ByteArrayOutputStream();
    25
    bos.write("GET / HTTP 1.1".getBytes(ISO_8859_1));
    34
    bos.write("GET / HTTP 1.1".getBytes(ISO_8859_1));
    26
    bos.write(CRLF);
    35
    bos.write(CRLF);
    27
    bos.close();
    27
    bos.close();
    36
    bos.write("Host: localhost".getBytes(ISO_8859_1));
    Differences
    Expression1Expression2Difference
    closewriteMETHOD_INVOCATION_NAME_MISMATCH
    bos.close()bos.write("Host: localhost".getBytes(ISO_8859_1))ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression bos.close() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression bos.write("Host: localhost".getBytes(ISO_8859_1)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression bos.close() is a void method call, and thus it cannot be parameterized
    Expression bos.write("Host: localhost".getBytes(ISO_8859_1)) is a void method call, and thus it cannot be parameterized
    Expression bos.close() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression bos.write("Host: localhost".getBytes(ISO_8859_1)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression bos.close() is a void method call, and thus it cannot be parameterized
    Expression bos.write("Host: localhost".getBytes(ISO_8859_1)) is a void method call, and thus it cannot be parameterized
    36
    bos.write("Host: localhost".getBytes(ISO_8859_1));
    Precondition Violations (9)
    Row Violation
    1Expression bos.close() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression bos.write("Host: localhost".getBytes(ISO_8859_1)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression bos.close() is a void method call, and thus it cannot be parameterized
    4Expression bos.write("Host: localhost".getBytes(ISO_8859_1)) is a void method call, and thus it cannot be parameterized
    5Expression bos.close() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression bos.write("Host: localhost".getBytes(ISO_8859_1)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression bos.close() is a void method call, and thus it cannot be parameterized
    8Expression bos.write("Host: localhost".getBytes(ISO_8859_1)) is a void method call, and thus it cannot be parameterized
    9Clone fragment #1 returns variables bos, outputStream, response, buffer, inputStream, mirroredResponse, clientSocket , while Clone fragment #2 returns variables bos, outputStream, response, buffer, inputStream, mirroredResponse, clientSocket