Search in sources :

Example 1 with SeriesType

use of com.axibase.tsd.api.model.series.SeriesType in project atsd-api-test by axibase.

the class SeriesQueryForecastTimeFilterTest method buildForecastSettings.

private Forecast buildForecastSettings() {
    HoltWintersSettings hwSettings = new HoltWintersSettings().setAlpha(0.5).setBeta(0.5).setGamma(0.5).setAuto(false).setPeriod(new Period(1, TimeUnit.DAY));
    List<SeriesType> include = Arrays.asList(SeriesType.RECONSTRUCTED, SeriesType.FORECAST);
    return new Forecast().setHw(hwSettings).setInclude(include).setScoreInterval(new Interval(1, TimeUnit.DAY));
}
Also used : Forecast(com.axibase.tsd.api.model.series.query.transformation.forecast.Forecast) SeriesType(com.axibase.tsd.api.model.series.SeriesType) Period(com.axibase.tsd.api.model.Period) HoltWintersSettings(com.axibase.tsd.api.model.series.query.transformation.forecast.HoltWintersSettings) Interval(com.axibase.tsd.api.model.series.query.Interval)

Example 2 with SeriesType

use of com.axibase.tsd.api.model.series.SeriesType in project atsd-api-test by axibase.

the class ForecastFormTest method testFormSubmission.

@Test(enabled = true, dataProvider = "testCases")
public void testFormSubmission(int testCaseId, @NotNull String grouping, @Nullable String groupingTag, /* true - store forecasts under another metric in the series table
                                    * false - store forecasts under original metric in the forecasts table */
boolean storeUnderAnotherMetric, @NotNull List<SeriesKey> expectedSeriesKeys) throws Exception {
    String caseId = "Test case " + testCaseId + ". ";
    /* In each test case we do forecasts for the same set of series,
           but each time with a new metric,
           otherwise forecasts from later test cases will be mixed
           with forecasts stored during previous test cases. */
    String metric = Mocks.metric();
    insertSeries(metric);
    /* Calculate and store forecasts. */
    String producedMetric = storeUnderAnotherMetric ? "mock-" + metric : null;
    Response forecastResponse = sendForecastFormData(formData(metric, grouping, groupingTag, producedMetric));
    int statusCode = forecastResponse.getStatus();
    assertEquals(caseId + "Test case Forecast request failed with status code " + statusCode, Response.Status.OK.getStatusCode(), statusCode);
    /* Get stored forecasts, and wait a bit if stored forecasts count differs from expected,
           because ATSD may need some time to actually store forecasts.
           Also if forecasts are not stored the response can contains empty series,
           so need check that series in response are not empty.
        */
    List<Series> actualSeriesList = null;
    long start = System.currentTimeMillis();
    for (int i = 0; i < 40; i++) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        actualSeriesList = loadStoredForecasts(metric, producedMetric);
        if (expectedSeriesKeys.size() == actualSeriesList.size() && actualSeriesList.stream().noneMatch(series -> series.getData().isEmpty())) {
            break;
        }
    }
    long duration = System.currentTimeMillis() - start;
    String msg = caseId + "Duration: " + duration + "ms. Unexpected series count.";
    assertNotNull(actualSeriesList, msg);
    assertEquals(msg, expectedSeriesKeys.size(), actualSeriesList.size());
    /* Sort actual series by metric, entity, and tags to be able to compare them with expected in correct order. */
    Collections.sort(actualSeriesList);
    /* Convert expected series keys to expected series appending suitable metric and tag to each key. */
    SeriesType type = storeUnderAnotherMetric ? HISTORY : FORECAST;
    List<Series> expectedSeriesList = expectedSeriesKeys.stream().map(key -> toExpectedSeries(metric, producedMetric, type, key)).sorted().collect(Collectors.toList());
    int size = expectedSeriesList.size();
    for (int i = 0; i < size; i++) {
        String seriesIndex = "Series index = " + i + ". ";
        Series expectedSeries = expectedSeriesList.get(i);
        Series actualSeries = actualSeriesList.get(i);
        // check metric, entity and tags
        msg = caseId + seriesIndex + "Expected series key: " + expectedSeries.toString() + "Actual series: " + actualSeries.toString();
        assertTrue(expectedSeries.compareTo(actualSeries) == 0, msg);
        assertEquals(caseId + seriesIndex, expectedSeries.getType(), actualSeries.getType());
        if (expectedSeries.getType() == FORECAST) {
            assertEquals(caseId + seriesIndex, forecastSettingsName, actualSeries.getForecastName());
        }
        assertEquals(caseId + seriesIndex, 6, actualSeries.getData().size());
    }
}
Also used : Response(javax.ws.rs.core.Response) Mocks(com.axibase.tsd.api.util.Mocks) SeriesQuery(com.axibase.tsd.api.model.series.query.SeriesQuery) java.util(java.util) SeriesType(com.axibase.tsd.api.model.series.SeriesType) DataProvider(org.testng.annotations.DataProvider) HISTORY(com.axibase.tsd.api.model.series.SeriesType.HISTORY) Sample(com.axibase.tsd.api.model.series.Sample) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Test(org.testng.annotations.Test) Assert.assertNotNull(org.testng.Assert.assertNotNull) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Collectors(java.util.stream.Collectors) TimeUtil(com.axibase.tsd.api.util.TimeUtil) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Nullable(org.jetbrains.annotations.Nullable) SeriesMethod(com.axibase.tsd.api.method.series.SeriesMethod) Response(javax.ws.rs.core.Response) SeriesMethod.querySeriesAsList(com.axibase.tsd.api.method.series.SeriesMethod.querySeriesAsList) Assert.assertTrue(org.testng.Assert.assertTrue) NotNull(org.jetbrains.annotations.NotNull) FORECAST(com.axibase.tsd.api.model.series.SeriesType.FORECAST) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) Series(com.axibase.tsd.api.model.series.Series) Series(com.axibase.tsd.api.model.series.Series) SeriesType(com.axibase.tsd.api.model.series.SeriesType) Test(org.testng.annotations.Test)

Aggregations

SeriesType (com.axibase.tsd.api.model.series.SeriesType)2 SeriesMethod (com.axibase.tsd.api.method.series.SeriesMethod)1 SeriesMethod.querySeriesAsList (com.axibase.tsd.api.method.series.SeriesMethod.querySeriesAsList)1 Period (com.axibase.tsd.api.model.Period)1 Sample (com.axibase.tsd.api.model.series.Sample)1 Series (com.axibase.tsd.api.model.series.Series)1 FORECAST (com.axibase.tsd.api.model.series.SeriesType.FORECAST)1 HISTORY (com.axibase.tsd.api.model.series.SeriesType.HISTORY)1 Interval (com.axibase.tsd.api.model.series.query.Interval)1 SeriesQuery (com.axibase.tsd.api.model.series.query.SeriesQuery)1 Forecast (com.axibase.tsd.api.model.series.query.transformation.forecast.Forecast)1 HoltWintersSettings (com.axibase.tsd.api.model.series.query.transformation.forecast.HoltWintersSettings)1 Mocks (com.axibase.tsd.api.util.Mocks)1 TimeUtil (com.axibase.tsd.api.util.TimeUtil)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1 Response (javax.ws.rs.core.Response)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1