forked from sofastack/sofa-lookout
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* edit readme ,add travis and converalls * edit readme ,add budge * add testcase
- Loading branch information
Showing
38 changed files
with
1,776 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()); | ||
|
||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
client/lookout-api/src/test/java/com/alipay/lookout/api/IndicatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
client/lookout-api/src/test/java/com/alipay/lookout/api/NoopRegistryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
client/lookout-api/src/test/java/com/alipay/lookout/api/UtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
|
||
} | ||
} |
Oops, something went wrong.