Open Kilda Java Documentation
StatisticsBasicTest.java
Go to the documentation of this file.
1 /* Copyright 2017 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.atdd;
17 
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertNotEquals;
22 
24 
25 import com.fasterxml.jackson.core.type.TypeReference;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import cucumber.api.java.en.Then;
28 import org.glassfish.jersey.client.ClientConfig;
29 
30 import java.util.List;
31 import java.util.concurrent.TimeUnit;
32 import javax.ws.rs.client.Client;
33 import javax.ws.rs.client.ClientBuilder;
34 import javax.ws.rs.core.Response;
35 
36 public class StatisticsBasicTest {
37  public boolean test = false;
38 
40  }
41 
42  private List<Metric> getNumberOfDatapoints() throws Throwable {
43  System.out.println("\n==> OpenTSDB Metrics request");
44 
45  long current = System.currentTimeMillis();
46  Client client = ClientBuilder.newClient(new ClientConfig());
47 
48  Response response = client
49  .target(opentsdbEndpoint)
50  .path("/api/query")
51  .queryParam("start", "24h-ago")
52  .queryParam("m", "sum:pen.switch.tx-bytes")
53  .queryParam("timezone", "Australia/Melbourne")
54  .request().get();
55 
56  System.out.println(String.format("===> Response = %s", response));
57  System.out.println(String.format("===> OpenTSDB Metrics Time: %,.3f", getTimeDuration(current)));
58 
59  List<Metric> metrics = new ObjectMapper().readValue(
60  response.readEntity(String.class), new TypeReference<List<Metric>>() {});
61 
62  System.out.println(String.format("====> Metrics = %s", metrics));
63 
64  return metrics;
65  }
66 
67  @Then("^data go to database$")
68  public void dataCreated() throws Throwable {
69  TimeUnit.SECONDS.sleep(15);
70  List<Metric> result = getNumberOfDatapoints();
71 
72  assertFalse(result.isEmpty());
73  }
74 
75  @Then("^database keeps growing$")
76  public void database_keeps_growing() throws Throwable {
77  List<Metric> firstResult = getNumberOfDatapoints();
78  TimeUnit.SECONDS.sleep(15);
79  List<Metric> secondResult = getNumberOfDatapoints();
80 
81  assertNotEquals(firstResult, secondResult);
82  }
83 }
list result
Definition: plan-d.py:72
static double getTimeDuration(final long current)
Definition: FlowUtils.java:605