Open Kilda Java Documentation
ExamReport.java
Go to the documentation of this file.
1 /* Copyright 2018 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.testing.service.traffexam.model;
17 
18 import lombok.Value;
19 import lombok.experimental.NonFinal;
20 import org.springframework.util.StringUtils;
21 
22 import java.util.ArrayList;
23 import java.util.List;
24 
25 @Value
26 @NonFinal
27 public class ExamReport {
28 
29  private final Exam exam;
30  private final EndpointReport producerReport;
31  private final EndpointReport consumerReport;
32 
34  int kbps = producerReport.getBitsPerSecond().intValue() / 1024;
35  return new Bandwidth(kbps);
36  }
37 
41  public List<String> getErrors() {
42  List<String> errors = new ArrayList<>(2);
43  if (!StringUtils.isEmpty(producerReport.getError())) {
44  errors.add(String.format("producer: %s", producerReport.getError()));
45  }
46  if (!StringUtils.isEmpty(consumerReport.getError())) {
47  errors.add(String.format("consumer: %s", consumerReport.getError()));
48  }
49 
50  return errors;
51  }
52 
53  public boolean hasError() {
54  return !StringUtils.isEmpty(producerReport.getError()) || !StringUtils.isEmpty(consumerReport.getError());
55  }
56 
57  public boolean hasTraffic() {
58  return 0 < producerReport.getBytes();
59  }
60 
61  public boolean isTrafficLose() {
62  return 0 < producerReport.getLostPackets() || 0 < consumerReport.getLostPackets();
63  }
64 }