summaryrefslogtreecommitdiff
path: root/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/results/aggregation/ParticipantResultAggregatorTest.java
blob: db30595eddc6c14327e2f138c1b98503bb502042 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
 * 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.aggregation;

import java.util.Date;

import org.apache.qpid.disttest.message.ParticipantResult;
import org.apache.qpid.disttest.results.aggregation.ParticipantResultAggregator;

import junit.framework.TestCase;

public class ParticipantResultAggregatorTest extends TestCase
{
    private ParticipantResultAggregator _aggregator = new ParticipantResultAggregator(ParticipantResult.class, AGGREGATED_RESULT_NAME);

    private static final String TEST_NAME = "TEST_NAME";
    private static final String AGGREGATED_RESULT_NAME = "AGGREGATED_RESULT_NAME";
    private static final int TEST_ITERATION_NUMBER = 1;

    private static final long PARTICIPANT1_STARTDATE = 50;
    private static final long PARTICIPANT1_ENDDATE = 20000;
    private static final long PARTICIPANT1_TOTAL_PROCESSED = 1024;

    private static final long PARTICIPANT2_STARTDATE = 100;
    private static final long PARTICIPANT2_ENDDATE = 21000;
    private static final long PARTICIPANT2_TOTAL_PROCESSED = 2048;

    private static final long OVERALL_PROCESSED = PARTICIPANT1_TOTAL_PROCESSED + PARTICIPANT2_TOTAL_PROCESSED;
    private static final double OVERALL_TIMETAKEN = PARTICIPANT2_ENDDATE - PARTICIPANT1_STARTDATE;

    private static final double EXPECTED_AGGREGATED_ALL_THROUGHPUT = ((OVERALL_PROCESSED)/1024)/((OVERALL_TIMETAKEN)/1000);

    public void testStartAndEndDateForOneParticipantResult()
    {
        ParticipantResult result = new ParticipantResult();
        result.setStartDate(new Date(PARTICIPANT1_STARTDATE));
        result.setEndDate(new Date(PARTICIPANT1_ENDDATE));

        _aggregator.aggregate(result);
        ParticipantResult aggregratedResult = _aggregator.getAggregatedResult();
        assertEquals(PARTICIPANT1_STARTDATE, aggregratedResult.getStartInMillis());
        assertEquals(PARTICIPANT1_ENDDATE, aggregratedResult.getEndInMillis());
    }

    public void testStartAndEndDateForTwoParticipantResults()
    {
        ParticipantResult result1 = new ParticipantResult();
        result1.setStartDate(new Date(PARTICIPANT1_STARTDATE));
        result1.setEndDate(new Date(PARTICIPANT1_ENDDATE));

        ParticipantResult result2 = new ParticipantResult();
        result2.setStartDate(new Date(PARTICIPANT2_STARTDATE));
        result2.setEndDate(new Date(PARTICIPANT2_ENDDATE));

        _aggregator.aggregate(result1);
        _aggregator.aggregate(result2);

        ParticipantResult aggregratedResult = _aggregator.getAggregatedResult();
        assertEquals(PARTICIPANT1_STARTDATE, aggregratedResult.getStartInMillis());
        assertEquals(PARTICIPANT2_ENDDATE, aggregratedResult.getEndInMillis());
    }

    public void testComputeNumberOfMessagesProcessed()
    {
        ParticipantResult result1 = new ParticipantResult();
        result1.setNumberOfMessagesProcessed(10);

        ParticipantResult result2 = new ParticipantResult();
        result2.setNumberOfMessagesProcessed(15);

        _aggregator.aggregate(result1);
        _aggregator.aggregate(result2);

        ParticipantResult aggregratedResult = _aggregator.getAggregatedResult();
        assertEquals(25, aggregratedResult.getNumberOfMessagesProcessed());
    }

    public void testComputeTotalPayloadProcessed()
    {
        ParticipantResult result1 = new ParticipantResult();
        result1.setTotalPayloadProcessed(PARTICIPANT1_TOTAL_PROCESSED);

        ParticipantResult result2 = new ParticipantResult();
        result2.setTotalPayloadProcessed(PARTICIPANT2_TOTAL_PROCESSED);

        _aggregator.aggregate(result1);
        _aggregator.aggregate(result2);

        ParticipantResult aggregratedResult = _aggregator.getAggregatedResult();
        assertEquals(OVERALL_PROCESSED, aggregratedResult.getTotalPayloadProcessed());
    }

