Package org.springframework.xd.analytics.metrics.core

Examples of org.springframework.xd.analytics.metrics.core.AggregateCount


    }
    if (from == null) {
      from = fromValue(to, resolution);
    }

    AggregateCount aggregate = repository.getCounts(name, new Interval(from, to), resolution);

    return aggregateCountResourceAssembler.toResource(aggregate);
  }
View Full Code Here


    // Check the total
    assertEquals(total, aggregateCounterRepository.findOne(counterName).getValue());

    // Query the entire period
    Interval queryInterval = new Interval(start, end);
    AggregateCount aggregateCount = aggregateCounterRepository.getCounts(counterName, queryInterval,
        AggregateCountResolution.minute);
    assertEquals(counterName, aggregateCount.getName());
    assertEquals(queryInterval, aggregateCount.getInterval());
    long[] counts = aggregateCount.getCounts();
    // counts.length should include the end time's minute
    assertEquals((2 * 24 * 60) + 1, counts.length);
    assertEquals(27, counts[0]);
    assertEquals(28, counts[1]);
    assertEquals(59, counts[32]);
    for (int i = 33; i < counts.length; i++) {
      int expect = (i - 33) % 60;
      assertEquals("Count at index " + i + " should be " + expect, expect, counts[i]);
    }

    // Query a 24 hour period in minutes
    now = start.plusHours(5).withMinuteOfHour(0);
    queryInterval = new Interval(now, now.plusHours(24));

    aggregateCount = aggregateCounterRepository.getCounts(counterName, queryInterval, AggregateCountResolution.minute);
    counts = aggregateCount.getCounts();
    // Add 'now.plusHours(24)' minute time to the count
    assertEquals((24 * 60) + 1, counts.length);
    assertEquals(0, counts[0]); // on an hour boundary
    for (int i = 1; i < counts.length; i++) {
      int expect = i % 60;
      assertEquals("Count at index " + i + " should be " + expect, expect, counts[i]);
    }

    // Query the entire period in hours
    queryInterval = new Interval(start, end);
    aggregateCount = aggregateCounterRepository.getCounts(counterName, queryInterval, AggregateCountResolution.hour);
    counts = aggregateCount.getCounts();
    assertEquals(49, counts.length);
    // The first hour starts before the first counts are added
    assertEquals(1419, counts[0]); // sum [27..59]
    for (int i = 1; i < (counts.length - 1); i++) {
      assertEquals(1770, counts[i]); // sum [0..59]
    }
    // The last hour ends at 27th minute
    assertEquals(378, counts[counts.length - 1]); // sum [0..27]

    // Query the entire period in days
    aggregateCount = aggregateCounterRepository.getCounts(counterName, queryInterval, AggregateCountResolution.day);
    counts = aggregateCount.getCounts();
    assertEquals(3, counts.length);

    // Query beyond the period where we have data
    DateTime newStart = start.withYear(2012);
    aggregateCount = aggregateCounterRepository.getCounts(counterName, queryInterval.withStart(newStart), AggregateCountResolution.day);
    counts = aggregateCount.getCounts();
    assertEquals(368, counts.length);

    aggregateCount = aggregateCounterRepository.getCounts(counterName, queryInterval.withStart(newStart), AggregateCountResolution.month);
  }
View Full Code Here

    applicationContext = new AnnotationConfigApplicationContext(
        NullTimefieldAggregateCounterTestsConfig.class);

    input().send(new GenericMessage<Object>(""));

    AggregateCount counts = repository().getCounts("foo", 5, AggregateCountResolution.hour);
    assertThat(counts.getCounts(), equalTo(new long[] { 0, 0, 0, 0, 1 }));
  }
View Full Code Here

    input().send(new GenericMessage<Object>(Collections.singletonMap("ts", "14/10/1978")));

    DateTime from = new DateTime(1980, 1, 1, 0, 0);

    AggregateCount counts = repository().getCounts("foo", 5, from, AggregateCountResolution.year);
    assertThat(counts.getCounts(), equalTo(new long[] { 0, 0, 1, 0, 0 }));
  }
View Full Code Here

    }
    else {
      throw new IllegalStateException("Shouldn't happen. Unhandled resolution: " + resolution);
    }
    return new AggregateCount(getName(), interval, counts, resolution);
  }
View Full Code Here

      }
    }
    else {
      throw new IllegalStateException("Shouldn't happen. Unhandled resolution: " + resolution);
    }
    return new AggregateCount(name, interval, counts, resolution);
  }
View Full Code Here

TOP

Related Classes of org.springframework.xd.analytics.metrics.core.AggregateCount

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.