Package org.springframework.xd.analytics.metrics

Source Code of org.springframework.xd.analytics.metrics.AbstractRichGaugeRepositoryTests

/*
* Copyright 2011-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.xd.analytics.metrics;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import org.springframework.xd.analytics.metrics.core.RichGauge;
import org.springframework.xd.analytics.metrics.core.RichGaugeRepository;

/**
* @author Luke Taylor
*/
public abstract class AbstractRichGaugeRepositoryTests {

  protected abstract RichGaugeRepository createService();

  @Test
  public void getOrCreateReturnsCorrectInstance() throws Exception {
    RichGaugeRepository gs = createService();
    gs.setValue("test", 9.99);
    gs.setValue("test", 0.01);

    RichGauge g = gs.findOne("test");
    assertEquals("test", g.getName());
    assertEquals(0.01, g.getValue(), 1E-6);
    assertEquals(5.0, g.getAverage(), 1E-6);
    assertEquals(9.99, g.getMax(), 1E-6);
    assertEquals(0.01, g.getMin(), 1E-6);
  }

  @Test
  public void resetExistingGaugeCausesReset() throws Exception {
    RichGaugeRepository gs = createService();
    gs.setValue("test", 9.99);
    gs.reset("test");
    RichGauge g = gs.findOne("test");
    assertEquals(0.0, g.getValue(), 1E-6);
  }

  @Test
  public void testExponentialMovingAverage() throws Exception {
    RichGaugeRepository gs = createService();
    gs.setAlpha("test", 0.1);
    gs.setValue("test", 71.0);
    RichGauge g = gs.findOne("test");
    assertEquals(71.0, g.getAverage(), 1E-6);
    gs.setValue("test", 70.0);
    g = gs.findOne("test");
    assertEquals(71.0, g.getAverage(), 1E-6);
    gs.setValue("test", 69.0);
    g = gs.findOne("test");
    assertEquals(70.9, g.getAverage(), 1E-6);
    gs.setValue("test", 68.0);
    g = gs.findOne("test");
    assertEquals(70.71, g.getAverage(), 1E-6);
  }
}
TOP

Related Classes of org.springframework.xd.analytics.metrics.AbstractRichGaugeRepositoryTests

TOP
Copyright © 2018 www.massapi.com. 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.