rename#243 metrics module, rename

This commit is contained in:
Calvin
2013-12-16 17:35:32 +08:00
parent c0bcfc4851
commit 2aab34ff96
8 changed files with 22 additions and 20 deletions
@@ -17,7 +17,7 @@ import org.springside.examples.quickstart.repository.UserDao;
import org.springside.examples.quickstart.service.ServiceException;
import org.springside.examples.quickstart.service.account.ShiroDbRealm.ShiroUser;
import org.springside.modules.test.security.shiro.ShiroTestUtils;
import org.springside.modules.utils.Clock.MockedClock;
import org.springside.modules.utils.Clock.MockClock;
/**
* AccountService的测试用例, 测试Service层的业务逻辑.
@@ -45,7 +45,7 @@ public class AccountServiceTest {
public void registerUser() {
User user = UserData.randomNewUser();
Date currentTime = new Date();
accountService.setClock(new MockedClock(currentTime));
accountService.setClock(new MockClock(currentTime));
accountService.registerUser(user);
@@ -18,7 +18,8 @@ public class MetricsManager {
@PostConstruct
public void start() {
GraphiteReporter graphiteReporter = new GraphiteReporter(new InetSocketAddress("localhost", 2003));
scheduler = new ReportScheduler(MetricRegistry.INSTANCE, new ConsoleReporter(), graphiteReporter);
ConsoleReporter consoleReporter = new ConsoleReporter();
scheduler = new ReportScheduler(MetricRegistry.INSTANCE, consoleReporter, graphiteReporter);
scheduler.start(10, TimeUnit.SECONDS);
}
@@ -34,19 +34,19 @@ public interface Clock {
/**
* 可配置的时间提供者,用于测试.
*/
public static class MockedClock implements Clock {
public static class MockClock implements Clock {
private long time;
public MockedClock() {
public MockClock() {
this(0);
}
public MockedClock(Date date) {
public MockClock(Date date) {
this.time = date.getTime();
}
public MockedClock(long time) {
public MockClock(long time) {
this.time = time;
}
@@ -71,7 +71,7 @@ public class ReportScheduler {
try {
report();
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
}
}, period, period, unit);
@@ -89,9 +89,11 @@ public class ReportScheduler {
} catch (InterruptedException ignored) {
// do nothing
}
}
/**
* 给线程命名的线程工厂类,为了减少项目依赖,没有直接使用Guava里的实现。
*/
private static class NamedThreadFactory implements ThreadFactory {
private final ThreadGroup group;
private final AtomicInteger threadNumber = new AtomicInteger(1);
@@ -100,7 +102,7 @@ public class ReportScheduler {
private NamedThreadFactory(String name) {
final SecurityManager s = System.getSecurityManager();
this.group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
this.namePrefix = "metrics-" + name + "-thread-";
this.namePrefix = name;
}
@Override
@@ -20,21 +20,20 @@ public interface Clock {
public long getCurrentTime() {
return System.currentTimeMillis();
}
}
/**
* 可配置的时间提供者,用于测试.
*/
public static class MockedClock implements Clock {
public static class MockClock implements Clock {
private long time;
public MockedClock() {
public MockClock() {
this(0);
}
public MockedClock(long time) {
public MockClock(long time) {
this.time = time;
}
@@ -4,11 +4,11 @@ import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.springside.modules.metrics.utils.Clock.MockedClock;
import org.springside.modules.metrics.utils.Clock.MockClock;
public class CounterTest {
private MockedClock clock = new MockedClock();
private MockClock clock = new MockClock();
@Before
public void setup() {
@@ -4,13 +4,13 @@ import static org.junit.Assert.*;
import org.junit.Test;
import org.springside.modules.metrics.Execution.ExecutionTimer;
import org.springside.modules.metrics.utils.Clock.MockedClock;
import org.springside.modules.metrics.utils.Clock.MockClock;
public class ExecutionTest {
@Test
public void normal() {
MockedClock clock = new MockedClock();
MockClock clock = new MockClock();
Execution.clock = clock;
Counter.clock = clock;
Execution execution = new Execution(new Double[] { 90d });
@@ -11,7 +11,7 @@ import org.springside.modules.metrics.report.GraphiteReporter;
import org.springside.modules.metrics.report.ReportScheduler;
import org.springside.modules.metrics.report.Reporter;
import org.springside.modules.metrics.report.Slf4jReporter;
import org.springside.modules.metrics.utils.Clock.MockedClock;
import org.springside.modules.metrics.utils.Clock.MockClock;
public class ReporterTest {
@@ -41,7 +41,7 @@ public class ReporterTest {
private void runReport(Reporter reporter) {
MetricRegistry metricRegistry = new MetricRegistry();
MockedClock clock = new MockedClock();
MockClock clock = new MockClock();
Counter.clock = clock;
Execution.clock = clock;