summaryrefslogtreecommitdiff
path: root/java/perftests/src/test/java/org/apache/qpid/disttest/results/formatting/CSVFormaterTest.java
blob: 565f59d25bbac4f1b7b54b12b86fadea50b332c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.qpid.disttest.results.formatting;

import static org.apache.qpid.disttest.message.ParticipantAttribute.BATCH_SIZE;
import static org.apache.qpid.disttest.message.ParticipantAttribute.CONFIGURED_CLIENT_NAME;
import static org.apache.qpid.disttest.message.ParticipantAttribute.*;
import static org.apache.qpid.disttest.message.ParticipantAttribute.ERROR_MESSAGE;
import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_BROWSING_SUBSCRIPTION;
import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_DURABLE_SUBSCRIPTION;
import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_NO_LOCAL;
import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_SELECTOR;
import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_SYNCHRONOUS_CONSUMER;
import static org.apache.qpid.disttest.message.ParticipantAttribute.IS_TOPIC;
import static org.apache.qpid.disttest.message.ParticipantAttribute.ITERATION_NUMBER;
import static org.apache.qpid.disttest.message.ParticipantAttribute.MAXIMUM_DURATION;
import static org.apache.qpid.disttest.message.ParticipantAttribute.NUMBER_OF_MESSAGES_PROCESSED;
import static org.apache.qpid.disttest.message.ParticipantAttribute.PARTICIPANT_NAME;
import static org.apache.qpid.disttest.message.ParticipantAttribute.PAYLOAD_SIZE;
import static org.apache.qpid.disttest.message.ParticipantAttribute.PRIORITY;
import static org.apache.qpid.disttest.message.ParticipantAttribute.PRODUCER_INTERVAL;
import static org.apache.qpid.disttest.message.ParticipantAttribute.PRODUCER_START_DELAY;
import static org.apache.qpid.disttest.message.ParticipantAttribute.TEST_NAME;
import static org.apache.qpid.disttest.message.ParticipantAttribute.THROUGHPUT;
import static org.apache.qpid.disttest.message.ParticipantAttribute.TIME_TAKEN;
import static org.apache.qpid.disttest.message.ParticipantAttribute.TIME_TO_LIVE;
import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_NUMBER_OF_CONSUMERS;
import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_NUMBER_OF_PRODUCERS;
import static org.apache.qpid.disttest.message.ParticipantAttribute.TOTAL_PAYLOAD_PROCESSED;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

import junit.framework.TestCase;

import org.apache.qpid.disttest.controller.ResultsForAllTests;
import org.apache.qpid.disttest.controller.TestResult;
import org.apache.qpid.disttest.message.ParticipantAttribute;
import org.apache.qpid.disttest.message.ParticipantResult;

public class CSVFormaterTest extends TestCase
{
    private static final String TEST1 = "TEST1";
    private static final String PARTICIPANT = "PARTICIPANT";
    private static final String CONFIGURED_CLIENT1 = "CONFIGURED_CLIENT1";

    private CSVFormater _formatter = new CSVFormater();

    public void testResultsFileWithWithOneRow() throws Exception
    {
        ParticipantResult participantResult = mock(ParticipantResult.class);
        Map<ParticipantAttribute, Object> participantAttributes = getParticipantAttributes();

        when(participantResult.getAttributes()).thenReturn(participantAttributes);
        when(participantResult.getParticipantName()).thenReturn(PARTICIPANT);

        TestResult testResult = new TestResult(TEST1);
        testResult.addParticipantResult(participantResult);

        ResultsForAllTests resultsForAllTests = new ResultsForAllTests();
        resultsForAllTests.add(testResult);

        String output = _formatter.format(resultsForAllTests);

        String expectedOutput = readCsvOutputFileAsString("expectedOutput.csv");

        assertEquals(expectedOutput, output);
    }

    private Map<ParticipantAttribute, Object> getParticipantAttributes()
    {
        Map<ParticipantAttribute, Object> participantAttributes = new HashMap<ParticipantAttribute, Object>();

        participantAttributes.put(TEST_NAME, TEST1);
        participantAttributes.put(ITERATION_NUMBER, 0);
        participantAttributes.put(CONFIGURED_CLIENT_NAME, CONFIGURED_CLIENT1);
        participantAttributes.put(PARTICIPANT_NAME, PARTICIPANT);
        participantAttributes.put(NUMBER_OF_MESSAGES_PROCESSED, 0);
        participantAttributes.put(PAYLOAD_SIZE, 1);
        participantAttributes.put(PRIORITY, 2);
        participantAttributes.put(TIME_TO_LIVE, 3);
        participantAttributes.put(ACKNOWLEDGE_MODE, 4);
        participantAttributes.put(DELIVERY_MODE, 5);
        participantAttributes.put(BATCH_SIZE, 6);
        participantAttributes.put(MAXIMUM_DURATION, 7);
        participantAttributes.put(PRODUCER_START_DELAY, 8);
        participantAttributes.put(PRODUCER_INTERVAL, 9);
        participantAttributes.put(IS_TOPIC, true);
        participantAttributes.put(IS_DURABLE_SUBSCRIPTION, false);
        participantAttributes.put(IS_BROWSING_SUBSCRIPTION, true);
        participantAttributes.put(IS_SELECTOR, false);
        participantAttributes.put(IS_NO_LOCAL, true);
        participantAttributes.put(IS_SYNCHRONOUS_CONSUMER, false);
        participantAttributes.put(TOTAL_NUMBER_OF_CONSUMERS, 1);
        participantAttributes.put(TOTAL_NUMBER_OF_PRODUCERS, 2);
        participantAttributes.put(TOTAL_PAYLOAD_PROCESSED, 1024);
        participantAttributes.put(THROUGHPUT, 2048);
        participantAttributes.put(TIME_TAKEN, 1000);
        participantAttributes.put(ERROR_MESSAGE, "error");
        participantAttributes.put(MIN_LATENCY, 2l);
        participantAttributes.put(MAX_LATENCY, 9l);
        participantAttributes.put(AVERAGE_LATENCY, 5.0f);
        participantAttributes.put(LATENCY_STANDARD_DEVIATION, 2.0f);
        return participantAttributes;
    }

    private String readCsvOutputFileAsString(String filename) throws Exception
    {
        InputStream is = getClass().getResourceAsStream(filename);
        assertNotNull(is);

        StringBuilder output = new StringBuilder();

        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = null;
        while((line = br.readLine()) != null)
        {
            output.append(line);
            output.append("\n");
        }

        return output.toString();
    }

}