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

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


   * Retrieve information about a specific counter.
   */
  @ResponseBody
  @RequestMapping(value = "/{name}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
  public CounterResource display(@PathVariable("name") String name) {
    Counter c = repository.findOne(name);
    if (c == null) {
      throw new NoSuchMetricException(name, "There is no counter named '%s'");
    }
    return counterResourceAssembler.toResource(c);
  }
View Full Code Here


    mockMvc.perform(get("/metrics/counters/notthere")).andExpect(status().isNotFound());
  }

  @Test
  public void testExistingCounterRetrieval() throws Exception {
    when(counterRepository.findOne("iamthere")).thenReturn(new Counter("iamthere", 12L));

    mockMvc.perform(get("/metrics/counters/iamthere"))//
    .andExpect(status().isOk())//
    .andExpect(jsonPath("$.name").value("iamthere"))//
    .andExpect(jsonPath("$.value").value(12));
View Full Code Here

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

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

  @Test
  public void testNoPreexistingCounter() {
    MessageCounterHandler handler = new MessageCounterHandler(repo, "tupleCounter");
    Message<String> message = MessageBuilder.withPayload("Hi").build();
    handler.process(message);
    Counter counter = repo.findOne("tupleCounter");
    assertThat(counter.getValue(), equalTo(1L));

  }
View Full Code Here

  }

  @Test
  public void testPreexistingCounter() {
    Counter counter = new Counter("tupleCounter", 12L);
    repo.save(counter);
    MessageCounterHandler handler = new MessageCounterHandler(repo, "tupleCounter");
    Message<String> message = MessageBuilder.withPayload("Hi").build();
    handler.process(message);
    counter = repo.findOne("tupleCounter");
    assertThat(counter.getValue(), equalTo(13L));

  }
View Full Code Here

  }

  @Test
  public void testNullMsgHasNoEffect() {
    Counter counter = new Counter("tupleCounter", 12L);
    repo.save(counter);
    MessageCounterHandler handler = new MessageCounterHandler(repo, "tupleCounter");
    handler.process(null);
    counter = repo.findOne("tupleCounter");
    assertThat(counter.getValue(), equalTo(12L));
  }
View Full Code Here

    CounterRepository repo = counterRepository;
    String myCounterName = "myCounter";
    String yourCounterName = "yourCounter";

    // Create and save a Counter named 'myCounter'
    Counter c1 = new Counter(myCounterName);
    Counter myCounter = repo.save(c1);
    assertThat(myCounter.getName(), is(notNullValue()));
    // Create and save a Counter named 'yourCounter'
    Counter c2 = new Counter(yourCounterName);
    Counter yourCounter = repo.save(c2);
    assertThat(yourCounter.getName(), is(notNullValue()));
    assertTrue(repo.exists(yourCounterName));

    // Retrieve by name and compare for equality to previously saved instance.
    Counter result = repo.findOne(myCounterName);
    assertThat(result, equalTo(myCounter));

    result = repo.findOne(yourCounter.getName());
    assertThat(result, equalTo(yourCounter));
View Full Code Here

    return increment(name, 1L);
  }

  @Override
  public long increment(String name, long amount) {
    Counter c = getOrCreate(name);
    return c.increment(amount);
  }
View Full Code Here

    return c.increment(amount);
  }

  @Override
  public synchronized long decrement(String name) {
    Counter c = getOrCreate(name);
    return c.decrement(1L);
  }
View Full Code Here

    return c.decrement(1L);
  }

  @Override
  public synchronized void reset(String name) {
    save(new Counter(name));
  }
View Full Code Here

TOP

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

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.