    public void testComputeThroughput()
    {
        ParticipantResult result1 = new ParticipantResult();
        result1.setStartDate(new Date(PARTICIPANT1_STARTDATE));
        result1.setEndDate(new Date(PARTICIPANT1_ENDDATE));
        result1.setTotalPayloadProcessed(PARTICIPANT1_TOTAL_PROCESSED);

        ParticipantResult result2 = new ParticipantResult();
        result2.setStartDate(new Date(PARTICIPANT2_STARTDATE));
        result2.setEndDate(new Date(PARTICIPANT2_ENDDATE));
        result2.setTotalPayloadProcessed(PARTICIPANT2_TOTAL_PROCESSED);

        _aggregator.aggregate(result1);
        _aggregator.aggregate(result2);

        ParticipantResult aggregratedResult = _aggregator.getAggregatedResult();
        assertEquals(EXPECTED_AGGREGATED_ALL_THROUGHPUT, aggregratedResult.getThroughput(), 0.1);
    }

    public void testConstantTestNameAndIterationNumberRolledUp() throws Exception
    {
        ParticipantResult result1 = new ParticipantResult();
        result1.setTestName(TEST_NAME);
        result1.setIterationNumber(TEST_ITERATION_NUMBER);

        ParticipantResult result2 = new ParticipantResult();
        result2.setTestName(TEST_NAME);
        result2.setIterationNumber(TEST_ITERATION_NUMBER);

        _aggregator.aggregate(result1);
        _aggregator.aggregate(result2);

        ParticipantResult aggregratedResult = _aggregator.getAggregatedResult();
        assertEquals(TEST_ITERATION_NUMBER, aggregratedResult.getIterationNumber());
        assertEquals(TEST_NAME, aggregratedResult.getTestName());
    }

    public void testConstantPayloadSizesRolledUp() throws Exception
    {
        final int payloadSize = 1024;

        ParticipantResult result1 = new ParticipantResult();
        result1.setPayloadSize(payloadSize);

        ParticipantResult result2 = new ParticipantResult();
        result2.setPayloadSize(payloadSize);

        _aggregator.aggregate(result1);
        _aggregator.aggregate(result2);

        ParticipantResult aggregratedResult = _aggregator.getAggregatedResult();
        assertEquals(payloadSize, aggregratedResult.getPayloadSize());
    }

    public void testDifferingPayloadSizesNotRolledUp() throws Exception
    {
        final int payload1Size = 1024;
        final int payload2Size = 2048;

        ParticipantResult result1 = new ParticipantResult();
        result1.setPayloadSize(payload1Size);

        ParticipantResult result2 = new ParticipantResult();
        result2.setPayloadSize(payload2Size);

        _aggregator.aggregate(result1);
        _aggregator.aggregate(result2);

        ParticipantResult aggregratedResult = _aggregator.getAggregatedResult();
        assertEquals(0, aggregratedResult.getPayloadSize());
    }

    public void testSumNumberOfConsumerAndProducers() throws Exception
    {
        final int expectedNumberOfProducers = 1;
        final int expectedNumberOfConsumers = 2;

        ParticipantResult result1 = new ParticipantResult();
        result1.setTotalNumberOfConsumers(1);

        ParticipantResult result2 = new ParticipantResult();
        result2.setTotalNumberOfConsumers(1);

        ParticipantResult result3 = new ParticipantResult();
        result2.setTotalNumberOfProducers(1);

        _aggregator.aggregate(result1);
        _aggregator.aggregate(result2);
        _aggregator.aggregate(result3);

        ParticipantResult aggregratedResult = _aggregator.getAggregatedResult();
        assertEquals(expectedNumberOfConsumers, aggregratedResult.getTotalNumberOfConsumers());
        assertEquals(expectedNumberOfProducers, aggregratedResult.getTotalNumberOfProducers());
    }

}