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

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


  }

  @ResponseBody
  @RequestMapping(value = "/{name}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
  public FieldValueCounterResource display(@PathVariable("name") String name) {
    FieldValueCounter c = repository.findOne(name);
    if (c == null) {
      throw new NoSuchMetricException(name, "There is no field-value-counter named '%s'");
    }
    return fvcResourceAssembler.toResource(c);
  }
View Full Code Here


  @Test
  public void testExistingCounterRetrieval() throws Exception {
    Map<String, Double> values = new HashMap<String, Double>();
    values.put("VMW", 13.0);
    values.put("GOOG", 23.0);
    when(fieldValueCounterRepository.findOne("iamthere")).thenReturn(new FieldValueCounter("iamthere", values));

    mockMvc.perform(get("/metrics/field-value-counters/iamthere"))//
    .andExpect(status().isOk())//
    .andExpect(jsonPath("$.name").value("iamthere"))//
    .andExpect(jsonPath("$.counts['VMW']").value(13.0));
View Full Code Here

  @Test
  public void testCounterListing() throws Exception {
    FieldValueCounter[] counters = new FieldValueCounter[10];
    for (int i = 0; i < counters.length; i++) {
      counters[i] = new FieldValueCounter("c" + i);
    }
    when(fieldValueCounterRepository.findAll()).thenReturn(Arrays.asList(counters));

    mockMvc.perform(get("/metrics/field-value-counters")).andExpect(status().isOk())//
    .andExpect(jsonPath("$.content", Matchers.hasSize(10)));
View Full Code Here

  private final String mentionsFieldValueCounterName = "mentionsFieldValueCounter";

  @Test
  public void testCrud() {
    FieldValueCounter counter = new FieldValueCounter(tickersFieldValueCounterName);

    // Test with initial save
    FieldValueCounter fvTickersCounter = fieldValueCounterRepository.save(counter);
    assertThat(fieldValueCounterRepository.findOne(fvTickersCounter.getName()), notNullValue());

    fieldValueCounterRepository.increment(tickersFieldValueCounterName, "VMW");
    Map<String, Double> counts = fieldValueCounterRepository.findOne(tickersFieldValueCounterName).getFieldValueCount();
    assertThat(counts.get("VMW"), equalTo(1.0));
View Full Code Here

    Map<String, Double> fieldValueCount = new HashMap<String, Double>();
    fieldValueCount.put("elephant", 1.0);
    fieldValueCount.put("pig", 1.0);

    FieldValueCounter c1 = new FieldValueCounter(myFVCounter, fieldValueCount);
    FieldValueCounter myCounter = fieldValueCounterRepository.save(c1);
    assertThat(myCounter.getName(), is(myFVCounter));

    // Create and save a Counter named 'yourCounter'
    fieldValueCount = new HashMap<String, Double>();
    fieldValueCount.put("turtle", 5.0);
    fieldValueCount.put("fish", 6.0);
    fieldValueCount.put("bird", 7.0);
    FieldValueCounter c2 = new FieldValueCounter(yourFVCounter, fieldValueCount);
    FieldValueCounter yourCounter = fieldValueCounterRepository.save(c2);
    assertThat(yourCounter.getName(), is(yourFVCounter));

    // Retrieve by name
    FieldValueCounter result = fieldValueCounterRepository.findOne(myFVCounter);
    assertThat(result, is(notNullValue()));
    assertThat(result.getName(), equalTo(myCounter.getName()));
    assertThat(result.getFieldValueCount().size(), equalTo(2));
    fieldValueCount = result.getFieldValueCount();
    assertThat(fieldValueCount.get("elephant"), equalTo(1.0));
    assertThat(fieldValueCount.get("pig"), equalTo(1.0));

    result = fieldValueCounterRepository.findOne(yourCounter.getName());
    assertThat(result.getName(), equalTo(yourCounter.getName()));
    assertThat(result.getFieldValueCount().size(), equalTo(3));
    fieldValueCount = result.getFieldValueCount();
    assertThat(fieldValueCount.get("turtle"), equalTo(5.0));
    assertThat(fieldValueCount.get("fish"), equalTo(6.0));
    assertThat(fieldValueCount.get("bird"), equalTo(7.0));

    List<FieldValueCounter> counters = (List<FieldValueCounter>) fieldValueCounterRepository.findAll();
View Full Code Here

public class InMemoryFieldValueCounterRepository extends InMemoryMetricRepository<FieldValueCounter> implements
    FieldValueCounterRepository {

  @Override
  protected FieldValueCounter create(String name) {
    return new FieldValueCounter(name);
  }
View Full Code Here

    modifyFieldValue(name, fieldName, -1);
  }

  @Override
  public void reset(String name, String fieldName) {
    FieldValueCounter counter = getOrCreate(name);
    Map<String, Double> data = counter.getFieldValueCount();
    if (data.containsKey(fieldName)) {
      data.put(fieldName, 0D);
    }
  }
View Full Code Here

      data.put(fieldName, 0D);
    }
  }

  private void modifyFieldValue(String name, String fieldName, double delta) {
    FieldValueCounter counter = getOrCreate(name);
    Map<String, Double> data = counter.getFieldValueCount();
    double count = data.containsKey(fieldName) ? data.get(fieldName) : 0;
    data.put(fieldName, count + delta);
    save(counter);
  }
View Full Code Here

  public FieldValueCounter findOne(String name) {
    Assert.notNull(name, "The name of the FieldValueCounter must not be null");
    String metricKey = getMetricKey(name);
    if (redisTemplate.hasKey(metricKey)) {
      Map<String, Double> values = getZSetData(metricKey);
      FieldValueCounter c = new FieldValueCounter(name, values);
      return c;
    }
    else {
      return null;
    }
View Full Code Here

      if (!key.matches(this.metricPrefix
          + ".+?_\\d{4}\\.\\d{2}\\.\\d{2}-\\d{2}:\\d{2}")) {
        if (this.redisTemplate.type(key) == DataType.ZSET) {
          Map<String, Double> values = getZSetData(key);
          String name = key.substring(metricPrefix.length());
          FieldValueCounter c = new FieldValueCounter(name, values);
          counters.add(c);
        }
      }
    }
    return counters;
View Full Code Here

TOP

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

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.