Skip to content

Commit

Permalink
integrate travis and coveralls (#3)
Browse files Browse the repository at this point in the history
* edit readme ,add travis and converalls

* edit readme ,add budge

* add testcase
  • Loading branch information
luyiisme authored May 16, 2018
1 parent 8428f5a commit d0467ad
Show file tree
Hide file tree
Showing 38 changed files with 1,776 additions and 385 deletions.
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: java
sudo: false

jdk:
- oraclejdk8

install:
- mvn clean install -Dmaven.javadoc.skip=true -B -V

script:
- sh ./check_format.sh

after_success:
- mvn clean test cobertura:cobertura org.eluder.coveralls:coveralls-maven-plugin:report
278 changes: 278 additions & 0 deletions Formatter.xml

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions HEADER
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# SOFALookout

[![Build Status](https://travis-ci.org/alipay/sofa-lookout.svg?branch=master)](https://travis-ci.org/alipay/sofa-lookout)
[![Coverage Status](https://coveralls.io/repos/github/alipay/sofa-lookout/badge.svg?branch=master)](https://coveralls.io/github/alipay/sofa-lookout?branch=master)
![license](https://img.shields.io/badge/license-Apache--2.0-green.svg)
![maven](https://img.shields.io/github/release/alipay/sofa-lookout.svg)

[English Document](./README_EN.md)

访问 [WIKI](https://github.com/alipay/sofa-lookout/wiki) 查看完整的文档使用指南。
Expand Down
7 changes: 7 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# SOFALookout

[![Build Status](https://travis-ci.org/alipay/sofa-lookout.svg?branch=master)](https://travis-ci.org/alipay/sofa-lookout)
[![Coverage Status](https://coveralls.io/repos/github/alipay/sofa-lookout/badge.svg?branch=master)](https://coveralls.io/github/alipay/sofa-lookout?branch=master)
![license](https://img.shields.io/badge/license-Apache--2.0-green.svg)
![maven](https://img.shields.io/github/release/alipay/sofa-lookout.svg)

Visit [WIKI](https://github.com/alipay/sofa-lookout/wiki) for the full documentation, examples, and guides.

Lookout can help you to measure and monitor the status of the target system with its multi-dimensional metrics.
Lookout's multi-dimensional metrics refer to the [Metrics 2.0](http://metrics20.org/) standard.

Expand Down
12 changes: 12 additions & 0 deletions check_format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

BASEDIR=$(dirname $0)

cd ${BASEDIR}

# make sure git has no un commit files
if [ -n "$(git status --untracked-files=no --porcelain)" ]; then
echo "Please commit your change before run this shell, un commit files:"
git status --untracked-files=no --porcelain
exit -1
fi
1 change: 1 addition & 0 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ lookout-api支持被单独依赖和使用,方便植入您的项目代码,收
lookout 客户端提供了 SPI 机制(只需要实现 `com.alipay.lookout.spi.MetricsImporter` 接口),支持可以扩展一些公共的Metrics收集模块,比如默认提供的: jvm(lookout-ext-jvm)、os(lookout-ext-os)。

## 4.Metrics的注册表

- lookout-reg-prometheus 模块可以提供简单的 metrics 的查询服务,作为 lookout 的 exporter 被 prometheus 抓取;
- lookout-reg-server 模块可以定时向 lookout server 上报 metrics 数据;
- lookout-reg-dropwizard 模块可以降维映射为 dropwizard 注册表上;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//package com.alipay.lookout.jvm.memory;
//
///**
// * Created by [email protected] on 2017/2/16.
// */
//public class JvmGcMetricsImporterTest {
//
// @Test
// public void testGcInfo() {
// Registry registry = new DefaultRegistry();
// JvmGcMetricsImporter jvmGcMetricsImporter = new JvmGcMetricsImporter();
// jvmGcMetricsImporter.register(registry);
//
// for (int i = 0; i < 3; i++) {
// Iterator<Metric> it = registry.iterator();
// while (it.hasNext()) {
// Metric m = it.next();
// m.measure();
// }
//
// byte[] bytes = new byte[1024 * 1024 * 8];
// System.gc();
// }
//
// }
//}
package com.alipay.lookout.api;

import org.junit.Assert;
import org.junit.Test;

/**
* Created by [email protected] on 2018/5/16.
*/
public class DefaultIdTest {

@Test
public void testEquals() {

Id id1 = new DefaultId("name").withTag(new BasicTag("k1", "v1")).withTag(
new BasicTag("k2", "v2"));

Tag[] tags = new Tag[] { new BasicTag("k2", "v2"), new BasicTag("k1", "v1") };
Id id2 = new DefaultId("name").withTags(tags);
System.out.println(id1);
Assert.assertTrue(id1.equals(id2));
Assert.assertEquals(id1, id2);
Assert.assertEquals(id1.hashCode(), id2.hashCode());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 com.alipay.lookout.api;

import org.junit.Assert;
import org.junit.Test;

/**
* Created by [email protected] on 2018/5/16.
*/
public class IndicatorTest {

@Test
public void testAddMeasument() {
Indicator indicator = new Indicator(11l, NoopRegistry.INSTANCE.createId("name"));
indicator.addMeasurement("k", 1);
indicator.addMeasurement(new Measurement("K2", "V2"));
Assert.assertEquals(2, indicator.measurements().size());
Assert.assertEquals(11l, indicator.getTimestamp());
Assert.assertTrue(indicator.id() == NoopId.INSTANCE);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 com.alipay.lookout.api;

import com.alipay.lookout.api.composite.MixinMetric;
import com.alipay.lookout.api.info.Info;
import org.junit.Assert;
import org.junit.Test;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Created by [email protected] on 2018/5/16.
*/
public class NoopRegistryTest {
private Registry r = NoopRegistry.INSTANCE;

@Test
public void testNoopCounter() {
Counter counter = r.counter(r.createId("name"));
Assert.assertEquals(NoopCounter.INSTANCE, counter);
counter.inc(8);
counter.inc();
counter.dec(1);
counter.dec();
Assert.assertEquals(0, counter.count());
}

@Test
public void testNoopMixinMetric() {
MixinMetric mixinMetric = r.mixinMetric(r.createId("name"));
Assert.assertEquals(NoopMixinMetric.INSTANCE, mixinMetric);
Assert.assertEquals(NoopCounter.INSTANCE, mixinMetric.counter("c"));
Assert.assertEquals(NoopTimer.INSTANCE, mixinMetric.timer("t"));
Assert.assertEquals(NoopDistributionSummary.INSTANCE, mixinMetric.distributionSummary("t"));
Assert.assertEquals(null, mixinMetric.gauge("t", new Gauge<Number>() {
@Override
public Number value() {
return 1;
}
}));
}

@Test
public void testNoopInfo() {
Info info = r.info(r.createId("name"), new Info<String>() {
@Override
public String value() {
return "xx";
}
});
Assert.assertNull(null, info);
}

@Test
public void testNoopGauge() {
Gauge gauge = r.gauge(r.createId("name"), new Gauge() {
@Override
public Long value() {
return 1l;
}
});
Assert.assertNull(null, gauge);
}

@Test
public void testNoopDistributionSummary() {
DistributionSummary ds = r.distributionSummary(r.createId("name"));
Assert.assertEquals(NoopDistributionSummary.INSTANCE, ds);
ds.record(20);
Assert.assertEquals(0, ds.count());
Assert.assertEquals(0, ds.totalAmount());

}

@Test
public void testNoopTimer() throws Exception {
Timer timer = r.timer(r.createId("name"));
Assert.assertEquals(NoopTimer.INSTANCE, timer);
timer.record(2, TimeUnit.SECONDS);
Assert.assertEquals(0, timer.count());
Assert.assertEquals(0, timer.totalTime());

final AtomicInteger atomicInteger = new AtomicInteger(0);

timer.record(new Runnable() {
@Override
public void run() {
atomicInteger.incrementAndGet();
}
});
timer.record(new Callable<Long>() {
@Override
public Long call() throws Exception {
atomicInteger.incrementAndGet();
return 0l;
}
});
Assert.assertEquals(2, atomicInteger.get());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 com.alipay.lookout.api;

import org.junit.Assert;
import org.junit.Test;

/**
* Created by [email protected] on 2018/5/16.
*/
public class UtilsTest {

@Test
public void testGetTagValue() {

Id id = new DefaultId("name").withTag("k1", "v1").withTag("k2", "v2");

Assert.assertEquals("v1", Utils.getTagValue(id, "k1"));
Assert.assertNull(Utils.getTagValue(id, "k3"));

}
}
Loading

0 comments on commit d0467ad

Please sign in to comment.